Skip to content

A common HAL NVMC abstraction - needed? #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
huntc opened this issue Jul 12, 2021 · 4 comments · Fixed by #337
Closed

A common HAL NVMC abstraction - needed? #336

huntc opened this issue Jul 12, 2021 · 4 comments · Fixed by #337

Comments

@huntc
Copy link
Contributor

huntc commented Jul 12, 2021

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();
@Dirbaio
Copy link
Member

Dirbaio commented Jul 13, 2021

The driver could impl NorFlash and MultiwriteNorFlash from embedded_storage :)

@bors bors bot closed this as completed in 7a0be8a Jul 20, 2021
@ia0
Copy link
Contributor

ia0 commented Jan 8, 2022

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
Copy link
Contributor Author

huntc commented Jan 8, 2022

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
Copy link
Contributor

ia0 commented Jan 8, 2022

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

bors bot added a commit that referenced this issue Jan 10, 2022
373: Implement MultiwriteNorFlash for nRF52 boards that support it r=jonas-schievink a=ia0

This PR implements `MultiwriteNorFlash` as suggested [here](#336 (comment)).

I only listed nRF52 boards that support writing twice to the same word, because I'm not familiar with the other boards or crate features.

Co-authored-by: ia0 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants