diff --git a/bsp/stm32/docs/How to make a STM32 BSP for RT-Thread.md b/bsp/stm32/docs/How to make a STM32 BSP for RT-Thread.md index ff0ead3e28c..d8afb417334 100644 --- a/bsp/stm32/docs/How to make a STM32 BSP for RT-Thread.md +++ b/bsp/stm32/docs/How to make a STM32 BSP for RT-Thread.md @@ -100,10 +100,18 @@ Configure the system clock, peripheral pins, etc. The steps are shown in the fig #### 3.2.2 Copy initialization function -The function `SystemClock_Config()` is placed in the **board.c** file, which is responsible for initializing the system clock. When using the CubeMX tool to reconfigure the system clock, this function needs to be updated. This function is generated by the CubeMX tool and is placed in the file `board/CubeMX_Config/Src/main.c` by default. However, this file does not include in our project, so we need to copy this function from main.c to the board.c file. In the entire BSP making process, this function is the only function to be copied. The content of this function is as follows: +The function `SystemClock_Config()` is placed in the **board.c** file, which is responsible for initializing the system clock. When using the CubeMX tool to reconfigure the system clock, this function needs to be updated. This function is generated by the CubeMX tool and is placed in the file `board/CubeMX_Config/Src/main.c` by default. However, this file does not include in our project, so we need to copy this function from main.c to the board.c file. The content of this function is as follows: ![board_1](./figures_en/board_1.png) +If your MCU clock tree is relatively advanced and you have configured peripherals to use PLL2, PLL3, or other non-default settings, resulting in the generation of the `PeriphCommonClock_Config()` function, please copy it as well. Since `rt-thread` does not explicitly call this function, you can manually add a call to it within `SystemClock_Config()`. The function content may look like the following: + +![board_pclock](figures_en/board_pclock.png) + +If your MCU includes an MPU peripheral and you do not want to use the `Memory Protection` provided by `rt-thread`, but instead prefer the configuration generated by `CubeMX`, you can copy `MPU_Config()`. Similarly, since `rt-thread` does not explicitly call this function, you can use `INIT_BOARD_EXPORT` or other methods to ensure it is called automatically. The function content may look like the following (it is recommended to configure it carefully in sections for actual use): + +![board_mpu](figures_en/board_mpu.png) + The relevant parameters of FLASH and RAM are configured in the **board.h** file. What needs to be modified in this file is the parameters controlled by the two macros `STM32_FLASH_SIZE` and `STM32_SRAM_SIZE`. The flash size of the STM32F103C8Tx chip used in the BSP produced this time is 64k, and the size of the ram is 20k, so the file is modified as follows: ![Modified board.h](./figures_en/board_h.png) diff --git "a/bsp/stm32/docs/STM32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" "b/bsp/stm32/docs/STM32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" index b70fa1439b7..4fb48c67579 100644 --- "a/bsp/stm32/docs/STM32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" +++ "b/bsp/stm32/docs/STM32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" @@ -141,10 +141,18 @@ BSP 的制作过程分为如下五个步骤: 在 **board.c** 文件中存放了函数 `SystemClock_Config()` ,该函数负责初始化系统时钟。当使用 CubeMX 工具对系统时钟重新配置的时候,需要更新这个函数。 -该函数由 CubeMX 工具生成,默认存放在`board/CubeMX_Config/Src/main.c` 文件中。但是该文件并没有被包含到我们的工程中,因此需要将这个函数从 main.c 中拷贝到 board.c 文件中。在整个 BSP 的制作过程中,这个函数是唯一要要拷贝的函数,该函数内容如下所示: +该函数由 CubeMX 工具生成,默认存放在`board/CubeMX_Config/Src/main.c` 文件中。但是该文件并没有被包含到我们的工程中,因此需要将这个函数从 main.c 中拷贝到 board.c 文件中。该函数内容如下所示: ![board_1](./figures/board_1.png) +如果你的MCU时钟树较为高级,且配置了外设使用PLL2、PLL3等非默认情况,生成了`PeriphCommonClock_Config()`函数,请也拷贝它。由于`rt-thread`并不会显式调用它,可在`SystemClock_Config()`中手动增加调用它。该函数内容可能如下所示: + +![board_pclock](figures/board_pclock.png) + +如果你的MCU包含MPU外设且并不想使用`rt-thread`提供的`Memory Protection`,想使用`cubemx`配置的内容时,可以拷贝生成的`MPU_Config()`。同样`rt-thread`不会显式调用它,你可以修改一下后使用`INIT_BOARD_EXPORT`等方式让其自动调用。该函数内容可能如下所示(实际使用建议分块仔细配置): + +![board_mpu](figures/board_mpu.png) + 在 **board.h** 文件中配置了 FLASH 和 RAM 的相关参数,这个文件中需要修改的是 `STM32_FLASH_SIZE` 和 `STM32_SRAM_SIZE` 这两个宏控制的参数。本次制作的 BSP 所用的 STM32F103RBTx 芯片的 flash 大小为 128k,ram 的大小为 20k,因此对该文件作出如下的修改: ![修改 board.h](./figures/board_h.png) diff --git a/bsp/stm32/docs/figures/board_mpu.png b/bsp/stm32/docs/figures/board_mpu.png new file mode 100644 index 00000000000..64efb350c0f Binary files /dev/null and b/bsp/stm32/docs/figures/board_mpu.png differ diff --git a/bsp/stm32/docs/figures/board_pclock.png b/bsp/stm32/docs/figures/board_pclock.png new file mode 100644 index 00000000000..69f4e78a3b3 Binary files /dev/null and b/bsp/stm32/docs/figures/board_pclock.png differ diff --git a/bsp/stm32/docs/figures_en/board_mpu.png b/bsp/stm32/docs/figures_en/board_mpu.png new file mode 100644 index 00000000000..64efb350c0f Binary files /dev/null and b/bsp/stm32/docs/figures_en/board_mpu.png differ diff --git a/bsp/stm32/docs/figures_en/board_pclock.png b/bsp/stm32/docs/figures_en/board_pclock.png new file mode 100644 index 00000000000..69f4e78a3b3 Binary files /dev/null and b/bsp/stm32/docs/figures_en/board_pclock.png differ