diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-10-16 04:54:48 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-10-16 05:35:29 +0200 |
| commit | aff77d2b65952368ea464f1b6950896afa093677 (patch) | |
| tree | 4ff245fbb7695669cb5a6bd4e948d613ddd17098 /tests/stm32/src/bin | |
| parent | a7c6999670dd477914b0b83e2dc32ae2bf4701be (diff) | |
stm32/rng: add test.
Diffstat (limited to 'tests/stm32/src/bin')
| -rw-r--r-- | tests/stm32/src/bin/rng.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/stm32/src/bin/rng.rs b/tests/stm32/src/bin/rng.rs new file mode 100644 index 000000000..65da737d0 --- /dev/null +++ b/tests/stm32/src/bin/rng.rs | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | // required-features: rng | ||
| 2 | #![no_std] | ||
| 3 | #![no_main] | ||
| 4 | #![feature(type_alias_impl_trait)] | ||
| 5 | |||
| 6 | #[path = "../common.rs"] | ||
| 7 | mod common; | ||
| 8 | use common::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_stm32::rng::Rng; | ||
| 11 | use embassy_stm32::{bind_interrupts, peripherals, rng}; | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | |||
| 14 | #[cfg(any(feature = "stm32l4a6zg", feature = "stm32h755zi", feature = "stm32f429zi"))] | ||
| 15 | bind_interrupts!(struct Irqs { | ||
| 16 | HASH_RNG => rng::InterruptHandler<peripherals::RNG>; | ||
| 17 | }); | ||
| 18 | #[cfg(any(feature = "stm32l073rz"))] | ||
| 19 | bind_interrupts!(struct Irqs { | ||
| 20 | RNG_LPUART1 => rng::InterruptHandler<peripherals::RNG>; | ||
| 21 | }); | ||
| 22 | #[cfg(not(any( | ||
| 23 | feature = "stm32l4a6zg", | ||
| 24 | feature = "stm32l073rz", | ||
| 25 | feature = "stm32h755zi", | ||
| 26 | feature = "stm32f429zi" | ||
| 27 | )))] | ||
| 28 | bind_interrupts!(struct Irqs { | ||
| 29 | RNG => rng::InterruptHandler<peripherals::RNG>; | ||
| 30 | }); | ||
| 31 | |||
| 32 | #[embassy_executor::main] | ||
| 33 | async fn main(_spawner: Spawner) { | ||
| 34 | let p: embassy_stm32::Peripherals = embassy_stm32::init(config()); | ||
| 35 | |||
| 36 | let mut rng = Rng::new(p.RNG, Irqs); | ||
| 37 | |||
| 38 | let mut buf1 = [0u8; 16]; | ||
| 39 | unwrap!(rng.async_fill_bytes(&mut buf1).await); | ||
| 40 | info!("random bytes: {:02x}", buf1); | ||
| 41 | |||
| 42 | let mut buf2 = [0u8; 16]; | ||
| 43 | unwrap!(rng.async_fill_bytes(&mut buf2).await); | ||
| 44 | info!("random bytes: {:02x}", buf2); | ||
| 45 | |||
| 46 | defmt::assert!(buf1 != buf2); | ||
| 47 | |||
| 48 | info!("Test OK"); | ||
| 49 | cortex_m::asm::bkpt(); | ||
| 50 | } | ||
