clion开发stm32f4系列(一)————移植rt-thread os系统

avatar
作者
猴君
阅读量:0

前言

  1. 本次使用的rt-thread的版本为5.0.2
  2. 基于rt-thread sudio生成的源码进行拷贝和修改
  3. 工程基于上次创建工程的项目进行修改。
  4. 本次工程只是用了serial和pin组件,其他后面用到再进行添加

拷贝rt-thread源码库

在这里插入图片描述

通过CMakeLists来进行管理

顶级(rt-thread目录)

在这里插入图片描述

cmake_minimum_required(VERSION 3.22)  project(rt-thread) add_library(rt-thread INTERFACE)  # Enable CMake support for ASM and C languages enable_language(C ASM) add_subdirectory(components) add_subdirectory(libcpu) target_compile_definitions(rt-thread INTERFACE  )  target_include_directories(rt-thread INTERFACE         ./         ./include  ) #[[------------------------SRC-------------------]] set(os_src         ./src/clock.c         ./src/components.c #        ./src/cpu.c         ./src/idle.c         ./src/ipc.c         ./src/irq.c         ./src/kservice.c         ./src/mem.c         ./src/memheap.c         ./src/mempool.c         ./src/object.c         #        ./src/scheduler_mp.c         ./src/scheduler_up.c         ./src/SConscript         ./src/signal.c         ./src/slab.c         ./src/thread.c         ./src/timer.c )   target_sources(rt-thread INTERFACE         ${os_src} )  target_link_directories(rt-thread INTERFACE )  target_link_libraries(rt-thread INTERFACE )  # Validate that STM32CubeMX code is compatible with C standard if (CMAKE_C_STANDARD LESS 11)     message(ERROR "Generated code requires C11 or higher") endif ()    

libcpu目录配置

在这里插入图片描述

 target_include_directories(rt-thread INTERFACE          ./arm/cortex-m4/  )  target_sources(rt-thread INTERFACE          ./arm/cortex-m4/context_gcc.S         ./arm/cortex-m4/cpuport.c  ) 

components目录(此CMAkeLists文件主要用于添加具体的组件)

在这里插入图片描述

add_subdirectory(finsh) add_subdirectory(drivers) 

driver目录(此文件添加共有源码和管理抽象层的具体组件)

在这里插入图片描述

target_include_directories(rt-thread INTERFACE         ./include  )  target_sources(rt-thread INTERFACE         ipc/completion.c         ipc/dataqueue.c         ipc/pipe.c         ipc/ringblk_buf.c         ipc/ringbuffer.c         ipc/waitqueue.c         ipc/workqueue.c )  add_subdirectory(core) add_subdirectory(misc) add_subdirectory(serial) 

core 目录

在这里插入图片描述

target_sources(rt-thread INTERFACE          ./device.c  ) 

msic 目录

在这里插入图片描述

target_sources(rt-thread INTERFACE          ./pin.c ) 

serial目录

在这里插入图片描述

target_sources(rt-thread INTERFACE     ./serial.c ) 

硬件实现层(drivers目录)

在这里插入图片描述

cmake_minimum_required(VERSION 3.22)  project(stm32f4-driver) add_library(stm32f4-driver INTERFACE)  # Enable CMake support for ASM and C languages enable_language(C ASM) target_compile_definitions(stm32f4-driver INTERFACE     -DSOC_SERIES_STM32F4 )  target_include_directories(stm32f4-driver INTERFACE         ./         ./include         ./include/config )  target_sources(rt-thread INTERFACE         ./board.c         ./drv_common.c         ./drv_clk.c         ./drv_gpio.c         ./drv_usart.c  )  target_link_directories(stm32f4-driver INTERFACE )  target_link_libraries(stm32f4-driver INTERFACE )  # Validate that STM32CubeMX code is compatible with C standard if (CMAKE_C_STANDARD LESS 11)     message(ERROR "Generated code requires C11 or higher") endif ()    

改造cmake目录中

在这里插入图片描述

cmake_minimum_required(VERSION 3.22)  project(stm32cubemx) add_library(stm32cubemx INTERFACE)  # Enable CMake support for ASM and C languages enable_language(C ASM)  target_compile_definitions(stm32cubemx INTERFACE         USE_HAL_DRIVER         STM32F407xx         $<$<CONFIG:Debug>:DEBUG> )  target_include_directories(stm32cubemx INTERFACE         ../../Core/Inc         ../../Drivers/STM32F4xx_HAL_Driver/Inc         ../../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy         ../../Drivers/CMSIS/Device/ST/STM32F4xx/Include         ../../Drivers/CMSIS/Include )  target_sources(stm32cubemx INTERFACE         ../../Core/Src/main.c         ../../Core/Src/gpio.c         #    ../../Core/Src/stm32f4xx_it.c         ../../Core/Src/stm32f4xx_hal_msp.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c         ../../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c         ../../Core/Src/system_stm32f4xx.c #        ../../Core/Src/sysmem.c #        ../../Core/Src/syscalls.c         ../../startup_stm32f407xx.s )  target_link_directories(stm32cubemx INTERFACE )  target_link_libraries(stm32cubemx INTERFACE )  # Validate that STM32CubeMX code is compatible with C standard if (CMAKE_C_STANDARD LESS 11)     message(ERROR "Generated code requires C11 or higher") endif ()    

根CMakeLists文件调整

在这里插入图片描述

添加自定义的应用目录

在这里插入图片描述

target_include_directories(stm32cubemx INTERFACE         ./inc  ) target_sources(stm32cubemx INTERFACE         ./src/main.c ) 

调整链接文件和汇编文件

v在这里插入图片描述

在这里插入图片描述

## 调整

cmake_minimum_required(VERSION 3.22)  # # This file is generated only once, # and is not re-generated if converter is called multiple times. # # User is free to modify the file as much as necessary #  # Setup compiler settings set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS ON)   # Define the build type if (NOT CMAKE_BUILD_TYPE)     set(CMAKE_BUILD_TYPE "Debug") endif ()  # Set the project name set(CMAKE_PROJECT_NAME csdn_stm32f407zgt6)  # Include toolchain file include("cmake/gcc-arm-none-eabi.cmake")  # Enable compile command to ease indexing with e.g. clangd set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)  # Enable CMake support for ASM and C languages enable_language(C ASM)  # Core project settings project(${CMAKE_PROJECT_NAME}) message("Build type: " ${CMAKE_BUILD_TYPE}) # Create an executable object type add_executable(${CMAKE_PROJECT_NAME})  # Add STM32CubeMX generated sources #add_subdirectory(cmake/stm32cubemx) add_subdirectory(cmake/rt_stm32cumx) add_subdirectory(Drivers/Bsp) add_subdirectory(Middleware/rt-thread) add_subdirectory(Middleware/drivers)  add_subdirectory(applications)   # Link directories setup target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE         # Add user defined library search paths )  # Add sources to executable target_sources(${CMAKE_PROJECT_NAME} PRIVATE         # Add user sources here )  # Add include paths target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE         # Add user defined include paths )  # Add project symbols (macros) target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE         # Add user defined symbols )  # Add linked libraries target_link_libraries(${CMAKE_PROJECT_NAME}         stm32cubemx          # Add user defined libraries         stm32f4_bsp         rt-thread         stm32f4-driver  )  

测试结果

在这里插入图片描述

通过debug测试(移植ok)

在这里插入图片描述

    广告一刻

    为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!