Skip to content

Commit b245c18

Browse files
CYFS3Rbb666
authored andcommitted
[docs]Update the contribution document
1 parent dd7da0f commit b245c18

7 files changed

Lines changed: 258 additions & 36 deletions

File tree

documentation/7.contribution/INDEX.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ All the real-time operating system kernel and open source components can be used
88

99
@subpage page_rtt_code_style_en
1010

11-
@subpage page_howto_doxygen
11+
@subpage page_bsp_contribution_guide_en
12+
13+
@subpage page_howto_doxygen
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# BSP 贡献规范
2+
3+
本文说明新增或调整 BSP 时应遵循的目录层级关系,避免把板级、芯片级和架构级代码混放。
4+
5+
## BSP 目录层级
6+
7+
BSP 目录根据共享代码所在层级,主要分为厂商级共享和厂商 + 系列级共享两类。无论采用哪种结构,都应遵循以下原则:
8+
9+
- `board/` 放置板级初始化、引脚、时钟、链接脚本等只属于当前开发板的内容。
10+
- 上层或同级共享 `libraries/` 放置同一厂商或同一系列 BSP 共用的芯片库、HAL、CMSIS、SDK、驱动和驱动适配代码,驱动目录也应放在 `libraries/` 下。
11+
- 同级 `tools/` 放置同一厂商或同一系列 BSP 共用的辅助脚本。
12+
13+
若多个 BSP 共用同一个软件包或 SDK,不应在每个 BSP 目录下重复维护,应放在共享层级或使用软件包机制,并由 BSP 通过构建脚本引用。新增 BSP 时不要随意新建额外层级,也不要把 BSP 代码放入 `components/``src/``include/` 等非 BSP 目录;抽象驱动框架属于 `components/drivers/`,芯片或 CPU 架构公共移植代码属于 `libcpu/`
14+
15+
### 厂商级共享目录结构(以 STM32 为例)
16+
17+
STM32 BSP 通常直接位于 `bsp/stm32/<board>`,同一厂商下多个 BSP 共用的驱动适配、模板、工具和软件包选择放在 `bsp/stm32/libraries/``bsp/stm32/tools/`
18+
19+
```text
20+
bsp/stm32/
21+
├── libraries/
22+
│ ├── HAL_Drivers/ # STM32 BSP 共用的驱动适配
23+
│ ├── drivers/ # 多个 STM32 BSP 共用的驱动(如有)
24+
│ ├── templates/ # 新增 BSP 参考模板
25+
│ └── Kconfig # 原厂 HAL/CMSIS 软件包选择
26+
├── tools/ # 厂商级辅助脚本
27+
├── stm32f407-atk-explorer/
28+
│ ├── board/ # 当前开发板专用的初始化、引脚、时钟、链接脚本
29+
│ ├── Kconfig
30+
│ ├── SConscript
31+
│ └── SConstruct
32+
└── stm32f429-atk-apollo/
33+
├── board/
34+
├── Kconfig
35+
├── SConscript
36+
└── SConstruct
37+
```
38+
39+
### 厂商 + 系列级共享目录结构(以 NXP 为例)
40+
41+
NXP 这类 BSP 通常会先按厂商、产品线或芯片系列分层,再把当前系列共用的驱动适配、模板、工具和软件包选择放在系列目录下。例如 i.MX RT 使用 `bsp/nxp/imx/imxrt/libraries/`,LPC55S 使用 `bsp/nxp/lpc/lpc55sxx/libraries/`,MCX 按 `mcxa``mcxc``mcxe``mcxn` 等系列分别维护 `libraries/`
42+
43+
NXP 目录下也存在一些历史 BSP,例如 `lpc176x` 这类单 BSP 目录,或少量旧目录使用 `Libraries/` 命名。新增或重构 BSP 时不应继续扩散旧结构;若驱动、SDK 或模板需要被多个 BSP 复用,应迁移或放入对应系列的 `libraries/``tools/` 层级。
44+
45+
```text
46+
bsp/nxp/
47+
├── imx/
48+
│ └── imxrt/
49+
│ ├── libraries/
50+
│ │ ├── drivers/ # i.MX RT 系列共用的驱动和驱动适配
51+
│ │ ├── templates/ # 新增 BSP 参考模板
52+
│ │ └── Kconfig # NXP i.MX RT SDK 软件包选择
53+
│ ├── tools/ # 当前系列 BSP 共用的辅助脚本
54+
│ └── imxrt1052-nxp-evk/
55+
│ ├── board/ # 当前开发板专用的初始化、引脚、时钟、链接脚本
56+
│ ├── Kconfig
57+
│ ├── SConscript
58+
│ └── SConstruct
59+
├── lpc/
60+
│ └── lpc55sxx/
61+
│ ├── libraries/ # LPC55S 系列共用的驱动适配、模板和软件包选择
62+
│ ├── tools/
63+
│ └── lpc55s69_nxp_evk/
64+
│ ├── board/
65+
│ ├── Kconfig
66+
│ ├── SConscript
67+
│ └── SConstruct
68+
└── mcx/
69+
├── tools/ # MCX 系列共用工具
70+
└── mcxn/
71+
├── libraries/ # MCXN 系列共用的 CMSIS、系列驱动和软件包选择
72+
└── frdm-mcxn947/
73+
├── board/
74+
├── Kconfig
75+
├── SConscript
76+
└── SConstruct
77+
```
78+
79+
### 原厂 HAL/SDK 软件包
80+
81+
若原厂 HAL、CMSIS 或 SDK 已经以 RT-Thread 软件包形式提供,BSP 不应再提交或维护重复的完整源码副本。BSP 应通过 `Kconfig` 选择相应 `PKG_USING_*` 软件包,并在 `SConscript` 中按配置引用软件包内容;`pkgs --update` 负责下载软件包源码。
82+
83+
这种情况下,`libraries/` 主要保留驱动适配、可复用驱动、模板、工具脚本和软件包选择逻辑。不要把 `pkgs --update` 下载出的软件包目录作为 BSP 源码提交,也不要让 `scons --dist` 打包当前 BSP 没有启用的软件包或库文件。
84+
85+
## 提交要求
86+
87+
- 新增 BSP 应保持层级清晰,只提交当前开发板必需的板级文件。
88+
- 同一厂商或同一系列 BSP 共用的库、驱动适配、可复用驱动、模板和脚本应放在共享 `libraries/``tools/` 层级,避免在多个 BSP 中重复拷贝。
89+
- 驱动适配代码和可复用驱动应放在 `libraries/` 下,不应放在单个开发板目录中。
90+
- 原厂 HAL、CMSIS 或 SDK 已软件包化时,应优先通过软件包机制引用,不应在 BSP 中重复提交软件包源码。
91+
- 构建脚本应从共享层级引用公共代码,`scons --dist` 打包时不应带入当前 BSP 不需要的软件包或库文件。
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
@page page_bsp_contribution_guide_en BSP Contribution Guide
2+
3+
# BSP Contribution Guide
4+
5+
This document describes the directory hierarchy requirements for adding or
6+
updating BSPs, so board-level, chip-level, and architecture-level code stay in
7+
clear layers.
8+
9+
## BSP Directory Hierarchy
10+
11+
BSP directories usually fall into two hierarchy styles depending on where shared
12+
code is kept: vendor-level sharing, and vendor + series-level sharing. In either
13+
case, follow these principles:
14+
15+
- `board/` contains board initialization, pin settings, clock settings, linker
16+
scripts, and other files that only belong to the current board.
17+
- The upper or sibling shared `libraries/` directory contains chip libraries,
18+
HAL, CMSIS, SDK, drivers, and driver adaptation code shared by BSPs from the
19+
same vendor or series. Driver directories should also be placed under
20+
`libraries/`.
21+
- The sibling `tools/` directory contains helper scripts shared by BSPs from the
22+
same vendor or series.
23+
24+
If multiple BSPs share the same package or SDK, do not maintain duplicate copies
25+
under each BSP. Put the shared source in the common layer or use the package
26+
mechanism, then reference it from the BSP build scripts. When adding a BSP, do
27+
not create extra directory levels without a clear need, and do not place BSP
28+
code under non-BSP directories such as `components/`, `src/`, or `include/`.
29+
Abstract driver frameworks belong in `components/drivers/`, and shared chip or
30+
CPU architecture porting code belongs in `libcpu/`.
31+
32+
### Vendor-Level Shared Layout (STM32 Example)
33+
34+
STM32 BSPs are usually placed directly under `bsp/stm32/<board>`. Driver
35+
adaptation code, templates, tools, and package selections shared by STM32 BSPs
36+
are kept under `bsp/stm32/libraries/` and `bsp/stm32/tools/`:
37+
38+
```text
39+
bsp/stm32/
40+
├── libraries/
41+
│ ├── HAL_Drivers/ # Driver adaptation shared by STM32 BSPs
42+
│ ├── drivers/ # Drivers shared by multiple STM32 BSPs, if any
43+
│ ├── templates/ # Reference templates for new BSPs
44+
│ └── Kconfig # Vendor HAL/CMSIS package selections
45+
├── tools/ # Vendor-level helper scripts
46+
├── stm32f407-atk-explorer/
47+
│ ├── board/ # Board-only initialization, pins, clocks, linker scripts
48+
│ ├── Kconfig
49+
│ ├── SConscript
50+
│ └── SConstruct
51+
└── stm32f429-atk-apollo/
52+
├── board/
53+
├── Kconfig
54+
├── SConscript
55+
└── SConstruct
56+
```
57+
58+
### Vendor + Series-Level Shared Layout (NXP Example)
59+
60+
NXP-style BSPs are usually split first by vendor, product line, or chip series.
61+
Driver adaptation code, templates, tools, and package selections shared by a
62+
series are kept under that series directory. For example, i.MX RT uses
63+
`bsp/nxp/imx/imxrt/libraries/`, LPC55S uses
64+
`bsp/nxp/lpc/lpc55sxx/libraries/`, and MCX keeps separate `libraries/`
65+
directories under series such as `mcxa`, `mcxc`, `mcxe`, and `mcxn`.
66+
67+
The NXP tree also contains historical BSP layouts, such as single-BSP LPC
68+
directories like `lpc176x`, and a few older directories named `Libraries/`.
69+
Do not extend those legacy layouts when adding or restructuring BSPs. If
70+
drivers, SDK code, or templates are reused by multiple BSPs, move or place them
71+
under the corresponding series-level `libraries/` and `tools/` layer.
72+
73+
```text
74+
bsp/nxp/
75+
├── imx/
76+
│ └── imxrt/
77+
│ ├── libraries/
78+
│ │ ├── drivers/ # Drivers and driver adaptation shared by i.MX RT BSPs
79+
│ │ ├── templates/ # Reference templates for new BSPs
80+
│ │ └── Kconfig # NXP i.MX RT SDK package selections
81+
│ ├── tools/ # Helper scripts shared by this series
82+
│ └── imxrt1052-nxp-evk/
83+
│ ├── board/ # Board-only initialization, pins, clocks, linker scripts
84+
│ ├── Kconfig
85+
│ ├── SConscript
86+
│ └── SConstruct
87+
├── lpc/
88+
│ └── lpc55sxx/
89+
│ ├── libraries/ # Driver adaptation, templates, and package selections shared by LPC55S BSPs
90+
│ ├── tools/
91+
│ └── lpc55s69_nxp_evk/
92+
│ ├── board/
93+
│ ├── Kconfig
94+
│ ├── SConscript
95+
│ └── SConstruct
96+
└── mcx/
97+
├── tools/ # Helper tools shared by MCX series
98+
└── mcxn/
99+
├── libraries/ # CMSIS, series drivers, and package selections shared by MCXN BSPs
100+
└── frdm-mcxn947/
101+
├── board/
102+
├── Kconfig
103+
├── SConscript
104+
└── SConstruct
105+
```
106+
107+
### Vendor HAL/SDK Packages
108+
109+
If the vendor HAL, CMSIS, or SDK is already provided as an RT-Thread package,
110+
the BSP should not submit or maintain another full copy of the same source code.
111+
The BSP should select the corresponding `PKG_USING_*` package in `Kconfig` and
112+
reference package contents from `SConscript` according to the enabled
113+
configuration. `pkgs --update` is responsible for downloading package sources.
114+
115+
In this case, `libraries/` mainly keeps driver adaptation code, reusable
116+
drivers, templates, helper scripts, and package selection logic. Do not commit
117+
package directories downloaded by `pkgs --update` as BSP source, and do not let
118+
`scons --dist` include packages or libraries that are not enabled by the current
119+
BSP.
120+
121+
## Submission Requirements
122+
123+
- Keep the BSP hierarchy clear and only submit board-level files required by the
124+
current board.
125+
- Libraries, driver adaptation code, reusable drivers, templates, and scripts
126+
shared by BSPs from the same vendor or series should be placed in the shared
127+
`libraries/` or `tools/` layer to avoid duplicate copies across BSPs.
128+
- Driver adaptation code and reusable drivers should be placed under
129+
`libraries/`, not under a single board directory.
130+
- If the vendor HAL, CMSIS, or SDK has been packaged, prefer the package
131+
mechanism and do not submit duplicate package source code under the BSP.
132+
- Build scripts should reference common code from the shared layer, and
133+
`scons --dist` should not include packages or libraries that are not required
134+
by the current BSP.

