-
-
Notifications
You must be signed in to change notification settings - Fork 959
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
Nimble: Reduce power usage, add compatibility to LFCLK calibration #1052
Conversation
does this pr , allow better battery usage @StarGate01 ? |
@trman Refer to https://mynewt.apache.org/v1_7_0/network/ble_setup/ble_lp_clock.html#crystal-settle-time-configuration
I have not yet performed long-running power measurements, my Pinetime is going strong for days. I'll report back when I have reliable measurements, these tests can take days or weeks. |
825a3f2
to
82f7e53
Compare
I've been using this for a couple of weeks, the battery life isn't enormously different but it has been performing well and bluetooth connectivity has been reliable as ever. The battery graph in gadgetbridge looks less steep and I've been getting about 5 days use down to 50% which is when I usually charge it. |
@kieranc Thank you for testing! I did not perform large-scale power measurements for the unmodified Infinitime versions - I am glad to see that your experience matches mine. |
46b201c
to
ee89011
Compare
InfiniTime formatting rules shouldn't apply to external libs. I'm updating the workflow to ignore the libs folder. |
I see that the formatting rules have been updated in 6171c9d , the CI format checks should pass now - but I don't have permission to re-trigger them. |
The checks use the workflow files from your branch, so it must be rebased to fix it. This will also allow the checks to be started. |
Thanks for this PR @StarGate01 ! I really appreciate all the efforts made to improve battery life! Have you considered upstreaming those changes to nimble? Many other project would probably be interested in reducing power usage! Also, are the changes to the log and to the critical section needed? |
@JF002 Thanks!
Yes, see apache/mynewt-nimble#1207 . Kind of hard, since Nimble does not use the NRF SDK in that way (yet). A documentation addition would be nice to have in any case.
Yes, especially It might be worth looking at apache/mynewt-nimble#1021 to further improve the critical section functions eventually. However, I don't know that much about the inner working of FreeRTOS interrupt handling, and the current solution works great.
These changes make it possible to in-depth debug Nimble. This is disabled by default, and can be enabled by changing these lines in the CMake file: https://github.com/InfiniTimeOrg/InfiniTime/pull/1051/files#diff-148715d6ea0c0ea0a346af3f6bd610d010d490eca35ac6a9b408748f7ca9e3f4R807 . This is part of my PR for improved debugging support. |
Awesome! Great work! I would very much like to keep nimble as close as possible to the original code so that we keep the possibility to switch to a submodule someday :) |
My best idea to integrate the NRF SDK LF clock calibaration compatibility into Nimble was this: apache/mynewt-nimble#1207 (comment) , essentially to define a weak fallback symbol which can get overloaded by the linker if the NRF SDK is used. I admit that this is kind of a hack, but it should work - although I have not tested it. Ultimatly, there should be a PR created in Nimble to address this, and an amendment made to the documentation at https://mynewt.apache.org/latest/network/ble_setup/ble_lp_clock.html , to warn users of potential incompatibilies with code that switches the HF clock (e.g. the NRF SDK LF calibaration routines). I have paused work on upstreaming this to Nimble due to the unclear state of the NRF SDK usage, and because I got no feedback on my weak symbol idea yet - however, to be fair, I don't have it verified to be working. Maybe working on this PR only makes sense once Nimble is a proper submodule of InfiniTime, since the testing of the NRF SDK interactions becomes a lot easier then. I propose to continue the potential discussion concerning the Nimble upsteraming in apache/mynewt-nimble#1207 . |
i if i undertand right @StarGate01 @JF002 , it's not possible to merge this part on nimble because it's against their rule so it can be only be done here ? |
Nimble just does not use the NRF SDK currently, so the required functions do not exist. I proposed a potential solution in apache/mynewt-nimble#1207 (comment) , but this is hard to test and verify. Once InfiniTime uses Nimble as a proper submodule, this change would be much easier to upstream into Nimble. In the meantime, this can be merged into our "fork" of Nimble. |
Nimble's configuration handling is currently a significant pain for that to happen. We'd have to patch Nimble using CMake, which isn't very nice. |
@Riksu9000 Since you added the |
We should test this PR to make sure everything still works as expected and measure the decrease in power usage if possible. |
I plan on running detailed power analysis using the |
@Riksu9000 @trman @JF002 Using the PPK2, I performed several tests to determine the power consumption impact of this PR. A detailed analysis and logdata is available at https://github.com/StarGate01/p8b-infinitime/tree/master/poweranalysis .
This should enable a theoretical increased battery runtime of about Let me know what you think, and also if you find any errors in my calculations. |
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.
Battery life improvements are great. I think we can merge this and see if any issues pop up during 1.11.0 dev.
This configures Nimble to enable the HFCLOCK and other Bluetooth peripherals only when needed, but 1500 us in advance. This time is recommended by the Mynewt docs.
This allows better debugging of the bluetooth stack.
Nimble has to be aware of the low frequency clock calibration procedure, in order to not interfere with the usage of the HFCLK. For more info, see apache/mynewt-nimble#1207
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.
We'll merge this branch now that 1.10 has been released so that we can easily check for potential side-effects (and potentially battery live improvements).
Pull request InfiniTimeOrg#1052 reduces power usage by powering down ble crystal when in idle. The crystal startup time is set to 1500 (mynewt default) The nrf52 spec says it should be 360 in section 19.4.2. https://infocenter.nordicsemi.com/pdf/nRF52832_PS_v1.8.pdf I think we can safely lower it to 400. I've been using this parameter for several days. However, I only have a sealed device and cannot verify if this actually saves battery, or, if this parameter even works. So, I will set this PR as draft for now.
Pull request InfiniTimeOrg#1052 reduces power usage by powering down ble crystal when in idle. The crystal startup time is set to 1500 (mynewt default) The nrf52 spec says it should be 360 in section 19.4.2. https://infocenter.nordicsemi.com/pdf/nRF52832_PS_v1.8.pdf I think we can safely lower it to 400. I've been using this parameter for several days. However, I only have a sealed device and cannot verify if this actually saves battery, or, if this parameter even works. So, I will set this PR as draft for now.
This PR has been broken out of #1050 .
BLE_LL_RFMGMT_ENABLE_TIME
parameter)