2020-09-22 18:03:43 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
2021-03-17 02:48:16 +01:00
|
|
|
#![feature(min_type_alias_impl_trait)]
|
|
|
|
#![feature(impl_trait_in_bindings)]
|
2020-09-22 18:03:43 +02:00
|
|
|
#![feature(type_alias_impl_trait)]
|
2021-03-27 03:12:58 +01:00
|
|
|
#![allow(incomplete_features)]
|
2020-09-22 18:03:43 +02:00
|
|
|
|
|
|
|
#[path = "../example_common.rs"]
|
|
|
|
mod example_common;
|
|
|
|
|
2021-02-13 21:41:36 -03:00
|
|
|
use defmt::{assert_eq, panic};
|
2021-03-29 02:47:10 +02:00
|
|
|
use embassy::executor::Spawner;
|
2021-03-02 00:32:23 +01:00
|
|
|
use embassy::traits::flash::Flash;
|
2021-03-21 21:58:59 +01:00
|
|
|
use embassy_nrf::Peripherals;
|
2020-12-29 00:05:52 +01:00
|
|
|
use embassy_nrf::{interrupt, qspi};
|
2021-03-21 21:58:59 +01:00
|
|
|
use example_common::*;
|
2020-09-24 22:04:45 +02:00
|
|
|
|
2020-09-22 18:03:43 +02:00
|
|
|
const PAGE_SIZE: usize = 4096;
|
|
|
|
|
|
|
|
// Workaround for alignment requirements.
|
|
|
|
// Nicer API will probably come in the future.
|
|
|
|
#[repr(C, align(4))]
|
|
|
|
struct AlignedBuf([u8; 4096]);
|
|
|
|
|
2021-03-29 02:47:10 +02:00
|
|
|
#[embassy::main]
|
2021-05-12 01:57:01 +02:00
|
|
|
async fn main(spawner: Spawner, p: Peripherals) {
|
2021-03-27 03:12:58 +01:00
|
|
|
let csn = p.P0_17;
|
|
|
|
let sck = p.P0_19;
|
|
|
|
let io0 = p.P0_20;
|
|
|
|
let io1 = p.P0_21;
|
|
|
|
let io2 = p.P0_22;
|
|
|
|
let io3 = p.P0_23;
|
2020-09-22 18:03:43 +02:00
|
|
|
|
2021-03-29 00:55:05 +02:00
|
|
|
let config = qspi::Config::default();
|
2020-12-29 00:05:52 +01:00
|
|
|
let irq = interrupt::take!(QSPI);
|
2021-04-14 17:00:28 +02:00
|
|
|
let mut q = qspi::Qspi::new(p.QSPI, irq, sck, csn, io0, io1, io2, io3, config);
|
2020-09-22 18:03:43 +02:00
|
|
|
|
|
|
|
let mut id = [1; 3];
|
2021-04-14 17:00:28 +02:00
|
|
|
q.custom_instruction(0x9F, &[], &mut id).await.unwrap();
|
2021-02-24 08:57:06 +01:00
|
|
|
info!("id: {}", id);
|
2020-09-22 18:03:43 +02:00
|
|
|
|
|
|
|
// Read status register
|
2021-03-21 20:54:09 +01:00
|
|
|
let mut status = [4; 1];
|
2021-04-14 17:00:28 +02:00
|
|
|
q.custom_instruction(0x05, &[], &mut status).await.unwrap();
|
2020-09-22 18:03:43 +02:00
|
|
|
|
|
|
|
info!("status: {:?}", status[0]);
|
|
|
|
|
|
|
|
if status[0] & 0x40 == 0 {
|
|
|
|
status[0] |= 0x40;
|
|
|
|
|
2021-04-14 17:00:28 +02:00
|
|
|
q.custom_instruction(0x01, &status, &mut []).await.unwrap();
|
2020-09-22 18:03:43 +02:00
|
|
|
|
|
|
|
info!("enabled quad in status");
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut buf = AlignedBuf([0u8; PAGE_SIZE]);
|
|
|
|
|
|
|
|
let pattern = |a: u32| (a ^ (a >> 8) ^ (a >> 16) ^ (a >> 24)) as u8;
|
|
|
|
|
|
|
|
for i in 0..8 {
|
|
|
|
info!("page {:?}: erasing... ", i);
|
2021-04-14 17:00:28 +02:00
|
|
|
q.erase(i * PAGE_SIZE).await.unwrap();
|
2020-09-22 18:03:43 +02:00
|
|
|
|
|
|
|
for j in 0..PAGE_SIZE {
|
|
|
|
buf.0[j] = pattern((j + i * PAGE_SIZE) as u32);
|
|
|
|
}
|
|
|
|
|
|
|
|
info!("programming...");
|
2021-04-14 17:00:28 +02:00
|
|
|
q.write(i * PAGE_SIZE, &buf.0).await.unwrap();
|
2020-09-22 18:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for i in 0..8 {
|
|
|
|
info!("page {:?}: reading... ", i);
|
2021-04-14 17:00:28 +02:00
|
|
|
q.read(i * PAGE_SIZE, &mut buf.0).await.unwrap();
|
2020-09-22 18:03:43 +02:00
|
|
|
|
|
|
|
info!("verifying...");
|
|
|
|
for j in 0..PAGE_SIZE {
|
|
|
|
assert_eq!(buf.0[j], pattern((j + i * PAGE_SIZE) as u32));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info!("done!")
|
|
|
|
}
|