STM32CubeF0 icon indicating copy to clipboard operation
STM32CubeF0 copied to clipboard

Race condition in HAL_ADCEx_Calibration_Start()

Open pmacfarlane opened this issue 4 years ago • 2 comments

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.

pmacfarlane avatar Jan 21 '21 16:01 pmacfarlane

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

PLFSTM avatar Jan 29 '21 07:01 PLFSTM

ST Internal Reference: 100410

ALABSTM avatar Jan 29 '21 10:01 ALABSTM