add new hardware peripheral

This commit is contained in:
2026-05-25 18:41:46 +02:00
parent 8028dfd5fc
commit be5dd9632c
10 changed files with 91 additions and 18 deletions

2
Cargo.lock generated
View File

@@ -296,6 +296,7 @@ dependencies = [
name = "embassy-blinky"
version = "0.1.0"
dependencies = [
"cortex-m",
"cortex-m-rt",
"defmt 1.1.0",
"defmt-rtt",
@@ -309,6 +310,7 @@ dependencies = [
name = "embassy-button"
version = "0.1.0"
dependencies = [
"cortex-m",
"cortex-m-rt",
"defmt 1.1.0",
"defmt-rtt",

View File

@@ -11,6 +11,29 @@
See [blue-pill.md](docs/hardware/blue-pill.md) for wiring notes.
## Attached Hardware
- internal LED: `PC13`
- RGB LED:
- `PA5` = red
- `PA6` = green
- `PA7` = blue
- `PA4` = drive low for the LED return path
- 5-way button board:
- `PB12` = GND, drive low
- `PA10` = VCC, drive high
- `PB13` = right
- `PB14` = down
- `PB15` = left
- `PA8` = center
- `PA9` = up
- HMC5883L module:
- `PB4` = VCC, drive high
- `PB5` = GND, drive low
- `PB6` = SCL
- `PB7` = SDA
- `PB8` = DRDY
## Important Target Note
- Blue Pill `STM32F103` is Cortex-M3 and uses `thumbv7m-none-eabi`.
@@ -71,14 +94,15 @@ probe-rs chip list | rg STM32F103
- `blinky-basic` - plain `no_std` blink with a simple delay
- `blinky-timer` - periodic blink driven by a timer abstraction
- `button-input` - poll a button on `PA0`, mirror state on the LED, log transitions
- `button-input` - poll the center button on `PA8`, mirror state on the LED, log transitions
- `embassy-blinky` - minimal async blink with Embassy
- `embassy-button` - minimal Embassy polling loop for a button on `PA0`
- `embassy-button` - minimal Embassy polling loop for the center button on `PA8`
The button examples assume a simple external button:
The button examples assume the 5-way board is wired like this:
- one side to `PA0`
- one side to `3V3`
- `PB12` forced low for ground
- `PA10` forced high for power
- `PA8` used as the center button input
- internal pull-down enabled in firmware
- common ground still required for the probe

View File

@@ -13,12 +13,33 @@
- `set_low()` usually turns it on
- `set_high()` usually turns it off
## Button Assumption
## RGB LED
- The repo button examples use `PA0`
- Assumed wiring:
- button between `PA0` and `3V3`
- firmware enables internal pull-down
- `PA5` = red
- `PA6` = green
- `PA7` = blue
- `PA4` = drive low for the LED return path
## 5-Way Button Board
- `PB12` = GND, drive low
- `PA10` = VCC, drive high
- `PB13` = right
- `PB14` = down
- `PB15` = left
- `PA8` = center
- `PA9` = up
- Assumption: the button inputs read high when pressed
- The button examples use `PA8` as the default center button
- TODO: flip the input polarity if your module is active-low instead
## HMC5883L Module
- `PB4` = VCC, drive high
- `PB5` = GND, drive low
- `PB6` = SCL
- `PB7` = SDA
- `PB8` = DRDY
## Probe Wiring

View File

@@ -6,9 +6,9 @@ Each example is its own Cargo package.
- `blinky-basic` - simple delay, simple LED ownership story
- `blinky-timer` - periodic blink with a timer abstraction
- `button-input` - poll `PA0`, mirror state to `PC13`, log transitions
- `button-input` - poll the center button on `PA8`, mirror state to `PC13`, log transitions
- `embassy-blinky` - minimal Embassy executor and async blink
- `embassy-button` - minimal Embassy polling loop for `PA0`
- `embassy-button` - minimal Embassy polling loop for the center button on `PA8`
## Build One Example

View File

@@ -17,18 +17,25 @@ fn main() -> ! {
let mut rcc = dp.RCC.constrain();
let mut gpioa = dp.GPIOA.split(&mut rcc);
let mut gpiob = dp.GPIOB.split(&mut rcc);
let mut gpioc = dp.GPIOC.split(&mut rcc);
let button = gpioa.pa0.into_pull_down_input(&mut gpioa.crl);
// Assumes the center switch line goes high when pressed.
let button = gpioa.pa8.into_pull_down_input(&mut gpioa.crh);
let mut vcc = gpioa.pa10.into_push_pull_output(&mut gpioa.crh);
let mut gnd = gpiob.pb12.into_push_pull_output(&mut gpiob.crh);
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
let mut delay = cp.SYST.delay(&rcc.clocks);
gnd.set_low();
vcc.set_high();
let mut was_pressed = button.is_high();
led.set_high();
info!("button-input: PA0 button to 3V3 with internal pull-down");
info!("button-input: PA8 center button, PA10 high, PB12 low");
loop {
let pressed = button.is_high();
let pressed = !button.is_high();
if pressed != was_pressed {
was_pressed = pressed;

View File

@@ -6,6 +6,7 @@ publish = false
build = "build.rs"
[dependencies]
cortex-m.workspace = true
cortex-m-rt.workspace = true
defmt.workspace = true
defmt-rtt.workspace = true

View File

@@ -4,6 +4,7 @@
use defmt::info;
use defmt_rtt as _;
use cortex_m as _;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_time::Timer;

View File

@@ -6,6 +6,7 @@ publish = false
build = "build.rs"
[dependencies]
cortex-m.workspace = true
cortex-m-rt.workspace = true
defmt.workspace = true
defmt-rtt.workspace = true

View File

@@ -4,6 +4,7 @@
use defmt::info;
use defmt_rtt as _;
use cortex_m as _;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_time::Timer;
@@ -12,14 +13,17 @@ use panic_probe as _;
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
let button = Input::new(p.PA0, Pull::Down);
// Assumes the center switch line goes high when pressed.
let button = Input::new(p.PA8, Pull::Down);
let _vcc = Output::new(p.PA10, Level::High, Speed::Low);
let _gnd = Output::new(p.PB12, Level::Low, Speed::Low);
let mut led = Output::new(p.PC13, Level::High, Speed::Low);
let mut was_pressed = button.is_high();
info!("embassy-button: polling PA0 every 25 ms");
info!("embassy-button: polling PA8 every 25 ms");
loop {
let pressed = button.is_high();
let pressed = !button.is_high();
if pressed != was_pressed {
was_pressed = pressed;

View File

@@ -45,10 +45,22 @@ run-blinky:
cargo build -p blinky-basic
probe-rs run --chip {{chip}} target/{{target}}/debug/blinky-basic
run-timer:
cargo build -p blinky-timer
probe-rs run --chip {{chip}} target/{{target}}/debug/blinky-timer
run-button:
cargo build -p button-input
probe-rs run --chip {{chip}} target/{{target}}/debug/button-input
run-embassy-blinky:
cargo build -p embassy-blinky
probe-rs run --chip {{chip}} target/{{target}}/debug/embassy-blinky
run-embassy-button:
cargo build -p embassy-button
probe-rs run --chip {{chip}} target/{{target}}/debug/embassy-button
fmt:
cargo fmt --all