本帖最后由 KING阿飞 于 2022-9-11 15:37 编辑
【ESK32-30519 + ESK32-21001测评】移植RT-Thread Nano
首先,我们了解片上存储器是28 KB 片上 Flash 存储器用作指令 和 数据和选项存储 :16 KB 片上 SRAM,所以我选择小型的国产OS:RT-Thread Nano,作为项目评测OS。
一、移植过程
我们首先下载官方的资源包,资源包点此下载(https://www.holtek.com.cn/documents/10179/052fe018-3579-46e4-a3a8-32e53fbc0033)。我们找到例程项目,.\project_template\IP\Example\MDK_ARMv537(这里由于我的keil是537的),点开项目文件。
我们再安装RT-Thread Nano的离线安装包,离线安装包点此下载 (https://www.rt-thread.org/download/mdk/RealThread.RT-Thread.3.1.5.pack)。我们安装完成后,找到包管理器。
安装完毕后,需要修改的地方是:
1、将ht32f5xxxx_01_it.c文件中的,HardFault_Handler,PendSV_Handler,SysTick_Handler注释
2、修改RTOS中的board.c:
添加SysTick_Handler,调用rt_os_tick_callback。完善rt_hw_board_init。
/*
* Copyright (c) 2006-2019, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-05-24 the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include "ht32.h"
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
/*
* Please modify RT_HEAP_SIZE if you enable RT_USING_HEAP
* the RT_HEAP_SIZE max value = (sram size - ZI size), 1024 means 1024 bytes
*/
#define RT_HEAP_SIZE (8*1024)
static rt_uint8_t rt_heap[RT_HEAP_SIZE];
RT_WEAK void *rt_heap_begin_get(void)
{
return rt_heap;
}
RT_WEAK void *rt_heap_end_get(void)
{
return rt_heap + RT_HEAP_SIZE;
}
#endif
void rt_os_tick_callback(void)
{
rt_interrupt_enter();
rt_tick_increase();
rt_interrupt_leave();
}
u32 count = 0;
void SysTick_Handler(void)
{
rt_os_tick_callback();
count++;
}
/**
* This function will initial your board.
*/
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.
*/
/* SYSTICK configuration */
SYSTICK_ClockSourceConfig(SYSTICK_SRC_STCLK); // Default : CK_AHB/8
SYSTICK_SetReloadValue(SystemCoreClock / 8/ RT_TICK_PER_SECOND); // (CK_AHB/8/1000) = 1ms on chip
SYSTICK_IntConfig(ENABLE); // Enable SYSTICK Interrupt
SYSTICK_CounterCmd(SYSTICK_COUNTER_CLEAR);
SYSTICK_CounterCmd(SYSTICK_COUNTER_ENABLE);
/* 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
}
#ifdef RT_USING_CONSOLE
static int uart_init(void)
{
#error "TODO 2: Enable the hardware uart and config baudrate."
return 0;
}
INIT_BOARD_EXPORT(uart_init);
void rt_hw_console_output(const char *str)
{
#error "TODO 3: Output the string 'str' through the uart."
}
#endif
测试:
HT32F_DVB_LEDInit(HT_LED1);
HT32F_DVB_LEDInit(HT_LED2);
HT32F_DVB_LEDInit(HT_LED3);
HT32F_DVB_LEDOn(HT_LED1);
HT32F_DVB_LEDOff(HT_LED2);
HT32F_DVB_LEDOn(HT_LED3);
while (1) /* Infinite loop */
{
HT32F_DVB_LEDToggle(HT_LED1);
rt_thread_mdelay(500);
HT32F_DVB_LEDToggle(HT_LED2);
rt_thread_mdelay(500);
HT32F_DVB_LEDToggle(HT_LED3);
rt_thread_mdelay(500);
}
二、效果
HT32F54253移植测试(https://www.bilibili.com/video/BV1qG411V7s6/?vd_source=9f29628860df295e99637badd1e5e6ae)
|