aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-10-23 08:28:25 +0000
committerGitHub <[email protected]>2021-10-23 08:28:25 +0000
commitf3f3858328ed4f13efb3790e32ee4fba772b57a2 (patch)
tree2efed3b61dbd91881ba5227c2887316adb97241d /examples
parenta8797f84f69b7668a3f89b6cba3e39bce5649079 (diff)
parente78d226acd5e2dc5f2eecfc98269747daf7e0633 (diff)
Merge #444
444: nrf: add NVMC driver. r=lulf a=Dirbaio I haven't implemented `embassy_traits::Flash` because I want to change it to match embedded_storage, which is much better designed. Either way, NVMC can't do async anyway, so the best we could do is implementing the async trait in a blocking way... Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/nrf/Cargo.toml1
-rw-r--r--examples/nrf/src/bin/nvmc.rs44
2 files changed, 45 insertions, 0 deletions
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml
index b71dfa0d4..b89aa513f 100644
--- a/examples/nrf/Cargo.toml
+++ b/examples/nrf/Cargo.toml
@@ -30,3 +30,4 @@ embedded-hal = "0.2.6"
30panic-probe = { version = "0.2.0", features = ["print-defmt"] } 30panic-probe = { version = "0.2.0", features = ["print-defmt"] }
31futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 31futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
32rand = { version = "0.8.4", default-features = false } 32rand = { version = "0.8.4", default-features = false }
33embedded-storage = "0.2.0"
diff --git a/examples/nrf/src/bin/nvmc.rs b/examples/nrf/src/bin/nvmc.rs
new file mode 100644
index 000000000..f36895636
--- /dev/null
+++ b/examples/nrf/src/bin/nvmc.rs
@@ -0,0 +1,44 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[path = "../example_common.rs"]
6mod example_common;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_nrf::nvmc::Nvmc;
10use embassy_nrf::Peripherals;
11use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
12use example_common::*;
13
14#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello NVMC!");
17
18 // probe-run breaks without this, I'm not sure why.
19 Timer::after(Duration::from_secs(1)).await;
20
21 let mut f = Nvmc::new(p.NVMC);
22 const ADDR: u32 = 0x80000;
23
24 info!("Reading...");
25 let mut buf = [0u8; 4];
26 unwrap!(f.read(ADDR, &mut buf));
27 info!("Read: {=[u8]:x}", buf);
28
29 info!("Erasing...");
30 unwrap!(f.erase(ADDR, ADDR + 4096));
31
32 info!("Reading...");
33 let mut buf = [0u8; 4];
34 unwrap!(f.read(ADDR, &mut buf));
35 info!("Read: {=[u8]:x}", buf);
36
37 info!("Writing...");
38 unwrap!(f.write(ADDR, &[1, 2, 3, 4]));
39
40 info!("Reading...");
41 let mut buf = [0u8; 4];
42 unwrap!(f.read(ADDR, &mut buf));
43 info!("Read: {=[u8]:x}", buf);
44}