-
Notifications
You must be signed in to change notification settings - Fork 179
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 public functions to toggle PWREN bits #64
Conversation
Thanks for the PR! I believe that |
I find Since there is no way to clear Another concern of mine is that one particular feature — access to backup registers — commands implementation of completely independent feature — deep sleep mode. I fully understand why ownership abstraction over |
I disagree, in the current implementation, there is no indication that it would break the backup domain abstraction.
Agreed, tying the pwr registers and backup domain together isn't a perfect solution and I wouldn't mind having an abstraction where you need pass a PWR token to BKP in order to initialise it. That way, you could hand BKP back in order to disable the pwr regs. I think we may have discussed that in the PR I mentioned, but I can't remember. |
One option would be to require passing
But then again, it would require some way to unconstrain I think we can keep |
That sounds like a good option to me. @TeXitoi You had lots of comments on the RTC, do you see any problems with this approach? Sidenote:
I'm not a fan of runtime assertions in embedded systems, so I'd prefer something static |
I'll try to find the time to review this PR before the end of the week. |
I can't find any harm on |
It is used for low power modes. For example, in table 15 in section 5.3.5, it says you need to set PDDS in PWR_CR and WUF in PWR_CSR. If I recall correctly, those can't be written to unless PWRen has been set. |
Yes, @TheZoq2 is absolutely correct. I've written a post about the specifics https://vasiliev.me/blog/sending-stm32f1-to-deep-sleep-with-rust/. The lack of access to |
Nicely written blog post, I have been trying to make deep sleep work as well, but I can't quite get it to go below one milliamp in my project. I'd be fine with merging this, but since the only use case is to go to sleep which itself is a bit of a strange process, do you think it would make more sense to add a function to do that directly? |
I am not entirely sure that would be possible. There is a lot of configuration involved: which low power mode you want to enable, whether or not you want to wake up on a watchdog timer or WKUP pin, which peripherals to disable, etc, etc, etc. Also, the place to finally call |
Yea, perhaps it's not as easy as I think it would be, I might give it a try at some point though. For now, i'd be happy to merge this if you remove the |
Done |
Very nice, thanks! |
Discussion started in #62 so I'll just copy description from there:
When enabling standby mode, there is a need to set
PWREN
bit in APB1 ENR register.Right now it can be achieved by calling
constrain
onrcc.bkp
. https://github.com/stm32-rs/stm32f1xx-hal/blob/master/src/rcc.rs#L367And while it does set the right bits in the right places, it enables other registers as well, which may to may not be desirable.
Ideally, I'd like to be able to do it manually:
Or maybe just call a function that does it for me, something like what
set_sleepdeep()
does: https://github.com/rust-embedded/cortex-m/blob/master/src/peripheral/scb.rs#L585As suggested by @TheZoq2 in the same issue #62 (comment), this is the PR for further discussion.