ADC2 Calibration fails on 10% of chips in Dual Mode STM32H745
I have seen a few other posts about ADC2 calibration issues without resolution. I’m creating this new post to provide a resolution.
Using ADC1 and ADC2 in Dual mode on STM32H745 from CM4 running at 240 MHz. 10% of boards in production (20/200) were continuously watchdog resetting. This was traced to the ADC2 calibration getting stuck in a loop for 5 minutes (and hardware watchdog of 4s would trip). At 240 MHz, this timeout loop should only be 2.4s. (It would be better to use a timer function, but this is STM ADC HAL code)
/* Wait for calibration completion */
while (LL_ADC_IsCalibrationOnGoing(hadc->Instance) != 0UL)
{
wait_loop_index++;
if (wait_loop_index >= ADC_CALIBRATION_TIMEOUT)I’m not sure what is going on in the H7 silicon that makes the status register read so slow or why it isn’t changing in the expected 2.4s max, but STM provided a work-around. Change the order of initialization to remove the Dual Mode config from the .ioc - generated code in main and place it after that ADC calibration.
CM4 main.c
MX_ADC1_Init()
{
HAL_ADC_Init()
//HAL_ADCEx_MultiModeConfigChannel() // remove here ->
HAL_ADC_AnalogWDGConfig()
HAL_ADC_ConfigChannel()
}
MX_ADC2_Init()
{
HAL_ADC_Init()
HAL_ADC_ConfigChannel()
}
Then our app code starts
HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED)
HAL_ADCEx_Calibration_Start(&hadc2, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED); <- no longer getting stuck here
HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) // <- add here
HAL_ADC_Start(&hadc2)
HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)adcResultsDMA1, 256);
