這次簡單的給PY32移植一下RT-Thread Nano
開發(fā)板:PY32F003_StartKit (PY32F003F16U Flash 32K SRAM 4K)
IDE:MDK5
1.準(zhǔn)備工作
這里bsp我直接使用廠商提供的bsp,原本想要直接選擇芯片自己新建工程的,但是根據(jù)官方的教程一直沒有成功于是就直接用現(xiàn)成的bsp了
下載:點(diǎn)擊Pack installer
選擇RT-Thread進(jìn)行下載
Manage Rum-Time Environment,本次我們就只移植kernel,shell暫時(shí)我還用不上所以就先不移植了
2.清除重定義
rt-thread在運(yùn)行過程中會(huì)使用到HandFault_Handler和PendSV_Handler用于線程切換,異常處理,所以需要將py32f0xx_it.c中的這兩個(gè)函數(shù)刪除,否則鏈接時(shí)會(huì)提示重定義
還有mdk中main函數(shù)的入口函數(shù)extern int Super$main(void);原來是在system_py32f0xx.c中實(shí)現(xiàn)的,rtthread也進(jìn)行了接管在啟動(dòng)流程中是如下流程
rt_application_init->main_thread_entry->Super$main(void),所以我們需要把system_py32f0xx.c中的刪除
3.完成rt_hw_board_init
void rt_hw_board_init(void)
{
/*
TODO 1: OS Tick Configuration
Enable the hardware timer and call the rt_os_tick_callback function
periodically with the frequency RT_TICK_PER_SECOND.
*/
/* Call components board initial (use INIT_BOARD_EXPORT()) */
HAL_Init();
APP_SystemClockConfig(); // 配置系統(tǒng)時(shí)鐘
SystemCoreClockUpdate(); // 對系統(tǒng)時(shí)鐘進(jìn)行更新
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif
}
4.修改內(nèi)存堆
因?yàn)檫@個(gè)芯片sram很小所以我這里就給了2KB
#define RT_HEAP_SIZE (2*1024)
static rt_uint8_t rt_heap[RT_HEAP_SIZE];
5.愉快的點(diǎn)燈
/**
@file main.c
@author MCU Application Team
@brief Main program body
- @attention
? Copyright (c) Puya Semiconductor Co.
All rights reserved.
? Copyright (c) 2016 STMicroelectronics.
All rights reserved.
This software component is licensed by ST under BSD 3-Clause license,* the "License"; You may not use this file except in compliance with the
License. You may obtain a copy of the License at:
opensource.org/licenses/BSD-3-Clause
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include
/* Private define ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private user code ---------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/**
@brief 應(yīng)用程序入口函數(shù).
@retval int
*/
static void APP_LedConfig(void);
int main(void)
{
APP_LedConfig();
while (1)
{
rt_thread_delay(500);
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_5);
}
}
/* *
@brief 錯(cuò)誤執(zhí)行函數(shù)
@param 無
@retval 無
*/
void APP_ErrorHandler(void)
{
/* 無限循環(huán) */
while (1)
{
}
}
static void APP_LedConfig(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOB_CLK_ENABLE(); /* GPIOB時(shí)鐘使能 */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; /* 推挽輸出 */
GPIO_InitStruct.Pull = GPIO_PULLUP; /* 使能上拉 */
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; /* GPIO速度 */
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* GPIO初始化 */
}
#ifdef USE_FULL_ASSERT
/* *
@brief 輸出產(chǎn)生斷言錯(cuò)誤的源文件名及行號
@param file:源文件名指針
@param line:發(fā)生斷言錯(cuò)誤的行號
@retval 無
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* 用戶可以根據(jù)需要添加自己的打印信息,
例如: printf("Wrong parameters value: file %s on line %d\\r\\n", file, line) */
/* 無限循環(huán) */
while (1)
{
}
}
#endif /* USE_FULL_ASSERT */
/** ********************** (C) COPYRIGHT Puya END OF FILE *************/
結(jié)果:LED亮滅500ms.
-
led燈
+關(guān)注
關(guān)注
22文章
1592瀏覽量
107768 -
FlaSh
+關(guān)注
關(guān)注
10文章
1614瀏覽量
147667 -
SRAM芯片
+關(guān)注
關(guān)注
0文章
65瀏覽量
12045 -
RT-Thread
+關(guān)注
關(guān)注
31文章
1265瀏覽量
39853
發(fā)布評論請先 登錄
相關(guān)推薦
評論