diff options
| author | Caleb Jamison <[email protected]> | 2024-08-29 12:28:23 -0400 |
|---|---|---|
| committer | Caleb Jamison <[email protected]> | 2024-08-29 21:08:25 -0400 |
| commit | 0434798439b9037a4fa5f30165879292e388f042 (patch) | |
| tree | e800bac5821057f524ac1d91175c9dd59ba4e0cf /examples | |
| parent | 372270a9b962196ede9c60a705cc3138ba592fec (diff) | |
Import otp from rp-hal, helper fns for chipid and randid
Again, credit to @thejpster for doing the hard part and figuring out the
otp.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rp23/src/bin/otp.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/rp23/src/bin/otp.rs b/examples/rp23/src/bin/otp.rs new file mode 100644 index 000000000..c4d79c6ea --- /dev/null +++ b/examples/rp23/src/bin/otp.rs | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | //! This example shows reading the OTP constants on the RP235x. | ||
| 2 | |||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | |||
| 6 | use defmt::*; | ||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use embassy_rp::block::ImageDef; | ||
| 9 | use embassy_rp::otp; | ||
| 10 | use embassy_time::Timer; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | #[link_section = ".start_block"] | ||
| 14 | #[used] | ||
| 15 | pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe(); | ||
| 16 | |||
| 17 | // Program metadata for `picotool info` | ||
| 18 | #[link_section = ".bi_entries"] | ||
| 19 | #[used] | ||
| 20 | pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [ | ||
| 21 | embassy_rp::binary_info::rp_program_name!(c"OTP Read Example"), | ||
| 22 | embassy_rp::binary_info::rp_cargo_version!(), | ||
| 23 | embassy_rp::binary_info::rp_program_description!(c"OTP Read Example"), | ||
| 24 | embassy_rp::binary_info::rp_program_build_attribute!(), | ||
| 25 | ]; | ||
| 26 | |||
| 27 | #[embassy_executor::main] | ||
| 28 | async fn main(_spawner: Spawner) { | ||
| 29 | let _ = embassy_rp::init(Default::default()); | ||
| 30 | // | ||
| 31 | // add some delay to give an attached debug probe time to parse the | ||
| 32 | // defmt RTT header. Reading that header might touch flash memory, which | ||
| 33 | // interferes with flash write operations. | ||
| 34 | // https://github.com/knurling-rs/defmt/pull/683 | ||
| 35 | Timer::after_millis(10).await; | ||
| 36 | |||
| 37 | let unique_id = unwrap!(otp::get_unique_id()); | ||
| 38 | info!("Unique id:{:X}", unique_id); | ||
| 39 | |||
| 40 | let private_rand = unwrap!(otp::get_private_random_number()); | ||
| 41 | info!("Private Rand:{:X}", private_rand); | ||
| 42 | |||
| 43 | loop { | ||
| 44 | Timer::after_secs(1).await; | ||
| 45 | } | ||
| 46 | } | ||