documentation/7.contribution/coding_style_cn.md

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -289,30 +289,15 @@ rt_timer + 动词短语的形式表示能够应用于 timer 对象的方法。
289289

290290
## 14.格式化代码
291291

292-
格式化代码是指通过脚本自动整理你的代码,并使其符合 RT-Thread 的编码规范。本文提供以下两种自动格式化代码方法,可以自行选择或配合使用
292+
RT-Thread 现在使用 clang-format 作为统一的代码格式化工具。提交 C/C++、头文件及相关源文件前,请优先使用仓库根目录的 `.clang-format` 配置进行格式化,不要再使用与该配置不一致的手工排版或旧的 astyle 参数
293293

294-
### 使用 astyle 格式化
294+
常用命令如下:
295295

296-
用 astyle 自动格式化代码,参数如下:
297-
298-
--style=allman
299-
--indent=spaces=4
300-
--indent-preproc-block
301-
--pad-oper
302-
--pad-header
303-
--unpad-paren
304-
--suffix=none
305-
--align-pointer=name
306-
--lineend=linux
307-
--convert-tabs
308-
--verbose
309-
310-
能满足函数空格、缩进、函数语句等的规范。
311-
312-
### 使用 formatting 格式化
296+
```shell
297+
clang-format -style=file -i path/to/file.c
298+
clang-format -style=file -i path/to/file.h
299+
```
313300

