working hal_test

This commit is contained in:
Priec
2025-10-20 22:37:21 +02:00
parent da01c4593e
commit deee05afb5
13 changed files with 721 additions and 425 deletions

View File

@@ -1,30 +1,24 @@
// src/bin/main.rs
#![no_std]
#![no_main]
use defmt_rtt as _;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_time::{Duration, Timer};
use embassy_stm32::init;
use embassy_stm32::Config;
use embassy_time::Delay;
use embedded_hal::delay::DelayNs;
use panic_probe as _;
use panic_halt as _;
#[cortex_m_rt::entry]
fn main() -> ! {
defmt::info!("Starting blinky on STM32U575ZI-Q...");
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = init(Config::default());
// Initialize peripherals with the default clock tree for STM32U5.
let p = embassy_stm32::init(Config::default());
// Onboard LED (PB7 on NUCLEOU575ZIQ)
let mut led = Output::new(p.PB7, Level::Low, Speed::Low);
let mut delay = Delay;
// The user LED on NUCLEO-U575ZI-Q is typically on port B, pin 0 (verify silkscreen)
let mut led = Output::new(p.PB0, Level::Low, Speed::Low);
loop {
led.set_high();
delay.delay_ms(500); // needs embedded_hal::delay::DelayNs in scope
Timer::after(Duration::from_millis(500)).await;
led.set_low();
delay.delay_ms(500);
Timer::after(Duration::from_millis(500)).await;
}
}

View File

@@ -1,46 +1 @@
#![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)
}
}