STM32F103移植threadx

threadx简介

Azure RTOS 是一个实时操作系统 (RTOS),适用于由微控制器 (MCU) 提供支持的物联网 (IoT) 和边缘设备。 Azure RTOS 旨在支持高度受限设备(电池供电,并且闪存容量不到 64 KB)。

Azure RTOS 提供 EAL4+ 通用准则安全认证环境,包括通过 IPsec 实现的全 IP 层安全性以及通过 TLS 和 DTLS 实现的套接字层安全性。 我们的软件加密库已获得 FIPS 140-2 认证。 此外,我们还采用硬件加密功能、通过 ThreadX MODULES 实现的内存保护技术,以及 ARM TrustZone ARMv8-M 安全功能支持。

Azure RTOS 平台是运行时解决方案的集合,包括 Azure RTOS ThreadX、Azure RTOS NetX 和 NetX Duo、Azure RTOS FileX、Azure RTOS GUIX 和 Azure RTOS USBX。

开发环境:野火指南者,ubuntu16.04

编译环境:arm-none-ebi-gcc

编译工具:CMakeLists.txt

linux下使用CMakeLists.txt搭建stm32f103的方法参见这篇博客:

STM2F103开发环境搭建:LINUX + CMakelists_JR in the tree的博客-CSDN博客

1. threadx准备

从github上下载源码:

git clone https://github.com/azure-rtos/threadx.git

threadx内核部分,文件夹common:
在这里插入图片描述

野火指南者属于cortex-M3系列,需要用到的ports文件如下:
在这里插入图片描述
移植过程中需要修改的是tx_initialize_low_level.S,该文件接管了stm32的中断向量表,该文件中主要修改以下3个部分:

a)设置剩余可用ram的首地址__RAM_segment_used_end__

在链接脚本STM32F103VETx_FLASH.ld中设置该地址:

/* User_heap_stack section, used to check that there is enough RAM left */
  ._user_heap_stack :
  {
    . = ALIGN(8);
    PROVIDE ( end = . );
    PROVIDE ( _end = . );
    . = . + _Min_Heap_Size;
    . = . + _Min_Stack_Size;
    . = ALIGN(8);
    __RAM_segment_used_end__ = .;
  } >RAM

b)设置时钟与rtos的心跳,指南者的时钟为72M,设置rtos心跳为1000hz(此处频率过大,系统就会频繁调度,频率过低实时性能差,一般设置为1000hz)

SYSTEM_CLOCK      =   72000000
SYSTICK_CYCLES    =   ((SYSTEM_CLOCK / 1000) -1)

c)设置中断向量表首地址,tx_initialize_low_level.S中用到的向量表首地址为_vectors,启动文件中用到的为g_pfnVectors,将_vectors整体替换为g_pfnVectors
在这里插入图片描述
在这里插入图片描述

2 CMakeLists.txt修改

主要是包含新增文件

enable_language(ASM)
FILE(GLOB_RECURSE LIBRARY_SRC_LIST ${PROJECT_SOURCE_DIR}/library/*.c)
FILE(GLOB_RECURSE BOARD_SRC_LIST ${PROJECT_SOURCE_DIR}/board/*.c)
SET(STARTUP_SRC library/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103xe.s)
FILE(GLOB_RECURSE STARTUP_SRC_THREADX ${PROJECT_SOURCE_DIR}/library/threadx/ports/src/*.S)

include_directories(
    library/CMSIS/Device/ST/STM32F1xx/Include
    library/CMSIS/Include
    library/STM32F1xx_HAL_Driver/Inc
    library/STM32F1xx_HAL_Driver/Inc/Legacy
    library/threadx/common/inc
    library/threadx/ports/inc
    board/inc
    board/gpio
    board/usart
    board/timer
)

使用cmake生成Makefile

cmake ../ -DCMAKE_VERBOSE_MAKEFILE:string=on -DCMAKE_BUILD_TYPE:string=Debug

make编译报错:SysTick_HandlerPendSV_Handler重定义

CMakeFiles/shell_proj.elf.dir/library/threadx/ports/src/tx_initialize_low_level.S.o: in function `__tx_SysTickHandler':
threadx_proj/library/threadx/ports/src/tx_initialize_low_level.S:211: multiple definition of `SysTick_Handler'; 
CMakeFiles/shell_proj.elf.dir/board/src/stm32f1xx_it.c.o:threadx_proj/board/src/stm32f1xx_it.c:193: first defined here

CMakeFiles/shell_proj.elf.dir/library/threadx/ports/src/tx_thread_schedule.S.o: in function `__tx_ts_handler':
threadx_proj/library/threadx/ports/src/tx_thread_schedule.S:153: multiple definition of `PendSV_Handler'; 
CMakeFiles/shell_proj.elf.dir/board/src/stm32f1xx_it.c.o:threadx_proj/board/src/stm32f1xx_it.c:179: first defined here

tx_initialize_low_level.S中实现了SysTick_HandlerPendSV_Handler,删除stm32f1xx_it.c中两者的定义。重新make后编译通过。

烧录下载后串口打印:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值