Add flash example & flash HIL test
This commit is contained in:
@ -22,6 +22,7 @@ embedded-hal-async = { version = "=0.1.0-alpha.2" }
|
||||
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||
embedded-io = { version = "0.3.0", features = ["async"] }
|
||||
embedded-storage = { version = "0.3" }
|
||||
|
||||
[profile.dev]
|
||||
debug = 2
|
||||
|
48
tests/rp/src/bin/flash.rs
Normal file
48
tests/rp/src/bin/flash.rs
Normal file
@ -0,0 +1,48 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::flash::{ERASE_SIZE, FLASH_BASE};
|
||||
use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const ADDR_OFFSET: u32 = 0x4000;
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let mut flash = embassy_rp::flash::Flash::<_, { 2 * 1024 * 1024 }>::new(p.FLASH);
|
||||
|
||||
let mut buf = [0u8; ERASE_SIZE];
|
||||
defmt::unwrap!(flash.read(ADDR_OFFSET, &mut buf));
|
||||
|
||||
info!("Addr of flash block is {:x}", ADDR_OFFSET + FLASH_BASE as u32);
|
||||
info!("Contents start with {=[u8]}", buf[0..4]);
|
||||
|
||||
defmt::unwrap!(flash.erase(ADDR_OFFSET, ADDR_OFFSET + ERASE_SIZE as u32));
|
||||
|
||||
defmt::unwrap!(flash.read(ADDR_OFFSET, &mut buf));
|
||||
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;
|
||||
}
|
||||
|
||||
defmt::unwrap!(flash.write(ADDR_OFFSET, &mut buf));
|
||||
|
||||
defmt::unwrap!(flash.read(ADDR_OFFSET, &mut buf));
|
||||
info!("Contents after write starts with {=[u8]}", buf[0..4]);
|
||||
if buf.iter().any(|x| *x != 0xDA) {
|
||||
defmt::panic!("unexpected");
|
||||
}
|
||||
|
||||
info!("Test OK");
|
||||
cortex_m::asm::bkpt();
|
||||
}
|
Reference in New Issue
Block a user