Microcontroller firmware for controlling the lights and volume dial for tonari.
More info outlined here:
https://blog.tonari.no/rust-simple-hardware-project
dfu-util
(brew install dfu-util
, apt install dfu-util
, etc.)stm32flash
(brew install stm32flash
, apt install stm32flash
, etc.)serial-monitor
(cargo install serial-monitor
)The current firmware uses this model:
STM32F411RE
This firmware can also be debugged on a USB-C "black pill" board, linked here: Board Info
The firmware also used to run on the cheaper STM32F103-based boards. Look in the commit history for working with that. It might be beneficial in the future to support both simultaneously and enable one or the other via feature flags.
rustup target add thumbv7em-none-eabihf
You can use the Makefile for easy development.
# Build and flash the firmware
make flash
# Monitor the serial output
make monitor
Simply connect the host computer to the STM32 dev board via a USB cable.
Using a CP2102 (3.3v logic) or another USB-Serial converter, connect its TX
to pin A10
and its RX
to pin A9
.
Also connect 3.3v from the CP2102 to the 3.3v pin on the STM32, and do the same for ground.
If you try to power the STM32 from its USB port without this power connection, it won't work.
cargo build
will create an ARM ELF file, but we need it in a binary .bin
format.
cargo install cargo-binutils
rustup component add llvm-tools-preview
cargo objcopy --release -- -O binary panel-brain-firmware.bin
On the "black pill" board, hold down the BOOT0
button, press and release NRST
(reset button), then let get of BOOT0
to get into flashing mode.
Find your USB-UART converter path via a tool like serial-monitor
or however you prefer. On MacOS it turned up as /dev/cu.SLAB_USBtoUART
but results will vary.
dfu-util -D panel-brain-firmware.bin -d "0483:df11" -a 0 -s 0x08000000
stm32flash -b 230400 -w panel-brain-firmware.bin -v /dev/cu.SLAB_USBtoUART
In the spirit of doing everything in Rust, you can install a straightforward serial monitor via Cargo:
cargo install serial-monitor
Simply invoke it with serial-monitor
and it will begin monitoring the first serial port it finds.
You can also pass it a specific device with
serial-monitor -p /dev/cu.SLAB_USBtoUART
Set the baud rate with the -b
flag:
serial-monitor -b 9600 -p /dev/cu.SLAB_USBtoUART
v*.tar.gz
tarball release on githubblackmagic_dfu_swlink.bin
in the tarball.stm32flash -R -b 230400 -w blackmagic_dfu-swlink.bin -v <PATH_TO_YOUR_SERIAL_DEVICE_HERE>
blackmagic-native.bin
from the release tarball as well.dfu-util -d 1d50:6018,:6017 -s 0x08002000:leave -D blackmagic-native.bin
3v3
, GND
, SWDIO
, and SWCLK
.arm-none-eabi-gdb target/thumbv7em-none-eabihf/release/panel-firmware
(you will need a GNU ARM toolchain for this)target extended-remote /dev/cu.usbmodem95C55F961
(or wherever your blackmagic probe shows up as a device)monitor swdp_scan
attach 1