nRF52840 Power Management Stage 1 v2.1 - Boot lockout fix - #2088
Conversation
e3c0529 to
d5f6c76
Compare
|
Good job |
Improvements: - Add configurable battery chemistry - Add per-chemistry LPCOMP wake threshold and boot lockout voltage - Add configurable enabled/disabled state for boot lockout - Reduce Li-ion/Li-Po lockout threshold to 3.0V from 3.3V - Initialise FS earlier in the startup process to allow reading configured settings for boot lock Fixes: - Add additional shutdown reason "None" for instances where the reason isn't set - Boot lockout disabled by default
d5f6c76 to
e32e30b
Compare
|
Tested on a couple of boards now without issues so far. Ready to be reviewed. |
|
Does setting pwrmgt.bootlock to off also prevent the low voltage shutdown? or is it only for boot? |
|
I truly understand what @entr0p1 wanted to do here and I respect it, however: I feel this became tad too over-engineered and we need to regroup and make it really simple: |
|
@recrof appreciate the respectful approach you've taken, I'm not fussed if it has to be pared right back or removed entirely. The fix is here if desired, but if you'd rather a different approach I won't be offended if you want to close it and do that. |
100% agree.
This is the most crucial point. #1413 was not ready for merging and still got merged for v1.12. It broke a lot of setups and now three months and three releases later things are still broken. People need to modify their firmware manually and climb on roofs because of this. Can we please either:
Thanks! |
|
When the final decision has been made and code merged and released it will be important to communicate about this in any case. I personally believe we will be seeing more and more LTO and Sodium-ion based repeaters in the future. |
I've implemented this as a quick fix in #2377. After deciding on and implementing a proper solution this can be reenabled. |
|
I've been thinking about this more and based on what @recrof said I remembered we already have an auto shutdown voltage in the companion firmware (I think its in others now too?). Couldn't we basically drop this entire feature out of the codebase and just build on that to make the voltage configurable via the CLI? No chemistries, wake, or lockouts to worry about and the code basically exists and just needs a pref added. Thoughts? |
|
My thoughts after being on the 2088 adventure: |
|
Regarding the app percentage display: The app could configure the battery chemistry for pecentage display purposes on the app level instead of polling it from the device. It's then saved locally in the app preferences. That way the device stays clean of any unnecessary settings; boot lock voltage can be configured freely by expert users and we can still have a sensible percentage display in the app. |
|
looking at this it does look like this is trying to do a lot at once. Instead of trying to add battery chemistry on here i would instead look at building this on top of my battery chemistry implementation at #1176. You could just do an ifdef for the different cell types and use that to set the minimum voltage either hard coded or perhaps even just fetch the last value in OCV_ARRAY as that should line up with 0% to the devices configured chemistry. In most cases though for Liion it will set it to 3.1v though instead of your proposed 3.0v if you take the OCV route. |
|
I understand the apprehension here, but I really want to get this one off my plate once and for all and put an end to the frustration and complaints. So we really need to make a call on what we want here. If I distil down the various conversations on what people want, I can think of these options:
Its already opt-in (disabled by default) in this PR so that's implied. What do we think? |
|
Yes, this really should be pushed out the door, especially since not having it can (and has) cause(d) serious operational problems. 1 is not an option. 2 sounds good, will keep it simple and solves the core of the problem. 3 sounds equally good to me - but I'm in no position to judge whether it's a base which will have future use, or falls under YAGNI. Regardless of whether it's 2 or 3, please get this merged 🙏 |
|
i think 2 makes the most sense to get this out quickly. It massively reduces the code change and if someone else wants to use this with a different chemistry they can just do a build with the voltage overriden to match their chemistry themselves until there is a better way merged in for battery chemistry management. |
|
Here is my $0.02 |
|
Great feedback folks, all makes perfect sense to me. So now it seems we've boiled down to option 2 or 3. I put my "think like recrof" hat on for a moment and even though it does feed the app useful info about chemistry, it would be simpler for the firmware to let Liam hard-code the chemistry in the app. The reason I say that is that the percentage reading doesn't actually come from the firmware in the first place; its derived in the app. That said it would probably be nice to have it there on the board so its just another piece of information to be interrogated and calculated more consistency by the various apps that now interface with these boards, but if having the chemistry selection is going to be the next stalemate I'd rather just rip it out. We could then have (as suggested) the shutdown voltage and wake divider ref as configurables, with a guidance table based on chemistry. Rather than trying to protect people from themselves I think it just needs to be a case of "here's the advice, ignore it at your own peril". So.. basically option 2 I guess? Apologies for the ping folks however I need the cavalry so we can put this to bed - @recrof @oltaco @ripplebiz do you have any strong opinions on which of the 3 options I mentioned is most favourable to you? I'd love to get the fix merged before the next release. |
|
@entr0p1 2. all the way. |
|
Sorry for the late response and not exactly the answer you are looking for, but here are my 3 cents....
A 3rd order polynomial can be used to fit ANY of the battery chemistries to within a 1% accuracy. Giving a fairly close approximation to ANY battery. This is what the applications actually need to display the percentage. A polynomial is also more efficient in terms of calculation time and storage space vs. a piece wise linear table (typically 10 points or option 2 which is only 2 points) Apps actually need the polynomial rather than the type name which they then use to choose a look table (piece-wise linear) or ideally the four polynomial coefficients. So my vote is #2.5 which is in order of priority is: #2 with coefficients of 0, 0, b, -b/a. y = ax + b #3, this is what Apps "really" need (yes the two points does this but with a very low accuracy). But a polynomial is what they actually need to create a single piece of code that covers ALL batteries, all it needs is the coefficients. LiFe = aXexp3 + bXexp2 + cX + d As NerdHerder said external charge controllers can never be accommodated so let's just do internal batteries where the voltage can be measured. The default should be "on" with the LIon coefficients. The CLI has an option to turn it "on/off" with the four coefficients. set batterytype off 1 2 3 4 set batterytype on 1 2 3 4 Set the shutdown voltage at 2% and the turn on at 5% (this is to give it a little power to start transmitting, which draws more) This is simple and covers most bases... |
|
Here is some data showing the improvement with a higher order model. https://www.sba.org.br/Proceedings/SBAI/SBAI2017/SBAI17/papers/paper_29.pdf Figure 6 shows that the Model Simulation Error is less than 3% for a 3rd order model and 11% for a first order model. So for two additional coefficients you get an 8% improvement in "accuracy". This seems worth it. This is way beyond a simplistic model but: A static model cannot adjust for temperature or number of charge cycle affect. Some devices have a temperature sensor and the charge cycles can be counted and either could be added to improve the accuracy. But 3% should be plenty good enough. I hope you consider option 2.5 |
|
I choose Option 2. Follow KISS. Simplicity works best. |
|
My use case is the Solar Xiao board (from FloodWave Systems) with LiFePO4 batteries. |
|
Big thank you @1nerdherder for stepping in to get something in the meantime, much appreciated :) I've finished the first rough cut of the code and have some pre-compiled copies based on 1.16 for the Xiao nRF52840, RAK4631 and Heltec T114. I have only flashed the Heltec T114 and RAK4631 thus far. They boot fine, the values can be set, and so far no incorrect boot locks. I will get the boards on a lab bench today at some point and test the lockout and subsequent recovery. For now, here's the builds I'm working with. These are very likely to change before I push the code into the PR, so if you want to hold out for the final, do so. heltec_t114_repeater-v1.16.0-DEV-pwrmgt-v2.2-beta1.zip To configure the lockout voltage, you need to run: E.g. To configure the LPCOMP REFSEL for booting the board back up from lockout when the battery voltage increases, you need to run: The setting values correspond to the following REFSEL values: More detail on what these mean is available here: https://docs.nordicsemi.com/r/bundle/ps_nrf52840/page/lpcomp.html As a quick reference point, on the RAK4631 I've used 5 for both Li-ion and LFP. This is purely based on math and not tested yet, will likely need to be revised. The boards will still recover when external power is introduced via USB or Solar (I.e. VBUS in) as before. |
|
Request for feedback from the core dev team (and of course the very patient testers along for the ride) - is there appetite here to tie this value to the runtime low voltage shutdown so it is both configurable to the user via CLI, and there is one setting to configure the low voltage threshold that is specifically set by the user? My thinking is if we want to do this, now is the time. We don't want to surprise people with it later by and having one unified setting for both makes it very clear where the threshold is coming from. This change is already long awaited and expected so there's ample attention on the details, its already disabled by default, and it just might save a few more browned out repeaters. If we want it, its trivial at this point for me to add it in as well. The provisions were already there in the code for it. |
|
Will you be posting a table of suggested settings for different chemistries (because we didn’t go with path #3)?I’ll be getting some time later this evening to give it a go.On Jun 7, 2026, at 17:55, Dom ***@***.***> wrote:entr0p1 left a comment (meshcore-dev/MeshCore#2088)
I've now tested the lockout and subsequent LPCOMP recovery on the Xiao nRF52840 and am stoked to announce it works as intended.
I set the lockout to 3.0V and the REFSEL to wake around 3.3-3.7V. I connected a power supply to the VBAT rail, ran the board down to about 2.9V and rebooted. Confirmed it did not boot. Then I slowly raised the voltage up to about 3.7V and the board booted. The CLI output shows LPCOMP is what booted the board and boot lock is what powered it off.
I'll test some more boards and thresholds to ensure everything is robust before pushing the commit.
IMG_20260608_035135.jpg (view on web)
IMG_20260608_103533.jpg (view on web)
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
|
I have successfully loaded the Xiao code and was able to get and set pwrmgt.lpcomp and pwrmgt.lvshutdown parameters via config.meshcore.io on USB. The older parameters (pwrmgt.batt) are no longer accepted. |
|
Alright, further testing has shown the board is pulling more power than it should in the "SYSTEMOFF" state. Its definitely "powered off", but just flagging I'm aware and looking into it. I will be putting a table of the REFSEL values and rough voltage ranges in the documentation for the power management module, but here is a rough cut in the meantime:
For the Xiao, LFP is a bit awkward. You can err on the side of caution and set your REFSEL to 3/8 ( The next option would be 5/16 ( |
|
Howdy folks, Quick update on this - I'm still working on the code, particularly around the shutdown process to ensure it is as robust and consistent between boards as possible. I've managed to make a lot of it less board-specific which is great; less maintenance overhead, less duplication of code, less places for things to go wrong. I should have the next beta available for you all some time this week/next weekend. |
|
Setting this back to draft as the commit is nearing completion. We will need testers for as many boards as possible to make sure things work right. I have ordered a few boards that I don't yet have to try and hit as much of the testing as I can. Hang in there guys, its nearly done :) |
|
How is this going? I have Rak4631, T114, T096, T-echo Lite, Xiao Nrf52 and Wio L1 pro for NRF52 type. |
Your sixth sense is impeccable - just finished it this afternoon. I have one annoying quirk to solve around the sensecap solar, but that shouldn't be difficult. I'm flashing some boards to do a preliminary test before sharing it. I expect I'll have a build for you within a couple hours. |
|
@IoTThinks First cab off the rank - Lilygo T-Echo Lite. Tested and confirmed the shutdown and subsequent wake works. lilygo_techo_lite_repeater-v1.16.0-DEV-pwrmgt-v2.2-beta2.zip To configure: Reference list of the thresholds you can use for the LPCOMP value:
I used a value of 13 for pwrmgt.lpcompwake, which triggered the wake at the high end of the range (around 3.7V). I'll be testing the T114 next and will post the beta build once it all works. Edit: fixed the file name. Mistakenly labelled RAK4631. |
|
Updated builds - this drops the LPCOMP hysteresis threshold as it might be a bit heavy-handed for some of the wider dividers (e.g. a lot of heltec boards use ~4.9). Adding the Heltec T114 as lockout and recovery tests have passed. pwrmgt.lpcompwake set to 2 for the T114 and the wake occurred at ~4.15V. heltec_t114-nodisplay_repeater-v1.16.0-DEV-pwrmgt-v2.2-beta3.zip |
can you please share rak4631 build as well? uArt mesh motherboard is pretty popular in Czech republic and they would want to test it with LTO cells. |
|
@entr0p1 May I know why the numbers are not linear from 1 to 16? |
@recrof Sure thing, its next in queue. Just getting the shutdown process right for it and running a bench power supply test before I share it.
@IoTThinks its the way Nordic have them laid out, unfortunately. It does make it challenging to find the "sweet spot" for some boards on particular chemistries. Here's the documentation reference: https://docs.nordicsemi.com/r/bundle/ps_nrf52840/page/lpcomp.html?section=register.REFSEL |
|
@entr0p1 I believe the first and the second parts is about voltage steps 1/8 or 1/16. If we use 1/16 for finer steps, then we can only care about the second parts. |
|
@IoTThinks I think you're on the right track, just a few caveats worth mentioning which I've listed below.
For example, the Heltec T114 shows a range of 3.68-4.04 V at lpcompwake setting 2 (see below). When I stepped the voltage up, the board didn't actually wake until crossing ~4.15V (according to the power supply).
|
|
@entr0p1 I see. No idea why all esp32 boards are just so trivial on this aspect. NRF52 should be similar. |
|
@IoTThinks Technically we can allow it to reboot loop but it carries the risk of flash corruption and just generally "isn't good" as a practice. At least with the board fully powered down, it can recoup the batteries and not sporadically join and leave the mesh. For those that really want to commit, they can use external low voltage cutoffs (similar to yourself), or a hardware watchdog. These can hold the reset pin closed when the voltage is too low and release them when it normalises. I know of people using them on ESP32 boards for other projects that swear by them. At least with LPCOMP, even if finicky, we have a choice to use it or not to :) RAK4631 build coming shortly. I've rolled the firmware, just testing it now. |
|
@entr0p1 Is there anyway we can have a correct lpcompwake via "self-learning". I think many users will not know what should we set for lpcompwake. |
|
@IoTThinks I like the idea, but if I'm honest I don't think it would be reliable and it would be chunky code-wise. This was similar to what I had on the initial version of this PR; user selects a chemistry and we have a predefined REFSEL value for that chemistry. Having it learn would mean watching the thresholds and knowing what "0%" vs "100%" actually looks like. The "not knowing what to set" concern is valid, but I think this will likely be a setting used by more advanced operators. For example, I'll be using it extensively on hard to reach boards. At least when the batteries are going down, I know I can forcibly reboot to lock the board in a safe state and it will bring itself back when charge levels are stable. That said, I'll be providing a table of the boards in the docs with the rough voltage thresholds to Not all boards will work for all chemistries as the REFSEL won't always land in a "sweet spot", but it's not worth throwing the baby out with the bathwater over either. I still think there's good value in having the LPCOMP option for those that want it or don't have the means/inclination to go the hardware watchdog approach. |
|
@recrof here's the RAK4631 build. Since the SX1262 doesn't have a hard power switch via pin, I used an SPI sleep command (same as radiolib does). This got the SYSTEMOFF current draw down from 5mA to being so low that the power supply doesn't register a draw (0.000A shown). Very happy with it. Here are the
rak4631_repeater-v1.16.0-DEV-pwrmgt-v2.2-beta3.zip Edit: Tomorrow will be Xiao nRF52840 as I know that will likely be the next eagerly awaited. |
|
As it turns out, that little SX1262 sleep trick works very well even on boards that can toggle the SX1262_POWER_EN pin. All of these now read 0.000mA current when in SYSTEMOFF and still recover perfectly. Xiao added. Tested with
Full list of current files: heltec_t114-nodisplay_repeater-v1.16.0-DEV-pwrmgt-v2.2-beta4.zip |
|
Just a heads up here, dev has diverged way too far from where I started with this PR. I'll be opening a few smaller ones in anticipation of the bigger change, otherwise the maintainers will hunt me down and tar + feather me for the size of the PR :) |
|
Hello @entr0p1| |
|
I will use another approach. To deepsleep at 3.0v and wakeup every hour to check voltage. Deepsleep takes less than 10uA and can stay for months. |
|
(Your posting form 8. Jun 2026) @1nerdherder , I really appreciate your former work and have it working successful im my local node. THX & regards! |
|
@HPunktErbert - Hello. |





Improvements:
Fixes: