Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
BSP
RT-Thread
rt-thread主仓 BSP瘦身指南
发布于 2025-04-07 22:49:01 浏览:23
订阅该版
[tocm] # BSP瘦身指南说明 ## 1. 为什么要实施BSP瘦身计划 由于bsp目前过于大,现在大家下载整个rtthread也过于庞大,但是下下来之后,大部分是bsp的内容,bsp和.git的内容占到大小的90%左右。 实际上RTTHREAD内部代码占到100M左右,包括文档。差不多3%左右。目前BSP大头也是芯片比较多的厂商。 之前为了方便大家能够实现开箱即用的快速开发形式,将HAL库放到BSP中,但是随着bsp越来越多,HAL也越来越庞大,而且大部分是用不到的芯片。所以为了能够方便各个芯片用户的快速使用,将厂商SDK以软件包的形式上传,保留RTTHREAD的适配,可以放到BSP中。 本指南以stm32为例。 ## 2. 操作流程 > 操作流程大致可以分为三步。以 **stm32f4** 为例。 ### 1. 软件包索引仓库更新 - 软件包目前统一放到下面的目录中,bsp中默认选中即可。 https://github.com/RT-Thread/packages/tree/master/peripherals/hal-sdk ##### 1. fork一份软件包索引仓库 **仓库地址:**[RT-Thread/packages: packages index repository for rt-thread.](https://github.com/RT-Thread/packages)  ##### 2. 将fork的仓库克隆到本地 ```bash git clone https://github.com/fengmuyou/packages.git ```  ##### 3. 打开本地仓库进行修改 在本地打开克隆的索引仓库,创建一个新的分支,在**packages\peripherals\hal-sdk**路径下创建**stm32**文件夹 ```bash git checkout -b "f4_hal" //创建一个新分支 ```  ##### 4. 添加stm32f4索引文件夹 在**stm32**下添加**stm32f4_cmsis_driver**文件夹和**stm32f4_hal_driver**文件夹,在两个文件夹下分别添加**Kconfig**、**package.json**这两个文件 - **stm32f4_cmsis_drivers** - **Kconfig** ```makefile # Kconfig file for package stm32f4_cmsis_driver menuconfig PKG_USING_STM32F4_CMSIS_DRIVER bool "STM32 F4 CMSIS driver package" select PKG_USING_CMSIS_CORE default n if PKG_USING_STM32F4_CMSIS_DRIVER config PKG_STM32F4_CMSIS_DRIVER_PATH string default "/packages/peripherals/hal-sdk/stm32/stm32f4_cmsis_driver" choice prompt "Version" help Select the package version config PKG_USING_STM32F4_CMSIS_DRIVER_LATEST_VERSION bool "latest" endchoice config PKG_STM32F4_CMSIS_DRIVER_VER string default "latest" if PKG_USING_STM32F4_CMSIS_DRIVER_LATEST_VERSION endif ``` - **package.json** ```java { "name": "stm32f4_cmsis_driver", "description": "STM32 F4 CMSIS driver package", "description_zh": "STM32 F4 CMSIS 驱动包", "enable": "PKG_USING_STM32F4_CMSIS_DRIVER", "keywords": [ "stm32f4_cmsis_driver", "STM32" ], "category": "peripherals", "author": { "name": "RT-Thread-packages", "email": "package_team@rt-thread.com", "github": "RT-Thread-packages" }, "license": "Apache-2.0", "repository": "https://github.com/RT-Thread-packages/stm32f4_cmsis_driver", "icon": "unknown", "homepage": "https://github.com/RT-Thread-packages/stm32f4_cmsis_driver#readme", "doc": "unknown", "site": [ { "version": "latest", "URL": "https://github.com/RT-Thread-packages/stm32f4_cmsis_driver.git", "filename": "", "VER_SHA": "master" } ] } ``` - **stm32f4_hal_driver** - **Kconfig** ```makefile # Kconfig file for package stm32f4_hal_driver menuconfig PKG_USING_STM32F4_HAL_DRIVER bool "STM32 F4 HAL driver package" select PKG_USING_STM32F4_CMSIS_DRIVER default n if PKG_USING_STM32F4_HAL_DRIVER config PKG_STM32F4_HAL_DRIVER_PATH string default "/packages/peripherals/hal-sdk/stm32/stm32f4_hal_driver" choice prompt "Version" help Select the package version config PKG_USING_STM32F4_HAL_DRIVER_LATEST_VERSION bool "latest" endchoice config PKG_STM32F4_HAL_DRIVER_VER string default "latest" if PKG_USING_STM32F4_HAL_DRIVER_LATEST_VERSION endif ``` - **package.json** ```java { "name": "stm32f4_hal_driver", "description": "STM32 F4 HAL driver package", "description_zh": "STM32 F4 HAL 驱动包", "enable": "PKG_USING_STM32F4_HAL_DRIVER", "keywords": [ "stm32f4_hal_driver", "STM32" ], "category": "peripherals", "author": { "name": "RT-Thread-packages", "email": "package_team@rt-thread.com", "github": "RT-Thread-packages" }, "license": "BSD-3-Clause", "repository": "https://github.com/RT-Thread-packages/stm32f4_hal_driver", "icon": "unknown", "homepage": "https://github.com/RT-Thread-packages/stm32f4_hal_driver#readme", "doc": "unknown", "site": [ { "version": "latest", "URL": "https://github.com/RT-Thread-packages/stm32f4_hal_driver.git", "filename": "", "VER_SHA": "master" } ] } ``` **注意!!!**:**仓库地址要保证正确,软件包才能正确的被拉下来**。  ##### 5. 修改Kconfig文件 在**stm32**文件夹下的 **Kconfig** 文件里添加配置,确保能找到对应的**Kconfig**文件  ##### 6. 工作流文件修改 在**workflows/aciont_tool.yml** 文件里添加 **pkgs --update**,这个修改一次即可,后续添加其他软件包索引不用再修改。  ##### 7. 修改完之后进行提交 ```bash git add . git commit -m "add stm32_f4 软件包仓库索引" git push origin f4_hal ``` ##### 8. 创建pr,等待审核合并。 ### 2. 软件包仓库更新 ##### 1. 软件包分为cmsis与drivers - 首先就是分别 *fork* **cmsis **与 **drivers** 两个软件包仓库,并克隆仓库到本地,在本地创建一个新分支再进行修改。 ##### 2. 适配stm32f4_cmsis_driver - 创建一个新的分支 ```bash git checkout -b f4_cmsis //创建一个新分支 ``` - 添加 **SConscript** 文件 - 添加 **启动文件** 选择以及 **system_stm32f4xx.c** 文件,芯片型号宏定义在 **stm32f4xx.h** 文件下可以找到。 ```python from building import * import os # Import environment variables Import('env') # Get the current working directory cwd = GetCurrentDir() # Initialize include paths and source files list path = [os.path.join(cwd, 'Include')] src = [os.path.join(cwd, 'Source', 'Templates', 'system_stm32f4xx.c')] # Map microcontroller units (MCUs) to their corresponding startup files mcu_startup_files = { 'STM32F401xC': 'startup_stm32f401xc.s', 'STM32F401xE': 'startup_stm32f401xe.s', 'STM32F405xx': 'startup_stm32f405xx.s', 'STM32F407xx': 'startup_stm32f407xx.s', 'STM32F410Cx': 'startup_stm32f410cx.s', 'STM32F410Rx': 'startup_stm32f410rx.s', 'STM32F410Tx': 'startup_stm32f410tx.s', 'STM32F411xE': 'startup_stm32f411xe.s', 'STM32F412Cx': 'startup_stm32f412cx.s', 'STM32F412Rx': 'startup_stm32f412rx.s', 'STM32F412Vx': 'startup_stm32f412vx.s', 'STM32F412Zx': 'startup_stm32f412zx.s', 'STM32F413xx': 'startup_stm32f413xx.s', 'STM32F415xx': 'startup_stm32f415xx.s', 'STM32F417xx': 'startup_stm32f417xx.s', 'STM32F423xx': 'startup_stm32f423xx.s', 'STM32F427xx': 'startup_stm32f427xx.s', 'STM32F429xx': 'startup_stm32f429xx.s', 'STM32F437xx': 'startup_stm32f437xx.s', 'STM32F439xx': 'startup_stm32f439xx.s', 'STM32F446xx': 'startup_stm32f446xx.s', 'STM32F469xx': 'startup_stm32f469xx.s', 'STM32F479xx': 'startup_stm32f479xx.s', } # Check each defined MCU, match the platform and append the appropriate startup file for mcu, startup_file in mcu_startup_files.items(): if mcu in env.get('CPPDEFINES', []): if rtconfig.PLATFORM in ['gcc', 'llvm-arm']: src += [os.path.join(cwd, 'Source', 'Templates', 'gcc', startup_file)] elif rtconfig.PLATFORM in ['armcc', 'armclang']: src += [os.path.join(cwd, 'Source', 'Templates', 'arm', startup_file)] elif rtconfig.PLATFORM in ['iccarm']: src += [os.path.join(cwd, 'Source', 'Templates', 'iar', startup_file)] break # Define the build group group = DefineGroup('STM32F4-CMSIS', src, depend=['PKG_USING_STM32F4_CMSIS_DRIVER'], CPPPATH=path) # Return the build group Return('group') ``` - 添加 **stm32_update.py** 文件,并运行,对启动文件进行修改 ps:该文件可在软件包stm32f4_cmsis_driver下查看。 ``` python stm32_update.py //运行stm32_update.py ``` ps:对启动文件修改主要是将**gcc**下启动文件的入口函数由 **main** 改成 **entry**。  以及将**arm**下启动文件的堆的大小改为0。  - 修改完成后提交 ```bash git add . git commit -m "adapt stm32f4 cmsis for rtt" git push origin f4_cmsis ``` - 创建pr,等待审核合并。 ##### 3. 适配stm32f4_hal_driver - 创建一个新的分支 ```bash git checkout -b f4_drivers //创建一个新分支 ``` - 添加 **SConscript **文件,可根据 **rt-thread\bsp\stm32\libraries\STM32F4xx_HAL** 文件夹下的 **SConscript** 对应着修改,改变文件引用的路径。 ```python from building import * import os cwd = GetCurrentDir() path = [os.path.join(cwd, 'Inc')] src_path = os.path.join(cwd, 'Src') path += [os.path.join(cwd, 'Inc/Legacy')] CPPDEFINES = ['USE_HAL_DRIVER'] src = [ os.path.join(src_path, 'stm32f4xx_hal.c'), os.path.join(src_path, 'stm32f4xx_hal_cec.c'), os.path.join(src_path, 'stm32f4xx_hal_cortex.c'), os.path.join(src_path, 'stm32f4xx_hal_crc.c'), os.path.join(src_path, 'stm32f4xx_hal_cryp.c'), os.path.join(src_path, 'stm32f4xx_hal_cryp_ex.c'), os.path.join(src_path, 'stm32f4xx_hal_dma.c'), os.path.join(src_path, 'stm32f4xx_hal_dma_ex.c'), os.path.join(src_path, 'stm32f4xx_hal_pwr.c'), os.path.join(src_path, 'stm32f4xx_hal_pwr_ex.c'), os.path.join(src_path, 'stm32f4xx_hal_rcc.c'), os.path.join(src_path, 'stm32f4xx_hal_rcc_ex.c'), os.path.join(src_path, 'stm32f4xx_hal_rng.c'), os.path.join(src_path, 'stm32f4xx_hal_gpio.c'), ] if GetDepend(['RT_USING_SERIAL']) or GetDepend(['RT_USING_NANO', 'RT_USING_CONSOLE']): src += [os.path.join(src_path, 'stm32f4xx_hal_uart.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_usart.c')] if GetDepend(['RT_USING_I2C']): src += [os.path.join(src_path, 'stm32f4xx_hal_i2c.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_i2c_ex.c')] if GetDepend(['RT_USING_SPI']): src += [os.path.join(src_path, 'stm32f4xx_hal_spi.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_qspi.c')] if GetDepend(['RT_USING_USB']): src += [os.path.join(src_path, 'stm32f4xx_hal_pccard.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_pcd.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_pcd_ex.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_hcd.c')] src += [os.path.join(src_path, 'stm32f4xx_ll_usb.c')] if GetDepend(['RT_USING_CAN']): src += [os.path.join(src_path, 'stm32f4xx_hal_can.c')] if GetDepend(['RT_USING_HWTIMER']) or GetDepend(['RT_USING_PWM']) or GetDepend(['RT_USING_PULSE_ENCODER']): src += [os.path.join(src_path, 'stm32f4xx_hal_tim.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_tim_ex.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_lptim.c')] if GetDepend(['BSP_USING_ETH']): if GetDepend(['BSP_ETH_LEGACY_MODULE_ENABLED']): src += [os.path.join(src_path, 'Legacy/stm32f4xx_hal_eth.c')] else: src += [os.path.join(src_path, 'stm32f4xx_hal_eth.c')] if GetDepend(['RT_USING_ADC']): src += [os.path.join(src_path, 'stm32f4xx_hal_adc.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_adc_ex.c')] if GetDepend(['RT_USING_DAC']): src += [os.path.join(src_path, 'stm32f4xx_hal_dac.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_dac_ex.c')] if GetDepend(['RT_USING_RTC']): src += [os.path.join(src_path, 'stm32f4xx_hal_rtc.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_rtc_ex.c')] if GetDepend(['RT_USING_WDT']): src += [os.path.join(src_path, 'stm32f4xx_hal_iwdg.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_wwdg.c')] if GetDepend(['RT_USING_SDIO']): src += [os.path.join(src_path, 'stm32f4xx_ll_sdmmc.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_sd.c')] if GetDepend(['RT_USING_AUDIO']): src += [os.path.join(src_path, 'stm32f4xx_hal_i2s.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_i2s_ex.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_sai.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_sai_ex.c')] if GetDepend(['RT_USING_MTD_NOR']): src += [os.path.join(src_path, 'stm32f4xx_hal_nor.c')] if GetDepend(['RT_USING_MTD_NAND']): src += [os.path.join(src_path, 'stm32f4xx_hal_nand.c')] if GetDepend(['BSP_USING_FMC']): src += [os.path.join(src_path, 'stm32f4xx_ll_fmc.c')] src += [os.path.join(src_path, 'stm32f4xx_ll_fsmc.c')] if GetDepend(['BSP_USING_SDRAM']): src += [os.path.join(src_path, 'stm32f4xx_hal_sdram.c')] if GetDepend(['BSP_USING_EXT_FMC_IO']): src += [os.path.join(src_path, 'stm32f4xx_hal_sram.c')] if GetDepend(['BSP_USING_ON_CHIP_FLASH']): src += [os.path.join(src_path, 'stm32f4xx_hal_flash.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_flash_ex.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_flash_ramfunc.c')] if GetDepend(['BSP_USING_LTDC']): src += [os.path.join(src_path, 'stm32f4xx_hal_ltdc.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_ltdc_ex.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_dma2d.c')] src += [os.path.join(src_path, 'stm32f4xx_ll_dma2d.c')] src += [os.path.join(src_path, 'stm32f4xx_hal_dsi.c')] group = DefineGroup('STM32F4-HAL', src, depend = ['PKG_USING_STM32F4_HAL_DRIVER'], CPPPATH = path, CPPDEFINES = CPPDEFINES) Return('group') ``` - 修改完成后提交 ```bash git add . git commit -m "adapt stm32f4 drivers for rtt" git push origin f4_drivers ``` - 创建pr,等待审核合并。 ### 3. 主线仓库更新 > 这里bsp的修改以**stm32f407-rt-spark**为例,具体的需要把f4系列所有的bsp都进行修改,编译测试通过后再提交。 ##### 1. 准备工作 **fork** 一份最新的主线仓库,克隆到本地,基于**master**分支创建一个新的分支。 - 创建一个新的分支 ```bash git checkout -b f4_sdk ``` ##### 2. 在主线仓库目录(bsp\stm32\libraries\Kconfig)中 select PKG_USING_STM32xx_HAL_DRIVER  ##### 3. 修改SConstruct文件  ##### 4. board文件夹下的SConscript  ##### 5. 在port文件夹下添加SConscript文件  **ps**: **stm32f407-rt-spark** 的 port 文件夹下有**SConscript**文件,我们只需简单的修改即可。有些bsp的port文件下没有**SConscript**文件,需要我们自己添加,可以参考这里进行修。 ##### 6. 在 README.md 文件添加说明 在 **快速上手** 下添加说明 - **中文版本** ~~~bash **请注意!!!** 在执行编译工作前请先打开ENV执行以下指令(该指令用于拉取必要的HAL库及CMSIS库,否则无法通过编译): ```bash pkgs --update ``` ~~~ - **英文版本** ~~~bash **Attention please!!!** Before the compilation work, please open ENV and execute the following command (this command is used to pull the necessary HAL library and CMSIS library, otherwise it cannot be compiled): ```bash pkgs --update ``` ~~~ ##### 7.编译结果 > 确保能编译 packages 下的 f4_hal 文件  ##### 8. 烧录测试 > 将rt-thread.elf文件烧录到板子上,观察是否能够正常运行。  ***ps:板子支持的一些外设也需要在env中开启,进行编译测试。*** ##### 9. 删除主线上的STM32F4_HAL驱动 ***ps: 请把f4系列所有的bsp都进行修改,测试通过后在删除主线上的 STM32F4_HAL 驱动。***  ##### 10.修改工作流文件 在**workflows/aciont_tool.yml** 文件里添加 **pkgs --update**,这个修改一次即可,后续添加其他修改其他bsp不用再修改。  ##### 11.提交到远程仓库 全部测试没问题后,提交的远程仓库。 ```bash git add . git commit -m "bsp:Separate STM32F4 HAL drivers" git push origin f4_sdk ``` ##### 12. 创建pr,等待审核合并。
0
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
mushroom
这家伙很懒,什么也没写!
文章
1
回答
0
被采纳
0
关注TA
发私信
相关文章
1
STM32 407 串口接收数据 系统卡死
2
RTT nrf24l01 设备驱动程序
3
stm32f10x串口只能发送数据,无法接收
4
第一次尝试移植rt-thread 到stm32F103系列问题
5
有人把stm32L07xx的bsp移到rtt上来了吗?求一个
6
rt-thread线程调度异常在stm32f103芯片上
7
RTT是否支持STM32F429
8
请问谁有 STM32F40x HAL + RT-THREAD 模板
9
rt-thread在stm32f411下的移植问题
10
针对STM32F7系列平台的MPU,Cache特性,需要注意哪些问题?
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
rt-smart
RTC
FAL
I2C_IIC
cubemx
ESP8266
UART
WIZnet_W5500
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
GD32
定时器
ADC
flashDB
编译报错
socket
中断
rt_mq_消息队列_msg_queue
keil_MDK
Debug
SFUD
ulog
msh
C++_cpp
at_device
本月问答贡献
RTT_逍遥
4
个答案
2
次被采纳
踩姑娘的小蘑菇
4
个答案
1
次被采纳
a1012112796
3
个答案
1
次被采纳
聚散无由
3
个答案
1
次被采纳
加缪
1
个答案
1
次被采纳
本月文章贡献
出出啊
1
篇文章
2
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
3
次点赞
crystal266
2
篇文章
1
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部