2022-10-26 10:01:52 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
2023-08-16 17:51:47 +02:00
|
|
|
teleprobe_meta::target!(b"rpi-pico");
|
2022-10-26 10:01:52 +02:00
|
|
|
|
|
|
|
use defmt::*;
|
|
|
|
use embassy_executor::Spawner;
|
2023-07-25 23:54:33 +02:00
|
|
|
use embassy_rp::flash::{Async, ERASE_SIZE, FLASH_BASE};
|
2023-10-15 01:57:25 +02:00
|
|
|
use embassy_time::Timer;
|
2022-10-26 10:01:52 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
2023-07-25 23:54:33 +02:00
|
|
|
const ADDR_OFFSET: u32 = 0x8000;
|
2022-10-26 10:01:52 +02:00
|
|
|
|
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_rp::init(Default::default());
|
|
|
|
info!("Hello World!");
|
|
|
|
|
2022-10-27 12:41:06 +02:00
|
|
|
// add some delay to give an attached debug probe time to parse the
|
|
|
|
// defmt RTT header. Reading that header might touch flash memory, which
|
|
|
|
// interferes with flash write operations.
|
|
|
|
// https://github.com/knurling-rs/defmt/pull/683
|
2023-10-15 01:57:25 +02:00
|
|
|
Timer::after_millis(10).await;
|
2022-10-27 12:41:06 +02:00
|
|
|
|
2023-07-25 23:54:33 +02:00
|
|
|
let mut flash = embassy_rp::flash::Flash::<_, Async, { 2 * 1024 * 1024 }>::new(p.FLASH, p.DMA_CH0);
|
2022-10-26 10:01:52 +02:00
|
|
|
|
2023-05-16 11:28:35 +02:00
|
|
|
// Get JEDEC id
|
2023-08-18 13:12:19 +02:00
|
|
|
let jedec = defmt::unwrap!(flash.blocking_jedec_id());
|
2023-05-16 11:28:35 +02:00
|
|
|
info!("jedec id: 0x{:x}", jedec);
|
|
|
|
|
|
|
|
// Get unique id
|
|
|
|
let mut uid = [0; 8];
|
2023-08-18 13:12:19 +02:00
|
|
|
defmt::unwrap!(flash.blocking_unique_id(&mut uid));
|
2023-05-16 11:28:35 +02:00
|
|
|
info!("unique id: {:?}", uid);
|
|
|
|
|
2022-10-26 10:01:52 +02:00
|
|
|
let mut buf = [0u8; ERASE_SIZE];
|
2023-08-18 13:12:19 +02:00
|
|
|
defmt::unwrap!(flash.blocking_read(ADDR_OFFSET, &mut buf));
|
2022-10-26 10:01:52 +02:00
|
|
|
|
|
|
|
info!("Addr of flash block is {:x}", ADDR_OFFSET + FLASH_BASE as u32);
|
|
|
|
info!("Contents start with {=[u8]}", buf[0..4]);
|
|
|
|
|
2023-08-18 13:12:19 +02:00
|
|
|
defmt::unwrap!(flash.blocking_erase(ADDR_OFFSET, ADDR_OFFSET + ERASE_SIZE as u32));
|
2022-10-26 10:01:52 +02:00
|
|
|
|
2023-08-18 13:12:19 +02:00
|
|
|
defmt::unwrap!(flash.blocking_read(ADDR_OFFSET, &mut buf));
|
2022-10-26 10:01:52 +02:00
|
|
|
info!("Contents after erase starts with {=[u8]}", buf[0..4]);
|
|
|
|
if buf.iter().any(|x| *x != 0xFF) {
|
|
|
|
defmt::panic!("unexpected");
|
|
|
|
}
|
|
|
|
|
|
|
|
for b in buf.iter_mut() {
|
|
|
|
*b = 0xDA;
|
|
|
|
}
|
|
|
|
|
2023-08-18 13:12:19 +02:00
|
|
|
defmt::unwrap!(flash.blocking_write(ADDR_OFFSET, &mut buf));
|
2022-10-26 10:01:52 +02:00
|
|
|
|
2023-08-18 13:12:19 +02:00
|
|
|
defmt::unwrap!(flash.blocking_read(ADDR_OFFSET, &mut buf));
|
2022-10-26 10:01:52 +02:00
|
|
|
info!("Contents after write starts with {=[u8]}", buf[0..4]);
|
|
|
|
if buf.iter().any(|x| *x != 0xDA) {
|
|
|
|
defmt::panic!("unexpected");
|
|
|
|
}
|
|
|
|
|
2023-07-25 23:54:33 +02:00
|
|
|
let mut buf = [0u32; ERASE_SIZE / 4];
|
|
|
|
|
|
|
|
defmt::unwrap!(flash.background_read(ADDR_OFFSET, &mut buf)).await;
|
|
|
|
info!("Contents after write starts with {=u32:x}", buf[0]);
|
|
|
|
if buf.iter().any(|x| *x != 0xDADADADA) {
|
|
|
|
defmt::panic!("unexpected");
|
|
|
|
}
|
|
|
|
|
2022-10-26 10:01:52 +02:00
|
|
|
info!("Test OK");
|
|
|
|
cortex_m::asm::bkpt();
|
|
|
|
}
|