summaryrefslogtreecommitdiff
path: root/ports/stm32/adc.c
diff options
context:
space:
mode:
authoryn386 <wf.yn386@gmail.com>2022-10-22 16:56:56 +0900
committerDamien George <damien@micropython.org>2022-11-18 14:38:58 +1100
commit2154ee21635c85baf07e50ca1bfaf8c89cae192a (patch)
tree436236c86a29ab8dfc0eef96d17f0bf1c15d09e9 /ports/stm32/adc.c
parenta74e4fabeb0d7bc4dc68284047248fa173f5237b (diff)
stm32/adc: Fix reading internal ADC channels on L4 MCUs.
For STM32L4 series, the internal sensors are connected to: - ADC1_IN0: Internal voltage reference - ADC1_IN17: Temperature sensor - ADC1_IN18: VBAT battery voltage monitoring but ADC_CHANNEL_VREFINT, ADC_CHANNEL_VBAT, ADC_CHANNEL_TEMPSENSOR are not defined as 0, 17, 18. This commit converts channel 0, 17, 18 to ADC_CHANNEL_x in adc_get_internal_channel().
Diffstat (limited to 'ports/stm32/adc.c')
-rw-r--r--ports/stm32/adc.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c
index 02bbbb58d..5aa7ce426 100644
--- a/ports/stm32/adc.c
+++ b/ports/stm32/adc.c
@@ -216,6 +216,14 @@ static inline uint32_t adc_get_internal_channel(uint32_t channel) {
if (channel == 16) {
channel = ADC_CHANNEL_TEMPSENSOR;
}
+ #elif defined(STM32L4)
+ if (channel == 0) {
+ channel = ADC_CHANNEL_VREFINT;
+ } else if (channel == 17) {
+ channel = ADC_CHANNEL_TEMPSENSOR;
+ } else if (channel == 18) {
+ channel = ADC_CHANNEL_VBAT;
+ }
#endif
return channel;
}