Add configurable nRF52 battery profiles with LiFePO4 cutoff

This commit is contained in:
mikecarper committed 2026-09-30 01:11:10 -07:00
1 parent ddcc1de467
commit 11d64b3db3
31 files changed
+692 -32

No files matched your search

+2
View File
@@ -212,6 +212,8 @@ should use command `0x42`. See [Companion radio binary protocol](companion_proto
| Bridge | [`get/set bridge.secret`](cli_commands.md#set-the-esp-now-secret) | ESP-NOW is ESP32 only | No | No | No |
| Board | [`get bootloader.ver`](cli_commands.md#view-the-bootloader-version-nrf52-only) | nRF52 bootloader metadata | Yes | Yes | Yes |
| Board | [`get pwrmgt.support`; `get pwrmgt.source`; `get pwrmgt.bootreason`; `get pwrmgt.bootmv`](nrf52_power_management.md#cli-commands) | Board power-management implementation | Feature | Feature | Feature |
| Board | [`get/set pwrmgt.bootlock`; `get/set pwrmgt.cutoff`](cli_commands.md#configure-nrf52-battery-protection) | nRF52 power-management boards with a text CLI | Feature | Feature | Feature |
| Board | [`get/set battery.profile`; `get/set battery.empty`; `get/set battery.full`; `get/set adc.multiplier`](cli_commands.md#configure-nrf52-battery-protection) | nRF52 power-management boards with a text CLI; relative ADC calibration | Feature | Feature | Feature |
| Ethernet | [`eth.status`](cli_commands.md#view-ethernet-connection-status) | Ethernet target | Feature | Feature | No |
| Browser OTA | [`start ota [ap]`; `stop ota`](cli_commands.md#start-or-stop-an-over-the-air-ota-firmware-update) | ESP32 browser uploader | No | No | No |
| WebConfig | [`start webconfig [ap]`; `stop webconfig`; `get/set webui`](cli_commands.md#browser-configuration-portal-esp32-repeater-and-room-server) | ESP32 WebConfig | No | No | No |
+71 -1
View File
@@ -1836,7 +1836,13 @@ through binary command `0x42`; this command does not report the Bluetooth PIN.
**Default:** `0.0` (value defined by board)
**Note:** Returns "Error: unsupported by this board" if hardware doesn't support it
**Note:** On nRF52 boards with power management and a boot-voltage setting,
this is a saved *relative* calibration: `1.000` keeps the board conversion,
`1.050` raises all reported battery millivolts by 5%, and `0` resets to
`1.000`. The allowed range is `0.500`–`1.500`. This affects boot protection,
running cutoff, telemetry, battery alerts, and percentage. Calibrate against a
voltmeter before enabling a low cutoff. Other boards retain their existing
board-specific multiplier behavior, or return unsupported.
---
@@ -4790,6 +4796,70 @@ manufacturer images and the boards still requiring untouched factory dumps.
---
#### Configure nRF52 battery protection
**Usage:** `get pwrmgt.bootlock`, `set pwrmgt.bootlock <2500-4200>`
**Usage:** `get pwrmgt.cutoff`, `set pwrmgt.cutoff <off|2500-4200>`
Values are battery millivolts and are saved in internal storage. The boot lock
defaults to each board's compiled threshold and takes effect on the next boot.
Boards whose compiled boot lock is disabled also accept `set pwrmgt.bootlock off`.
The running cutoff
defaults to `off`; when enabled, three valid low readings at 30-second
intervals shut the node down. Both checks are bypassed while externally
powered. A nonzero cutoff cannot exceed the boot lock, and the boot lock
cannot be disabled while a cutoff is active. A fixed 2000 mV pre-check
protects flash on boards with a nonzero compiled boot lock before the saved
setting can be loaded. In the `custom` profile, the lower limit for the boot
lock and running cutoff is 2000 mV. Firmware warns when any saved voltage is
below 2500 mV; that experimental range may brown out the board or interrupt
flash writes. These commands are available on nRF52 boards with
`NRF52_POWER_MANAGEMENT` and a boot-voltage configuration, in roles with a
text CLI. The KISS modem has no text CLI for changing these settings.
`battery.profile` selects saved voltage-to-percentage endpoints and protection
settings. `liion` uses 3000 mV = 0%, 4200 mV = 100%, the board's original boot
lock, and running cutoff off. `lifepo4` uses 2700 mV = 0%, 3550 mV = 100%,
2900 mV boot lock, and 2700 mV running cutoff. `custom` starts with the current
values and allows endpoint overrides. These percentages are simple voltage
estimates; they are not an accurate state-of-charge measurement under load.
```text
get battery.profile
set battery.profile lifepo4
set battery.profile liion
set battery.profile custom
get battery.empty
set battery.empty 2700
get battery.full
set battery.full 3550
get adc.multiplier
set adc.multiplier 1.050
```
The custom empty/full endpoints may be 2000–4200 mV and must be at least 100 mV
apart. Setting either endpoint automatically selects `custom`; boot lock and
cutoff remain separately adjustable. `get pwrmgt.bootlock` and
`get pwrmgt.cutoff` show the values in force after selecting a profile.
For a RAK3401/RAK13302 LiFePO₄ cell:
```text
set battery.profile lifepo4
```
The 2.7 V cutoff is a cell-protection choice, not a guarantee of 1 W RF
output. The [RAK13302 datasheet](https://docs.rakwireless.com/product-categories/wisblock/rak13302/datasheet-vd/)
specifies 3.0 V minimum at VBAT and lists 5 V / 1 A peak for 30 dBm output.
Use a cutoff at or above 3.0 V if keeping the radio within its published
battery-input range matters; verify the actual voltage under transmit load.
The shutdown wake comparator has a separate fixed hardware reference. Changing
these millivolt settings does not change that wake threshold; a unit may need
to charge above it or have USB power restored before it wakes.
---
### Ethernet (when Ethernet support is compiled in)
Ethernet support is available on RAK4631 boards with a RAK13800 (W5100S) Ethernet module. Use the `_ethernet` firmware variants (e.g. `RAK_4631_repeater_ethernet`) to enable this feature.
+10 -4
View File
@@ -190,6 +190,13 @@ Power management status can be queried via the CLI:
| `get pwrmgt.bootreason` | Returns reset and shutdown reason strings |
| `get pwrmgt.bootmv` | Returns boot voltage in millivolts |
Boards with nRF52 power management and a text CLI also support saved
`pwrmgt.bootlock`, `pwrmgt.cutoff`, `battery.profile`, `battery.empty`,
`battery.full`, and relative `adc.multiplier` settings. See the
[CLI reference](cli_commands.md#configure-nrf52-battery-protection) for their
ranges, board-specific defaults, and wake behavior. KISS builds honor a saved
policy if one exists, but have no text CLI for changing it.
On boards without power management enabled, `get pwrmgt.source` and
`get pwrmgt.bootmv` return:
```
@@ -212,11 +219,10 @@ DEBUG: PWRMGT: Boot voltage = 3450 mV (threshold = 3300 mV)
DEBUG: PWRMGT: LPCOMP wake configured (AIN7, ref=3/8 VDD)
```
## Phase 2 (Planned)
## Further power-management work (Planned)
- Runtime voltage monitoring
- Voltage state machine (Normal -> Warning -> Critical -> Shutdown)
- Configurable thresholds
- A voltage state machine (Normal -> Warning -> Critical -> Shutdown)
- Configurable wake comparator thresholds
- Load shedding callbacks for power reduction
- Deep sleep integration
- Scheduled wake-up