aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32l0
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2025-05-23 14:15:15 +0200
committerGitHub <[email protected]>2025-05-23 14:15:15 +0200
commit94f9b2707486ca3eade5bf4b237edf3d6aa90f35 (patch)
treeed91d32d5c462bc919957bc6ea3eccccd9c0d260 /examples/stm32l0
parentf7405493c184ce453ac3f7ba97f7f2689f978194 (diff)
parentc88bc972316634da586589adcefa49bb02a2cf0f (diff)
Merge pull request #4228 from okhsunrog/adding_eeprom
Adding EEPROM support to embassy-stm32
Diffstat (limited to 'examples/stm32l0')
-rw-r--r--examples/stm32l0/src/bin/eeprom.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/stm32l0/src/bin/eeprom.rs b/examples/stm32l0/src/bin/eeprom.rs
new file mode 100644
index 000000000..370246644
--- /dev/null
+++ b/examples/stm32l0/src/bin/eeprom.rs
@@ -0,0 +1,32 @@
1#![no_std]
2#![no_main]
3
4use defmt::{info, unwrap};
5use embassy_executor::Spawner;
6use embassy_stm32::flash::{Flash, EEPROM_BASE, EEPROM_SIZE};
7use {defmt_rtt as _, panic_probe as _};
8
9#[embassy_executor::main]
10async fn main(_spawner: Spawner) {
11 let p = embassy_stm32::init(Default::default());
12
13 info!("Hello Eeprom! Start: {}, Size: {}", EEPROM_BASE, EEPROM_SIZE);
14
15 const ADDR: u32 = 0x0;
16
17 let mut f = Flash::new_blocking(p.FLASH);
18
19 info!("Reading...");
20 let mut buf = [0u8; 8];
21 unwrap!(f.eeprom_read_slice(ADDR, &mut buf));
22 info!("Read: {=[u8]:x}", buf);
23
24 info!("Writing...");
25 unwrap!(f.eeprom_write_slice(ADDR, &[1, 2, 3, 4, 5, 6, 7, 8]));
26
27 info!("Reading...");
28 let mut buf = [0u8; 8];
29 unwrap!(f.eeprom_read_slice(ADDR, &mut buf));
30 info!("Read: {=[u8]:x}", buf);
31 assert_eq!(&buf[..], &[1, 2, 3, 4, 5, 6, 7, 8]);
32}