-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cpu/stm32: add backup battery monitoring (VBAT) #16989
Conversation
This needs a rebase 😉 |
7acde56
to
4cc3502
Compare
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.
Sorry for losing track of this again!
Looks good in general, I like a dedicated, simple API for something simple as opposed to a big generic API that makes the simple things hard.
It would be a laudable task to unify the stm32 ADC implementations, maybe adc_ng will get us there.
A bit of bikeshedding ahead 😉
cpu/stm32/Makefile.features
Outdated
stm32wl% \ | ||
|
||
ifneq (,$(filter $(STM32_WITH_VBAT),$(CPU_MODEL))) | ||
FEATURES_PROVIDED += vbat |
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.
since you started that bikeshedding last time 😉
Why not periph_vbat
?
Battery monitoring seems to be more a peripheral thing than battery RAM.
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.
The name periph_vbat
is surely comprehensible. But I personally would not call it like that because probably no datasheet would list it as an extra peripheral because it is a feature of the ADC. I saw that there is cpu/efm32/drivers/coretemp/coretemp.c
which is also samples an ADC channel. So I decided to implement VBAT similar to this. So you think it should rather be periph_vbat
?
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.
Although that is efm32_coretemp
(and I think a generic version should be periph_coretemp
).
Generally I understand the periph_
prefix as something that needs a per-CPU implementation as opposed to a generic module. (I see that this makes the case for periph_backup_ram
…)
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.
Yes I think it should just be coretemp
😅. Because if my use case or application requires the core temperature, I´d rather do USEMODULE += coretemp
and not care if my CPU is efm32
. Or better, coretem
could pull in efm32_coretemp
for efm32
but that´s not the case right now.
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.
Ah yes or periph_coretemp
like you said.
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.
Anyway, I have no problem with periph_
, if you think it´s better.
cpu/stm32/drivers/vbat/vbat.c
Outdated
/* f0 */ | ||
#if defined(CPU_LINE_STM32F031x6) || defined(CPU_LINE_STM32F038xx) || \ | ||
defined(CPU_LINE_STM32F042x6) || defined(CPU_LINE_STM32F048xx) || \ | ||
defined(CPU_LINE_STM32F051x8) || defined(CPU_LINE_STM32F058xx) || \ | ||
defined(CPU_LINE_STM32F071xB) || defined(CPU_LINE_STM32F072xB) || \ | ||
defined(CPU_LINE_STM32F078xx) || defined(CPU_LINE_STM32F091xC) || \ | ||
defined(CPU_LINE_STM32F098xx) | ||
#define VBAT_ADC_SCALE 2 | ||
#define VBAT_ADC_MIN_MV 1650 | ||
#define ADC_CCR_REG (ADC->CCR) | ||
/* f2 */ | ||
#elif defined(CPU_LINE_STM32F205xx) || defined(CPU_LINE_STM32F207xx) || \ | ||
defined(CPU_LINE_STM32F215xx) || defined(CPU_LINE_STM32F217xx) | ||
#define VBAT_ADC_SCALE 2 | ||
#define VBAT_ADC_MIN_MV 1800 | ||
#define ADC_CCR_REG (ADC->CCR) | ||
/* f3 */ |
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.
I think this would better belong to cpu/stm32/include/periph/<line>/periph_cpu.h
but if you prefer it here I won't argue
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.
Since nothing else uses it, I´d keep it there.
4cc3502
to
51c8531
Compare
51c8531
to
952ebf0
Compare
952ebf0
to
15ba731
Compare
Murdock found some issues |
485f8ac
to
705cf84
Compare
When doing |
Not sure, maybe @leandrolanzieri has an idea. |
705cf84
to
8c08424
Compare
drivers/periph_common/Kconfig.vbat
Outdated
if KCONFIG_USEMODULE_PERIPH_VBAT | ||
|
||
config VBAT_ADC_VREF_MV | ||
int "ADC reference voltage in mV" | ||
default 3300 | ||
help | ||
This is the reference voltage (VREF) of the ADC. | ||
Often VREF is connected with VDDA, which is equal to VDD. | ||
|
||
endif # KCONFIG_USEMODULE_PERIPH_VBAT |
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.
The reason it does not show up when TEST_KCONFIG=1
is that, when that flag is active, Makefile dependency resolution does not run -> USEMODULE_PERIPH_VBAT
is not defined. Although it implies some duplication, I'd go with the option of defining it again, in the first menuconfig. It could look something like:
menuconfig MODULE_PERIPH_VBAT
bool "Backup Battery monitoring driver"
depends on HAS_PERIPH_VBAT
depends on HAS_PERIPH_ADC
depends on TEST_KCONFIG
select MODULE_PERIPH_ADC
if MODULE_PERIPH_VBAT
config MODULE_PERIPH_INIT_VBAT
bool "Auto initialize VBAT ADC line"
default y if MODULE_PERIPH_INIT
config VBAT_ADC_VREF_MV
int "ADC reference voltage in mV"
default 3300
endif # MODULE_PERIPH_VBAT
menuconfig KCONFIG_USEMODULE_PERIPH_VBAT
bool "Configure backup battery monitoring peripheral driver"
depends on USEMODULE_PERIPH_VBAT
help
Configure backup battery monitoring peripheral driver using Kconfig.
config VBAT_ADC_VREF_MV
int "ADC reference voltage in mV"
default 3300
depends on KCONFIG_USEMODULE_PERIPH_VBAT
help
This is the reference voltage (VREF) of the ADC.
Often VREF is connected with VDDA, which is equal to VDD.
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.
Thank you. I am going to squash that in right away.
8c08424
to
e3509fc
Compare
Thank you. |
Contribution description
This PR adds a driver to monitor the backup battery status for many
stm32
based boards withADC
.To check which boards support battery monitoring, I did:
grep -I -r '_VBAT' | cut -d' ' -f1 | sort | uniq
in cmsis-header-stm32.As a reference of how to calculate the voltage value from the ADC sample I found this.
Testing procedure
I tested
tests/driver_vbat
withnucleo-f767zi
.Issues/PRs references
This PR includes #16870 and was created to have battery monitoring independent.