You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
extract / add example for use with nrf52, perhaps other platforms?
flash Control wrapper provides DynamicFile over NVMC:
use core::cell::UnsafeCell;use embedded_storage::nor_flash::{NorFlash,ReadNorFlash};use nrf52840_hal::nvmc::Nvmc;use nrf52840_pac::NVMC;constFILE_START:usize = 0x00080000;constFILE_LEN:usize = 256*1024;pubstructFlashControl{nvm:UnsafeCell<Nvmc<NVMC>>,len:usize,}unsafeimplSyncforFlashControl{}implFlashControl{/// Create a new flash controller from device [`NVMC`]pubfnnew(nvmc:NVMC) -> Self{// Chunk of memory available to flash control// TODO: work out how to extract segments from linker file..?let section = unsafe{
core::slice::from_raw_parts_mut(FILE_STARTas*constu8as*mutu8,FILE_LEN)};Self{nvm:UnsafeCell::new(Nvmc::new(nvmc, section)),len:FILE_LEN,}}}/// GhostFAT dynamic file implementation for our Flash controllerimpl<constBLOCK_SIZE:usize> ghostfat::DynamicFile<BLOCK_SIZE>forFlashControl{fnlen(&self) -> usize{self.len}fnread_chunk(&self,index:usize,buff:&mut[u8]) -> usize{
defmt::info!("Read file chunk: 0x{:02x} index: 0x{:08x} len: {}", index, index *BLOCK_SIZE, buff.len());let res = unsafe{(*self.nvm.get()).read((index *BLOCK_SIZE)asu32, buff)};// Read dataifletErr(e) = res {
defmt::error!("Failed to read index: 0x{:08x} len: {}: {:?}", index,Nvmc::<NVMC>::ERASE_SIZE, defmt::Debug2Format(&e));return0;}return buff.len()}fnwrite_chunk(&mutself,index:usize,data:&[u8]) -> usize{
defmt::info!("Write file index: 0x{:08x}", index);// Erase on writes to the first address in the block// TODO: this assumes chunk writes are always aligned / ordered...// i _think_ but am not _sure_ this is correctif index % Nvmc::<NVMC>::ERASE_SIZE == 0{ifletErr(e) = self.nvm.get_mut().erase((index *BLOCK_SIZE)asu32,Nvmc::<NVMC>::ERASE_SIZEasu32){
defmt::error!("Failed to erase index: 0x{:08x} len: {}: {:?}", index,Nvmc::<NVMC>::ERASE_SIZE, defmt::Debug2Format(&e));return0;}}// Write dataifletErr(e) = self.nvm.get_mut().write((index *BLOCK_SIZE)asu32, data){
defmt::error!("Failed to write index: 0x{:08x} len: {}: {:?}", index,Nvmc::<NVMC>::ERASE_SIZE, defmt::Debug2Format(&e));return0;}return data.len();}}
which can then be used with rtic, usb_device, usb_scsi:
extract / add example for use with nrf52, perhaps other platforms?
flash Control wrapper provides
DynamicFile
overNVMC
:which can then be used with
rtic
,usb_device
,usb_scsi
:The text was updated successfully, but these errors were encountered: