flash store: move unsafe, organise memory.x

This commit is contained in:
topquark12 2021-01-13 17:23:29 +08:00
parent 0200aa69bd
commit 1c71fbb6a7
2 changed files with 10 additions and 12 deletions

View File

@ -11,7 +11,7 @@ MEMORY
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
} }
_stack_start = ORIGIN(CCMRAM) + LENGTH(CCMRAM);
_dfu_msg = ORIGIN(DFU_MSG);
_config_start = ORIGIN(CONFIG);
_flash_start = ORIGIN(FLASH); _flash_start = ORIGIN(FLASH);
_config_start = ORIGIN(CONFIG);
_dfu_msg = ORIGIN(DFU_MSG);
_stack_start = ORIGIN(CCMRAM) + LENGTH(CCMRAM);

View File

@ -20,17 +20,17 @@ pub struct FlashBackend {
flash: FLASH, flash: FLASH,
} }
unsafe fn get_offset() -> usize { fn get_offset() -> usize {
(&_config_start as *const usize as usize) - (&_flash_start as *const usize as usize) unsafe {
(&_config_start as *const usize as usize) - (&_flash_start as *const usize as usize)
}
} }
impl StoreBackend for FlashBackend { impl StoreBackend for FlashBackend {
type Data = [u8]; type Data = [u8];
fn data(&self) -> &Self::Data { fn data(&self) -> &Self::Data {
unsafe { &self.flash.read()[get_offset()..(get_offset() + FLASH_SECTOR_SIZE)]
&self.flash.read()[get_offset()..(get_offset() + FLASH_SECTOR_SIZE)]
}
} }
type Error = Error; type Error = Error;
@ -40,10 +40,8 @@ impl StoreBackend for FlashBackend {
} }
fn program(&mut self, offset: usize, payload: &[u8]) -> Result<(), Self::Error> { fn program(&mut self, offset: usize, payload: &[u8]) -> Result<(), Self::Error> {
unsafe { self.flash.unlocked()
self.flash.unlocked() .program(get_offset() + offset, payload.iter().cloned())
.program(get_offset() + offset, payload.iter().cloned())
}
} }
fn backup_space(&self) -> &'static mut [u8] { fn backup_space(&self) -> &'static mut [u8] {