AT32 F435简介4/N ChibiOS porting plan

2023-12-20 23:45:52

1. 源由

  1. 对比STM32 F405进行AT32 F435 MCU的资料研读,期望获取更多差异化信息;
  2. 配合ChibiOS的porting工作,有理有据;
  3. 寻找AT32 F435的一些亮点功能和特性;

2. 框图

ChibiOS总体框图

根据ChibiOS总体框图,整个ChibiOS移植涉及以下几个部分:

  • Startup Code: ./os/common/startup
  • RT Port Layer: ./os/common/ports
  • HAL Board Layer: ./os/hal/boards
  • HAL Port Layer: ./os/hal/ports

3. Makefile

以STM32H743为例,分析如下:

Makefile
 ├──> [Licensing files]
 │   └──> $(CHIBIOS)/os/license/license.mk
 ├──> [Startup files]
 │   └──> $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32h7xx.mk
 ├──> [HAL-OSAL files]
 │   ├──> $(CHIBIOS)/os/hal/hal.mk
 │   ├──> $(CHIBIOS)/os/hal/ports/STM32/STM32H7xx/platform.mk
 │   ├──> $(CHIBIOS)/os/hal/boards/ST_NUCLEO144_H743ZI/board.mk
 │   └──> $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk
 ├──> [RTOS files]
 │   ├──> $(CHIBIOS)/os/rt/rt.mk
 │   └──> $(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/mk/port.mk
 ├──> [Auto-build files in ./source recursively.]
 │   └──> $(CHIBIOS)/tools/mk/autobuild.mk
 ├──> [Other files]
 │   ├──> $(CHIBIOS)/os/test/test.mk
 │   ├──> $(CHIBIOS)/test/rt/rt_test.mk
 │   └──> $(CHIBIOS)/test/oslib/oslib_test.mk
 ├──> $(STARTUPLD)/STM32H743xI.ld
 ├──> $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/rules.mk
 └──> $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/arm-none-eabi.mk

4. 分析

接下来结合2/3章节,分析移植ChibiOS涉及的内容:

4.1 Startup Code

$(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32h7xx.mk内容包含:

# List of the ChibiOS generic STM32H7xx startup and CMSIS files.
STARTUPSRC = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/crt1.c
          
STARTUPASM = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/crt0_v7m.S \
             $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/vectors.S

STARTUPINC = $(CHIBIOS)/os/common/portability/GCC \
             $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC \
             $(CHIBIOS)/os/common/startup/ARMCMx/devices/STM32H7xx \
             $(CHIBIOS)/os/common/ext/ARM/CMSIS/Core/Include \
             $(CHIBIOS)/os/common/ext/ST/STM32H7xx

STARTUPLD  = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/ld

# Shared variables
ALLXASMSRC += $(STARTUPASM)
ALLCSRC    += $(STARTUPSRC)
ALLINC     += $(STARTUPINC)
  • 启动代码定义,详见:
$(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32h7xx.mk
 ├──> [ARMCMx_GCC_STARTUP]
 │   └──> $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/crt1.c
 ├──> [ARMCMx_GCC_STARTUP_V7M]
 │   └──> $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/crt0_v7m.S
 └──> [ARMCMx_GCC_VECTORS Cortex-Mx Interrupt Vectors]
     └──> $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/vectors.S
  • 地址符号定义,详见:
$(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32h7xx.mk
 ├──> $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/ld/rules_stacks.ld
 ├──> $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/ld/rules_code.ld
 ├──> $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/ld/rules_data.ld
 └──> $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/ld/rules_memory.ld

4.2 RT Port Layer

$(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/mk/port.mk内容包含:

# List of the ChibiOS/RT ARMv7M generic port files.
PORTSRC = $(CHIBIOS)/os/common/ports/ARMv7-M/chcore.c
          
PORTASM = $(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/chcoreasm.S

PORTINC = $(CHIBIOS)/os/common/portability/GCC \
          $(CHIBIOS)/os/common/ports/ARM-common \
          $(CHIBIOS)/os/common/ports/ARMv7-M

# Shared variables
ALLXASMSRC += $(PORTASM)
ALLCSRC    += $(PORTSRC)
ALLINC     += $(PORTINC)
  • $(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/chcoreasm.S代码定义:

a) __port_switch
b) __port_thread_start
c) __port_switch_from_isr

  • $(CHIBIOS)/os/common/ports/ARMv7-M/chcore.c代码定义:

a) SVC_Handler
b) PendSV_Handler
c) port_init
d) __port_set_region
e) __port_irq_epilogue

4.3 HAL Board Layer

$(CHIBIOS)/os/hal/boards/ST_NUCLEO144_H743ZI/board.mk内容包含:

# List of all the board related files.
BOARDSRC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO144_H743ZI/board.c

# Required include directories
BOARDINC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO144_H743ZI

# Shared variables
ALLCSRC += $(BOARDSRC)
ALLINC  += $(BOARDINC)

$(CHIBIOS)/os/hal/boards/ST_NUCLEO144_H743ZI/board.c代码定义:

