Skip to main content
d.zipperle.5512730769682947E12
Associate II
Dec 18, 2025 10:44 AM UTC
Question

ADC calibration when using DualMode on a STM32H743

Post edited by ST moderator to be inline with the community rules for the code sharing. In next time please use </> button to paste your code and a linker script content. Please read this post: How to insert source code.

Hello,

I ran into a very strange problem with a STM32H743 that I don't understand.

I have the following config sequence:

  1. MX_ADC1_Init() -> generated by CubeMX
  2. MX_ADC2_Int() -> generated by CubeMX
  3. HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED)
  4. HAL_ADCEx_Calibration_Start(&hadc2, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED)

The MX_ADC1_Init() contains the following generated code:

 multimode.Mode = ADC_DUALMODE_REGSIMULT;
 multimode.DualModeData = ADC_DUALMODEDATAFORMAT_DISABLED;
 multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE;
 if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
 {
 Error_Handler();
 }

This worked without a problem on all my boards so far and I was able to start a DMA conversion. However, I just got a new hardware batch (exactly the same PCB design as the previous ones) and here the HAL_ADCEx_Calibration_Start for the ADC2 (ADC1 works fine) always gets stuck for multiple seconds, until it timeouts and fails...

By playing around with the initialization sequence, I was able to find out that apparantely I have to call HAL_ADCEx_Calibration_Start for both ADCs before configuring the MultiMode.

Is wasn't able to find anything on this in the ApplicationNotes. Is there some explanation for my observation? What is the reason for the ADC2 calibration to get stuck, even though the ADC was not started before?

Is this a bug in the CubeMX generated code (that the MultiMode is configured too early)?

 

4 replies

ST Employee
Dec 24, 2025 11:23 AM UTC

Dear @d.zipperle.5512730769682947E12 

The STM32H7 ADCs share some internal resources when operating in dual mode.
Calibration is a hardware process that adjusts internal offsets and linearity for each ADC. When Multi-Mode is configured, ADC1 and ADC2 become interdependent for conversion synchronization and data sharing.
Configuring Multi-Mode before calibration can cause ADC2 calibration to stall because ADC2 is effectively "linked" to ADC1 and cannot complete its standalone calibration properly.

The HAL driver function HAL_ADCEx_Calibration_Start() expects the ADC to be in a reset or independent state.
If Multi-Mode is already configured, ADC2 is no longer independent; it waits for triggers and synchronization from ADC1.
This causes the calibration routine on ADC2 to wait indefinitely (or eventually timeout) because the calibration sequence requires ADC2 to be free from multi-Mode synchronization constraints.

BR

Lobna

 

d.zipperle.5512730769682947E12
Associate II
Dec 24, 2025 11:52 AM UTC

@lobna thank you for your detailed response!

This makes absolutely sense to me and means after changing the init sequence to perform the calibration before configuration of the MultiMode, the code should be correct.

However, I don't understand how I haven't run into this issue earlier. The previous sequence worked without problems on the same hardware. After doing more testing, I found that this issue only appears on ~25% of my boards (and is always resolved after changing the init sequence).

And also this means that the CubeMX generated initialization code is faulty, because when enabling the MultiMode config in CubeMX, the generated code will always apply the MultiMode config in MX_ADC1_Init() before any calibration was applied by the user code. 

ST Employee
Dec 24, 2025 2:39 PM UTC

Dear @d.zipperle.5512730769682947E12 

Regarding your first question: Variations in silicon quality, temperature, supply voltage, and PCB layout tolerances can influence the timing and behavior of ADC calibration. Moreover, differences in power-up sequences or electrical noise may affect the ADC’s internal state, which can increase the chances of calibration stalls.

As for CubeMX, the generated initialization code may not fully adhere to the recommended best practices for dual ADC calibration. I will escalate this internally for further evaluation.

BR

Lobna

Visitor II
Nov 2, 2026 4:11 PM UTC

Update: This might be a workaround

 

Dear ST,

Is there an update on this? The CubeIDE auto-generated code makes it impossible to calibrate ADC2 in dual simultaneous mode.

Calibration using HAL functions cannot start earlier than ADC initialization, because hadc2 structures aren’t populated yet. But calibration after the initialization cannot happen, because -as mentioned above-, as soon as ADC1 is configured in dual simultaneous mode, ADC2 will depend on it and will not react to individual triggers.

Without any knowledge of STM32CubeIDE internals, I think all that would be needed is the change in the order of ADC initialization (so that ADC2 comes first, then a /*USER CODE */ section, allowing for calibration, then ADC1 in dual mode), or perhaps some checkbox under the ADC config tab, for including calibration call in the init code.

Below is an excerpt of the STM32CubeIDE the auto-generated code, showing no option to make ADC2 calibration work:

 

main() {

(...) /* Excerpt from main function */

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_ADC1_Init();
MX_ADC2_Init();
/* USER CODE BEGIN 2 */

(...)
}


/**
* @brief ADC1 Initialization Function
* @param None
* @retval None
*/
static void MX_ADC1_Init(void)
{

/* USER CODE BEGIN ADC1_Init 0 */

/* USER CODE END ADC1_Init 0 */

ADC_MultiModeTypeDef multimode = {0};
ADC_ChannelConfTypeDef sConfig = {0};

/* USER CODE BEGIN ADC1_Init 1 */

/* USER CODE END ADC1_Init 1 */

/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_16B;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc1.Init.OversamplingMode = DISABLE;
hadc1.Init.Oversampling.Ratio = 1;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}

/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_DUALMODE_REGSIMULT;
multimode.DualModeData = ADC_DUALMODEDATAFORMAT_DISABLED;
multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
Error_Handler();
}

/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_17;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_16CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
sConfig.OffsetSignedSaturation = DISABLE;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */

/* USER CODE END ADC1_Init 2 */

}

/**
* @brief ADC2 Initialization Function
* @param None
* @retval None
*/
static void MX_ADC2_Init(void)
{

/* USER CODE BEGIN ADC2_Init 0 */

/* USER CODE END ADC2_Init 0 */

ADC_ChannelConfTypeDef sConfig = {0};

/* USER CODE BEGIN ADC2_Init 1 */

/* USER CODE END ADC2_Init 1 */

/** Common config
*/
hadc2.Instance = ADC2;
hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
hadc2.Init.Resolution = ADC_RESOLUTION_16B;
hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc2.Init.LowPowerAutoWait = DISABLE;
hadc2.Init.ContinuousConvMode = DISABLE;
hadc2.Init.NbrOfConversion = 1;
hadc2.Init.DiscontinuousConvMode = DISABLE;
hadc2.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
hadc2.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc2.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc2.Init.OversamplingMode = DISABLE;
hadc2.Init.Oversampling.Ratio = 1;
if (HAL_ADC_Init(&hadc2) != HAL_OK)
{
Error_Handler();
}

/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_15;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_16CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
sConfig.OffsetSignedSaturation = DISABLE;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC2_Init 2 */

/* USER CODE END ADC2_Init 2 */

}

 

Thanks!!