From ea35221d413159128abd72edae6b7ac4b354de1f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 27 Sep 2024 19:55:16 +0200 Subject: [PATCH] clean up --- bootloader/src/lib.rs | 6 +++--- bootloader/src/main.rs | 12 ++++++------ flashloader/src/main.rs | 6 +++--- vorago-reb1/examples/nvm.rs | 6 +----- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/bootloader/src/lib.rs b/bootloader/src/lib.rs index 2fc897a..24e41a6 100644 --- a/bootloader/src/lib.rs +++ b/bootloader/src/lib.rs @@ -4,7 +4,7 @@ use core::convert::Infallible; /// Simple trait which makes swapping the NVM easier. NVMs only need to implement this interface. pub trait NvmInterface { - fn write(&mut self, address: u32, data: &[u8]) -> Result<(), Infallible>; - fn read(&mut self, address: u32, buf: &mut [u8]) -> Result<(), Infallible>; - fn verify(&mut self, address: u32, data: &[u8]) -> Result; + fn write(&mut self, address: usize, data: &[u8]) -> Result<(), Infallible>; + fn read(&mut self, address: usize, buf: &mut [u8]) -> Result<(), Infallible>; + fn verify(&mut self, address: usize, data: &[u8]) -> Result; } diff --git a/bootloader/src/main.rs b/bootloader/src/main.rs index a10ed7c..70e287b 100644 --- a/bootloader/src/main.rs +++ b/bootloader/src/main.rs @@ -78,15 +78,15 @@ pub struct NvmWrapper(pub M95M01); // Newtype pattern. We could now more easily swap the used NVM type. impl NvmInterface for NvmWrapper { - fn write(&mut self, address: u32, data: &[u8]) -> Result<(), core::convert::Infallible> { + fn write(&mut self, address: usize, data: &[u8]) -> Result<(), core::convert::Infallible> { self.0.write(address, data) } - fn read(&mut self, address: u32, buf: &mut [u8]) -> Result<(), core::convert::Infallible> { + fn read(&mut self, address: usize, buf: &mut [u8]) -> Result<(), core::convert::Infallible> { self.0.read(address, buf) } - fn verify(&mut self, address: u32, data: &[u8]) -> Result { + fn verify(&mut self, address: usize, data: &[u8]) -> Result { self.0.verify(address, data) } } @@ -133,9 +133,9 @@ fn main() -> ! { } } - nvm.write(BOOTLOADER_CRC_ADDR, &bootloader_crc.to_be_bytes()) + nvm.write(BOOTLOADER_CRC_ADDR as usize, &bootloader_crc.to_be_bytes()) .expect("writing CRC failed"); - if let Err(e) = nvm.verify(BOOTLOADER_CRC_ADDR, &bootloader_crc.to_be_bytes()) { + if let Err(e) = nvm.verify(BOOTLOADER_CRC_ADDR as usize, &bootloader_crc.to_be_bytes()) { if RTT_PRINTOUT { rprintln!( "error: CRC verification for bootloader self-flash failed: {:?}", @@ -185,7 +185,7 @@ fn check_own_crc(sysconfig: &pac::Sysconfig, cp: &cortex_m::Peripherals, nvm: &m rprintln!("BL CRC blank - prog new CRC"); } // Blank CRC, write it to NVM. - nvm.write(BOOTLOADER_CRC_ADDR, &crc_calc.to_be_bytes()) + nvm.write(BOOTLOADER_CRC_ADDR as usize, &crc_calc.to_be_bytes()) .expect("writing CRC failed"); // The Vorago bootloader resets here. I am not sure why this is done but I think it is // necessary because somehow the boot will not work if we just continue as usual. diff --git a/flashloader/src/main.rs b/flashloader/src/main.rs index 59e5fa6..80da7b3 100644 --- a/flashloader/src/main.rs +++ b/flashloader/src/main.rs @@ -324,12 +324,12 @@ mod app { let mut buf = [0u8; 4]; cx.local .nvm - .read(base_addr + 32, &mut buf) + .read(base_addr as usize + 32, &mut buf) .expect("reading from NVM failed"); buf[0] += 1; cx.local .nvm - .write(base_addr + 32, &buf) + .write(base_addr as usize + 32, &buf) .expect("writing to NVM failed"); let tm = cx .local @@ -405,7 +405,7 @@ mod app { ); cx.local .nvm - .write(offset, data) + .write(offset as usize, data) .expect("writing to NVM failed"); let tm = cx .local diff --git a/vorago-reb1/examples/nvm.rs b/vorago-reb1/examples/nvm.rs index df0d00a..714b9a1 100644 --- a/vorago-reb1/examples/nvm.rs +++ b/vorago-reb1/examples/nvm.rs @@ -1,10 +1,6 @@ //! Example application which interfaces with the boot EEPROM. #![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 _; @@ -51,7 +47,7 @@ fn main() -> ! { nvm.read(PAGE_SIZE - 2, &mut read_buf[0..8]).unwrap(); assert_eq!(&read_buf[0..8], &write_buf[0..8]); - nvm.write(0, &orig_content); + nvm.write(0, &orig_content).unwrap(); loop { timer.delay_ms(500); }