#申請(qǐng)原創(chuàng)# #有獎(jiǎng)活動(dòng)#
【目的】移植RT-Thread nano到FTHR-G0140開發(fā)板上,并實(shí)現(xiàn)任務(wù)的創(chuàng)建與運(yùn)行。
【開發(fā)環(huán)境】
MDK5.28
【移植步驟】
1、打開一個(gè)可以亮燈的基礎(chǔ)例程,這里打開示例的GPIO工程。
2、Nano Pack 安裝:我們從官網(wǎng)下載安裝文件,RT-Thread Nano 離線安裝包下載,下載結(jié)束后雙擊文件進(jìn)行安裝:

3、添加 RT-Thread Nano 到工程,打開已經(jīng)準(zhǔn)備好的可以運(yùn)行的裸機(jī)程序,將 RT-Thread 添加到工程。如下圖,點(diǎn)擊 Manage Run-Time Environment。

4、現(xiàn)在可以在 Project 看到 RT-Thread RTOS 已經(jīng)添加進(jìn)來了,展開 RTOS,可以看到添加到工程的文件:

5、適配 RT-Thread Nano
中斷與異常處理
RT-Thread 會(huì)接管異常處理函數(shù) HardFault_Handler() 和懸掛處理函數(shù) PendSV_Handler(),這兩個(gè)函數(shù)已由 RT-Thread 實(shí)現(xiàn),所以需要?jiǎng)h除工程里中斷服務(wù)例程文件中的這兩個(gè)函數(shù),避免在編譯時(shí)產(chǎn)生重復(fù)定義。

系統(tǒng)時(shí)鐘配置
需要在 board.c 中實(shí)現(xiàn) 系統(tǒng)時(shí)鐘配置(為 MCU、外設(shè)提供工作時(shí)鐘)與 os tick 的配置 (為操作系統(tǒng)提供心跳 / 節(jié)拍)。
如下代碼所示,用戶需要在 board.c 文件中系統(tǒng)初始化和 OS Tick 的配置,cortex-m0 架構(gòu)使用 SysTick_Handler()
我們修改函數(shù)內(nèi)容如下:
#define SYSCLK_HSI_XXMHz 72000000
void rt_os_tick_callback(void)
{
rt_interrupt_enter();
rt_tick_increase();
rt_interrupt_leave();
}
void SysTick_Handler(void)
{
rt_os_tick_callback();
}
/**
* This function will initial your board.
*/
void rt_hw_board_init(void)
{
SysTick_Config(SYSCLK_HSI_XXMHz/1000);
/*
* 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()) */
#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
}

同時(shí)我們打開rttconfig.h,在Memory Management Configuation中關(guān)閉動(dòng)態(tài)內(nèi)存池管理

然后我們就可以編譯工程了:
Program Size: Code=6560 RO-data=556 RW-data=148 ZI-data=3172
FromELF: creating hex file...
".ObjectsGPIO_LED_Toggle.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:02
6、創(chuàng)建兩個(gè)任務(wù),并啟動(dòng):
struct rt_thread thread1;
struct rt_thread thread2;
char thread1_stack[512];
char thread2_stack[512];
void thread1_entry(void*param)
{
while (1)
{
printf("thread1 is runningrn");
rt_thread_mdelay(200);
}
}
void thread2_entry(void*param)
{
while (1)
{
printf("thread2is runningrn");
rt_thread_mdelay(400);
}
}
void thread1_init(void)
{
rt_err_t fd=rt_thread_init(&thread1,"thread1",&thread1_entry,0,&thread1_stack[0],sizeof(thread1_stack),10,10);
if(fd < 0)
{
printf("thread1 init is fail rn");
}
else
{
printf("thread1init is success rn");
}
rt_thread_startup(&thread1);
}
void thread2_init(void)
{
rt_err_t fd=rt_thread_init(&thread2,"thread2",&thread2_entry,0,&thread2_stack[0],sizeof(thread2_stack),10,10);
if(fd < 0)
{
printf("thread2 init is fail rn");
}
else
{
printf("thread2init is success rn");
}
rt_thread_startup(&thread2);
}
/***********************************************************************************************************************
* @brief This function is main entrance
* @note main
* @param none
* @retval none
*********************************************************************************************************************/
int main(void)
{
PLATFORM_Init();
thread1_init();
thread2_init();
while (1)
{
}
}
7、實(shí)驗(yàn)效果:
編譯后下載到開發(fā)板,我們就可以看到RT-Thread成功啟動(dòng)了兩個(gè)任,打印效果如下:

【總結(jié)】作為這款芯片是基于Cortex-M0核,廠家采用了標(biāo)準(zhǔn)的CMSIS結(jié)構(gòu),使得移植RTT比較成功。
審核編輯黃宇
-
開發(fā)板
+關(guān)注
關(guān)注
25文章
5186瀏覽量
98716 -
RTT
+關(guān)注
關(guān)注
0文章
65瀏覽量
17263 -
RT-Thread
+關(guān)注
關(guān)注
31文章
1315瀏覽量
40672 -
靈動(dòng)微
+關(guān)注
關(guān)注
4文章
175瀏覽量
22767 -
MM32
+關(guān)注
關(guān)注
1文章
106瀏覽量
845
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
FTHR-G0140開發(fā)板LED點(diǎn)燈

RT-Thread開發(fā),如何有效學(xué)習(xí)RT-Thread的五個(gè)步驟

移植RT-Thread的原理與方法
STM32WB55在RT-Thread系統(tǒng)上移植官方藍(lán)牙BLE功能

RT-Thread Studio驅(qū)動(dòng)SD卡

基于RoboMasterC型開發(fā)板的RT-Thread使用分享(一)
【項(xiàng)目移植】國民技術(shù)N32G4FR開發(fā)板:RT-Thread Nano移植FinSH
機(jī)智云設(shè)備移植RT-Thread

RT-Thread qemu mps2-an385 bsp移植制作 :環(huán)境搭建篇

rt-studio潘多拉開發(fā)板最新rt-thread不能運(yùn)行解決辦法

【QEMU系列】不用開發(fā)板運(yùn)行RT-Thread指南-ARM架構(gòu)

評(píng)論