Skip to content

Commit 2154ee2

Browse files
yn386dpgeorge
authored andcommitted
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().
1 parent a74e4fa commit 2154ee2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ports/stm32/adc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ static inline uint32_t adc_get_internal_channel(uint32_t channel) {
216216
if (channel == 16) {
217217
channel = ADC_CHANNEL_TEMPSENSOR;
218218
}
219+
#elif defined(STM32L4)
220+
if (channel == 0) {
221+
channel = ADC_CHANNEL_VREFINT;
222+
} else if (channel == 17) {
223+
channel = ADC_CHANNEL_TEMPSENSOR;
224+
} else if (channel == 18) {
225+
channel = ADC_CHANNEL_VBAT;
226+
}
219227
#endif
220228
return channel;
221229
}

0 commit comments

Comments
 (0)