feat(stm32): Add STM32 ADC support to AnalogBatteryLevel (#9369)
Integrate STM32 battery monitoring into AnalogBatteryLevel, supporting external GPIO ADC pins as well as internal VBAT channel. Features: - ADC reading using STM32 LL (Lower Layer) macros supporting external ADC channels and internal VBAT channel (AVBAT) - ADC compensation using STM32 LL macros with factory-calibrated VREFINT (AVREF) for accurate voltage measurement - LFP battery OCV curve for STM32WL using AVBAT (STM32 VDD absolute maximum supply voltage 3.9V, direct connection of Li-Po batteries is not supported) Internal VBAT channel implemented in: - Russell - RAK3172 In these variants, ADC_MULTIPLIER = (1.01f * 3) = 3.30 as there is a 3:1 internal divider (DS13105 Rev 12 §5.3.21), and a bit of tolerance as the actual 10% spec leads to readings much too high. Assisted-by: Claude:sonnet-4-5 Signed-off-by: Andrew Yong <me@ndoo.sg>
This commit is contained in:
@@ -16,6 +16,11 @@ Do not expect a working Meshtastic device with this target.
|
||||
#define LED_POWER PA0 // Green LED
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define BATTERY_PIN AVBAT
|
||||
// ADC_MULTIPLIER: 3.0 = internal 1:3 bridge divider (DS13105§3.18.3)
|
||||
// Margin: 1.10 = AVBAT divider tolerance ±10% (Table 82)
|
||||
#define ADC_MULTIPLIER (1.01f * 3)
|
||||
|
||||
#define RAK3172
|
||||
#define SERIAL_PRINT_PORT 1
|
||||
|
||||
|
||||
@@ -13,6 +13,16 @@
|
||||
// #define EXT_CHRG_DETECT PA5
|
||||
// #define EXT_PWR_DETECT PA4
|
||||
|
||||
#define BATTERY_PIN AVBAT
|
||||
// ADC_MULTIPLIER: 3.0 = internal 1:3 bridge divider (DS13105§3.18.3)
|
||||
// Margin: 1.10 = AVBAT divider tolerance ±10% (Table 82)
|
||||
#define ADC_MULTIPLIER (1.01f * 3)
|
||||
/*
|
||||
Sample OCV curve for Li-SOCl2 primary lithium cells (e.g. Saft cells have fresh OCV of 3.67V)
|
||||
#define NUM_OCV_POINTS 11
|
||||
#define OCV_ARRAY 3670, 3650, 3630, 3610, 3590, 3560, 3530, 3480, 3400, 3200, 2500
|
||||
*/
|
||||
|
||||
// Bosch Sensortec BME280
|
||||
#define HAS_SENSOR 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user