314-
使用 [formatting](https://github.com/mysterywolf/formatting) 扫描文件来格式化代码:formatting 可以满足编码规则的基本要求,如:
301+
批量格式化时应只处理本次修改相关的源文件,避免对无关文件做大范围格式化。若某个子目录存在自己的 `.clang-format`,以离文件最近的配置为准。
315302

316-
- 将源文件编码统一为 UTF-8
317-
- 将 TAB 键替换为 4 空格
318-
- 将每行末尾多余的空格删除,并统一换行符为 '\n'
303+
除 clang-format 外,仍需保持源文件编码为 UTF-8,行尾使用 `\n`,删除行尾多余空格,并避免提交由编辑器自动产生的无关格式化变更。

documentation/7.contribution/coding_style_en.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,24 @@ When creating a new object, think twice on memory allocations: whether a static
211211
object could be created or it could only created dynamically on the heap. Allocations
212212
can be slower, but may be necessary in dynamic environments.
213213

214-
# 14. Use astyle to format the code automatically
215-
parameters: --style=allman
216-
--indent=spaces=4
217-
--indent-preproc-block
218-
--pad-oper
219-
--pad-header
220-
--unpad-paren
221-
--suffix=none
222-
--align-pointer=name
223-
--lineend=linux
224-
--convert-tabs
225-
--verbose
214+
# 14. Format Code
215+
216+
RT-Thread now uses clang-format as the unified code formatting tool. Before
217+
submitting C/C++ source files, header files, and related source files, format
218+
them with the `.clang-format` configuration in the repository root. Do not use
219+
manual formatting or old astyle parameters that conflict with this configuration.
220+
221+
Common commands:
222+
223+
clang-format -style=file -i path/to/file.c
224+
clang-format -style=file -i path/to/file.h
225+
226+
When formatting files in batches, limit the command to files related to the
227+
current change and avoid large unrelated formatting changes. If a subdirectory
228+
has its own `.clang-format`, use the nearest configuration for files under that
229+
directory.
230+
231+
In addition to clang-format, keep source files encoded as UTF-8, use `\n` line
232+
endings, remove trailing whitespace, and avoid committing unrelated formatting
233+
changes produced by editors.
226234

documentation/Doxyfile.1.9.1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ EXCLUDE = ./0.doxygen/mainpage.h \
931931
./6.components/device-driver/clock_time/clock_timer_zh.md \
932932
./env/env-vscode.md \
933933
./7.contribution/coding_style_cn.md \
934+
./7.contribution/bsp_contribution_guide_cn.md \
934935
../src/utest/perf/README.md
935936

936937
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or

documentation/Doxyfile.1.9.8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ EXCLUDE = ./0.doxygen/mainpage.h \
10211021
./6.components/device-driver/clock_time/clock_timer_zh.md \
10221022
./env/env-vscode.md \
10231023
./7.contribution/coding_style_cn.md \
1024+
./7.contribution/bsp_contribution_guide_cn.md \
10241025
../src/utest/perf/README.md
10251026

10261027
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or

0 commit comments

Comments
 (0)