RT-Thread is an open-source embedded operating system from China, with the current version being 2.2. It supports many microcontrollers, such as the STM32 series, and can even run on Bluetooth BLE chips. Despite resource constraints in microcontrollers, deploying an easy-to-use micro operating system is beneficial for project development and code management.
Required Tools
- An STM32 development board with USB download capability
- Ubuntu system
- USB to serial cable
I’m using the classic ALIENTEK STM32 MINI V2.0
development board with an STM32F103RBT6
chip, and Ubuntu version 16.04
1. Download the Cross-compilation Toolchain
- Download the
gcc-arm-none-eabi
cross-compilation toolchain. For 16.04 systems, simply useapt install gcc-arm-none-eabi
to install
2. Download RT-Thread Compilation Tools
- This system uses scons for compilation. For 16.04 systems, use
apt install scons
to install
3. Download the Source Code
- Download the RT-Thread system from:
https://github.com/RT-Thread
- Extract the directory
4. Modify the Compilation Project
- Enter the
bsp/stm32f10x
directory - Edit the
rtconfig.py
file - Change CROSS_TOOL to gcc
5. Configure for Your Board
- Configure the crystal oscillator in
stm32f10x.h
viaHSE_VALUE
, for example 800000 - Configure RAM in
board.h
viaSTM32_SRAM_SIZE
, for example 20 - Configure the LED in
led.c
6. Compile the Source Code
- Run
scons
in thebsp/stm32f10x
directory to generate the rtthread.bin file
7. Flash the Code
- You can use Jlink for downloading. Download the Linux executable file from the Jlink official website. Since I’m using a Debian system, I can directly open the JLink_Linux_V614a_x86_64.deb file to install. Then, in the system’s lib/ directory, execute the
JlinkExe
file to download and flash the program through Jlink. - Here I used a more convenient serial port flashing method. First set pin B0 to high level, B1 to low level, then use the STM32flash-5.0 software for flashing.
- Download from
https://sourceforge.net/projects/stm32flash/
- Extract the directory, run make in that directory to get stm32flash
- Copy
rtthread.bin
to that directory, connect the USB to serial cable, then entersudo ./stm32flash -w rtthread.bin -v -g 0x0 /dev/ttyUSB0
, wherettyUSB0
is the serial device
- Download from
8. Verify Success
- If you can see the LED blinking, the deployment was successful