MC02 开发板(STM32H723VGTx)的 LibXR / XRobot BSP / LibXR and XRobot BSP for the MC02 board (STM32H723VGTx)
MC02 开发板使用 STM32H723VGTx,系统为 FreeRTOS,终端通过 USB HS CDC(usb_otg_hs_cdc)提供。外设由 CubeMX 工程 CtrBoard-H7_ALL.ioc 配置,libxr 命令生成入口源文件 User/app_main.cpp,并在其中用 XR_REGISTER 完成硬件注册,覆盖 GPIO、PWM、ADC、DAC、SPI、UART、FDCAN、RamFS、终端和 Database。每个 FDCAN 同时以 fdcanN(LibXR::FDCAN)和 canN(LibXR::CAN)注册。配置中的硬件名即这些注册名,例如 pwm_tim12_ch2、spi2、usart1、fdcan1。数据库 database 由 User/libxr_config.yaml 中 database 的设置生成,block_size 为 32,即 H7 Flash 的最小写入单元(32 字节)。
CtrBoard-H7_ALL.ioc CubeMX 工程
Core/ Drivers/ CubeMX 生成的初始化代码与 ST HAL / CMSIS
Middlewares/ FreeRTOS、LibXR 子模块
Modules/modules.yaml 使用的模块(`xrobot:` 记录 XRobot 版本)
Modules/sources.yaml 源
xrobot.lock 每个模块使用的提交(lock)
User/app_main.cpp 入口源文件,硬件注册并调用 XROBOT_MAIN()
User/libxr_config.yaml LibXR 外设参数,包括数据库(`generator:` 记录 CodeGenerator 版本)
User/xrobot.yaml 配置
cmake/ 工具链文件(CubeMX 写出的原文)与 LibXR.CMake(编译设置)
Modules/<owner>/<Repo>/、Modules/CMakeLists.txt 和 User/xrobot_main.hpp 由 xrobot 生成,已列入 .gitignore。
The MC02 board uses an STM32H723VGTx and runs FreeRTOS. The terminal is provided over USB HS CDC (usb_otg_hs_cdc). The peripherals are configured in the CubeMX project CtrBoard-H7_ALL.ioc; the libxr command generates the entry source User/app_main.cpp, which performs the hardware registration with XR_REGISTER for GPIO, PWM, ADC, DAC, SPI, UART, FDCAN, RamFS, the terminal and the Database. Each FDCAN is registered both as fdcanN (LibXR::FDCAN) and as canN (LibXR::CAN). The hardware names used in a configuration are these registered names, for example pwm_tim12_ch2, spi2, usart1 and fdcan1. The database database is generated from the database setting in User/libxr_config.yaml, with block_size 32, the minimum write unit of the H7 Flash (32 bytes).
Modules/<owner>/<Repo>/, Modules/CMakeLists.txt and User/xrobot_main.hpp are generated by xrobot and listed in .gitignore.
| 配置 | 用途 |
|---|---|
User/xrobot.yaml |
蜂鸣器报警:xrobot-org/BuzzerAlarm 实例 buzzer 使用 pwm_tim12_ch2,报警频率 1500 Hz,报警时长与间隔均为 300 ms |
配置的格式见 XRobot 文档。
| Configuration | Purpose |
|---|---|
User/xrobot.yaml |
Buzzer alarm: xrobot-org/BuzzerAlarm instance buzzer on pwm_tim12_ch2, alarm frequency 1500 Hz, alarm duration and delay 300 ms each |
The configuration format is described in the XRobot documentation.
构建使用 CMake、Ninja 和 ST 的 starm-clang 工具链(STM32CubeCLT 或 VS Code STM32Cube 扩展提供),starm-clang 位于 PATH 中。预设使用 cmake/starm-clang.cmake(picolibc 配置)。XRobot 为 1.0.0,LibXR CodeGenerator 为 6.0.0,与 Modules/modules.yaml 的 xrobot: 和 User/libxr_config.yaml 的 generator: 一致。
git clone --recursive https://github.com/QDU-Robomaster/bsp-dev-mc02.git
cd bsp-dev-mc02
pip install xrobot==1.0.0 libxr==6.0.0
xrobot setup
cmake --preset Debug
cmake --build --preset Debugxrobot setup 拉取模块、检查配置并生成 User/xrobot_main.hpp。CMake 预设为 Debug 和 Release,产物为 build/<预设>/CtrBoard-H7_ALL.elf;未指定构建类型时 CMakeLists.txt 使用 Debug。应用代码的优化级别为 Debug -Og、Release -Os,由 cmake/LibXR.CMake 开头 “Project settings” 块中的 LIBXR_OPT_DEBUG 和 LIBXR_OPT_RELEASE 设置,作用范围见 LibXR.CMake。
在 CubeMX 中修改并重新生成代码后,运行 libxr stm32 setup 更新 User/app_main.cpp、User/app_main.h、User/flash_map.hpp、User/libxr_config.yaml 和 cmake/LibXR.CMake,User Code 区域保留。命令说明见 LibXR_CppCodeGenerator。
.github/workflows/xrobot_stm32.yml 调用 XRobot 仓库中的共享工作流 bsp-stm32-ci.yml,写出工程名 CtrBoard-H7_ALL 和构建类型 Debug,构建默认配置的固件;推送到 master(打下一个补丁号标签)或推送 v* 标签时发布该固件。共享工作流的检查项与发布的文件见 BSP CI。
Building uses CMake, Ninja and ST's starm-clang toolchain (provided by STM32CubeCLT or the VS Code STM32Cube extension), with starm-clang on PATH. The presets use cmake/starm-clang.cmake (picolibc configuration). XRobot is 1.0.0 and the LibXR CodeGenerator is 6.0.0, matching xrobot: in Modules/modules.yaml and generator: in User/libxr_config.yaml.
xrobot setup fetches the Modules, checks the configurations and generates User/xrobot_main.hpp. The CMake presets are Debug and Release, and the output is build/<preset>/CtrBoard-H7_ALL.elf; without a build type, CMakeLists.txt uses Debug. The application code is optimized with -Og in Debug and -Os in Release, set by LIBXR_OPT_DEBUG and LIBXR_OPT_RELEASE in the "Project settings" block at the top of cmake/LibXR.CMake; what each setting applies to is described in LibXR.CMake.
After changing and regenerating the code in CubeMX, libxr stm32 setup updates User/app_main.cpp, User/app_main.h, User/flash_map.hpp, User/libxr_config.yaml and cmake/LibXR.CMake, and keeps the User Code regions. The commands are described in LibXR_CppCodeGenerator.
.github/workflows/xrobot_stm32.yml calls the shared workflow bsp-stm32-ci.yml of the XRobot repository and names the project CtrBoard-H7_ALL and the build type Debug, building the firmware of the default configuration; a push to master, which tags the next patch version, or a v* tag push publishes that firmware. The checks of the shared workflow and the published files are described in BSP CI.
DevMC02.jdebug 是 SEGGER Ozone 工程,设备为 STM32H723VG,调试接口为 SWD(4 MHz),加载 build/Debug/CtrBoard-H7_ALL.elf。先构建 Debug 预设,再在 Ozone 中打开该工程即可下载并调试。运行后通过 USB HS CDC 连接终端。
DevMC02.jdebug is a SEGGER Ozone project for the STM32H723VG over SWD (4 MHz) that loads build/Debug/CtrBoard-H7_ALL.elf. After building the Debug preset, opening the project in Ozone downloads and debugs the firmware. At run time the terminal is available over USB HS CDC.
本仓库以 Apache-2.0 发布,见 LICENSE;随仓库分发的第三方代码的许可见 NOTICE。
This repository is released under Apache-2.0, see LICENSE; the licenses of the bundled third-party code are listed in NOTICE.