aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-05-24 12:41:52 +0200
committerRasmus Melchior Jacobsen <[email protected]>2023-05-25 20:07:41 +0200
commit7477785bbb469a1d8d3cf21a74fd61cb12f59640 (patch)
tree3a801ffbc87c577ff686cc4aec4d489e1dc5f18e
parent0e90e98e9b477302a3cd2550dbd438907ed10ca6 (diff)
Align examples
-rw-r--r--examples/stm32f3/src/bin/flash.rs5
-rw-r--r--examples/stm32f4/src/bin/flash.rs14
-rw-r--r--examples/stm32f4/src/bin/flash_async.rs81
-rw-r--r--examples/stm32f7/src/bin/flash.rs5
-rw-r--r--examples/stm32h7/src/bin/flash.rs5
-rw-r--r--examples/stm32l0/src/bin/flash.rs5
-rw-r--r--examples/stm32l1/src/bin/flash.rs5
-rw-r--r--examples/stm32wl/src/bin/flash.rs5
8 files changed, 100 insertions, 25 deletions
diff --git a/examples/stm32f3/src/bin/flash.rs b/examples/stm32f3/src/bin/flash.rs
index e40ad4fc0..0e5fb0658 100644
--- a/examples/stm32f3/src/bin/flash.rs
+++ b/examples/stm32f3/src/bin/flash.rs
@@ -4,8 +4,7 @@
4 4
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, interrupt};
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]
@@ -15,7 +14,7 @@ async fn main(_spawner: Spawner) {
15 14
16 const ADDR: u32 = 0x26000; 15 const ADDR: u32 = 0x26000;
17 16
18 let mut f = Flash::new(p.FLASH).into_regions().bank1_region; 17 let mut f = unsafe { Flash::new(p.FLASH, interrupt::take!(FLASH)).into_regions().bank1_region.into_blocking() };
19 18
20 info!("Reading..."); 19 info!("Reading...");
21 let mut buf = [0u8; 8]; 20 let mut buf = [0u8; 8];
diff --git a/examples/stm32f4/src/bin/flash.rs b/examples/stm32f4/src/bin/flash.rs
index bd3a7c95e..de4ecdb8f 100644
--- a/examples/stm32f4/src/bin/flash.rs
+++ b/examples/stm32f4/src/bin/flash.rs
@@ -4,7 +4,7 @@
4 4
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, interrupt};
8use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
9 9
10#[embassy_executor::main] 10#[embassy_executor::main]
@@ -14,7 +14,7 @@ async fn main(_spawner: Spawner) {
14 14
15 // Once can also call `into_regions()` to get access to NorFlash implementations 15 // Once can also call `into_regions()` to get access to NorFlash implementations
16 // for each of the unique characteristics. 16 // for each of the unique characteristics.
17 let mut f = Flash::new(p.FLASH); 17 let mut f = Flash::new(p.FLASH, interrupt::take!(FLASH));
18 18
19 // Sector 5 19 // Sector 5
20 test_flash(&mut f, 128 * 1024, 128 * 1024); 20 test_flash(&mut f, 128 * 1024, 128 * 1024);
@@ -31,19 +31,19 @@ fn test_flash(f: &mut Flash, offset: u32, size: u32) {
31 31
32 info!("Reading..."); 32 info!("Reading...");
33 let mut buf = [0u8; 32]; 33 let mut buf = [0u8; 32];
34 unwrap!(f.blocking_read(offset, &mut buf)); 34 unwrap!(f.read(offset, &mut buf));
35 info!("Read: {=[u8]:x}", buf); 35 info!("Read: {=[u8]:x}", buf);
36 36
37 info!("Erasing..."); 37 info!("Erasing...");
38 unwrap!(f.blocking_erase(offset, offset + size)); 38 unwrap!(f.erase_blocking(offset, offset + size));
39 39
40 info!("Reading..."); 40 info!("Reading...");
41 let mut buf = [0u8; 32]; 41 let mut buf = [0u8; 32];
42 unwrap!(f.blocking_read(offset, &mut buf)); 42 unwrap!(f.read(offset, &mut buf));
43 info!("Read after erase: {=[u8]:x}", buf); 43 info!("Read after erase: {=[u8]:x}", buf);
44 44
45 info!("Writing..."); 45 info!("Writing...");
46 unwrap!(f.blocking_write( 46 unwrap!(f.write_blocking(
47 offset, 47 offset,
48 &[ 48 &[
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, 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,
@@ -53,7 +53,7 @@ fn test_flash(f: &mut Flash, offset: u32, size: u32) {
53 53
54 info!("Reading..."); 54 info!("Reading...");
55 let mut buf = [0u8; 32]; 55 let mut buf = [0u8; 32];
56 unwrap!(f.blocking_read(offset, &mut buf)); 56 unwrap!(f.read(offset, &mut buf));
57 info!("Read: {=[u8]:x}", buf); 57 info!("Read: {=[u8]:x}", buf);
58 assert_eq!( 58 assert_eq!(
59 &buf[..], 59 &buf[..],
diff --git a/examples/stm32f4/src/bin/flash_async.rs b/examples/stm32f4/src/bin/flash_async.rs
new file mode 100644
index 000000000..c9d9df34b
--- /dev/null
+++ b/examples/stm32f4/src/bin/flash_async.rs
@@ -0,0 +1,81 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::{info, unwrap};
6use embassy_executor::Spawner;
7use embassy_time::{Timer, Duration};
8use embassy_stm32::flash::Flash;
9use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Speed};
10use embassy_stm32::{interrupt};
11use {defmt_rtt as _, panic_probe as _};
12
13#[embassy_executor::main]
14async fn main(spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default());
16 info!("Hello Flash!");
17
18 let mut f = Flash::new(p.FLASH, interrupt::take!(FLASH));
19
20 // Led should blink uninterrupted during ~2sec erase operation
21 spawner.spawn(blinky(p.PB7.degrade())).unwrap();
22
23 // Test on bank 2 in order not to stall CPU.
24 test_flash(&mut f, 1024 * 1024, 128 * 1024).await;
25}
26
27#[embassy_executor::task]
28async fn blinky(p: AnyPin) {
29 let mut led = Output::new(p, Level::High, Speed::Low);
30
31 loop {
32 info!("high");
33 led.set_high();
34 Timer::after(Duration::from_millis(300)).await;
35
36 info!("low");
37 led.set_low();
38 Timer::after(Duration::from_millis(300)).await;
39 }
40}
41
42async fn test_flash<'a>(f: &mut Flash<'a>, offset: u32, size: u32) {
43 info!("Testing offset: {=u32:#X}, size: {=u32:#X}", offset, size);
44
45 info!("Reading...");
46 let mut buf = [0u8; 32];
47 unwrap!(f.read(offset, &mut buf));
48 info!("Read: {=[u8]:x}", buf);
49
50 info!("Erasing...");
51 unwrap!(f.erase(offset, offset + size).await);
52
53 info!("Reading...");
54 let mut buf = [0u8; 32];
55 unwrap!(f.read(offset, &mut buf));
56 info!("Read after erase: {=[u8]:x}", buf);
57
58 info!("Writing...");
59 unwrap!(
60 f.write(
61 offset,
62 &[
63 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,
64 29, 30, 31, 32
65 ]
66 )
67 .await
68 );
69
70 info!("Reading...");
71 let mut buf = [0u8; 32];
72 unwrap!(f.read(offset, &mut buf));
73 info!("Read: {=[u8]:x}", buf);
74 assert_eq!(
75 &buf[..],
76 &[
77 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,
78 30, 31, 32
79 ]
80 );
81} \ No newline at end of file
diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs
index aabfe8557..717c82e86 100644
--- a/examples/stm32f7/src/bin/flash.rs
+++ b/examples/stm32f7/src/bin/flash.rs
@@ -4,9 +4,8 @@
4 4
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, interrupt};
8use embassy_time::{Duration, Timer}; 8use embassy_time::{Duration, Timer};
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
@@ -19,7 +18,7 @@ async fn main(_spawner: Spawner) {
19 // wait a bit before accessing the flash 18 // wait a bit before accessing the flash
20 Timer::after(Duration::from_millis(300)).await; 19 Timer::after(Duration::from_millis(300)).await;
21 20
22 let mut f = Flash::new(p.FLASH).into_regions().bank1_region3; 21 let mut f = unsafe { Flash::new(p.FLASH, interrupt::take!(FLASH)).into_regions().bank1_region3.into_blocking() };
23 22
24 info!("Reading..."); 23 info!("Reading...");
25 let mut buf = [0u8; 32]; 24 let mut buf = [0u8; 32];
diff --git a/examples/stm32h7/src/bin/flash.rs b/examples/stm32h7/src/bin/flash.rs
index 7ee9838c9..aab72cae8 100644
--- a/examples/stm32h7/src/bin/flash.rs
+++ b/examples/stm32h7/src/bin/flash.rs
@@ -4,9 +4,8 @@
4 4
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, interrupt};
8use embassy_time::{Duration, Timer}; 8use embassy_time::{Duration, Timer};
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
@@ -19,7 +18,7 @@ async fn main(_spawner: Spawner) {
19 // wait a bit before accessing the flash 18 // wait a bit before accessing the flash
20 Timer::after(Duration::from_millis(300)).await; 19 Timer::after(Duration::from_millis(300)).await;
21 20
22 let mut f = Flash::new(p.FLASH).into_regions().bank2_region; 21 let mut f = unsafe { Flash::new(p.FLASH, interrupt::take!(FLASH)).into_regions().bank2_region.into_blocking() };
23 22
24 info!("Reading..."); 23 info!("Reading...");
25 let mut buf = [0u8; 32]; 24 let mut buf = [0u8; 32];
diff --git a/examples/stm32l0/src/bin/flash.rs b/examples/stm32l0/src/bin/flash.rs
index 337425028..0ed0d05fc 100644
--- a/examples/stm32l0/src/bin/flash.rs
+++ b/examples/stm32l0/src/bin/flash.rs
@@ -4,8 +4,7 @@
4 4
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, interrupt};
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]
@@ -15,7 +14,7 @@ async fn main(_spawner: Spawner) {
15 14
16 const ADDR: u32 = 0x26000; 15 const ADDR: u32 = 0x26000;
17 16
18 let mut f = Flash::new(p.FLASH).into_regions().bank1_region; 17 let mut f = unsafe { Flash::new(p.FLASH, interrupt::take!(FLASH)).into_regions().bank1_region.into_blocking() };
19 18
20 info!("Reading..."); 19 info!("Reading...");
21 let mut buf = [0u8; 8]; 20 let mut buf = [0u8; 8];
diff --git a/examples/stm32l1/src/bin/flash.rs b/examples/stm32l1/src/bin/flash.rs
index 38feb0d76..c4d7d029c 100644
--- a/examples/stm32l1/src/bin/flash.rs
+++ b/examples/stm32l1/src/bin/flash.rs
@@ -4,8 +4,7 @@
4 4
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, interrupt};
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]
@@ -15,7 +14,7 @@ async fn main(_spawner: Spawner) {
15 14
16 const ADDR: u32 = 0x26000; 15 const ADDR: u32 = 0x26000;
17 16
18 let mut f = Flash::new(p.FLASH).into_regions().bank1_region; 17 let mut f = unsafe { Flash::new(p.FLASH, interrupt::take!(FLASH)).into_regions().bank1_region.into_blocking() };
19 18
20 info!("Reading..."); 19 info!("Reading...");
21 let mut buf = [0u8; 8]; 20 let mut buf = [0u8; 8];
diff --git a/examples/stm32wl/src/bin/flash.rs b/examples/stm32wl/src/bin/flash.rs
index e6bc2865c..df51ceb68 100644
--- a/examples/stm32wl/src/bin/flash.rs
+++ b/examples/stm32wl/src/bin/flash.rs
@@ -4,8 +4,7 @@
4 4
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, interrupt};
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]
@@ -15,7 +14,7 @@ async fn main(_spawner: Spawner) {
15 14
16 const ADDR: u32 = 0x36000; 15 const ADDR: u32 = 0x36000;
17 16
18 let mut f = Flash::new(p.FLASH).into_regions().bank1_region; 17 let mut f = unsafe { Flash::new(p.FLASH, interrupt::take!(FLASH)).into_regions().bank1_region.into_blocking() };
19 18
20 info!("Reading..."); 19 info!("Reading...");
21 let mut buf = [0u8; 8]; 20 let mut buf = [0u8; 8];