Skip to content

Commit 4d3a544

Browse files
committed
STM32L0 ADC internal channels update
1 parent 06bca28 commit 4d3a544

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

targets/TARGET_STM/TARGET_STM32L0/analogin_device.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@
3535
#include "pinmap.h"
3636
#include "mbed_error.h"
3737
#include "PeripheralPins.h"
38-
#include <stdbool.h>
3938

4039
void analogin_init(analogin_t *obj, PinName pin)
4140
{
42-
static bool adc_calibrated = false;
4341
uint32_t function = (uint32_t)NC;
4442

4543
// ADC Internal Channels "pins" (Temperature, Vref, Vbat, ...)
@@ -92,9 +90,7 @@ void analogin_init(analogin_t *obj, PinName pin)
9290
error("Cannot initialize ADC");
9391
}
9492

95-
// ADC calibration is done only once
96-
if (!adc_calibrated) {
97-
adc_calibrated = true;
93+
if (!HAL_ADCEx_Calibration_GetValue(&obj->handle, ADC_SINGLE_ENDED)) {
9894
HAL_ADCEx_Calibration_Start(&obj->handle, ADC_SINGLE_ENDED);
9995
}
10096

@@ -171,7 +167,9 @@ uint16_t adc_read(analogin_t *obj)
171167
return 0;
172168
}
173169

174-
ADC1->CHSELR = 0; // [TODO] Workaround. To be removed after Cube driver is corrected.
170+
/* Reset ADC channel selection register */
171+
ADC1->CHSELR = 0;
172+
175173
HAL_ADC_ConfigChannel(&obj->handle, &sConfig);
176174

177175
HAL_ADC_Start(&obj->handle); // Start conversion

targets/TARGET_STM/TARGET_STM32L0/device/stm32l0xx_hal_adc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
/* Includes ------------------------------------------------------------------*/
4545
#include "stm32l0xx_hal_def.h"
4646

47+
/* Include low level driver */
48+
#include "stm32l0xx_ll_adc.h"
49+
4750
/** @addtogroup STM32L0xx_HAL_Driver
4851
* @{
4952
*/

0 commit comments

Comments
 (0)