Skip to content

Commit f96f9c2

Browse files
committed
[STM32F3xx] bug fix multiple ADC channels using multiple ADC blocks
When two or more analogue inputs are initialized on more than one ADC HW block the initialisation fails with: Cannot initialize ADC The reason is the reusage of just one ADC_HandleTypeDef for all initializations (in mbed\targets\hal\TARGET_STM\TARGET_STM32F3\analogin_api.c). After the first (successful) ADC initialisation AdcHandle.State is set to HAL_ADC_STATE_READY). But for another ADC block initialisation the AdcHandle.State has to be reset so that the HAL initialize it (in mbed\targets\cmsis\TARGET_STM\TARGET_STM32F3\stm32f3xx_hal_adc_ex.c line 424). When this state is not reset the HAL returns with an initialization error. And this error induces the above mbed error message. The error message can be reproduced just with AnalogIn in1(xx); AnalogIn in2(yy); where xx and yy belongs to two different ADC blocks.
1 parent 3209e18 commit f96f9c2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F3/analogin_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,31 @@ void analogin_init(analogin_t *obj, PinName pin)
7373
#if defined(ADC1)
7474
if ((obj->adc == ADC_1) && adc1_inited) return;
7575
if (obj->adc == ADC_1) {
76+
AdcHandle.State = HAL_ADC_STATE_RESET;
7677
__ADC1_CLK_ENABLE();
7778
adc1_inited = 1;
7879
}
7980
#endif
8081
#if defined(ADC2)
8182
if ((obj->adc == ADC_2) && adc2_inited) return;
8283
if (obj->adc == ADC_2) {
84+
AdcHandle.State = HAL_ADC_STATE_RESET;
8385
__ADC2_CLK_ENABLE();
8486
adc2_inited = 1;
8587
}
8688
#endif
8789
#if defined(ADC3)
8890
if ((obj->adc == ADC_3) && adc3_inited) return;
8991
if (obj->adc == ADC_3) {
92+
AdcHandle.State = HAL_ADC_STATE_RESET;
9093
__ADC34_CLK_ENABLE();
9194
adc3_inited = 1;
9295
}
9396
#endif
9497
#if defined(ADC4)
9598
if ((obj->adc == ADC_4) && adc4_inited) return;
9699
if (obj->adc == ADC_4) {
100+
AdcHandle.State = HAL_ADC_STATE_RESET;
97101
__ADC34_CLK_ENABLE();
98102
adc4_inited = 1;
99103
}

0 commit comments

Comments
 (0)