aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-04-11 15:03:53 -0700
committerFelipe Balbi <[email protected]>2025-05-09 07:25:23 -0700
commit8e7e4332b40707e8d36338ad8ec486320bb3538f (patch)
treebb4a56fbdde354eee72c997f141b2c2e487d390a /examples
parent64a2b9b2a36adbc26117b8e76ae2b178a5e3eb9f (diff)
Add embassy-imxrt RNG driver
Diffstat (limited to 'examples')
-rw-r--r--examples/mimxrt6/src/bin/rng.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/mimxrt6/src/bin/rng.rs b/examples/mimxrt6/src/bin/rng.rs
new file mode 100644
index 000000000..5f64cb96a
--- /dev/null
+++ b/examples/mimxrt6/src/bin/rng.rs
@@ -0,0 +1,40 @@
1#![no_std]
2#![no_main]
3
4extern crate embassy_imxrt_examples;
5
6use defmt::*;
7use embassy_executor::Spawner;
8use embassy_imxrt::rng::Rng;
9use embassy_imxrt::{bind_interrupts, peripherals, rng};
10use rand::RngCore;
11use {defmt_rtt as _, panic_probe as _};
12
13bind_interrupts!(struct Irqs {
14 RNG => rng::InterruptHandler<peripherals::RNG>;
15});
16
17#[embassy_executor::main]
18async fn main(_spawner: Spawner) {
19 let p = embassy_imxrt::init(Default::default());
20
21 info!("Initializing RNG");
22 let mut rng = Rng::new(p.RNG, Irqs);
23 let mut buf = [0u8; 65];
24
25 // Async interface
26 unwrap!(rng.async_fill_bytes(&mut buf).await);
27 info!("random bytes: {:02x}", buf);
28
29 // RngCore interface
30 let mut random_bytes = [0; 16];
31
32 let random_u32 = rng.next_u32();
33 let random_u64 = rng.next_u64();
34
35 rng.fill_bytes(&mut random_bytes);
36
37 info!("random_u32 {}", random_u32);
38 info!("random_u64 {}", random_u64);
39 info!("random_bytes {}", random_bytes);
40}