STM32CubeF0
STM32CubeF0 copied to clipboard
Race condition in HAL_ADCEx_Calibration_Start()
This problem was seen on an STM32F030 but I imagine would be seen on any similar MCU using the HAL.
Sometimes, calls to HAL_ADCEx_Calibration_Start() will fail. This is especially true if you set the tick frequency to 100Hz or less.
The issue is here:
` tickstart = HAL_GetTick();
/* Wait for calibration completion */
while(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADCAL))
{
if((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT)`
If we get a tick interrupt immediately after the first call to HAL_GetTick(), this adds 10 to the tick value (assuming a 100Hz tick).
We then immediately timeout and return a failure.
This problem may (or may not) also exist in the HAL libraries for other MCUs.
Hi @pmacfarlane
A similar issue on HAL ADC has been identified on another STM32 series: small internal timeout checks are vulnerable to race condition and a correction is under study.
Regards
ST Internal Reference: 100410