千家信息网

AWTK 在 RT-Thread 上的移植是怎样的

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,AWTK 在 RT-Thread 上的移植是怎样的,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。AWTK 在 RT-Th
千家信息网最后更新 2026年11月02日AWTK 在 RT-Thread 上的移植是怎样的

AWTK 在 RT-Thread 上的移植是怎样的,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

AWTK 在 RT-Thread 上的移植笔记

下面以 STM32f103ze 为例,介绍了 AWTK 在 RTOS 上移植的经验。与其说移植,倒不如说是集成。所做的事情不过是把 AWTK 放到 RTOS 的一个线程中执行而已。

1. 加入 RT-Thread 相关文件。

AWTK 已经移植到 STM32f103ze 裸系统上,为了简单起见,直接在 awtk-stm32f103ze-raw 基础上加入 RT-Thread 支持。

  • 在 Keil 中增加下列文件:

rtthread/rtthread/bsprtthread/cortex-m3rtthread/cortex-m3/context_gcc.Srtthread/cortex-m3/context_iar.Srtthread/cortex-m3/context_rvds.Srtthread/cortex-m3/cpuport.crtthread/cortex-m3/SConscriptrtthread/includertthread/include/libcrtthread/include/libc/libc_dirent.hrtthread/include/libc/libc_errno.hrtthread/include/libc/libc_fcntl.hrtthread/include/libc/libc_fdset.hrtthread/include/libc/libc_ioctl.hrtthread/include/libc/libc_signal.hrtthread/include/libc/libc_stat.hrtthread/include/rtdbg.hrtthread/include/rtdebug.hrtthread/include/rtdef.hrtthread/include/rthw.hrtthread/include/rtlibc.hrtthread/include/rtm.hrtthread/include/rtservice.hrtthread/include/rtthread.hrtthread/rtconfig.hrtthread/srcrtthread/src/clock.crtthread/src/cpu.crtthread/src/device.crtthread/src/idle.crtthread/src/ipc.crtthread/src/irq.crtthread/src/Kconfigrtthread/src/kservice.crtthread/src/mem.crtthread/src/memheap.crtthread/src/mempool.crtthread/src/object.crtthread/src/scheduler.crtthread/src/SConscriptrtthread/src/signal.crtthread/src/slab.crtthread/src/thread.crtthread/src/timer.c
  • 增加 include 的路径

rtthreadrtthread/include
  • 修改配置文件

根据自己的需要修改配置 rtthread/rtconfig.h

一般来说不需要修改,使用官方提供的即可。我用的是 stm32f103-mini-system 项目中的。

2. 加入针对 RT-Thread 实现的线程和同步的函数。

src/platforms/rtt/mutex.csrc/platforms/rtt/semaphore.csrc/platforms/rtt/thread.csrc/platforms/common/sys_tick.c

3. 实现rtos.c。

参考stm32/libraries/HAL_Drivers/drv_common.c和components.c修改的。

#include "rthw.h"#include "rtthread.h"static bool_t s_kernel_inited = FALSE;static bool_t rtos_is_inited(void) {  return s_kernel_inited;}static uint32_t s_heap[2 * 1024];ret_t rtos_init(void) {  rt_hw_interrupt_disable();  /* show version */  rt_show_version();#ifdef RT_USING_HEAP  rt_system_heap_init((void*)s_heap, s_heap + sizeof(s_heap) / sizeof(s_heap[0]));#endif  /* initialize scheduler system */  rt_system_scheduler_init();  /* initialize timer */  rt_system_timer_init();  /* initialize timer thread */  rt_system_timer_thread_init();  /* initialize idle thread */  rt_thread_idle_init();  s_kernel_inited = TRUE;  return RET_OK;}ret_t rtos_start(void) {  /* start scheduler */  rt_system_scheduler_start();  return RET_OK;}void rtos_tick(void) {  if (rtos_is_inited()) {    rt_interrupt_enter();    rt_tick_increase();    rt_interrupt_leave();  }}void rtos_delay(uint32_t ms) {  rt_thread_delay(ms);}

4. 在线程中启动 AWTK

void* awtk_thread(void* args) {  gui_app_start(320, 480);  return NULL;}static ret_t awtk_start_ui_thread(void) {  tk_thread_t* ui_thread = tk_thread_create(awtk_thread, NULL);  return_value_if_fail(ui_thread != NULL, RET_BAD_PARAMS);  tk_thread_set_priority(ui_thread, 3);  tk_thread_set_name(ui_thread, "awtk");  tk_thread_set_stack_size(ui_thread, 2048);  return tk_thread_start(ui_thread);}int main() {  hardware_prepare();  platform_prepare();  rtos_init();  awtk_start_ui_thread();  rtos_start();}

这里与裸系统不同的地方,主要有两个:


    1. 在线程中启动 AWTK。


    1. 要提前调用 platform_prepare,platform_prepare 负责初始化内存,放在 tk_init 中就有些晚,需要单独提出来调用。

为此 platform_prepare 函数做了防重复调用的处理。

static bool_t s_inited = FALSE;static uint32_t s_heam_mem[4096];ret_t platform_prepare(void) {        if(!s_inited) {                s_inited = TRUE;    tk_mem_init(s_heam_mem, sizeof(s_heam_mem));        }  return RET_OK;}

AWTK 集成 RTOS 是非常简单的,以上过程大概花了 2 个小时吧。只要 RTOS 本身好移植,集成 AWTK 和 RTOS 只是分分钟的问题。

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对的支持。

移植 线程 文件 函数 系统 帮助 支持 配置 不同 清楚 为此 一般来说 两个 事情 内存 内容 分分钟 只是 地方 基础 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网科技深圳 科技互联网公司装修 互联网金融与金融科技 上海互联网科技有限公司 互联网未来科技 善班互联网科技有限公司 人人互联网科技是培训 甘肃拓世互联网科技有限公司 华中科技有哪些互联网大佬 温州喔噻互联网科技有限公司 阿里巴巴算科技企业还是互联网 千方科技属于互联网企业吗 江阴互联网智能科技产品进口 阿里互联网科技企业 工业互联网等科技实现智能化赋能 2021互联网科技公司排名 互联网第三次科技革命特征 互联网安防科技感 广州互联网高科技取餐柜 瑞安市蟠桃会互联网科技有限公司 广州宏创互联网科技 亿策互联网科技 互联网养老 桔豆科技 团飞科技与伯堂互联网服务平台 重庆威客帮互联网科技 现代互联网科技股 千方科技属于互联网企业吗 互联网科技公司有风险吗 互联网科技与大数据专业 互联网科技公司营业执照怎么办理
0