summaryrefslogtreecommitdiff
path: root/examples/stm32f4/src/bin
diff options
context:
space:
mode:
authorchemicstry <chemicstry@gmail.com>2022-07-14 19:41:39 +0300
committerchemicstry <chemicstry@gmail.com>2022-07-14 19:41:39 +0300
commit039acda3a8b9549a6056aafdc4344ea4c76b9f60 (patch)
tree296db6c63f322586b224401f9d7dce9f151ad430 /examples/stm32f4/src/bin
parente4cacc3bb812c8870584c513020f0747146c860a (diff)
downloadembassy-039acda3a8b9549a6056aafdc4344ea4c76b9f60.zip
Fix writing to last sector of F4 flash
Diffstat (limited to 'examples/stm32f4/src/bin')
-rw-r--r--examples/stm32f4/src/bin/flash.rs30
1 files changed, 20 insertions, 10 deletions
diff --git a/examples/stm32f4/src/bin/flash.rs b/examples/stm32f4/src/bin/flash.rs
index b531d6f1..ad45df82 100644
--- a/examples/stm32f4/src/bin/flash.rs
+++ b/examples/stm32f4/src/bin/flash.rs
@@ -7,36 +7,46 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::flash::Flash;
use embassy_stm32::Peripherals;
-use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
use {defmt_rtt as _, panic_probe as _};
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello Flash!");
- const ADDR: u32 = 0x10_0000;
+ let mut f = Flash::unlock(p.FLASH);
- // wait a bit before accessing the flash
- Timer::after(Duration::from_millis(300)).await;
+ // Sector 5
+ test_flash(&mut f, 128 * 1024, 128 * 1024);
- let mut f = Flash::unlock(p.FLASH);
+ // Sector 11, last in bank 1
+ test_flash(&mut f, (1024 - 128) * 1024, 128 * 1024);
+
+ // Sectors 12..=16, start of bank 2 (16K, 16K, 16K, 16K, 64K)
+ test_flash(&mut f, 1024 * 1024, 128 * 1024);
+
+ // Sectors 23, last in bank 2
+ test_flash(&mut f, (2048 - 128) * 1024, 128 * 1024);
+}
+
+fn test_flash(f: &mut Flash, offset: u32, size: u32) {
+ info!("Testing offset: {=u32:#X}, size: {=u32:#X}", offset, size);
info!("Reading...");
let mut buf = [0u8; 32];
- unwrap!(f.read(ADDR, &mut buf));
+ unwrap!(f.read(offset, &mut buf));
info!("Read: {=[u8]:x}", buf);
info!("Erasing...");
- unwrap!(f.erase(ADDR, ADDR + 128 * 1024));
+ unwrap!(f.erase(offset, offset + size));
info!("Reading...");
let mut buf = [0u8; 32];
- unwrap!(f.read(ADDR, &mut buf));
+ unwrap!(f.read(offset, &mut buf));
info!("Read after erase: {=[u8]:x}", buf);
info!("Writing...");
unwrap!(f.write(
- ADDR,
+ offset,
&[
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,
30, 31, 32
@@ -45,7 +55,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
info!("Reading...");
let mut buf = [0u8; 32];
- unwrap!(f.read(ADDR, &mut buf));
+ unwrap!(f.read(offset, &mut buf));
info!("Read: {=[u8]:x}", buf);
assert_eq!(
&buf[..],