Skip to content

andrrei509/stm32-jojo-buzzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STM32 Rust Buzzer: JoJo's Bizarre Adventure Theme

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.

Prerequisites

Before using this project, ensure your computer has the necessary tools installed:

  1. Rust Toolchain: Install Rust via rustup.
  2. Architecture Target: The STM32U545 requires the ARMv8-M target. Install it by running: rustup target add thumbv8m.main-none-eabihf
  3. Flashing Tool: Install probe-rs to flash and debug the firmware: cargo install probe-rs-tools

Hardware Used & No-Breadboard Wiring

  • 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 (-) PinGND header
  • Buzzer Positive (+) PinD12 header (Maps to MCU pin PA6)

Software Architecture

The project is written in #![no_std] Rust using the embassy-stm32 hardware abstraction layer.

  • PWM Generation: The buzzer is driven by the SimplePwm driver utilizing hardware timer TIM3, Channel 1 on pin PA6.
  • 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.

Running the Code

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

About

A bare-metal Rust buzzer implementation playing Giorno's Theme (Il Vento D'Oro) (JoJo's Bizarre Adventure: Golden Wind)

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages