This article will explain how to program the Black Pill STM32F4 microcontrollers. It can be considered the big brother of the STM32F1 series, more powerful, and with all the features of the F1 version.
One of the most exciting features of the Black Pill variant of STM32 has a built-in ROM bootloader that cannot be disabled or erased, and this makes it a fool-proof way always to be able to recover your microcontroller code.
But now we start to look at the STM32 family of microcontrollers, and then we’ll go deep into the STM32F4 series and learn how to use/program.
SMT32 details
The STM32 family of 32-bit microcontrollers is based on the Arm® Cortex®-M processor.
These products combine very high performance, real-time capabilities, digital signal processing, low-power / low-voltage operation, and connectivity while maintaining full integration and ease of development.
The range of STM32 microcontrollers, based on an industry-standard core, comes with a vast choice of tools and software to support project development, making this family of products ideal for small projects and end-to-end platforms.
Here the most commons STM32 STM32F103C8T6 STM32F401 STM32F411 ST-Link v2 ST-Link v2 official
Specs
There is a wide variety of stm32; here is a schematization of the main categories.
A more detailed classification can do with the part number decoding:
STM32F051R8
STM32xxwwyz
- xx – Family
- ww – subtype: differs in the equipment of peripherals and this depends on certain family
- y – Package pin count
- z – FLASH memory size
Family: [xx]
Code | Core | Max freq [MHz] | Max FLASH [KB] | Max SRAM [KB] | Target |
---|---|---|---|---|---|
F0 | Cortex-M0 | 48 | 256 | 32 | Mainstream |
F1 | Cortex-M3 | 72 | 1024 | 96 | Mainstream |
F2 | Cortex-M3 | 120 | 1024 | 128 | High performance |
F3 | Cortex-M4F | 72 | 512 | 80 | Mainstream |
F4 | Cortex-M4F | 180 | 2048 | 384 | High performance |
G0 | Cortex-M0+ | 64 | 128 | 36 | Mainstream |
G4 | Cortex-M4F | 170 | 512 | 128 | Mainstream |
F7 | Cortex-M7F | 216 | 2048 | 512 | High performance |
H7 | Cortex-M7F | 480 | 2048 | 1024 | High performance |
WB | Cortex-M4F | 64 | 1024 | 256 | Wireless |
WL | Cortex-M4 | 48 | 256 | 64 | Wireless |
L0 | Cortex-M0+ | 32 | 192 | 20 | Ultra-low-power |
L1 | Cortex-M3 | 32 | 512 | 80 | Ultra-low-power |
L4 | Cortex-M4F | 80 | 1024 | 320 | Ultra-low-power |
L4+ | Cortex-M4F | 120 | 2048 | 640 | Ultra-low-power |
L5 | Cortex-M33F | 110 | 512 | 256 | Ultra-low-power |
U5 | Cortex-M33F | 160 | 2048 | 786 | Ultra-low-power |
Package pin count [y]
Code | Number of pins |
---|---|
A | 169 |
B | 208 |
C | 48 |
F | 20 |
G | 28 |
H | 40 |
I | 176 |
J | 8/72 |
K | 32 |
M | 81 |
N | 216 |
Q | 132 |
R | 64 |
T | 36 |
U | 63 |
V | 100 |
Z | 144 |
FLASH memory size [z]
Code | FLASH size [KB] |
---|---|
4 | 16 |
6 | 32 |
8 | 64 |
B | 128 |
Z | 192 |
C | 256 |
D | 384 |
E | 512 |
F | 768 |
G | 1024 |
H | 1536 |
I | 2048 |
STM32F4 details
STM32F4 series of high-performance MCUs with DSP and FPU instructions
The ARM® Cortex®-M4-based STM32F4 MCU series leverages ST’s NVM technology and ART Accelerator™ to reach the industry’s highest benchmark scores for Cortex-M-based microcontrollers with up to 225 DMIPS/608 CoreMark executing from Flash memory at up to 180 MHz operating frequency.
With dynamic power scaling, the current consumption running from Flash ranges from 89 µA/MHz on the STM32F410 up to 260 µA/MHz on the STM32F439.
The STM32F4 series consists of eight compatible product lines of digital signal controllers (DSC), a perfect symbiosis of the real-time control capabilities of an MCU, and the signal processing performance of a digital signal processor (DSP):
- Advanced lines:
- 180 MHz CPU/225 DMIPS, up to 2 Mbytes of dual-bank Flash memory with SDRAM and Chrom-ART Accelerator™
- STM32F469/479 – Quad-SPI interface, LCD-TFT controller and MPI-DSI interface
- STM32F429/439 – LCD-TFT controller
- STM32F427/437 – serial audio interface, more performance and lower static power consumption
- 180 MHz CPU/225 DMIPS, up to 2 Mbytes of dual-bank Flash memory with SDRAM and Chrom-ART Accelerator™
- Foundation lines:
- STM32F446 – 180 MHz/225 DMIPS, up to 512 Kbytes of Flash memory with dual Quad-SPI and SDRAM interfaces
- STM32F407/417 – 168 MHz CPU/210 DMIPS, up to 1 Mbyte of Flash memory adding Ethernet MAC and camera interface
- STM32F405/415 – 168 MHz CPU/210 DMIPS, up to 1 Mbyte of Flash memory with advanced connectivity and encryption
- Access lines: The entry-level microcontrollers of the STM32F4 series!
- 84 MHz CPU/105 DMIPS, the smallest, cost-effective solution with outstanding power efficiency (Dynamic Efficiency™)
- STM32F401 – Less than 3 x 3mm with USB 2.0FS OTG and SDIO interfaces
- 100 MHz CPU/125 DMIPS, outstanding power efficiency (Dynamic Efficiency™) and Batch Acquisition Mode (BAM), a new smart DMA-optimizing power consumption for data batching
- STM32F410 – New milestone in outstanding power efficiency (89 µA/MHz and 6 µA in Stop mode), true random number generator, low-power timer, and DAC.
- STM32F411 – High RAM density and enhanced peripheral set such as USB 2.0FS OTG and up to 5 SPI interfaces.
- STM32F412 – High RAM and Flash memory density, USB interface, and enhanced peripheral set including a flexible external static memory controller with up to 16-bit data bus for LCD and external memory control, dual-mode Quad-SPI, CAN, DFSDM, and TRNG.
- STM32F413/F423 – Extends STM32F412 features with higher RAM and Flash memory density and an enhanced peripheral set including 10 UARTs, 3 CANs, SAI interface, a low-power timer, 2 DACs, 2 DFSDM with up to 6 filters. The STM32F423 includes AES encryption.
- 84 MHz CPU/105 DMIPS, the smallest, cost-effective solution with outstanding power efficiency (Dynamic Efficiency™)
Pinouts
The F401 model is one of the most popular, also considering the very affordable cost.
WeAct STM32F401CCU6 Black-Pill: high-resolution pinout and specs
The 411 version is certainly more performing, which also has an extra SPI, timer and I2S.
It is important to note pins 10 and 41 that F411 is not tolerant to 5V (check the red color of the square).
WeAct STM32F411CEU6 Black-Pill: high-resolution pinout and specs
But the 5V tolerance is one of the most important features of these F4xx series.
Arduino STM32 from STMicroelectronics
We must add the URL descriptor to our Arduino IDE.
https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
Go to File –> Preferences and add the URL on “Additional Boards Manager URLs.”
Then you must add a new board to Boards Manager
The boards to select are STM32 MCU-based boards.
Now you can choose the specified device:
Now we are going to select the specified board.
As already said, these devices have a DFU bootloader already uploaded, so you can use USB to program, and you must select the DFU bootloader.
To use Serial to debug your code, you must select "USB support (if It's available): "CDC (generic 'Serial' supersede U(S)ART)"
Install STM32CubeProgrammer
To work, you also need to install the STM32CubeProgrammer released from STMicroelectronics.
You can download It from here.
Select boot mode
Put this device in boot mode:
- hold down BOOT0 button;
- push NRST button;
- release NRST;
- release BOOT0.
Now you have the red PWR led only.
Simple Blink sketch for STM32F4
My device has an LED on PA13.
/*
Blink for STM32F4
Turns an LED on for one second, then off for one second, repeatedly.
http://www.mischianti.org
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
// while (!Serial) {
// ; // wait for serial port to connect. Needed for native USB port only
// }
Serial.println(F("Serial OK!"));
pinMode(PC13, OUTPUT);
}
void loop() {
digitalWrite(PC13, HIGH);
Serial.println(F("HIGH!"));
delay(1000);
digitalWrite(PC13, LOW);
Serial.println(F("LOW!"));
delay(1000);
}
Now start the upload.
-------------------------------------------------------------------
STM32CubeProgrammer v2.9.0
-------------------------------------------------------------------
USB speed : Full Speed (12MBit/s)
Manuf. ID : STMicroelectronics
Product ID : STM32 BOOTLOADER
SN : 31A035713237
FW version : 0x011a
Board : --
Device ID : 0x0433
Device name : STM32F401xD/E
Flash size : 8 MBytes (default)
Device type : MCU
Revision ID : --
Device CPU : Cortex-M4
Memory Programming ...
Opening and parsing file: sketch_feb22a.ino.bin
File : sketch_feb22a.ino.bin
Size : 24296 Bytes
Address : 0x08000000
Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 1]
erasing sector 0000 @: 0x08000000 done
erasing sector 0001 @: 0x08004000 done
Download in Progress:
File download complete
Time elapsed during download operation: 00:00:01.101
RUNNING Program ...
Address: : 0x8000000
Start operation achieved successfully
If all It’s ok, your C13 LED starts to blink, and as if by magic new Serial port has appeared, for me COM12.
When connecting the serial monitor to the COM port, you get this result:
Serial OK!
HIGH!
LOW!
HIGH!
LOW!
HIGH!
LOW!
HIGH!
LOW!
HIGH!
Thanks
- STM32F1 Blue-Pill: pinout, specs, and Arduino IDE configuration (STM32duino and STMicroelectronics)
- STM32: program (STM32F1) via USB with STM32duino bootloader
- STM32: programming (STM32F1 STM32F4) via USB with HID boot-loader
- STM32F4 Black-Pill: pinout, specs, and Arduino IDE configuration
- STM32: ethernet w5500 with plain HTTP and SSL (HTTPS)
- STM32: ethernet enc28j60 with plain HTTP and SSL (HTTPS)
- STM32: WiFiNINA with ESP32 WiFi Co-Processor
- How to use SD card with stm32 and SdFat library
- \STM32: SPI flash memory FAT FS
- STM32: internal RTC, clock, and battery backup (VBAT)
- STM32 LoRa
- STM32 Power saving
- STM32F1 Blue-Pill clock and frequency management
- STM32F4 Black-Pill clock and frequency management
- Intro and Arduino vs STM framework
- Library LowPower, wiring, and Idle (STM Sleep) mode
- Sleep, deep sleep, shutdown, and power consumption
- Wake up from RTC alarm and Serial
- Wake up from the external source
- Backup domain intro and variable preservation across reset
- RTC backup register and SRAM preservation
- STM32 send emails with attachments and SSL (like Gmail): w5500, enc28j60, SD, and SPI Fash
- FTP server on STM32 with w5500, enc28j60, SD Card, and SPI Flash
- Connecting the EByte E70 to STM32 (black/blue pill) devices and a simple sketch example