🛠 Zephyr RTOS sur la Nucleo-F401RE : west build, devicetree et west flash

STM32 Nucleo-64 F4 family — flagship: Nucleo-F401RE · intermediaire · Schéma : IMG-stm32f4-nucleo-intermediaire-6-stm32f4nuc-zephyr-blinky-ouest.svg — fenêtre de terminal exécutant west build -b nucleo_f401re puis west flash vers la Nucleo, console série ttyACM0 affichant Hello World

Goals

Build and flash Zephyr RTOS on the Nucleo-F401RE. The board is an in-tree Zephyr target (nucleo_f401re) maintained on main, and the official board doc walks through west build -b nucleo_f401re samples/hello_world + west flash, with output on /dev/ttyACM0. Because the LED comes from the board devicetree, the same blinky source runs on every Nucleo.

Hardware

Steps

  1. Create a Zephyr workspace and initialize main (the board YAML declares 96 KiB RAM / 512 KiB flash).
  2. Build the sample: west build -b nucleo_f401re samples/hello_world
  3. Flash: west flash — the default runner is the STM32CubeProgrammer runner; OpenOCD and J-Link runners also work, all driving the on-board ST-LINK over SWD.
  4. Open /dev/ttyACM0 (Linux) or the ST-LINK COM port (Windows) at 115200.

Code (devicetree-driven blinky)

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

/* led0 = LD2 = PA5 comes from the board DTS, not from this file */
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);

int main(void)
{
    if (!gpio_is_ready_dt(&led)) return -1;
    gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);

    while (1) {
        gpio_pin_toggle_dt(&led);
        k_msleep(500);              /* RTOS sleep, not busy-wait */
    }
    return 0;
}

Build it with west build -b nucleo_f401re samples/basic/blinky.

Why Zephyr on this board

Expected result

hello_world prints Hello World! nucleo_f401re on the serial console; blinky pulses LD2 every 500 ms. Same source, same command line, any Nucleo-64 board — only the -b target changes.

Common mistakes

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials