🛠 Premier téléversement sur la STM32F4DISCOVERY avec l'Arduino STM32duino
Objective
Bring the STM32F4DISCOVERY (STM32F407VGT6 MCU: Cortex-M4F at 168 MHz, 1024 KB of flash, 192 KB of RAM including 64 KB in Core-Coupled Memory (CCM), LQFP100 package) to life using the Arduino ecosystem. By the end of this tutorial, an LED sweep will run on the board and the USER button will respond — with no external wiring required.
Hardware
- 1 STM32F4DISCOVERY board + micro-USB data cable
- The micro-USB port to use is the one connected to the integrated ST-LINK/V2-A: this is the port that programs the board; no external tool is needed
- PC with Arduino IDE
Installation
- In the Arduino IDE, open the Board Manager and install “STM32 STM32 boards by STMicroelectronics” (Arduino_Core_STM32).
- Select the Discovery family, then the “STM32F407G-DISC1” board (constant
DISCO_F407VG, variantSTM32F4xx/F407V(E-G)T_F417V(E-G)T, cortex-m4 with hardware FPUfpv4-sp-d16, 1 MB of flash / 128 KB of data). - Upload: programming is done via the embedded ST-LINK/V2-A (SWD); there is no user-side DFU bootloader on this port.
Pitfall #1: The Serial Port
The Zephyr documentation is explicit: “ST-Link Virtual Com Port is not wired to chip serial port” on stock boards. The Arduino variant, however, labels USART2 (PA2/PA3) as “Connected to ST-Link” — a documented contradiction depending on the revision (jumpers in the CN3/CN5 area need to be checked, and are missing on some boards). Practical rule: test Serial, and if nothing appears, connect an external serial cable to PA2/PA3 (UART2) at 115200 8N1.
Full Code
// Balayage des 4 LED + bouton USER — broches du variant officiel DISCO_F407VG
const int ledPins[4] = {LED_GREEN, LED_ORANGE, LED_RED, LED_BLUE}; // PD12, PD13, PD14, PD15
void setup {
for (int i = 0; i < 4; i++) pinMode(ledPins[i], OUTPUT);
pinMode(USER_BTN, INPUT); // PA0, pull-down externe sur la carte
Serial.begin(115200); // USART2 PA2/PA3 — voir le piège ci-dessus
Serial.println("STM32F4DISCOVERY ready");
}
void loop {
for (int i = 0; i < 4; i++) {
digitalWrite(ledPins[i], HIGH);
delay(150);
digitalWrite(ledPins[i], LOW);
}
if (digitalRead(USER_BTN) == HIGH) { // actif à l'état HAUT sur cette carte
Serial.println("USER pressed");
}
}
Expected Verification
The green, orange, red, and then blue LEDs (pins PD12 to PD15) light up in sequence upon power-up. The USER button (PA0, shared with the MCU's WKUP function) reads high when pressed. If the serial output remains silent, it is not your code: refer to the external cable on UART2.
Common Errors
- Programming via the OTG micro-USB port instead of the ST-LINK port: these are two distinct connectors; only the latter programs the board on a stock card.
- Using a charge-only micro-USB cable: the ST-LINK will be invisible.
- Relying on
Serialwithout checking the VCP wiring for your board revision (Issue #1 documented by Zephyr). - Forgetting that the pins are 3.3 V (VDD 1.8 to 3.6 V, most pins are 5 V tolerant according to the F407 datasheet): do not apply 5 V directly to a pin without verification.
- Confusing this with the F401/F411 Discovery kits: the 6-axis LSM330 IMU is on those boards, not on the original STM32F4DISCOVERY.
Other tutorials for this board
- Zephyr RTOS sur la STM32F4DISCOVERY : west build et west flash
- MicroPython sur la STM32F4DISCOVERY : REPL interactif et pilotage des LED
- STM32Cube HAL et BSP officiel : LED, bouton et accéléromètre avec détection automatique
- Lecture audio sur le codec CS43L22 : I2S, classe D et les limitations du BSP
- USB OTG FS sur le port micro-AB : se faire passer pour un périphérique classe CDC
- Acquérir le micro PDM MP45DT02 : I2S2, filtre PDM-vers-PCM et contraintes de sortie