🛠 Zephyr RTOS sur la Nucleo-F401RE : west build, devicetree et west flash
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
- 1× Nucleo-F401RE + micro-USB cable
- PC with the Zephyr SDK and the
westworkspace tool installed (Zephyr Getting Started guide)
Steps
- Create a Zephyr workspace and initialize
main(the board YAML declares 96 KiB RAM / 512 KiB flash). - Build the sample:
west build -b nucleo_f401re samples/hello_world - 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. - 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
- The board doc lists the full peripheral set: 12-bit ADC (16 ch), RTC, 1 advanced + 7 general-purpose timers, 2 watchdogs, 3× USART/UART, 3× I2C, 4× SPI, SDIO, USB OTG FS, DMA, I2S.
- The board YAML ships Arduino-compat GPIO/I2C/SPI bindings (
arduino_gpio,arduino_i2c,arduino_spi), so shield-style code can move between the Arduino core and Zephyr. k_msleepyields to the kernel — your blink coexists with drivers and threads instead of hogging the CPU.
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
- Leaving CubeProgrammer or a serial monitor open during
west flash: the ST-LINK is busy and the runner fails. - Expecting a bootloader drive: there is none — flashing is SWD through the ST-LINK.
- Following old mbed tutorials: mbed's online services were sunset in July 2026 ; Zephyr (or the Mbed CE fork) is the maintained path.
Autres tutoriels pour cette carte
- Prise en main de la Nucleo-F401RE : ST-LINK, LED LD2 et alimentation
- Premier Blink Arduino sur la Nucleo-F401RE avec le core STM32duino
- Console série sur le ST-LINK VCP : printf, ADC 12 bits et piège du USB
- STM32CubeF4 et HAL : blink + UART printf générés pour la Nucleo-F401RE
- ADC 12 bits et PWM sur la Nucleo-F401RE : oversampling, millivolts et LED en fondu
- Bare-metal sur le STM32F401 : clignoter LD2 en écrivant les registres GPIO