diff options
| author | Zach <[email protected]> | 2024-02-17 12:04:53 -0600 |
|---|---|---|
| committer | Zach <[email protected]> | 2024-02-17 12:04:53 -0600 |
| commit | dd9f0d9d9e73feffce371ab7fda714b09b268715 (patch) | |
| tree | 586fb16591606e0fe80f175fee3d68fc27c2cd25 /examples/stm32u5/src | |
| parent | 377e58e408f830f79171a470ba602b7d8bc525e4 (diff) | |
support u5 flash
Diffstat (limited to 'examples/stm32u5/src')
| -rw-r--r-- | examples/stm32u5/src/bin/flash.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/examples/stm32u5/src/bin/flash.rs b/examples/stm32u5/src/bin/flash.rs new file mode 100644 index 000000000..e4fd6bb9c --- /dev/null +++ b/examples/stm32u5/src/bin/flash.rs | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::{info, unwrap}; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::flash::Flash; | ||
| 7 | use embassy_time::Timer; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | #[embassy_executor::main] | ||
| 11 | async fn main(_spawner: Spawner) { | ||
| 12 | let p = embassy_stm32::init(Default::default()); | ||
| 13 | info!("Hello Flash!"); | ||
| 14 | |||
| 15 | const ADDR: u32 = 0x8_0000; // This is the offset into the third region, the absolute address is 4x32K + 128K + 0x8_0000. | ||
| 16 | |||
| 17 | // wait a bit before accessing the flash | ||
| 18 | Timer::after_millis(300).await; | ||
| 19 | |||
| 20 | let mut f = Flash::new_blocking(p.FLASH).into_blocking_regions().bank1_region; | ||
| 21 | |||
| 22 | info!("Reading..."); | ||
| 23 | let mut buf = [0u8; 32]; | ||
| 24 | unwrap!(f.blocking_read(ADDR, &mut buf)); | ||
| 25 | info!("Read: {=[u8]:x}", buf); | ||
| 26 | |||
| 27 | info!("Erasing..."); | ||
| 28 | unwrap!(f.blocking_erase(ADDR, ADDR + 256 * 1024)); | ||
| 29 | |||
| 30 | info!("Reading..."); | ||
| 31 | let mut buf = [0u8; 32]; | ||
| 32 | unwrap!(f.blocking_read(ADDR, &mut buf)); | ||
| 33 | info!("Read after erase: {=[u8]:x}", buf); | ||
| 34 | |||
| 35 | info!("Writing..."); | ||
| 36 | unwrap!(f.blocking_write( | ||
| 37 | ADDR, | ||
| 38 | &[ | ||
| 39 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, | ||
| 40 | 30, 31, 32 | ||
| 41 | ] | ||
| 42 | )); | ||
| 43 | |||
| 44 | info!("Reading..."); | ||
| 45 | let mut buf = [0u8; 32]; | ||
| 46 | unwrap!(f.blocking_read(ADDR, &mut buf)); | ||
| 47 | info!("Read: {=[u8]:x}", buf); | ||
| 48 | assert_eq!( | ||
| 49 | &buf[..], | ||
| 50 | &[ | ||
| 51 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, | ||
| 52 | 30, 31, 32 | ||
| 53 | ] | ||
| 54 | ); | ||
| 55 | } | ||
