🛠 Premier téléversement sur la STM32F4DISCOVERY avec l'Arduino STM32duino

STM32F4DISCOVERY (STM32F407VGT6 Discovery kit) · debutant · Schéma : STM32F4DISCOVERY vue de dessus avec les quatre LED utilisateur (verte PD12, orange PD13, rouge PD14, bleue PD15), le bouton USER sur PA0 et les deux ports micro-USB (ST-LINK à gauche, OTG FS à droite) ; à côté, l'Arduino IDE avec la carte STM32F407G-DISC1 sélectionnée.

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

Installation

  1. In the Arduino IDE, open the Board Manager and install “STM32 STM32 boards by STMicroelectronics” (Arduino_Core_STM32).
  2. Select the Discovery family, then the “STM32F407G-DISC1” board (constant DISCO_F407VG, variant STM32F4xx/F407V(E-G)T_F417V(E-G)T, cortex-m4 with hardware FPU fpv4-sp-d16, 1 MB of flash / 128 KB of data).
  3. 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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials