STM32 Nucleo
Board
- https://en.wikipedia.org/wiki/STM32#Development_boards
- NUCLEO-F302R8 board for STM32F302R8T6 MCU with 72 MHz Cortex-M4F core, 64 KB flash, 16 KB SRAM.
Documentation
Software - Void Linux
- Install software
xi stlink - Set up udev rules (as root)
#/etc/udev/rules.d/stm32nucleo.rules SUBSYSTEM!="usb|usb_device", ACTION!="add", GOTO="stm32nucleo_end" ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", SYMLINK+="stm32-%k", MODE="660", GROUP="input" LABEL="stm32nucleo_end" - Connect device
- Probe for the device
st-info --probe; should print something like this:
Found 1 stlink programmers version: V2J33S25 serial: 066FFF5155xxxxxxxxxxxxx flash: 65536 (pagesize: 2048) sram: 40960 chipid: 0x439 dev-type: STM32F301_F302_F318 - Read boot or flash area
st-flash read /tmp/boot.bin 0x0 0x10000 # flash if booting from flash st-flash read /tmp/flash.bin 0x8000000 0x10000 # flash
Debugging
- Install tools
xi cross-arm-none-eabi cross-arm-none-eabi-gdb - Using GDB
- Connect to device
st-util - Run GDB
arm-none-eabi-gdb -ex 'target extended-remote localhost:4242'
- Connect to device
Using OpenOCD
- Install
xi openocd inetutils-telnet - Run server
openocd -f interface/stlink.cfg -f target/stm32f3x.cfg - It should print something like
Info : STLINK V2J33M25 (API v2) VID:PID 0483:374B Info : Target voltage: 3.238345 Info : [stm32f3x.cpu] Cortex-M4 r0p1 processor detected Info : [stm32f3x.cpu] target has 6 breakpoints, 4 watchpoints - Now you can telnet to the debugger:
telnet localhost 4444
halt reg # read output register of port B read_memory 0x48000414 32 1 # disable LED on PB-13 write_memory 0x48000414 32 0x0 # enable LED on PB-13 write_memory 0x48000414 32 0x2000
Rust
Tools:
rustup target add thumbv7em-none-eabihf
rustup component add llvm-tools-preview
cargo install cargo-binutils
cargo install cargo-generate
Template project
cargo generate --git https://github.com/rust-embedded/cortex-m-quickstart
Edit .cargo/config.toml and comment other and un-comment target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) .
It should now build:
cargo build
cargo readobj -- --file-headers
To see assembly (look for 00000484 <main>:):
cargo objdump --release -- --disassemble --no-show-raw-insn --print-imm-hex
QEMU
Install QEMU:
xi qemu libnuma
Build example program:
#![no_std]
#![no_main]
use panic_halt as _;
use cortex_m_rt::entry;
use cortex_m_semihosting::{debug, hprintln};
#[entry]
fn main() -> ! {
hprintln!("Hello, world!").unwrap();
// exit QEMU
// NOTE do not run this on hardware; it can corrupt OpenOCD state
debug::exit(debug::EXIT_SUCCESS);
loop {}
}
Build:
cargo build --release
Run (note we are using netduinoplus2 device,device as it uses M4 CPU as well, see: https://qemu.readthedocs.io/en/master/system/arm/stm32.html):
qemu-system-arm \
-cpu cortex-m4 \
-machine netduinoplus2 \
-nographic \
-semihosting-config enable=on,target=native \
-kernel target/thumbv7em-none-eabihf/release/stm32-nucleo-test
It should print Hello, world!.