aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-04-05 10:55:31 +0200
committerRasmus Melchior Jacobsen <[email protected]>2023-04-05 10:55:31 +0200
commit2a49e11cb0ffd3e0d9a0cc94444f293de523b47f (patch)
treed5d415fd27d7507107fc89a6d45ec46b49dc4f6c /examples/stm32f4
parent57d3d4d58148fefbd6db4770918b52f31ded0124 (diff)
Align flash examples
Diffstat (limited to 'examples/stm32f4')
-rw-r--r--examples/stm32f4/src/bin/flash.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/examples/stm32f4/src/bin/flash.rs b/examples/stm32f4/src/bin/flash.rs
index 7ea068a42..bd3a7c95e 100644
--- a/examples/stm32f4/src/bin/flash.rs
+++ b/examples/stm32f4/src/bin/flash.rs
@@ -5,7 +5,6 @@
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
8use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::main] 10#[embassy_executor::main]
@@ -13,6 +12,8 @@ async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default()); 12 let p = embassy_stm32::init(Default::default());
14 info!("Hello Flash!"); 13 info!("Hello Flash!");
15 14
15 // Once can also call `into_regions()` to get access to NorFlash implementations
16 // for each of the unique characteristics.
16 let mut f = Flash::new(p.FLASH); 17 let mut f = Flash::new(p.FLASH);
17 18
18 // Sector 5 19 // Sector 5
@@ -30,19 +31,19 @@ fn test_flash(f: &mut Flash, offset: u32, size: u32) {
30 31
31 info!("Reading..."); 32 info!("Reading...");
32 let mut buf = [0u8; 32]; 33 let mut buf = [0u8; 32];
33 unwrap!(f.read(offset, &mut buf)); 34 unwrap!(f.blocking_read(offset, &mut buf));
34 info!("Read: {=[u8]:x}", buf); 35 info!("Read: {=[u8]:x}", buf);
35 36
36 info!("Erasing..."); 37 info!("Erasing...");
37 unwrap!(f.erase(offset, offset + size)); 38 unwrap!(f.blocking_erase(offset, offset + size));
38 39
39 info!("Reading..."); 40 info!("Reading...");
40 let mut buf = [0u8; 32]; 41 let mut buf = [0u8; 32];
41 unwrap!(f.read(offset, &mut buf)); 42 unwrap!(f.blocking_read(offset, &mut buf));
42 info!("Read after erase: {=[u8]:x}", buf); 43 info!("Read after erase: {=[u8]:x}", buf);
43 44
44 info!("Writing..."); 45 info!("Writing...");
45 unwrap!(f.write( 46 unwrap!(f.blocking_write(
46 offset, 47 offset,
47 &[ 48 &[
48 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, 49 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,7 +53,7 @@ fn test_flash(f: &mut Flash, offset: u32, size: u32) {
52 53
53 info!("Reading..."); 54 info!("Reading...");
54 let mut buf = [0u8; 32]; 55 let mut buf = [0u8; 32];
55 unwrap!(f.read(offset, &mut buf)); 56 unwrap!(f.blocking_read(offset, &mut buf));
56 info!("Read: {=[u8]:x}", buf); 57 info!("Read: {=[u8]:x}", buf);
57 assert_eq!( 58 assert_eq!(
58 &buf[..], 59 &buf[..],