summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuuki NAGAO <wf.yn386@gmail.com>2023-07-08 11:04:20 +0900
committerDamien George <damien@micropython.org>2023-07-13 12:39:12 +1000
commitd9764ad1408f4cdf981a1e0f4db380a4cb4fe94c (patch)
treeea5ae4377f595dbac4ecf30191bbc90f95645577
parent0ba94a67ba72f2e04bfc26dcf0ed687addd0d740 (diff)
stm32/adc: Fix reading internal ADC channels on G4 MCUs.
For STM32G4 series, the internal sensors are connected to: - ADC1_IN16: Temperature sensor - ADC1_IN17: Battery voltage monitoring - ADC1_IN18: Internal voltage reference but ADC_CHANNEL_TEMPSENSOR_ADC1, ADC_CHANNEL_VBAT, ADC_CHANNEL_VREFINT are not defined as 16, 17, 18. This commit converts channel 16, 17, 18 to ADC_CHANNEL_x in adc_get_internal_channel(). Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
-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 fc0882286..93eaa93f0 100644
--- a/ports/stm32/adc.c
+++ b/ports/stm32/adc.c
@@ -220,6 +220,14 @@ static inline uint32_t adc_get_internal_channel(uint32_t channel) {
if (channel == 16) {
channel = ADC_CHANNEL_TEMPSENSOR;
}
+ #elif defined(STM32G4)
+ if (channel == 16) {
+ channel = ADC_CHANNEL_TEMPSENSOR_ADC1;
+ } else if (channel == 17) {
+ channel = ADC_CHANNEL_VBAT;
+ } else if (channel == 18) {
+ channel = ADC_CHANNEL_VREFINT;
+ }
#elif defined(STM32L4)
if (channel == 0) {
channel = ADC_CHANNEL_VREFINT;