diff options
| author | Zach <[email protected]> | 2024-02-17 14:00:03 -0600 |
|---|---|---|
| committer | Zach <[email protected]> | 2024-02-17 14:00:03 -0600 |
| commit | f9e7fc6e5e3a8c50fb425735a48e65040185413b (patch) | |
| tree | 7c6af2c0690e875e18a6f6c3b586c0fa05cd2184 /examples | |
| parent | 377e58e408f830f79171a470ba602b7d8bc525e4 (diff) | |
u5 - add working rng example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32u5/src/bin/rng.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/stm32u5/src/bin/rng.rs b/examples/stm32u5/src/bin/rng.rs new file mode 100644 index 000000000..3a5bce097 --- /dev/null +++ b/examples/stm32u5/src/bin/rng.rs | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::rng::Rng; | ||
| 7 | use embassy_stm32::{bind_interrupts, peripherals, rng}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | bind_interrupts!(struct Irqs { | ||
| 11 | RNG => rng::InterruptHandler<peripherals::RNG>; | ||
| 12 | }); | ||
| 13 | |||
| 14 | #[embassy_executor::main] | ||
| 15 | async fn main(_spawner: Spawner) { | ||
| 16 | let p = embassy_stm32::init(Default::default()); | ||
| 17 | |||
| 18 | info!("Hello World!"); | ||
| 19 | |||
| 20 | let mut rng = Rng::new(p.RNG, Irqs); | ||
| 21 | |||
| 22 | let mut buf = [0u8; 16]; | ||
| 23 | unwrap!(rng.async_fill_bytes(&mut buf).await); | ||
| 24 | info!("random bytes: {:02x}", buf); | ||
| 25 | } | ||
