Skip to main content
RKTK API Docs RKTK Home Repo

rktk_drivers_rp/
flash.rs

1use embassy_rp::{
2    Peri,
3    dma::{self, ChannelInstance},
4    flash::Flash,
5    interrupt,
6    peripherals::FLASH,
7};
8use rktk::drivers::interface::storage::StorageDriver;
9use rktk_drivers_common::storage::flash_sequential_map::FlashSequentialMapStorage;
10
11/// Utility to initialize flash and initialize it as storage driver.
12///
13/// This function uses fixed flash area for storage: from 1MB to 3MB.
14/// If you need different area, you can create [`Flash`] and [`FlashSequentialMapStorage`] directly.
15pub fn init_storage<D: ChannelInstance, const SIZE: usize>(
16    flash: Peri<'static, FLASH>,
17    dma: Peri<'static, D>,
18    irq: impl interrupt::typelevel::Binding<D::Interrupt, dma::InterruptHandler<D>> + 'static,
19) -> impl StorageDriver {
20    let flash = Flash::<_, _, SIZE>::new(flash, dma, irq);
21
22    const FLASH_START: u32 = 1024 * 1024;
23    const FLASH_SIZE: u32 = 2 * 1024 * 1024;
24
25    FlashSequentialMapStorage::new(flash, FLASH_START, FLASH_SIZE)
26}