Let's compete to light up the LED in the Fastest way!
Davis
Posted on December 30, 2020
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
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
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
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
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");
}
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
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
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
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
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
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
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
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;
}
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
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
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
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
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
}
}
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
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.
Posted on December 30, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.