diff options
| author | Mathias <[email protected]> | 2022-10-26 10:01:52 +0200 |
|---|---|---|
| committer | Mathias <[email protected]> | 2022-10-26 12:24:04 +0200 |
| commit | 80e58426fcf40b6cea28368e43a7289e827461cf (patch) | |
| tree | 48ce94c3404b3b95c082914376d5510658a18f38 /tests | |
| parent | ad0eb3f4bd2b124fcb7cda6d6bd88e2b12632ea7 (diff) | |
Add flash example & flash HIL test
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/rp/Cargo.toml | 1 | ||||
| -rw-r--r-- | tests/rp/src/bin/flash.rs | 48 |
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index d6770d6e9..48c88e85b 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml | |||
| @@ -22,6 +22,7 @@ embedded-hal-async = { version = "=0.1.0-alpha.2" } | |||
| 22 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 22 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 23 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 23 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 24 | embedded-io = { version = "0.3.0", features = ["async"] } | 24 | embedded-io = { version = "0.3.0", features = ["async"] } |
| 25 | embedded-storage = { version = "0.3" } | ||
| 25 | 26 | ||
| 26 | [profile.dev] | 27 | [profile.dev] |
| 27 | debug = 2 | 28 | debug = 2 |
diff --git a/tests/rp/src/bin/flash.rs b/tests/rp/src/bin/flash.rs new file mode 100644 index 000000000..4cbd78fe9 --- /dev/null +++ b/tests/rp/src/bin/flash.rs | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_rp::flash::{ERASE_SIZE, FLASH_BASE}; | ||
| 8 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 10 | |||
| 11 | const ADDR_OFFSET: u32 = 0x4000; | ||
| 12 | |||
| 13 | #[embassy_executor::main] | ||
| 14 | async fn main(_spawner: Spawner) { | ||
| 15 | let p = embassy_rp::init(Default::default()); | ||
| 16 | info!("Hello World!"); | ||
| 17 | |||
| 18 | let mut flash = embassy_rp::flash::Flash::<_, { 2 * 1024 * 1024 }>::new(p.FLASH); | ||
| 19 | |||
| 20 | let mut buf = [0u8; ERASE_SIZE]; | ||
| 21 | defmt::unwrap!(flash.read(ADDR_OFFSET, &mut buf)); | ||
| 22 | |||
| 23 | info!("Addr of flash block is {:x}", ADDR_OFFSET + FLASH_BASE as u32); | ||
| 24 | info!("Contents start with {=[u8]}", buf[0..4]); | ||
| 25 | |||
| 26 | defmt::unwrap!(flash.erase(ADDR_OFFSET, ADDR_OFFSET + ERASE_SIZE as u32)); | ||
| 27 | |||
| 28 | defmt::unwrap!(flash.read(ADDR_OFFSET, &mut buf)); | ||
| 29 | info!("Contents after erase starts with {=[u8]}", buf[0..4]); | ||
| 30 | if buf.iter().any(|x| *x != 0xFF) { | ||
| 31 | defmt::panic!("unexpected"); | ||
| 32 | } | ||
| 33 | |||
| 34 | for b in buf.iter_mut() { | ||
| 35 | *b = 0xDA; | ||
| 36 | } | ||
| 37 | |||
| 38 | defmt::unwrap!(flash.write(ADDR_OFFSET, &mut buf)); | ||
| 39 | |||
| 40 | defmt::unwrap!(flash.read(ADDR_OFFSET, &mut buf)); | ||
| 41 | info!("Contents after write starts with {=[u8]}", buf[0..4]); | ||
| 42 | if buf.iter().any(|x| *x != 0xDA) { | ||
| 43 | defmt::panic!("unexpected"); | ||
| 44 | } | ||
| 45 | |||
| 46 | info!("Test OK"); | ||
| 47 | cortex_m::asm::bkpt(); | ||
| 48 | } | ||
