🛠 Zephyr RTOS sur la STM32F4DISCOVERY : west build et west flash

STM32F4DISCOVERY (STM32F407VGT6 Discovery kit) · debutant · Schéma : flux de compilation Zephyr pour la carte stm32f4_disco — ligne de commande west build, fichier .elf produit, puis west flash via le ST-LINK/V2-A intégré ; la LED LD4 verte (PD12) clignote sur la carte.

Objective

Set up a professional development workflow on the STM32F4DISCOVERY with Zephyr RTOS, which officially supports the board under the name stm32f4_disco. You will compile the blinky example, flash it via the onboard ST-LINK/V2-A, and understand why the serial console does not work by default.

Hardware

Compilation and flashing

# Une fois l'espace de travail Zephyr installé (west init / west update) :
west build -b stm32f4_disco samples/basic/blinky
west flash

The default runner is STM32CubeProgrammer, which communicates with the board's ST-LINK/V2-A. Documented alternatives: west flash --runner openocd (OpenOCD provides a ready-to-use board file, stm32f4discovery.cfg, using SWD with srst_only) or --runner jlink.

The code

/* blinky — build: west build -b stm32f4_disco samples/basic/blinky */
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

#define LED_NODE DT_ALIAS(led0)

int main(void)
{
        const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios);

        gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
        while (1) {
                gpio_pin_toggle_dt(&led);
                k_msleep(500);
        }
        return 0;
}

Zephyr uses the Device Tree: DT_ALIAS(led0) refers to the user LED defined in the board description, not a hard-coded pin number. The four physical LEDs are LD4 (green, PD12), LD3 (orange, PD13), LD5 (red, PD14), and LD6 (blue, PD15) — the board has eight LEDs in total, including LD1 (USB), LD2 (3.3 V power), and LD7/LD8 (VBUS/OTG overvoltage).

The console: a pitfall to know

Zephyr's default serial settings are 115200 8N1, but the board documentation warns: the ST-LINK's virtual serial port is not connected to the chip's serial port. For console output, plan for an external serial cable on pins UART2, PA2/PA3. Without this, printk goes nowhere — this is the number one point of confusion for beginners on this board.

Expected verification

After west flash, the LED blinks at 1 Hz (500 ms ON / 500 ms OFF), and the command displays Halting target CPU... followed by Successfully programmed. The board runs at 168 MHz (system clock configured from the 8 MHz HSE crystal via the board configuration).

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials