-
Notifications
You must be signed in to change notification settings - Fork 139
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
Provides common Nvmc functionality #337
Conversation
titanclass/thingy91-lorawan-nbiot@4a9f673 shows the positive impact of this abstraction. |
nrf-hal-common/src/nvmc.rs
Outdated
/// Interface to an NVMC instance. | ||
pub struct Nvmc<'a, T: Instance, const N: usize> { | ||
nvmc: T, | ||
storage: &'a mut [u32; N], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how you're planning on using this, but if you plan on offering non-blocking APIs we need to make sure this is mem::forget
-safe (presumably by making it 'static
)
Also some rationale on why this is const-generic instead of a dynamic slice would be nice, and why this is using u32
instead of u8
as the element type – does the NVMC have alignment requirements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, writes must be aligned to u32. I agree on the const generics though, a dynamic slice seems simpler.
Also, I'm not sure if there's UB issues with having a &mut
to the data while you modify it / erase it through magic register writes...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how you're planning on using this, but if you plan on offering non-blocking APIs we need to make sure this is
mem::forget
-safe (presumably by making it'static
)
Commit 70aad94 makes its 'static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also some rationale on why this is const-generic instead of a dynamic slice would be nice.
Commit 70aad94 changes this to a dynamic slice. Dunno what I was thinking. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I'm not sure if there's UB issues with having a
&mut
to the data while you modify it / erase it through magic register writes...?
I may not fully understand the question. However, the data isn't actually modified via registers... the NVMC is put into various modes and then regular memory operations ensue.
nrf-hal-common/src/nvmc.rs
Outdated
} | ||
|
||
pub trait Instance { | ||
fn enable_erase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if these methods are needed. I'd just do the #[cfg]
s in the logic above, which imo is much simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit c71362c attends to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit 7958ca2 reverts back to the trait methods because there is no common type representing the NVMC configuration. For the 52840, we have the CONFIG type which is a register of a _CONFIG struct. For the 9160 it is CONFIGNS and _CONFIGNS respectively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, commit e0e4482 figures it out. Deref
FTW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit 90b8818 also adds 52840 considerations.
@jonas-schievink @Dirbaio We now have tests for the NVMC via nRF52840-hal-tests, and things appear to be working! I want to go through things finely before converting from a draft PR, and write an example. I also want to do some boundary checks via my tests. Your feedback is appreciated! |
The embedded-storage traits are implemented to provide a higher level abstraction for reading and writing from/to flash storage. In the first instance, support is provided for the nRF52 series and the nRF9160, but other boards should be relatively easy to support.
This PR is complete and ready for a thorough review. |
bors r+ |
Build succeeded: |
The embedded-storage traits are implemented to provide a higher-level abstraction for reading and writing from/to flash storage. In the first instance, support is provided for the nRF52 boards and the nRF9160, but other boards should be relatively easy to support if required in the future.
Sample usage of writing to flash given some 32 bit aligned slice of bytes:
An example of establishing the
Nvmc
on the nRF9160:...where CONFIG points to flash:
...which can be expressed in a memory layout:
Testing on the nRF52840 device can be achieved via
cargo test --test nvmc
from within thenrf52840-hal-tests
folder.Fixes #336
TODO:
ReadNorFlash
methodsNorFlash
methodsInstance
for the nRF52840Instance
for the nRF9160