Author: Dulce Andrei-Marian
This project is built on top of the skeleton project for embedded Rust development on the STM32 Nucleo-U545RE-Q development board. It is pre-configured to use the asynchronous Embassy framework and defmt for logging.
This specific implementation plays "Il Vento D'oro" (Giorno's Theme) from JoJo's Bizarre Adventure using a passive buzzer and hardware PWM.
Before using this project, ensure your computer has the necessary tools installed:
- Rust Toolchain: Install Rust via rustup.
- Architecture Target: The STM32U545 requires the ARMv8-M target. Install it by running:
rustup target add thumbv8m.main-none-eabihf - Flashing Tool: Install
probe-rsto flash and debug the firmware:cargo install probe-rs-tools
- Microcontroller: STM32 Nucleo-U545RE-Q
- Actuator: Standard 2-pin passive buzzer
This project is designed to be plug-and-play without a breadboard. The passive buzzer is plugged directly into the Arduino-compatible female headers on the Nucleo board:
- Buzzer Negative (-) Pin ➔
GNDheader - Buzzer Positive (+) Pin ➔
D12header (Maps to MCU pinPA6)
The project is written in #![no_std] Rust using the embassy-stm32 hardware abstraction layer.
- PWM Generation: The buzzer is driven by the
SimplePwmdriver utilizing hardware timerTIM3, Channel 1 on pinPA6. - Asynchronous Delays: Note durations and rests are handled non-blockingly via
embassy_time::Timer. - Borrow Checker Handling: Changing the frequency of a timer requires a mutable borrow of the PWM instance, while setting the volume (duty cycle) requires borrowing the specific channel (
pwm.ch1()). To satisfy Rust's strict borrowing rules, inner scopes{ ... }are used to immediately drop the channel lock after adjusting the duty cycle, allowing the frequency to be safely updated on the next note.
1. Flash via PC: Connect the STM32 Nucleo-U545RE-Q board to your computer. Important: Make sure you use the USB-C STLK port on the board, not the USB USER port. Run the following command to compile the code, flash it to the board, and open the log console:
cargo run