Threadx rtos 移植指南(stm32f1)

Threadx 系统移植非常简单,下面记录 gnu 工具链移植步骤

库文件目录

.
├── cmake                        # CMakelist files for building the project
├── common                       # Core ThreadX files
├── common_modules               # Core ThreadX module files
├── common_smp                   # Core ThreadX SMP files
├── docs                         # Documentation supplements
├── ports                        # Architecture and compiler specific files. See below for directory breakdown     
│   ├── cortex_m7     
│   │   ├── iar                  # Example IAR compiler sample project
│   │   │   ├── example build    # IAR workspace and sample project files
│   │   │   ├── inc              # tx_port.h for this architecture
│   │   │   └── src              # Source files for this architecture
│   │   ├── ac6                  # Example ac6/Keil sample project
│   │   ├── gnu                  # Example gnu sample project
│   │   └── ...
│   └── ...        
├── ports_modules                # Architecture and compiler specific files for threadX modules
├── ports_smp                    # Architecture and compiler specific files for threadX SMP
├── samples                      # demo_threadx.c
└── utility                      # Test cases and utilities

移植只需要用到两个文件夹 common,port

以 cortex-m3/gnu 为例,文件夹为

├─example_build  # 移植好的例子,其中tx_initialize_low_level.S已经移植好了直接拿来使用
├─inc            # tx_port.h kernal基本数据结构,定义等等
└─src            # 底层汇编代码

系统移植

移植只需要修改这几个文件

  1. tx_initialize_low_level.S
  2. stm32f1xx_it.c
  3. STM32xxx_FLASH.ld
// tx_initialize_low_level.S

// 1. 这部分根据实际修改,作用于 tx_thread_sleep
SYSTEM_CLOCK      =   72000000	// 系统时钟主频
SYSTICK_CYCLES    =   ((SYSTEM_CLOCK / 1000) -1) // 1000代表1000Hz

// 2. 将系统向量表加入到启动中,所有需要修改一个地方,原本提供的向量为 _vectors
// 只需要将 _vectors 全部替换为 startup_stm32xxx.s 中的向量 g_pfnVectors
// stm32f1xx_it.c

// 需要注释掉两个中断
/**
  * @brief This function handles Pendable request for system service.
  */
void PendSV_Handler(void)
    
/**
  * @brief This function handles System tick timer.
  */
void SysTick_Handler(void)
// STM32xxx_FLASH.ld

// 需要修改一处,将 tx_initialize_low_level.S 中的 __RAM_segment_used_end__ 加入进来

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

完成以上三个文件的修改,再将源代码加入编译系统中,即完成了移植。

移植后注意事项

由于禁用了系统的时钟节拍中断,所以 Hal_delay 延时函数时效,要想继续使用,需要重新实现时间基准。

可使用系统提供的延时函数,tx_thread_sleep

posted @ 2024-04-02 10:25  创世~  阅读(642)  评论(0)    收藏  举报