RT Thread teaches you how to make BSP according to your own board

First of all, of course, to prepare the RT Thread source code, the latest version is 4.0.3, and the download address is https://gitee.com/rtthread/rt-thread.git

5 steps to make BSP

  1. Copy generic template
  2. Use CubeMX tool to configure the project
  3. Modify the Kconfig file in the BSP
  4. Modify the relevant files of the build project
  5. Regenerate the project

After the download is complete, unzip, open, and find bsp\stm32\libraries, which is a general library for making your own bsp.

first step

Copy a BSP of the same series as the template basis, and get your own BSP by modifying the BSP.

The chip model I use is STM32F103RCT6, so I copied the stm32f10x folder under the path of RT-Thread\rt-thread-master\bsp\stm32\libraries\templates as the base BSP.

Paste it into the path of RT-Thread\rt-thread-master\bsp\stm32 and rename the file to stm32f103-my-bsp

Open stm32f103-my-bsp, the file directory is as follows

Second step

Need to create a CubeMX project based on the target chip. The default CubeMX project is in the  CubeMX_Config folder, double-click to open the CubeMX_Config.ioc ​​project, pay attention to the file path

Open CubeMX to select the specific chip model on your board, I choose STM32F103RCT6 here

Then configure the basic GPIO port and a serial port as the output port of the shell component. My board uses UART3 as the serial port, so configure PB10 and PB11.

Then configure the serial port working mode under Connectivity and turn on the serial port interrupt.

Then switch to the Clock Configuration page to configure the clock. My board uses the internal crystal oscillator of the microcontroller, and the maximum frequency can run to 64MHz.

Then switch to the Prject Manager page, configure the project name and path to regenerate the CubeMX project at the specified address.

After generating the MDK project, only these four files need to be kept, and other files can be deleted.

Then find the main.c file under the Src file, open and copy the SystemClock_Config initialization code.

Replace the configured clock initialization code with the clock initialization code in board.c.

The Flash and RAM size of the chip are configured in board.h, which is changed to the corresponding size according to the actual chip used. STM32F103RCT6 Flash bit 256K RAM is 48K

third step

Modify the board/Kconfig file and open the Kconfig file

Then you need to modify the project construction related files, modify the link script, and open the link.sct file under linker_scripts.

Modify these three places according to the size of the chip's Flash and RAM, and express them in hexadecimal.

The other two link script files are link.icf used by iar and link.lds used by gcc compiler.

Then open the SConscript file and modify the startup file and chip model.

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.

The template file is the template file for generating MDK/IAR project. By modifying this file, you can set the chip model and download method used in the project. MDK4/MDK5/IAR project template file, as shown in the figure below

Double-click to open the template, modify the chip model and select the download and emulator.

After the selection is completed, the project can be closed.

Then enter the command menuconfig in the env interface to configure the project and generate a new rtconfig.h file.

And change the device name for console in Kernel Device Object under RT-Thread Kernel to uart3.

After exiting and saving, enter the command scons --target=mdk5 in env to regenerate the project

Now the new BSP can be used, double-click to open the project

After compiling, open PuTTY, download and successfully print out the logo information of RT Thread. BSP production is completed.

What should I do if I want to copy to another path after the BSP is made?

scons --dist

Using this command will generate the dist directory under the BSP directory. This is the directory structure of the development project, which contains the RT-Thread source code and BSP related projects. Irrelevant BSP folders and libcpu will be removed, and you can copy this at will Project to any directory for use.

After using this command, the dist folder will be produced in the current project directory, which contains all the files used to modify the project.

Open the stm32f103-my-bsp folder in the file and copy it to the required path to start the development of the new project.

This article refers to http://www.sohu.com/a/298141306_467791

Guess you like

Origin blog.csdn.net/qq_25186745/article/details/103808138