這次簡(jiǎn)單的給PY32移植一下RT-Thread Nano
開(kāi)發(fā)板:PY32F003_StartKit (PY32F003F16U Flash 32K SRAM 4K)
IDE:MDK5
1.準(zhǔn)備工作
這里bsp我直接使用廠商提供的bsp,原本想要直接選擇芯片自己新建工程的,但是根據(jù)官方的教程一直沒(méi)有成功于是就直接用現(xiàn)成的bsp了
下載:點(diǎn)擊Pack installer
選擇RT-Thread進(jìn)行下載
Manage Rum-Time Environment,本次我們就只移植kernel,shell暫時(shí)我還用不上所以就先不移植了
2.清除重定義
rt-thread在運(yùn)行過(guò)程中會(huì)使用到HandFault_Handler和PendSV_Handler用于線程切換,異常處理,所以需要將py32f0xx_it.c中的這兩個(gè)函數(shù)刪除,否則鏈接時(shí)會(huì)提示重定義
還有mdk中main函數(shù)的入口函數(shù)extern int Super$main(void);原來(lái)是在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(); // 對(duì)系統(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 無(wú)
@retval 無(wú)
*/
void APP_ErrorHandler(void)
{
/* 無(wú)限循環(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ò)誤的源文件名及行號(hào)
@param file:源文件名指針
@param line:發(fā)生斷言錯(cuò)誤的行號(hào)
@retval 無(wú)
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* 用戶可以根據(jù)需要添加自己的打印信息,
例如: printf("Wrong parameters value: file %s on line %d\\r\\n", file, line) */
/* 無(wú)限循環(huán) */
while (1)
{
}
}
#endif /* USE_FULL_ASSERT */
/** ********************** (C) COPYRIGHT Puya END OF FILE *************/
結(jié)果:LED亮滅500ms.
-
led燈
+關(guān)注
關(guān)注
22文章
1592瀏覽量
108458 -
FlaSh
+關(guān)注
關(guān)注
10文章
1644瀏覽量
148754 -
SRAM芯片
+關(guān)注
關(guān)注
0文章
65瀏覽量
12164 -
RT-Thread
+關(guān)注
關(guān)注
31文章
1306瀏覽量
40420
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
i.MX RT1170:VGLite移植RT-Thread Nano過(guò)程講解(上)
![i.MX <b class='flag-5'>RT</b>1170:VGLite<b class='flag-5'>移植</b><b class='flag-5'>RT-Thread</b> <b class='flag-5'>Nano</b>過(guò)程講解(上)](https://file1.elecfans.com/web2/M00/AD/2F/wKgaomVMUFCAD-6dAABXFv2-2a8881.png)
i.MX RT1170:VGLite移植RT-Thread Nano過(guò)程講解(下)
基于 Keil MDK 移植 RT-Thread Nano
如何基于CubeMX移植RT-Thread Nano?
基于 Keil MDK 移植 RT-Thread Nano
【國(guó)產(chǎn)MCU移植】HC32F460基于Keil MDK 移植 RT-Thread Nano
![【國(guó)產(chǎn)MCU<b class='flag-5'>移植</b>】HC32F460基于Keil MDK <b class='flag-5'>移植</b> <b class='flag-5'>RT-Thread</b> <b class='flag-5'>Nano</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
【國(guó)產(chǎn)MCU系列】在 HK32F030 上移植 RT-Thread Nano
![【國(guó)產(chǎn)MCU系列】在 HK32F030 上<b class='flag-5'>移植</b> <b class='flag-5'>RT-Thread</b> <b class='flag-5'>Nano</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
STM32 RT-Thread Nano(1)基于 Keil MDK 移植
![STM32 <b class='flag-5'>RT-Thread</b> <b class='flag-5'>Nano</b>(1)基于 Keil MDK <b class='flag-5'>移植</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
【國(guó)產(chǎn)MCU系列】在 HK32F030 上移植 RT-Thread Nano
![【國(guó)產(chǎn)MCU系列】在 HK32F030 上<b class='flag-5'>移植</b> <b class='flag-5'>RT-Thread</b> <b class='flag-5'>Nano</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
基于 Keil MDK 移植 RT-Thread Nano
![基于 Keil MDK <b class='flag-5'>移植</b> <b class='flag-5'>RT-Thread</b> <b class='flag-5'>Nano</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
評(píng)論