Initial commit

This commit is contained in:
2026-07-03 12:59:18 +02:00
commit fcf95f44e9
30 changed files with 8325 additions and 0 deletions

65
src/bin/12_embassy.rs Normal file
View File

@@ -0,0 +1,65 @@
// Embassy async loop.
// Show timers, tasks, and printing together.
// This is why a framework can beat a hand-written loop.
#![allow(unsafe_code)]
#![no_std]
#![no_main]
use cortex_m_semihosting::hprintln;
use embassy_executor::Spawner;
use embassy_time::{Duration, Ticker, Timer};
use panic_probe as _;
// Stub out interrupts that the PAC expects but this chapter does not use.
#[allow(non_snake_case)]
#[unsafe(no_mangle)]
pub extern "C" fn USB_HP_CAN1_TX() {}
// Stub out interrupts that the PAC expects but this chapter does not use.
#[allow(non_snake_case)]
#[unsafe(no_mangle)]
pub extern "C" fn USB_LP_CAN1_RX0() {}
// Stub out interrupts that the PAC expects but this chapter does not use.
#[allow(non_snake_case)]
#[unsafe(no_mangle)]
pub extern "C" fn CAN1_RX1() {}
// Stub out interrupts that the PAC expects but this chapter does not use.
#[allow(non_snake_case)]
#[unsafe(no_mangle)]
pub extern "C" fn CAN1_SCE() {}
// Stub out interrupts that the PAC expects but this chapter does not use.
#[allow(non_snake_case)]
#[unsafe(no_mangle)]
pub extern "C" fn RTC_ALARM() {}
// Stub out interrupts that the PAC expects but this chapter does not use.
#[allow(non_snake_case)]
#[unsafe(no_mangle)]
pub extern "C" fn USBWAKEUP() {}
#[embassy_executor::task]
async fn heartbeat() {
let mut ticker = Ticker::every(Duration::from_secs(1));
loop {
ticker.next().await;
hprintln!("embassy heartbeat");
}
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let _p = embassy_stm32::init(Default::default());
hprintln!("embassy boot");
spawner.spawn(heartbeat()).unwrap();
loop {
Timer::after_secs(2).await;
hprintln!("embassy main loop");
}
}