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
The Storage trait does not expose any alignment information, and one would thus assume that implementations of it would allow for unaligned reads, but RmwNorFlashStorage currently does not. As an example, the following code snippets fails to run:
use embedded_storage::nor_flash::*;use embedded_storage::ReadStorage;/// A fake storage driver, that requires reads to be aligned to 4 bytes, and which will fill all of them with 0xFFstructStrictApi;implErrorTypeforStrictApi{typeError = NorFlashErrorKind;}implReadNorFlashforStrictApi{constREAD_SIZE:usize = 4;fnread(&mutself,offset:u32,bytes:&mut[u8]) -> Result<(),Self::Error>{let offset = offset asusize;if offset % Self::READ_SIZE != 0 || bytes.len() % Self::READ_SIZE != 0{Err(NorFlashErrorKind::NotAligned)}else{for byte in bytes {*byte = 0xFF;}Ok(())}}fncapacity(&self) -> usize{8}}// Only required for RmwNorFlashStorage::newimplNorFlashforStrictApi{constWRITE_SIZE:usize = 4;constERASE_SIZE:usize = 4;fnerase(&mutself,from:u32,to:u32) -> Result<(),Self::Error>{unreachable!()}fnwrite(&mutself,offset:u32,bytes:&[u8]) -> Result<(),Self::Error>{unreachable!()}}fntest_read_unaligned(){letmut buffer = [0x00;4];letmut storage = RmwNorFlashStorage::new(StrictApi,&mut buffer);letmut my_buffer = [0x00;1];
storage.read(3,&mut my_buffer).unwrap();assert_eq!(my_buffer[0],0xFF);}
The text was updated successfully, but these errors were encountered:
The
Storage
trait does not expose any alignment information, and one would thus assume that implementations of it would allow for unaligned reads, butRmwNorFlashStorage
currently does not. As an example, the following code snippets fails to run:The text was updated successfully, but these errors were encountered: