aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f7/src
diff options
context:
space:
mode:
authorMatous Hybl <[email protected]>2022-05-03 16:16:37 +0200
committerMatous Hybl <[email protected]>2022-05-06 21:57:15 +0200
commit6d56f772e11eaae7495e08ba55d9c98d11e0ac09 (patch)
tree90b0b7466020cfa8fb0db7990599883ec86d9328 /examples/stm32f7/src
parentf3700b4e42fbb0e0e4876307ba5533b7b215f5e3 (diff)
Add F7 flash and bootloader support
Diffstat (limited to 'examples/stm32f7/src')
-rw-r--r--examples/stm32f7/src/bin/flash.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs
new file mode 100644
index 000000000..9eb8e4b94
--- /dev/null
+++ b/examples/stm32f7/src/bin/flash.rs
@@ -0,0 +1,59 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::{info, unwrap};
6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer};
8use embassy_stm32::flash::Flash;
9use embassy_stm32::Peripherals;
10use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
11
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14
15#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) {
17 info!("Hello Flash!");
18
19 const ADDR: u32 = 0x8_0000;
20
21 // wait a bit before accessing the flash
22 Timer::after(Duration::from_millis(300)).await;
23
24 let mut f = Flash::unlock(p.FLASH);
25
26 info!("Reading...");
27 let mut buf = [0u8; 32];
28 unwrap!(f.read(ADDR, &mut buf));
29 info!("Read: {=[u8]:x}", buf);
30
31 info!("Erasing...");
32 unwrap!(f.erase(ADDR, ADDR + 256 * 1024));
33
34 info!("Reading...");
35 let mut buf = [0u8; 32];
36 unwrap!(f.read(ADDR, &mut buf));
37 info!("Read after erase: {=[u8]:x}", buf);
38
39 info!("Writing...");
40 unwrap!(f.write(
41 ADDR,
42 &[
43 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
44 25, 26, 27, 28, 29, 30, 31, 32
45 ]
46 ));
47
48 info!("Reading...");
49 let mut buf = [0u8; 32];
50 unwrap!(f.read(ADDR, &mut buf));
51 info!("Read: {=[u8]:x}", buf);
52 assert_eq!(
53 &buf[..],
54 &[
55 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
56 25, 26, 27, 28, 29, 30, 31, 32
57 ]
58 );
59}