52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
|
#![no_main]
|
||
|
#![no_std]
|
||
|
|
||
|
use cortex_m_semihosting::debug;
|
||
|
|
||
|
use defmt_brtt as _; // global logger
|
||
|
|
||
|
use stm32f3xx_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() -> ! {
|
||
|
loop {
|
||
|
debug::exit(debug::EXIT_SUCCESS);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// 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) -> ! {
|
||
|
loop {
|
||
|
debug::exit(debug::EXIT_FAILURE);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 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)
|
||
|
}
|
||
|
}
|