Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions bsp/stm32/docs/How to make a STM32 BSP for RT-Thread.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,32 @@ The other two link script files are link.icf used by IAR and link.lds used by th

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

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:
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:

![Modify the startup file and chip model](./figures_en/SConscript.png)
```diff
# for module compiling
import os
Import('RTT_ROOT')
Import('env')
from building import *

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.
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)

- # The following macro definition statement exists in the template before modification:
- env.Append(CPPDEFINES = ['STM32H723xx'])# Target chip macro definition, hal library will use this macro definition for judgment
+ # Modify the macro definition to the corresponding chip model. For example, for STM32F103xB, the modified content is as follows:
+ env.Append(CPPDEFINES = ['STM32F103xB'])
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))

Return('objs')
```

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.

#### 3.4.3 Modify the project template

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

Env tool is required to regenerate the project.

Before regenerating the project, you must execute the `pkgs --update` command in the Env tool.

This command will automatically pull the corresponding HAL library package according to the Kconfig configuration, which is the key to subsequent compilation success.

#### 3.5.1 Regenerate the rtconfig.h file

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

- Perform functional tests on the BSP before submission to ensure that the BSP meets the requirements in the engineering configuration chapter before submission.
35 changes: 30 additions & 5 deletions bsp/stm32/docs/STM32系列BSP制作教程.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,35 @@ BSP 的制作过程分为如下五个步骤:

#### 3.4.2 修改构建脚本

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

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

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

注意:如果在文件夹中找不到相应系列的 .s 文件,可能是多个系列的芯片重用了相同的启动文件,此时可以在 CubeMX 中生成目标芯片的工程,查看使用了哪个启动文件,然后再修改启动文件名。
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)

- # 修改前模板中的存在如下宏定义语句:
- env.Append(CPPDEFINES = ['STM32H723xx'])# 目标芯片宏定义,hal库将使用这个宏定义作判断
+ # 修改宏定义为对应的芯片型号,例如对于STM32F103xB,修改后的内容如下:
+ env.Append(CPPDEFINES = ['STM32F103xB'])
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))

Return('objs')


```
注意:由于BSP瘦身计划,template目录下的模板已经过时,SConscript文件可能与示例有所差异,请参考实际BSP或等待更新。

#### 3.4.3 修改工程模板

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

### 3.5 重新生成工程
工程生成需要使用 Env 工具。

在进行工程生成前,必须在 Env 工具中执行 `pkgs --update` 命令。

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

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

Expand Down