Add embassy-imxrt RNG driver

This commit is contained in:
Felipe Balbi
2025-04-11 15:03:53 -07:00
parent 64a2b9b2a3
commit 8e7e4332b4
4 changed files with 299 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
#![no_std]
#![no_main]
extern crate embassy_imxrt_examples;
use defmt::*;
use embassy_executor::Spawner;
use embassy_imxrt::rng::Rng;
use embassy_imxrt::{bind_interrupts, peripherals, rng};
use rand::RngCore;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
RNG => rng::InterruptHandler<peripherals::RNG>;
});
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_imxrt::init(Default::default());
info!("Initializing RNG");
let mut rng = Rng::new(p.RNG, Irqs);
let mut buf = [0u8; 65];
// Async interface
unwrap!(rng.async_fill_bytes(&mut buf).await);
info!("random bytes: {:02x}", buf);
// RngCore interface
let mut random_bytes = [0; 16];
let random_u32 = rng.next_u32();
let random_u64 = rng.next_u64();
rng.fill_bytes(&mut random_bytes);
info!("random_u32 {}", random_u32);
info!("random_u64 {}", random_u64);
info!("random_bytes {}", random_bytes);
}