aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-07-31 10:35:28 +0000
committerGitHub <[email protected]>2023-07-31 10:35:28 +0000
commit958cace36dec6d0473c85a4129c871be9e563f2a (patch)
tree5d57d2e837558c74153eb3d60e135a4b12caa9fd /examples
parent2568c714c80267503554bcf090a2dbcd80b41e08 (diff)
parent0ddabf04234ca8ad877d6ae13cc690567d6f4832 (diff)
Merge pull request #1724 from bguruprasath5/stm32g0-flash-support
Added STM32G0 Flash Support
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32g0/src/bin/flash.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/stm32g0/src/bin/flash.rs b/examples/stm32g0/src/bin/flash.rs
new file mode 100644
index 000000000..ed9f2e843
--- /dev/null
+++ b/examples/stm32g0/src/bin/flash.rs
@@ -0,0 +1,44 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::flash::Flash;
8use {defmt_rtt as _, panic_probe as _};
9
10#[embassy_executor::main]
11async fn main(_spawner: Spawner) {
12 let p = embassy_stm32::init(Default::default());
13 info!("Hello World!");
14
15 let addr: u32 = 0x8000;
16
17 let mut f = Flash::new_blocking(p.FLASH).into_blocking_regions().bank1_region;
18
19 info!("Reading...");
20 let mut buf = [0u8; 32];
21 unwrap!(f.blocking_read(addr, &mut buf));
22 info!("Read: {=[u8]:x}", buf);
23 info!("Erasing...");
24 unwrap!(f.blocking_erase(addr, addr + 2 * 1024));
25
26 info!("Reading...");
27 let mut buf = [0u8; 32];
28 unwrap!(f.blocking_read(addr, &mut buf));
29 info!("Read after erase: {=[u8]:x}", buf);
30
31 info!("Writing...");
32 unwrap!(f.blocking_write(
33 addr,
34 &[
35 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,
36 30, 31, 32
37 ]
38 ));
39
40 info!("Reading...");
41 let mut buf = [0u8; 32];
42 unwrap!(f.blocking_read(addr, &mut buf));
43 info!("Read: {=[u8]:x}", buf);
44}