Skip to content

Commit

Permalink
Attempt to fix flash issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdavidmackenzie committed Mar 3, 2025
1 parent 36d0f30 commit 7021e2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
22 changes: 16 additions & 6 deletions porky/src/flash.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(feature = "pico1")]
use core::str;
use defmt::info;
use defmt::{error, info};
use ekv::flash::{self, PageID};
use ekv::{config, Database};
use embassy_rp::flash::{Blocking, Flash};
Expand Down Expand Up @@ -93,18 +93,28 @@ pub fn get_flash<'a>(flash_pin: FLASH) -> Flash<'a, FLASH, Blocking, FLASH_SIZE>

pub async fn db_init(
flash: Flash<'static, FLASH, Blocking, FLASH_SIZE>,
) -> Database<DbFlash<Flash<'static, FLASH, Blocking, FLASH_SIZE>>, NoopRawMutex> {
) -> Database<DbFlash<Flash<'static, FLASH, Blocking, FLASH_SIZE>>, NoopRawMutex>{
#[cfg(feature = "pico2")] // pico2 needs a delay
embassy_time::Timer::after_millis(10).await;

#[cfg(feature = "pico1")]
const OFFSET: usize = 0x0;
#[cfg(not(feature = "pico1"))] // The start of flash address needs adjusting on pico 2
const OFFSET: usize = 0x1000_0000;

let flash: DbFlash<Flash<_, _, FLASH_SIZE>> = DbFlash {
flash,
start: unsafe { &__config_start as *const u32 as usize },
start: unsafe { &__config_start as *const u32 as usize - OFFSET},
};
let db = Database::<_, NoopRawMutex>::new(flash, ekv::Config::default());

if db.mount().await.is_err() {
info!("Initializing Flash DB...");
db.format().await.unwrap();
info!("Formatting Flash DB...");
match db.format().await {
Ok(..) => info!("Flash Database is up"),
Err(_e) => error!("Error initializing Flash DB"),
}
}

info!("Flash Database is up");
db
}
1 change: 1 addition & 0 deletions porky/src/porky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ async fn main(spawner: Spawner) {
Database<DbFlash<Flash<'static, FLASH, Blocking, { flash::FLASH_SIZE }>>, NoopRawMutex>,
> = StaticCell::new();
let db = DATABASE.init(flash::db_init(flash).await);
// TODO log flash/db error here

#[cfg(feature = "wifi")]
static STATIC_BUF: StaticCell<[u8; 200]> = StaticCell::new();
Expand Down

0 comments on commit 7021e2c

Please sign in to comment.