aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-09-10 21:36:49 +0000
committerGitHub <[email protected]>2024-09-10 21:36:49 +0000
commit0bf9a2591b062f2f8409fe27c590e1783b139e38 (patch)
treec738996dd476da1fde72f23ef5eb05620498a8d4 /examples
parentaff1e7486210f6fa80627b92da5b24a1c8bf6017 (diff)
parente75903138a92e6c749454cee516c812df618bbfa (diff)
Merge pull request #3297 from CBJamo/rp2350_flash
rp: 2350 flash write and OTP
Diffstat (limited to 'examples')
-rw-r--r--examples/rp23/.cargo/config.toml3
-rw-r--r--examples/rp23/src/bin/flash.rs15
-rw-r--r--examples/rp23/src/bin/otp.rs46
3 files changed, 51 insertions, 13 deletions
diff --git a/examples/rp23/.cargo/config.toml b/examples/rp23/.cargo/config.toml
index f77e004dc..9a92b1ce2 100644
--- a/examples/rp23/.cargo/config.toml
+++ b/examples/rp23/.cargo/config.toml
@@ -1,6 +1,7 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2#runner = "probe-rs run --chip RP2040" 2#runner = "probe-rs run --chip RP2040"
3runner = "elf2uf2-rs -d" 3#runner = "elf2uf2-rs -d"
4runner = "picotool load -u -v -x -t elf"
4 5
5[build] 6[build]
6target = "thumbv8m.main-none-eabihf" 7target = "thumbv8m.main-none-eabihf"
diff --git a/examples/rp23/src/bin/flash.rs b/examples/rp23/src/bin/flash.rs
index 811561f26..84011e394 100644
--- a/examples/rp23/src/bin/flash.rs
+++ b/examples/rp23/src/bin/flash.rs
@@ -21,7 +21,7 @@ pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe();
21pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [ 21pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [
22 embassy_rp::binary_info::rp_program_name!(c"example"), 22 embassy_rp::binary_info::rp_program_name!(c"example"),
23 embassy_rp::binary_info::rp_cargo_version!(), 23 embassy_rp::binary_info::rp_cargo_version!(),
24 embassy_rp::binary_info::rp_program_description!(c"Blinky"), 24 embassy_rp::binary_info::rp_program_description!(c"Flash"),
25 embassy_rp::binary_info::rp_program_build_attribute!(), 25 embassy_rp::binary_info::rp_program_build_attribute!(),
26]; 26];
27 27
@@ -41,22 +41,13 @@ async fn main(_spawner: Spawner) {
41 41
42 let mut flash = embassy_rp::flash::Flash::<_, Async, FLASH_SIZE>::new(p.FLASH, p.DMA_CH0); 42 let mut flash = embassy_rp::flash::Flash::<_, Async, FLASH_SIZE>::new(p.FLASH, p.DMA_CH0);
43 43
44 // Get JEDEC id
45 let jedec = flash.blocking_jedec_id().unwrap();
46 info!("jedec id: 0x{:x}", jedec);
47
48 // Get unique id
49 let mut uid = [0; 8];
50 flash.blocking_unique_id(&mut uid).unwrap();
51 info!("unique id: {:?}", uid);
52
53 erase_write_sector(&mut flash, 0x00); 44 erase_write_sector(&mut flash, 0x00);
54 45
55 multiwrite_bytes(&mut flash, ERASE_SIZE as u32); 46 multiwrite_bytes(&mut flash, ERASE_SIZE as u32);
56 47
57 background_read(&mut flash, (ERASE_SIZE * 2) as u32).await; 48 background_read(&mut flash, (ERASE_SIZE * 2) as u32).await;
58 49
59 loop {} 50 info!("Flash Works!");
60} 51}
61 52
62fn multiwrite_bytes(flash: &mut embassy_rp::flash::Flash<'_, FLASH, Async, FLASH_SIZE>, offset: u32) { 53fn multiwrite_bytes(flash: &mut embassy_rp::flash::Flash<'_, FLASH, Async, FLASH_SIZE>, offset: u32) {
@@ -82,7 +73,7 @@ fn multiwrite_bytes(flash: &mut embassy_rp::flash::Flash<'_, FLASH, Async, FLASH
82 73
83 defmt::unwrap!(flash.blocking_read(ADDR_OFFSET + offset, &mut read_buf)); 74 defmt::unwrap!(flash.blocking_read(ADDR_OFFSET + offset, &mut read_buf));
84 info!("Contents after write starts with {=[u8]}", read_buf[0..4]); 75 info!("Contents after write starts with {=[u8]}", read_buf[0..4]);
85 if &read_buf[0..4] != &[0x01, 0x02, 0x03, 0x04] { 76 if read_buf[0..4] != [0x01, 0x02, 0x03, 0x04] {
86 defmt::panic!("unexpected"); 77 defmt::panic!("unexpected");
87 } 78 }
88} 79}
diff --git a/examples/rp23/src/bin/otp.rs b/examples/rp23/src/bin/otp.rs
new file mode 100644
index 000000000..106e514ca
--- /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
6use defmt::*;
7use embassy_executor::Spawner;
8use embassy_rp::block::ImageDef;
9use embassy_rp::otp;
10use embassy_time::Timer;
11use {defmt_rtt as _, panic_probe as _};
12
13#[link_section = ".start_block"]
14#[used]
15pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe();
16
17// Program metadata for `picotool info`
18#[link_section = ".bi_entries"]
19#[used]
20pub 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]
28async 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 chip_id = unwrap!(otp::get_chipid());
38 info!("Unique id:{:X}", chip_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}