on
2021-01-18
7:45 AM
- edited on
2025-08-01
5:40 AM
by
Laurids_PETERSE
Light up your LED in 30 seconds with 3 methods ( A Step By Step Tutorial )
This article is authored by RT-Thread, an ST Approved Partner
RT-Thread delivers a one-stop & free-to-use IDE RT-Thread Studio [http://bit.ly/2Gg3Wvn](https://t.co/psylBGL22o?amp=1) for STM32 IoT Development. It includes complete development, compilation, and debugging functions, has great support for STM32 series chips, and complete support for ST-Link J-Link DAP-Link debugger.
The hardware I used is ST's development board NUCLEO-F411RE, and the development board number is MB1136. If you don’t have this board, you can use other development boards instead, and modify the LED and USART pin configuration according to the actual hardware conditions.
Hardware list:
+ NUCLEO-F411RE board
+ Mini-USB cable
***Figure1 hardware***
The latest version of RT-Thread Studio is 2.0, which supports Windows 10 x64 operating system. The download link of RT-Thread Studio is
https://realthread-ide.rt-thread.org/Global/RT-Thread-Studio-setup-x86_64-latest.exe , After downloading the software, double-click to install
***Figure2 install***
To run Studio for the first time, you need to register and log in to your personal account. Click Sign up to register an account and you can log in
***Figure3 Sign up and login***
After successful login, you can see the welcome page of the software
***Figure4 IDE welcome page***
Close the welcome page, you can see the project manager and C/C++ development view, here we install some necessary resource packages to support the development of STM32 F411, the installation steps:
1. Click the SDK manager icon
2. Select PlatformIO 5.0.3.12 version
3. Click the Install Package button to execute the installation
***Figure5 SDK Manager***
Click the Create Project button in the upper left corner of the IDE to create a new project. Here we choose to create General Project and choose to use the PlatformIO platform. The steps are as follows:
+ Create General Project
+ Select Base On PlatformIO
+ Search f411re
+ Select Nucleo_f411re board and Arduino framework
***Figure6 Select Base On PlatformIO***
***Figure7 Select nucleo_f411re and Arduino***
The created nucleo_stm32f411re_arduino project is an empty project. Add the blinking code of the LED in src/main.cpp to realize the blinking of the LED.
```cpp #include <Arduino.h> void setup() { // write your initialization code here pinMode(LED_GREEN, OUTPUT); // set LED_GREEN pin as output mode Serial.begin(115200); // set Serial baudrate to 115200 bps } void loop() { // write your code here digitalWrite(LED_GREEN, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for 100 millisecond digitalWrite(LED_GREEN, LOW); // turn the LED off by making the voltage LOW delay(100); // wait for 100 millisecond Serial.print("hello world!\r\n"); } ```
After adding the LED blinking code in main.cpp and saving it, click the small hammer build icon to compile the project
***Figure7 Build project nucleo_f411re_arduino***
Link the Mini USB cable to the development board, click the download button on the toolbar, and then the program can be downloaded
***Figure8 Download to board***
After the download is complete, you can see that the green LED starts to blink, the IDE integrates a serial port terminal, open the serial port terminal, connect to the serial port, you can see the "hello world" message
***Figure9 Run on board***
RT-Thread Studio supports online simulation. Click the debug button on the toolbar to enter the debugging interface. The debugging simulation supports single-step, suspend and other debugging operations
***Figure10 Debug button***
***Figure11 Debug Windows***
RT-Thread Studio IDE can create the rt-thread os project of any chip of stm32 with one click, and do the porting of the operating system, serial port driver, and common peripheral driver. The steps to create the LED blinking project are as follows
Click the SDK Manager icon in the toolbar, select the STM32F4 chip support package 0.1.9 version in the pop-up SDK manager, and click to install the support package
***Figure12 Install STM32F4 Chip support package***
Click the create project icon in the upper left corner of the IDE, and select to create an RT-Thread project
***Figure13 Create RT-Thread OS project***
Make the following configuration in the creation wizard
+ RT-Thread version: 4.0.2
+ Chip: STM32F411RE
+ Serial port: UART2
+ Serial port sending pin: PA2
+ Serial port receiving pin: PA3
+ Debugger: ST-Link
+ Simulation interface: SWD
After the configuration is complete, click Finish to create the project
***Figure14 Config RT-Thread OS project***
***Figure15 One RT-Thread OS project***
The created RT-Thread project has been transplanted to the operating system, and the uart driver is connected to the system shell. At this time, the project is directly compiled, and input shell command through the serial terminal, but there is no LED Driver logic, here we can add the following code to the applications/main.c file to drive the LED
```cpp #include <rtthread.h> #include <rtdevice.h> #include <board.h> /* defined the LED0 pin: PA5 */ #define LED0_PIN GET_PIN(A, 5) int main(void) { int count = 1; /* set LED0 pin mode to output */ rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT); while (count++) { rt_thread_mdelay(100); rt_pin_write(LED0_PIN, PIN_HIGH); rt_thread_mdelay(100); rt_pin_write(LED0_PIN, PIN_LOW); rt_thread_mdelay(100); } return RT_EOK; } ```
***Figure16 Main.c source code***
After replacing the above code in the applications/main.c file, click the small hammer icon in the toolbar to compile the entire project. After the compilation is successful, the following information will be output
+ elf file size
+ flash occupancy
+ ram occupancy
***Figure17 Build Project***
Connect the Mini USB cable to the development board, click the download button on the toolbar, and then download the program. After the download is complete, you can see the LED lights blinking
***Figure18 Download program***
RT-Thread Studio supports online simulation. Click the debug button on the toolbar to enter the debugging interface. The debugging simulation supports single-step, suspend and other debugging operations
***Figure19 Debug program***
Click the Create Project button in the upper left corner of the IDE to create a new project. Here we choose to create General Project and choose to use the PlatformIO platform. The steps are as follows
+ Create General Project
+ Select Base On PlatformIO
+ Search f411re
+ Select nucleo_f411re board and Mbed framework
Figure Select Base On PlatformIO and Mbed
***Figure20 Create PlatformIO project***
***Figure21 Select Mbed***
The created nucleo_stm32f411re_mbed project is an empty project. Add the blinking code of the LED in src/main.cpp to realize the blinking of the LED
```cpp #include "mbed.h" #include "rtos.h" DigitalOut led(PA_5); // on-board LED int main() { while (1) { led = !led; ThisThread::sleep_for(100ms); // 100 millisecond } } ```
After adding the LED blinking code in main.cpp and saving it, click the small hammer build icon to compile the project
***Figure21 Build Mbed***
Connect the Mini USB cable to the development board, click the download button on the toolbar, and then download the program. After the download is complete, you can see the LED lights blinking.