Skip to content

Commit 62dcc8c

Browse files
committed
[ADC] Manage channel bank
For STM32L1xx, in Cat.3, Cat.4, Cat.5 and Cat.6 devices there are up to 42 multiplexed channels organized in 2 banks. Channels ADC_IN0 to ADC_IN31 are available in Bank A and channels ADC_IN0b to ADC_IN31b are available in Bank B. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent ddd8c38 commit 62dcc8c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

libraries/SrcWrapper/src/stm32/analog.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static PinName g_current_pin = NC;
9090
#endif
9191

9292
/* Private Functions */
93-
static uint32_t get_adc_channel(PinName pin)
93+
static uint32_t get_adc_channel(PinName pin, uint32_t *bank)
9494
{
9595
uint32_t function = pinmap_function(pin, PinMap_ADC);
9696
uint32_t channel = 0;
@@ -207,6 +207,15 @@ static uint32_t get_adc_channel(PinName pin)
207207
channel = 0;
208208
break;
209209
}
210+
#ifdef ADC_CHANNELS_BANK_B
211+
if (STM_PIN_ANALOG_CHANNEL_BANK_B(function)) {
212+
*bank = ADC_CHANNELS_BANK_B;
213+
} else {
214+
*bank = ADC_CHANNELS_BANK_A;
215+
}
216+
#else
217+
UNUSED(bank);
218+
#endif
210219
return channel;
211220
}
212221

@@ -746,6 +755,7 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
746755
__IO uint16_t uhADCxConvertedValue = 0;
747756
uint32_t samplingTime = ADC_SAMPLINGTIME;
748757
uint32_t channel = 0;
758+
uint32_t bank = 0;
749759

750760
if ((pin & PADC_BASE) && (pin < ANA_START)) {
751761
#if defined(STM32H7xx)
@@ -762,7 +772,7 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
762772
samplingTime = ADC_SAMPLINGTIME_INTERNAL;
763773
} else {
764774
AdcHandle.Instance = (ADC_TypeDef *)pinmap_peripheral(pin, PinMap_ADC);
765-
channel = get_adc_channel(pin);
775+
channel = get_adc_channel(pin, &bank);
766776
}
767777

768778
if (AdcHandle.Instance == NP) {
@@ -824,7 +834,9 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
824834
!defined(STM32MP1xx) && !defined(STM32WBxx)
825835
AdcHandle.Init.LowPowerAutoPowerOff = DISABLE; /* ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered */
826836
#endif
827-
#ifdef ADC_CHANNELS_BANK_A
837+
#ifdef ADC_CHANNELS_BANK_B
838+
AdcHandle.Init.ChannelsBank = bank;
839+
#elif defined(ADC_CHANNELS_BANK_A)
828840
AdcHandle.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
829841
#endif
830842
AdcHandle.Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */

0 commit comments

Comments
 (0)