diff options
| -rw-r--r-- | embassy-nrf-examples/src/bin/qspi_lowpower.rs | 81 |
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"] | ||
| 9 | mod example_common; | ||
| 10 | |||
| 11 | use core::mem; | ||
| 12 | use defmt::panic; | ||
| 13 | use embassy::executor::Spawner; | ||
| 14 | use embassy::time::{Duration, Timer}; | ||
| 15 | use embassy::traits::flash::Flash; | ||
| 16 | use embassy_nrf::Peripherals; | ||
| 17 | use embassy_nrf::{interrupt, qspi}; | ||
| 18 | use example_common::*; | ||
| 19 | |||
| 20 | // Workaround for alignment requirements. | ||
| 21 | // Nicer API will probably come in the future. | ||
| 22 | #[repr(C, align(4))] | ||
| 23 | struct AlignedBuf([u8; 64]); | ||
| 24 | |||
| 25 | #[embassy::main] | ||
| 26 | async 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 | } | ||
