Skip to content

Commit ec5f5e6

Browse files
authored
[docs] 修复 STM32 BSP 制作教程中的Sconscrip文件教程错误 (#11189)
1 parent 27b2ba5 commit ec5f5e6

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

bsp/stm32/docs/How to make a STM32 BSP for RT-Thread.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,32 @@ The other two link script files are link.icf used by IAR and link.lds used by th
166166

167167
The **SConscript** script determines the files to be added during the generation and compilation of the MDK/IAR project.
168168

169-
In this step, you need to modify the chip model and the address of the chip startup file. The modification content is shown in the figure below:
169+
In this step, you need to modify the chip model and the address of the chip startup file. There are two SConscript files in the BSP directory, and only the one in the root directory needs to be modified, as shown below:
170170

171-
![Modify the startup file and chip model](./figures_en/SConscript.png)
171+
```diff
172+
# for module compiling
173+
import os
174+
Import('RTT_ROOT')
175+
Import('env')
176+
from building import *
172177

173-
Note: If you cannot find the .s file of the corresponding series in the folder, it may be that multiple series of chips reuse the same startup file. At this time, you can generate the target chip project in CubeMX to see which startup file is used. Then modify the startup file name.
178+
cwd = GetCurrentDir()
179+
objs = []
180+
list = os.listdir(cwd)
181+
182+
- # The following macro definition statement exists in the template before modification:
183+
- env.Append(CPPDEFINES = ['STM32H723xx'])# Target chip macro definition, hal library will use this macro definition for judgment
184+
+ # Modify the macro definition to the corresponding chip model. For example, for STM32F103xB, the modified content is as follows:
185+
+ env.Append(CPPDEFINES = ['STM32F103xB'])
186+
for d in list:
187+
path = os.path.join(cwd, d)
188+
if os.path.isfile(os.path.join(path, 'SConscript')):
189+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
190+
191+
Return('objs')
192+
```
193+
194+
Note: Due to the BSP weight loss plan, the templates in the template directory are outdated, and the SConscript file may be different from the example. Please refer to the actual BSP or wait for an update.
174195

175196
#### 3.4.3 Modify the project template
176197

@@ -190,6 +211,10 @@ Modify the program download method:
190211

191212
Env tool is required to regenerate the project.
192213

214+
Before regenerating the project, you must execute the `pkgs --update` command in the Env tool.
215+
216+
This command will automatically pull the corresponding HAL library package according to the Kconfig configuration, which is the key to subsequent compilation success.
217+
193218
#### 3.5.1 Regenerate the rtconfig.h file
194219

195220
Enter the command menuconfig in the Env interface to configure the project and generate a new rtconfig.h file. As shown below:
@@ -255,5 +280,4 @@ The specifications of making STM32 BSP are mainly divided into three aspects: en
255280
- Only submit documents necessary for the BSP and delete irrelevant intermediate documents. Please check other BSPs for documents that can be submitted.
256281
- When submitting libraries of different series of STM32, please refer to the HAL libraries of f1/f4 series and delete redundant library files.
257282
- Compile and test the BSP before submission to ensure that it compiles properly under different compilers.
258-
- Perform functional tests on the BSP before submission to ensure that the BSP meets the requirements in the engineering configuration chapter before submission.
259-
283+
- Perform functional tests on the BSP before submission to ensure that the BSP meets the requirements in the engineering configuration chapter before submission.

bsp/stm32/docs/STM32系列BSP制作教程.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,35 @@ BSP 的制作过程分为如下五个步骤:
210210

211211
#### 3.4.2 修改构建脚本
212212

213-
**SConscript** 脚本决定 MDK/IAR 工程的生成以及编译过程中要添加文件
213+
**SConscript** 脚本决定 MDK/IAR 工程的生成以及编译过程中要添加的文件
214214

215-
在这一步中需要修改芯片型号以及芯片启动文件的地址,修改内容如下图所示
215+
在这一步中需要修改芯片型号以及芯片启动文件的地址,在BSP目录中存在两个SConscript文件,其中只有根目录下的需要修改,修改内容如下所示
216216

217-
![修改启动文件和芯片型号](./figures/SConscript.png)
217+
```diff
218+
# for module compiling
219+
import os
220+
Import('RTT_ROOT')
221+
Import('env')
222+
from building import *
218223

219-
注意:如果在文件夹中找不到相应系列的 .s 文件,可能是多个系列的芯片重用了相同的启动文件,此时可以在 CubeMX 中生成目标芯片的工程,查看使用了哪个启动文件,然后再修改启动文件名。
224+
cwd = GetCurrentDir()
225+
objs = []
226+
list = os.listdir(cwd)
227+
228+
- # 修改前模板中的存在如下宏定义语句:
229+
- env.Append(CPPDEFINES = ['STM32H723xx'])# 目标芯片宏定义,hal库将使用这个宏定义作判断
230+
+ # 修改宏定义为对应的芯片型号,例如对于STM32F103xB,修改后的内容如下:
231+
+ env.Append(CPPDEFINES = ['STM32F103xB'])
232+
for d in list:
233+
path = os.path.join(cwd, d)
234+
if os.path.isfile(os.path.join(path, 'SConscript')):
235+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
236+
237+
Return('objs')
238+
239+
240+
```
241+
注意:由于BSP瘦身计划,template目录下的模板已经过时,SConscript文件可能与示例有所差异,请参考实际BSP或等待更新。
220242

221243
#### 3.4.3 修改工程模板
222244

@@ -233,8 +255,11 @@ BSP 的制作过程分为如下五个步骤:
233255
![配置下载方式](./figures/template_3.png)
234256

235257
### 3.5 重新生成工程
258+
工程生成需要使用 Env 工具。
259+
260+
在进行工程生成前,必须在 Env 工具中执行 `pkgs --update` 命令。
236261

237-
重新生成工程需要使用 Env 工具。
262+
该命令会根据 Kconfig 配置自动拉取对应的 HAL 库软件包,这是后续编译成功的关键。
238263

239264
#### 3.5.1 重新生成 rtconfig.h 文件
240265

0 commit comments

Comments
 (0)