-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//! This example test the RP Pico on board LED. | ||
//! | ||
//! It does not work with the RP Pico W board. See wifi_blinky.rs. | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use defmt::*; | ||
use embassy_executor::Spawner; | ||
use embassy_rp::block::ImageDef; | ||
use embassy_rp::{bind_interrupts, gpio}; | ||
use embassy_rp::peripherals::TRNG; | ||
use embassy_rp::trng::Trng; | ||
use embassy_time::Timer; | ||
use gpio::{Level, Output}; | ||
use rand::{RngCore, SeedableRng}; | ||
use rand::rngs::SmallRng; | ||
use {defmt_rtt as _, panic_probe as _}; | ||
|
||
#[link_section = ".start_block"] | ||
#[used] | ||
pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe(); | ||
|
||
// Program metadata for `picotool info` | ||
#[link_section = ".bi_entries"] | ||
#[used] | ||
pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [ | ||
embassy_rp::binary_info::rp_program_name!(c"example"), | ||
embassy_rp::binary_info::rp_cargo_version!(), | ||
embassy_rp::binary_info::rp_program_description!(c"Blinky"), | ||
embassy_rp::binary_info::rp_program_build_attribute!(), | ||
]; | ||
|
||
bind_interrupts!(struct Irqs { | ||
TRNG_IRQ => embassy_rp::trng::InterruptHandler<TRNG>; | ||
}); | ||
|
||
#[embassy_executor::main] | ||
async fn main(_spawner: Spawner) { | ||
let peripherals = embassy_rp::init(Default::default()); | ||
// Initialize the TRNG with default configuration | ||
let mut trng = Trng::new(peripherals.TRNG, Irqs, embassy_rp::trng::Config::default()); | ||
// A buffer to collect random bytes in. | ||
let mut randomness = [0u8; 58]; | ||
// A small_rng pseudo RNG initialized from TRNG | ||
let mut small_rng = SmallRng::from_rng(trng).unwrap(); | ||
|
||
loop { | ||
|
||
trng.fill_bytes(&mut randomness).await; | ||
info!("Random bytes async {}", &randomness); | ||
trng.blocking_fill_bytes(&mut randomness).await; | ||
info!("Random bytes blocking {}", &randomness); | ||
let random_u32 = trng.next_u32(); | ||
let random_u64 = trng.next_u64(); | ||
info!("Random u32 {} u64 {}", random_u32, random_u64); | ||
small_rng.fill_bytes(&mut randomness); | ||
info!("Small rng {}", &randomness); | ||
Timer::after_millis(1000).await; | ||
|
||
} | ||
} |