aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf-examples/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-05-26 23:26:44 +0200
committerDario Nieuwenhuis <[email protected]>2021-05-26 23:28:40 +0200
commit565c606ff8b216689df6551808ee57038b8939cd (patch)
tree083769e7b4751b3ebc36adfba2e155afc5d9e714 /embassy-nrf-examples/src
parentde703eb6052e593eac0edbe5fd9346e507ed7c65 (diff)
nrf/qspi: add lowpower example
Diffstat (limited to 'embassy-nrf-examples/src')
-rw-r--r--embassy-nrf-examples/src/bin/qspi_lowpower.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/embassy-nrf-examples/src/bin/qspi_lowpower.rs b/embassy-nrf-examples/src/bin/qspi_lowpower.rs
new file mode 100644
index 000000000..9bbc87caa
--- /dev/null
+++ b/embassy-nrf-examples/src/bin/qspi_lowpower.rs
@@ -0,0 +1,81 @@
1#![no_std]
2#![no_main]
3#![feature(min_type_alias_impl_trait)]
4#![feature(impl_trait_in_bindings)]
5#![feature(type_alias_impl_trait)]
6#![allow(incomplete_features)]
7
8#[path = "../example_common.rs"]
9mod example_common;
10
11use core::mem;
12use defmt::panic;
13use embassy::executor::Spawner;
14use embassy::time::{Duration, Timer};
15use embassy::traits::flash::Flash;
16use embassy_nrf::Peripherals;
17use embassy_nrf::{interrupt, qspi};
18use example_common::*;
19
20// Workaround for alignment requirements.
21// Nicer API will probably come in the future.
22#[repr(C, align(4))]
23struct AlignedBuf([u8; 64]);
24
25#[embassy::main]
26async fn main(_spawner: Spawner, mut p: Peripherals) {
27 let mut irq = interrupt::take!(QSPI);
28
29 loop {
30 let mut config = qspi::Config::default();
31 config.deep_power_down = Some(qspi::DeepPowerDownConfig {
32 enter_time: 3, // tDP = 30uS
33 exit_time: 3, // tRDP = 35uS
34 });
35
36 let mut q = qspi::Qspi::new(
37 &mut p.QSPI,
38 &mut irq,
39 &mut p.P0_19,
40 &mut p.P0_17,
41 &mut p.P0_20,
42 &mut p.P0_21,
43 &mut p.P0_22,
44 &mut p.P0_23,
45 config,
46 )
47 .await;
48
49 let mut id = [1; 3];
50 q.custom_instruction(0x9F, &[], &mut id).await.unwrap();
51 info!("id: {}", id);
52
53 // Read status register
54 let mut status = [4; 1];
55 q.custom_instruction(0x05, &[], &mut status).await.unwrap();
56
57 info!("status: {:?}", status[0]);
58
59 if status[0] & 0x40 == 0 {
60 status[0] |= 0x40;
61
62 q.custom_instruction(0x01, &status, &mut []).await.unwrap();
63
64 info!("enabled quad in status");
65 }
66
67 let mut buf = AlignedBuf([0u8; 64]);
68
69 info!("reading...");
70 q.read(0, &mut buf.0).await.unwrap();
71 info!("read: {=[u8]:x}", buf.0);
72
73 // Drop the QSPI instance. This disables the peripehral and deconfigures the pins.
74 // This clears the borrow on the singletons, so they can now be used again.
75 mem::drop(q);
76
77 // Sleep for 1 second. The executor ensures the core sleeps with a WFE when it has nothing to do.
78 // During this sleep, the nRF chip should only use ~3uA
79 Timer::after(Duration::from_secs(1)).await;
80 }
81}