Start With STM 32 Black Pill and STM Cube Ide to Write a Program to Blink on Board LED Using HAL Programming

by ayush4514be23 in Circuits > Microcontrollers

720 Views, 0 Favorites, 0 Comments

Start With STM 32 Black Pill and STM Cube Ide to Write a Program to Blink on Board LED Using HAL Programming

STM32F303CCT6_RobotDyn_Black_Pill-2.jpg
STM32F303CCT6_RobotDyn_Black_Pill-2.jpg

The STM32F401/F411 Black Pill Development Board is an updated version of the popular F103 based Blue Pill. This newer version features a more powerful Core-M4F based ARM CPU. Both F401 and F411 processors supports DFU bootloader.

This tutorial covers the DFU bootloader. For other programming options, refer to this tutorial: Program STM32 Blue Pill (STM32F103C8T6) with Arduino IDE


Supplies

Screenshot 2024-03-03 215028.png

Download and install Arduino IDE

The first thing you need to do is to download and install the Arduino IDE to your computer. You can get the latest version from the official Arduino website: https://www.arduino.cc/en/Main/Software

Follow the link below to install the Arduino IDE:


Install STM32 Add-on to Arduino IDE

Install STM32 Add-on to Arduino IDE

In your Arduino IDE, go to File > Preferences

Add the URL below to Additional Board Manager URLs text box:

https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json

If the text box is not empty, you can separate the URLs with a comma.

Go to Tools > Board > Boards Manager

Search for STM32, select latest version and click Install.

There are a few megabytes of data to download and install, so be patient.

Once the installation is completed, quit and restart the Arduino IDE.


Install STM32CubeProg

Download and install STM32CubeProg from ST.com: https://www.st.com/en/development-tools/stm32cubeprog.html


Start the STM32CubeProg. It will look like this:

Close the STM32CubeProg.


Setup Arduino IDE

From the Tools > Board > STM32 Board, select Generic STM32F4 series

Select Tools > Board Part Number BlackPill F411CE

NOTE: This tutorial is based on STM32F411CE. For STM32F401CE, select BlackPill F401CC

Under USB Support, select CDC (generic "Serial" supersede U(S)ART)

Under Upload method, select SMT32CubeProgrammer(DFU)

These are your Tool configurations:

Connect STM32 Black Pill to your computer USB port.


Enable DFU Bootlaoder

Enable DFU bootlaoder

Use the onboard BOOT0 and NRST button to put the board into bootloader mode:

  • press and hold the BOOT0 button
  • press and release NRST (reset) button to power cycle the processor
  • release BOOT0 button


Upload Sketch

Create new sketch and copy / paste the code below:

/*
Blink onboard LED at 0.1 second interval
*/
void setup() {
// initialize digital pin PB2 as an output.
pinMode(PC13, OUTPUT); // LED connect to pin PC13
}
void loop() {
digitalWrite(PC13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for 100mS
digitalWrite(PC13, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for 100mS
}

Click on the upload button to compile and upload the code to STM32 Black Pill.

You should see the blue LED blink at 0.1 second interval.