-
Notifications
You must be signed in to change notification settings - Fork 4
Can I write multiple times without erase in between? #39
Comments
I think we cannot implement embedded-storage-async in a reasonable way since the ROM functions are blocking (and also not much documentation is available besides what is in the esp-idf source) We could try to implement things w/o the ROM functions which would give us all the freedom we want but that's a lot of effort I guess - there is not much documentation available (again - besides what is in esp-idf) |
oh wait, I was unclear. My question is not whether or not we can do async. Its more about whether or not it is safe to write multiple times, without erase. e.g. if the following is ok:
I'm using the excellent sequential-storage crate and wrap embedded-storage in a blocking adapter( BlockingAsync). In order to pop items, the flash implementation need to fulfill these properties ^^ |
Ah ok - I was confused since the link was for embedded-storage-async. t.b.h. I haven't tested that but I guess it should work |
Yeah sorry about that. I totally forgot that I'm using the wrapper and only wanted to know about the multiple writes. Ok, but then you also dont have more information about the rom function and I'll have to do a small test.... Thank you for answering |
I've validated this, and its indeed supported to write multiple times. The result is a bitwise-and. Perfect. Test Code#![no_std]
#![no_main]
use esp32c6_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng};
use esp_backtrace as _;
use esp_storage::FlashStorage;
use embedded_storage::nor_flash::NorFlash;
use embedded_storage::nor_flash::ReadNorFlash;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let _clocks = ClockControl::max(system.clock_control).freeze();
let mut rng = Rng::new(peripherals.RNG);
esp_println::logger::init_logger_from_env();
let mut buf1 = [0u8; 4096];
let mut buf2 = [0u8; 4096];
let mut buf3 = [0u8; 4096];
let mut buf4 = [0u8; 4096];
rng.read(&mut buf1).unwrap();
rng.read(&mut buf2).unwrap();
for i in 0..4096 {
buf3[i] = buf1[i] & buf2[i];
}
let mut fs = FlashStorage::new();
fs.erase(0x9000, 0x9000+0x4000).unwrap();
log::info!("Flash erased");
fs.write(0x9000, &buf1).unwrap();
log::info!("Wrote buf1");
fs.write(0x9000, &buf2).unwrap();
log::info!("Wrote buf2");
fs.read(0x9000, &mut buf4).unwrap();
log::info!("Read buf4 which should be buf1 & buf2 (bitwise and)");
assert_eq!(buf3, buf4);
log::info!("Success");
loop {}
} |
Currently the MultiwriteNorFlash trait is not implemented in this crate. Is this on purpose? I could not find out whether the underlying ROM function would actually allow this...
Thank you
The text was updated successfully, but these errors were encountered: