re-work NVM interface

This commit is contained in:
2024-09-27 19:06:13 +02:00
parent 0f3614465f
commit a1a5156caf
2 changed files with 78 additions and 42 deletions

View File

@ -2,12 +2,15 @@
#![no_main]
#![no_std]
use core::fmt::write;
use cortex_m::{asm, register::control::read};
use cortex_m_rt::entry;
use embedded_hal::delay::DelayNs;
use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use va108xx_hal::{pac, pwm::CountDownTimer, time::Hertz};
use vorago_reb1::m95m01::M95M01;
use vorago_reb1::m95m01::{M95M01, PAGE_SIZE};
const CLOCK_FREQ: Hertz = Hertz::from_raw(50_000_000);
@ -25,39 +28,30 @@ fn main() -> ! {
panic!("status register unexpected values");
}
let mut orig_content: [u8; 16] = [0; 16];
let mut read_buf: [u8; 16] = [0; 16];
let write_buf: [u8; 16] = [0; 16];
for (idx, val) in read_buf.iter_mut().enumerate() {
*val = idx as u8;
let mut orig_content: [u8; 512] = [0; 512];
let mut read_buf: [u8; 512] = [0; 512];
let mut write_buf: [u8; 512] = [0; 512];
for (idx, val) in write_buf.iter_mut().enumerate() {
*val = ((idx as u16) % (u8::MAX as u16 + 1)) as u8;
}
nvm.read(0x4000, &mut orig_content).unwrap();
nvm.read(0, &mut orig_content).unwrap();
// One byte write and read.
nvm.write(0x4000, &write_buf[0..1]).unwrap();
nvm.read(0x4000, &mut read_buf[0..1]).unwrap();
assert_eq!(write_buf[0], read_buf[0]);
read_buf.fill(0);
nvm.write_page(0, 0, &[1, 2, 3, 4]).unwrap();
nvm.read(0, &mut read_buf[0..4]).unwrap();
// Four bytes write and read.
nvm.write(0x4000, &write_buf[0..4]).unwrap();
nvm.read(0x4000, &mut read_buf[0..4]).unwrap();
assert_eq!(&read_buf[0..4], &write_buf[0..4]);
read_buf.fill(0);
// Full sixteen bytes
nvm.write(0x4000, &write_buf).unwrap();
nvm.read(0x4000, &mut read_buf).unwrap();
// Read the whole content. Write will internally be split across two page bounaries.
nvm.write(0, &write_buf).unwrap();
// Memory can be read in one go.
nvm.read(0, &mut read_buf).unwrap();
assert_eq!(&read_buf, &write_buf);
read_buf.fill(0);
// 3 bytes
nvm.write(0x4000, &write_buf[0..3]).unwrap();
nvm.read(0x4000, &mut read_buf[0..3]).unwrap();
assert_eq!(&read_buf[0..3], &write_buf[0..3]);
// Write along page boundary
nvm.write(PAGE_SIZE - 2, &write_buf[0..8]).unwrap();
nvm.read(PAGE_SIZE - 2, &mut read_buf[0..8]).unwrap();
assert_eq!(&read_buf[0..8], &write_buf[0..8]);
// Write back original content.
nvm.write(0x4000, &orig_content).unwrap();
nvm.write(0, &orig_content);
loop {
timer.delay_ms(500);
}