diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-02-18 17:48:57 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-18 17:48:57 +0000 |
| commit | e7af0f7f0010d391e7c926e785d5f3e923e0107c (patch) | |
| tree | ae12a6a9fa96b42c63cec63841ddb2b3cca48a85 | |
| parent | df6cf8da95169dcc13a18bee181f1708dd5be37b (diff) | |
| parent | f9e7fc6e5e3a8c50fb425735a48e65040185413b (diff) | |
Merge pull request #2592 from exzachlyvv/zvv/u5-rng
u5 - add working rng example
| -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 | } | ||
