cancel
Showing results for 
Search instead for 
Did you mean: 

Light up your LED in 30 seconds with NUCLEO-F411RE and IDE RT-Thread Studio

LauraCx
ST Employee

Light up your LED in 30 seconds with NUCLEO-F411RE and IDE RT-Thread Studio

0. Introduction

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

1. Install IDE 

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.
 

Step 0. Prepare Hardware

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
1582.png
  ***Figure1 hardware***

Step 1 Install

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
1583.png
***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
1584.png
***Figure3 Sign up and login***
After successful login, you can see the welcome page of the software
1585.png
  ***Figure4 IDE welcome page***
 

Step 2 Install PlatformIO Package

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
1588.png
***Figure5 SDK Manager***
 

2. Light up the LED with Arduino Framework

 

Step 0 Create stm32f411re Arduino project

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
1589.png
***Figure6 Select Base On PlatformIO***
1590.png
 ***Figure7 Select nucleo_f411re and Arduino***

Step 1 Add LED Blink Code

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");
}
```


Step 2 Build  nucleo_stm32f411re_arduino project

After adding the LED blinking code in main.cpp and saving it, click the small hammer build icon to compile the project 
1592.png
 ***Figure7 Build project nucleo_f411re_arduino***

Step 3 Download

Link the Mini USB cable to the development board, click the download button on the toolbar, and then the program can be downloaded 
1594.png
 ***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
1595.png
 ***Figure9  Run on board***

Step 4 Debug 

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  
1596.png
 ***Figure10  Debug button***
1597.png
 ***Figure11  Debug Windows***

3. Light up the LED with RT-Thread

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 
 

Step 0 Install STM32F4 chip support package


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 
1598.png
 ***Figure12  Install STM32F4 Chip support package***
 

Step 1 Create nucleo_stm32f411re_rt_thread project

Click the create project icon in the upper left corner of the IDE, and select to create an RT-Thread project 
1599.png
 ***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
1600.png
 ***Figure14  Config RT-Thread OS project***
1601.png
 ***Figure15  One RT-Thread OS project***


Step 2 Add LED Code

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


Step 3 Build nucleo_stm32f411re_rt_thread project

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
1602.png
***Figure17  Build Project***

Step 4 Download

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 
1604.png
***Figure18  Download program***
 

Step 5 Debug 

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  
1606.png
***Figure19  Debug program***

4. Light up the LED with Mbed Framework


Step 0 Create Mbed project

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
1607.png
***Figure20  Create PlatformIO project***
1608.png
***Figure21  Select Mbed***
 

Step 1 Add LED Code

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
    }
}
```


Step 2 Build  nucleo_stm32f411re_mbed project

After adding the LED blinking code in main.cpp and saving it, click the small hammer build icon to compile the project
1610.png
***Figure21  Build Mbed***


Step 3 Download

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. 
 
Version history
Last update:
‎2021-01-18 07:45 AM
Updated by: