DEV Community

Davis
Davis

Posted on

Let's compete to light up the LED in the Fastest way!

Light up the LED in 30 seconds with 3 methods.

1. Install IDE

Step 0. Prepare Hardware

The hardware used in this experience 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

  • ini-USB cable

Alt Text

Step 1 Install

RT-Thread Studio is a newly emerging embedded integrated development environment. After trial, it was found that it has relatively complete development, compilation, and debugging functions, complete support for STM32 series chips, and complete support for ST-Link J-Link DAP-Link debugger. Here to share the experience of using it.

The latest version of RT-Thread Studio is 2.0.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 successful login, you can see the welcome page of the software
Alt Text

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:

  • Click the SDK manager icon

  • Select PlatformIO 5.0.3.12 version

  • Click the Install Package button to execute the installation
    Alt Text

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

Alt Text

Alt Text

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.

#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");
}
Enter fullscreen mode Exit fullscreen mode

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

Alt Text

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

Alt Text

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

Alt Text

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

Alt Text

Alt Text

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
Alt Text

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

Alt Text

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

Alt Text

Alt Text

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

#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;
}
Enter fullscreen mode Exit fullscreen mode

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

Alt Text

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

Alt Text

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
Alt Text

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

Alt Text

Alt Text

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

#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
    }
}
Enter fullscreen mode Exit fullscreen mode

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
Alt Text

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.

Share your method below, and let's share.

Top comments (3)

Collapse
 
margguo profile image
margguo • Edited

it looks like the first and the last method use platformio, but the middle method looks smoothly too, it does support uart config...

Collapse
 
github0null profile image
null

It looks convenient and powerful. Does he get very slow, like Eclipse ?

Collapse
 
davis87842333 profile image
Davis

It is based on Eclipse but I feel it is much better than Eclipse. You could give it a try and find out more: rt-thread.io/download.html?downloa...

Some comments may only be visible to logged-in visitors. Sign in to view all comments.