a) gpio_init
b) stm32_gpio_init
c) __early_init
d) sdc_lld_is_card_inserted
e) sdc_lld_is_write_protected
f) mmc_lld_is_card_inserted
g) mmc_lld_is_write_protected
h) boardInit

4.4 HAL Port Layer

$(CHIBIOS)/os/hal/ports/STM32/STM32H7xx/platform.mk内容包含:

# Required platform files.
PLATFORMSRC := $(CHIBIOS)/os/hal/ports/common/ARMCMx/nvic.c \
               $(CHIBIOS)/os/hal/ports/STM32/STM32H7xx/stm32_isr.c \
               $(CHIBIOS)/os/hal/ports/STM32/STM32H7xx/hal_lld.c

# Required include directories.
PLATFORMINC := $(CHIBIOS)/os/hal/ports/common/ARMCMx \
               $(CHIBIOS)/os/hal/ports/STM32/STM32H7xx

# Optional platform files.
ifeq ($(USE_SMART_BUILD),yes)

# Configuration files directory
ifeq ($(HALCONFDIR),)
  ifeq ($(CONFDIR),)
    HALCONFDIR = .
  else
    HALCONFDIR := $(CONFDIR)
  endif
endif

HALCONF := $(strip $(shell cat $(HALCONFDIR)/halconf.h | egrep -e "\#define"))

else
endif

# Drivers compatible with the platform.
include $(CHIBIOS)/os/hal/ports/STM32/LLD/ADCv4/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/BDMAv1/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/CRYPv1/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/DACv1/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/DMAv2/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/EXTIv1/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/FDCANv1/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/GPIOv2/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/I2Cv3/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/MACv2/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/MDMAv1/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/OTGv1/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/QUADSPIv2/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/SDMMCv2/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/SPIv3/driver_v2.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/RNGv1/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/RTCv2/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/SYSTICKv1/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/TIMv1/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/USARTv3/driver.mk
include $(CHIBIOS)/os/hal/ports/STM32/LLD/xWDGv1/driver.mk

# Shared variables
ALLCSRC += $(PLATFORMSRC)
ALLINC  += $(PLATFORMINC)
  • 平台移植部分:

a) $(CHIBIOS)/os/hal/ports/common/ARMCMx/nvic.c
b) $(CHIBIOS)/os/hal/ports/STM32/STM32H7xx/stm32_isr.c
c) $(CHIBIOS)/os/hal/ports/STM32/STM32H7xx/hal_lld.c

  • 接口移植部分:

a) $(CHIBIOS)/os/hal/ports/STM32/LLD/ADCv4/driver.mk
b) $(CHIBIOS)/os/hal/ports/STM32/LLD/BDMAv1/driver.mk
c) $(CHIBIOS)/os/hal/ports/STM32/LLD/CRYPv1/driver.mk
d) $(CHIBIOS)/os/hal/ports/STM32/LLD/DACv1/driver.mk
e) $(CHIBIOS)/os/hal/ports/STM32/LLD/DMAv2/driver.mk
f) $(CHIBIOS)/os/hal/ports/STM32/LLD/EXTIv1/driver.mk
g) $(CHIBIOS)/os/hal/ports/STM32/LLD/FDCANv1/driver.mk
h) $(CHIBIOS)/os/hal/ports/STM32/LLD/GPIOv2/driver.mk
i) $(CHIBIOS)/os/hal/ports/STM32/LLD/I2Cv3/driver.mk
j) $(CHIBIOS)/os/hal/ports/STM32/LLD/MACv2/driver.mk
k) $(CHIBIOS)/os/hal/ports/STM32/LLD/MDMAv1/driver.mk
l) $(CHIBIOS)/os/hal/ports/STM32/LLD/OTGv1/driver.mk
m) $(CHIBIOS)/os/hal/ports/STM32/LLD/QUADSPIv2/driver.mk
n) $(CHIBIOS)/os/hal/ports/STM32/LLD/SDMMCv2/driver.mk
o) $(CHIBIOS)/os/hal/ports/STM32/LLD/SPIv3/driver_v2.mk
p) $(CHIBIOS)/os/hal/ports/STM32/LLD/RNGv1/driver.mk
q) $(CHIBIOS)/os/hal/ports/STM32/LLD/RTCv2/driver.mk
r) $(CHIBIOS)/os/hal/ports/STM32/LLD/SYSTICKv1/driver.mk
s) $(CHIBIOS)/os/hal/ports/STM32/LLD/TIMv1/driver.mk
t) $(CHIBIOS)/os/hal/ports/STM32/LLD/USARTv3/driver.mk
u) $(CHIBIOS)/os/hal/ports/STM32/LLD/xWDGv1/driver.mk

5. 总结

通过分析ChibiOS总体框图和Makefile,初步分析移植ChibiOS到特定的MCU上,需要完成的工作量。

通过科学合理安排:a) 任务优先级;b) 移植工作切片/分割;可逐步推进、完成相应移植工作。

6. 参考资料

【1】Ardupilot开源飞控之ChibiOS简介
【2】ARTERY AT32F435
【3】ST STM32F405/415

文章来源:https://blog.csdn.net/lida2003/article/details/135112271
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。