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