From 65ae71efffbb3f2d270887f2419d88018451875c Mon Sep 17 00:00:00 2001 From: cscherr Date: Wed, 30 Apr 2025 16:27:18 +0200 Subject: [PATCH] test: first example of tests on host --- examples/aes_ecb.rs | 3 ++- examples/test-on-host.rs | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 examples/test-on-host.rs diff --git a/examples/aes_ecb.rs b/examples/aes_ecb.rs index 617e6d8..6a7efb6 100755 --- a/examples/aes_ecb.rs +++ b/examples/aes_ecb.rs @@ -24,7 +24,8 @@ fn main() -> ! { let mut rcc = dp.RCC.freeze(Config::hsi16()); let mut delay = cp.SYST.delay(rcc.clocks); - compile_error!("The chip does not have an AES unit >:{"); + // WARN: Make sure your chip has AES + panic!("The chip does not have an AES unit >:"); let aes = hal::aes::AES::new(dp.AES, &mut rcc); let mut ecb_stream = aes.enable(::ecb_encrypt(), AES_KEY); let mut encbuf: [[u8; 16]; 4] = [[0; 16]; 4]; diff --git a/examples/test-on-host.rs b/examples/test-on-host.rs new file mode 100755 index 0000000..55a6530 --- /dev/null +++ b/examples/test-on-host.rs @@ -0,0 +1,51 @@ +#![cfg_attr(not(test), no_main)] +#![no_std] + +#[cfg(not(test))] +extern crate panic_halt; + +#[cfg(not(test))] +use cortex_m_rt::entry; +use hal::{pac, prelude::*, rcc::Config}; + +#[cfg(not(test))] +#[entry] +fn main() -> ! { + let dp = pac::Peripherals::take().unwrap(); + let cp = cortex_m::Peripherals::take().unwrap(); + + // Configure the clock. + let mut rcc = dp.RCC.freeze(Config::hsi16()); + + // Acquire the GPIOA peripheral. This also enables the clock for GPIOA in + // the RCC register. + let gpioa = dp.GPIOA.split(&mut rcc); + + // Configure PA5 as output. + let mut led = gpioa.pa5.into_push_pull_output(); + + // Get the delay provider. + let mut delay = cp.SYST.delay(rcc.clocks); + + loop { + led.set_high().unwrap(); + delay.delay_ms(500_u16); + + led.set_low().unwrap(); + delay.delay_ms(500_u16); + } +} + +#[cfg(test)] +fn main() -> ! { + loop {} +} + +#[cfg(test)] +mod tests { + + #[test] + fn test_it_works() { + assert!(true) + } +}