CH579M移植RT-THREAD实战笔记(KEIL5环境)
Posted 海里的鱼2022
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CH579M移植RT-THREAD实战笔记(KEIL5环境)相关的知识,希望对你有一定的参考价值。
确保能用的移植后的blink例子代码包见下载链接:
1. 下载添加RT-THREAD支持包
2. 在官方GPIO例程基础导入RT-THREAD
3. 配置rtconfig.h文件
4. 修改board.c文件
配置存储空间
#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 1024
// ADDED
#define CH579M_SRAM1_START (0x20000000)
#define CH579M_SRAM1_END (CH579M_SRAM1_START + 32 * 1024) // ???? = 0x20000000(??) + 32K(RAM??)
#if defined(__CC_ARM) || defined(__CLANG_ARM)
extern int Image$$RW_IRAM1$$ZI$$Limit; // RW_IRAM1,???????????????
#define HEAP_BEGIN ((void *)&Image$$RW_IRAM1$$ZI$$Limit)
#endif
#define HEAP_END CH579M_SRAM1_END
RT_WEAK void *rt_heap_begin_get(void)
return HEAP_BEGIN;
RT_WEAK void *rt_heap_end_get(void)
return (rt_uint32_t*)HEAP_END;
#endif
配置硬件驱动
void rt_hw_board_init()
/* ³õʼ»¯SysTick */
SysTick_Config( FREQ_SYS / RT_TICK_PER_SECOND );
/* µ÷ÓÃ×é¼þ³õʼ»¯º¯Êý (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif
GPIOA_SetBits(GPIO_Pin_9);
GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_PU); // RXD-ÅäÖÃÉÏÀÊäÈë
GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA); // TXD-ÅäÖÃÍÆÍìÊä³ö£¬×¢ÒâÏÈÈÃIO¿ÚÊä³ö¸ßµçƽ
UART1_DefInit();
rtconfig.h文件里定义重映射端口号
#define RT_CONSOLE_DEVICE_NAME "uart1"
5. 改main.c
主循环
int main()
rt_err_t result;
GPIOB_ModeCfg( GPIO_Pin_0, GPIO_ModeOut_PP_20mA );//PB0ÍÆÍìÊä³ö
rt_kprintf("RT thread sample.\\n");
led1_thread = /* Ï߳̿ØÖÆ¿éÖ¸Õë */
rt_thread_create( "led1", /* Ïß³ÌÃû×Ö */
led1_thread_entry, /* Ïß³ÌÈë¿Úº¯Êý */
RT_NULL, /* Ïß³ÌÈë¿Úº¯Êý²ÎÊý */
512, /* Ïß³ÌÕ»´óС */
21, /* Ï̵߳ÄÓÅÏȼ¶ */
10); /* Ïß³Ìʱ¼äƬ */
/* Æô¶¯Ị̈߳¬¿ªÆôµ÷¶È */
if (led1_thread != RT_NULL)
rt_thread_startup(led1_thread);
rt_kprintf("led thread start.\\n");
else
return -1;
定义blink任务
static void led1_thread_entry(void* parameter)
//char *str;
rt_uint32_t len ;
rt_kprintf("led thread init.\\n");
while (TRUE)
rt_kprintf("led thread running.\\n");
GPIOB_InverseBits(GPIO_Pin_0);
rt_thread_mdelay(500);
以上是关于CH579M移植RT-THREAD实战笔记(KEIL5环境)的主要内容,如果未能解决你的问题,请参考以下文章
《嵌入式系统 - RT-Thread开发笔记》 第三部分 RT-Thread 移植与设备驱动开发 - 第1章 RT-Thread 开发环境搭建 (Keil+env)