embassy hal
This commit is contained in:
30
hal_test/src/bin/main.rs
Normal file
30
hal_test/src/bin/main.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
// src/bin/main.rs
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt_rtt as _;
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Config;
|
||||
use embassy_time::Delay;
|
||||
use embedded_hal::delay::DelayNs;
|
||||
use panic_probe as _;
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
fn main() -> ! {
|
||||
defmt::info!("Starting blinky on STM32U575ZI-Q...");
|
||||
|
||||
// Initialize peripherals with the default clock tree for STM32U5.
|
||||
let p = embassy_stm32::init(Config::default());
|
||||
|
||||
// On‑board LED (PB7 on NUCLEO‑U575ZI‑Q)
|
||||
let mut led = Output::new(p.PB7, Level::Low, Speed::Low);
|
||||
let mut delay = Delay;
|
||||
|
||||
loop {
|
||||
led.set_high();
|
||||
delay.delay_ms(500); // needs embedded_hal::delay::DelayNs in scope
|
||||
led.set_low();
|
||||
delay.delay_ms(500);
|
||||
}
|
||||
}
|
||||
46
hal_test/src/lib.rs
Normal file
46
hal_test/src/lib.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
|
||||
// TODO(5) adjust HAL import
|
||||
// use some_hal as _; // memory layout
|
||||
|
||||
use panic_probe as _;
|
||||
|
||||
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
|
||||
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
|
||||
#[defmt::panic_handler]
|
||||
fn panic() -> ! {
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||
/// with status code 0.
|
||||
pub fn exit() -> ! {
|
||||
semihosting::process::exit(0);
|
||||
}
|
||||
|
||||
/// Hardfault handler.
|
||||
///
|
||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||
/// with an error. This seems better than the default, which is to spin in a
|
||||
/// loop.
|
||||
#[cortex_m_rt::exception]
|
||||
unsafe fn HardFault(_frame: &cortex_m_rt::ExceptionFrame) -> ! {
|
||||
semihosting::process::exit(1);
|
||||
}
|
||||
|
||||
// defmt-test 0.3.0 has the limitation that this `#[tests]` attribute can only be used
|
||||
// once within a crate. the module can be in any file but there can only be at most
|
||||
// one `#[tests]` module in this library crate
|
||||
#[cfg(test)]
|
||||
#[defmt_test::tests]
|
||||
mod unit_tests {
|
||||
use defmt::assert;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert!(true)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user