🛠 Rust embarqué et OpenOCD sur la Discovery F4 : chaîne complète sans CubeIDE

STM32F4DISCOVERY (STM32F407VGT6 Discovery kit) · avance · Schéma : chaîne de développement bare-metal de la STM32F4DISCOVERY — éditeur Rust (stm32f4xx-hal), compilateur cross thumbv7em, GDB pilotant OpenOCD (stm32f4discovery.cfg, ST-LINK, SWD) relié au STM32F407 ; en arrière-plan, la carte mémoire : flash 1024 Ko, SRAM 192 Ko dont 64 Ko CCM, 4 Ko sauvegardée.

Objective

Develop on Rust for the STM32F4DISCOVERY without any proprietary ST tools: the community HAL stm32f4xx-hal (stm32-rs, active in 2026 for the entire F4 family) + OpenOCD, which provides a ready-to-use board file stm32f4discovery.cfg (ST-LINK interface, SWD, srst_only, 64 KiB work area). This tutorial also documents the actual memory map of the F407VGT6, which "blinky" tutorials often gloss over.

The memory map before coding

Toolchain

# 1. Toolchain Rust bare-metal
rustup target add thumbv7em-none-eabihf   # M4F avec FPU materiel

# 2. OpenOCD voit la carte sans configuration maison :
openocd -f interface/stlink.cfg -f board/stm32f4discovery.cfg
#   (le fichier board embarque deja SWD + srst_only + workarea 64K)

# 3. Projet cargo avec stm32f4xx-hal (feature stm32f407, vgt = 1 Mo flash)
cargo build --release --target thumbv7em-none-eabihf
arm-none-eabi-gdb target/thumbv7em-none-eabihf/release/app \
    -ex "target remote :3333" -ex load

Code (stm32f4xx-hal)

// LED verte LD4 = PD12, orange LD3 = PD13 — broches verifiees BSP ST
use stm32f4xx_hal::{pac, prelude::*};

fn main -> ! {
    let dp = pac::Stm32::take.unwrap;
    let cp = cp_core::Peripherals::take.unwrap;
    let mut rcc = dp.RCC.constrain;
    let mut flash = dp.FLASH.constrain;
    // HSE 8 MHz (quartz de la carte) -> 168 MHz systeme
    let clocks = rcc.cfgr.use_hse(8.MHz)
        .sysclk(168.MHz).freeze(&mut flash.acr);

    let mut gpiod = dp.GPIOD.split(&mut rcc.ahb1);
    let mut green = gpiod.pd12.into_push_pull_output(&mut gpiod.moder,
                                                     &mut gpiod.afr);
    let mut delay = cp.SYST.delay(&rcc.clocks);

    loop {
        green.toggle(&mut gpiod.odr);
        delay.delay(1.secs);
    }
}

Why OpenOCD instead of CubeProgrammer?

Both work (Zephyr uses CubeProgrammer by default, with --runner openocd as an alternative). OpenOCD offers: open GDB scripts, reset_config srst_only compliant with the board design, and the same demo for CI integration. The tcl/board/stm32f4discovery.cfg file in the OpenOCD repository is the configuration reference.

Expected verification

Open On-Chip Debugger displays Target chip is STM32F4xx; the GDB load command writes to 0x08000000 and the green LED pulses at 1 Hz. In case the board is "stuck" in low power, srst_only ensures that it is the board's physical reset that acts, not a software reset from the ST-LINK.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials