aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f7/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-05-06 20:18:26 +0000
committerGitHub <[email protected]>2022-05-06 20:18:26 +0000
commit7e774ff8300cb4df6c561f99f1c33485256155e6 (patch)
treefa6000199428777b38df5a47862fd3629d939a63 /examples/stm32f7/src
parentf7af9a549f165419f4fa85c82b42a3e5b54d417e (diff)
parent8a80ae56854dec4cc052fcc999d16df9f3f73876 (diff)
Merge #755
755: Add support for flash and bootloader for F3, F7 and H7 r=matoushybl a=matoushybl Co-authored-by: Matous Hybl <[email protected]>
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}