flash_store: get to a working state

This commit is contained in:
Astro 2020-12-13 00:49:15 +01:00
parent 880a887c40
commit 97813f917d
2 changed files with 19 additions and 3 deletions

View File

@ -1,6 +1,8 @@
MEMORY MEMORY
{ {
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
/* reserved for config data */
CONFIG (rx) : ORIGIN = 0x8100000, LENGTH = 16K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 112K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 112K
RAM2 (xrw) : ORIGIN = 0x2001C000, LENGTH = 16K RAM2 (xrw) : ORIGIN = 0x2001C000, LENGTH = 16K
RAM3 (xrw) : ORIGIN = 0x20020000, LENGTH = 64K RAM3 (xrw) : ORIGIN = 0x20020000, LENGTH = 64K

View File

@ -1,3 +1,4 @@
use log::{info, error};
use stm32f4xx_hal::{ use stm32f4xx_hal::{
flash::{Error, FlashExt}, flash::{Error, FlashExt},
stm32::FLASH, stm32::FLASH,
@ -18,11 +19,12 @@ impl StoreBackend for FlashBackend {
type Data = [u8]; type Data = [u8];
fn data(&self) -> &Self::Data { fn data(&self) -> &Self::Data {
self.flash.read() &self.flash.read()[FLASH_SECTOR_OFFSET..(FLASH_SECTOR_OFFSET + FLASH_SECTOR_SIZE)]
} }
type Error = Error; type Error = Error;
fn erase(&mut self) -> Result<(), Self::Error> { fn erase(&mut self) -> Result<(), Self::Error> {
info!("erasing store flash");
self.flash.unlocked().erase(FLASH_SECTOR) self.flash.unlocked().erase(FLASH_SECTOR)
} }
@ -41,5 +43,17 @@ pub type FlashStore = Store<FlashBackend>;
pub fn store(flash: FLASH) -> FlashStore { pub fn store(flash: FLASH) -> FlashStore {
let backend = FlashBackend { flash }; let backend = FlashBackend { flash };
FlashStore::new(backend) let mut store = FlashStore::new(backend);
// just try to read the store
match store.get_bytes_used() {
Ok(_) => {}
Err(e) => {
error!("corrupt store, erasing. error: {:?}", e);
let _ = store.erase()
.map_err(|e| error!("flash erase failed: {:?}", e));
}
}
store
} }