-
Notifications
You must be signed in to change notification settings - Fork 172
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
Add support for reading and writing to the Backup Data Register (#83). #86
Conversation
Thanks for the PR, it looks good to me, and most of my comments are "bikeshedding" I'm not sure how I feel about Another option might be to ignore the names of the registers and make the indexes 0 based in the API. As far as I know, no other systems in the processor depends on data in these registers so where we put "1" won't make a difference. Whichever option we go with, it would be nice with a more clear comment saying which range of registers are available. Since I'm bikeshedding already, I think I would prefer Finally, could you add a line to |
No problem, bikeshedding is fine. |
0 based. I'm just not so sure about the u8, maybe it would be better to make it |
Hm, just noticed that travis failed for STM32F100 and STM32F101; are the SVD files broken and/or do we need to need to feature gate the backup domain stuff for STM32F103 and higher? |
stm32-rs have regression. STM32F103 and other have different types. |
I've found that the BKP_DR11 to BKP_DR42 registers do not work (writing a value to them and reading afterwards gives back 0). I already found that they used a different naming convention in the STM32F1 crate. Does anybody know more about this? |
stm32-rs/stm32-rs@58f8163 |
Related issue in old repo: |
@burrbull Thanks, I have tried your change and I saw that you've renamed I'll update this PR with my latest code. The code I'm using to test is: let mut buf_w: [u16; 42] = [0; 42];
for (i, d) in buf_w.iter_mut().enumerate() {
*d = (i + 1) as u16;
}
backup_domain.write_data_register_array(&buf_w, 0);
let mut buf_r: [u16; 42] = [0; 42];
backup_domain.read_data_register_array(&mut buf_r, 0);
for (i, (w, r)) in buf_w.iter().zip(buf_r.iter()).enumerate() {
if w != r {
hprintln!("{}: ERR w: {} ≠ r: {}", i, w, r).unwrap();
}
} Update: I've pushed the code to this PR. Please note that it requires the latest master from |
With this change |
Aah, I'm sorry for the trouble, thanks. Why do we split into |
pub fn read_data_register(&self, register: usize) -> u16 {
match register {
1..10 => read_drx!(self, dr, register-1),
11..42 => read_drx!(self, bkp_dr, register-11)
_=> unreachable!()
}
} |
Because
|
src/backup_domain.rs
Outdated
macro_rules! write_drx { | ||
($self:ident, $drx:ident, $idx:expr, $new:expr) => {{ | ||
unsafe { | ||
$self._regs.$drx[$idx].write(|w| w.bits($new.into())); |
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.
$self._regs.$drx[$idx].write(|w| w.d().bits($new));
And and unsafe
is not needed.
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.
Apparently, I still need unsafe
. I've added the .d()
part.
OK, so the following points are open:
Let me know if there is still something I can do! |
I think we should split each function on low/high variant, where first one will operate on |
I'm not a fan of runtime checks, so I'd prefer a feature gate. If we do do runtime checks, i'd prefer some sort of error over returning valid looking data like 0
I like this solution |
OK, I separated the functions in I dropped the array / buffer functions, because I think it would introduce to much functions for just the backup register. But I think this code is very straightforward to implement by the library user. Also they are not always practical (for example if I want to store a u32 in the backup data register, I would have to go from a I'm not sure how to do the feature gate:
Sorry, for the lots of back- and forward... |
What do we do with the feature gate? |
You can add @adamgreig promised make release this weekend. |
That feature does not exist, right? Besides, I see that it depends on model number and on the amount of flash memory:
The 84-byte data registers are only available in high-density, XL-density and connectivity line devices. |
One of the solution is to add feature gate for each type of microcontroller: stm32f1xxxx (stm32f103c8). They can depend on other features like |
That seems like a pretty reasonable solution to me, but I haven't heard the arguments against it |
I can make initial PR with these features. |
@TheZoq2 One of the arguments against it is that we'd have to maintain a database of details even most users will not even know or care about. I'm okay with having features for |
@mjepronk please, rebase your changes. |
@burrbull I think my repo was already up-to-date, but I've bumped the dependency |
This repo is already on 0.8 #88 :) |
Doh, sorry. I've merged... |
@mjepronk How about a rebase? 😉 |
@therealprof @burrbull Done, sorry for the confusion. I didn't do the |
This looks good to me, do we want to wait for #90 before merging? |
Yes, I will pick this up ASAP. Thanks! |
Is there anything left to do before we can merge this? |
Nope, I just missed the new pushed commits, thanks! Also, I feel like it's time for another release, any objections to that? @therealprof |
@TheZoq2 No objections. |
Cool, version 0.4.0 has been published 🎉 |
This is my first attempt at fixing issue #83.