nrf-rs/nrf-hal

A common HAL NVMC abstraction - needed?

huntc opened this issue · 4 comments

huntc commented

Do we need a common-hal abstraction for the NVMC as per https://github.com/NordicSemiconductor/nrfx/blob/7eca6c2dc02b24cbdaa3ba0e63a7195e34ebe07c/hal/nrf_nvmc.h#L259

Writing code to interact with the NVMC on the nRF9160 is quite error prone e.g. to write out a 32 bit slice given a static mut of CONFIG positioned in flash:

// Erase anything that's there
nvmc.configns.write(|w| w.wen().een());
unsafe {
    CONFIG[0] = 0xffffffff;
}
nvmc.configns.reset();

// Write the slice
nvmc.configns.write(|w| w.wen().wen());
unsafe {
    let mut k = 0;
    for i in (0..sliced_len).step_by(4) {
        let mut word = ...
        while !nvmc.ready.read().ready().bit_is_set() {}
        CONFIG[k] = word;
        cortex_m::asm::dmb();
        k += 1;
    }
}
nvmc.configns.reset();

The driver could impl NorFlash and MultiwriteNorFlash from embedded_storage :)

ia0 commented

Hi,

AFAIU #337 did not implement MultiwriteNorFlash as mentioned in the previous comment. I don't find any reference in the PR explaining why it's not possible. I guess not all boards support multiple writes. Is there a solution to implement the trait only when it's supported? Should I open a separate issue or reopen this one?

Thanks!

huntc commented

Hi,

AFAIU #337 did not implement MultiwriteNorFlash as mentioned in the previous comment. I don't find any reference in the PR explaining why it's not possible. I guess not all boards support multiple writes. Is there a solution to implement the trait only when it's supported? Should I open a separate issue or reopen this one?

Thanks!

I just implemented what I needed at the time. I’d suggest a new PR. Thanks.

ia0 commented

Sure thing! I created #373. I only implemented it for the nRF52 boards since I'm not familiar with the other ones.