cancel
Showing results for 
Search instead for 
Did you mean: 

ADC - Load linearity calibration codes from Flash

hendrik8903
Associate

Hi everybody,

i am currently working with the STM32H755ZI (Revision V) on a NUCLEO-144 Board and I need to use all three ADCs. To use these ADCs I need to calibrate them according to the reference manuals and the application notes. Calibrating the offset error with or also without the HAL-Library is pretty straight forward. To calibrate the linearity error the application note AN5354 (https://www.st.com/resource/en/application_note/an5354-getting-started-with-the-stm32h7-series-mcu-16bit-adc-stmicroelectronics.pdf) states that the ADCs are calibrated when fabricated and the calibration values are stored into flash. I could not find any information about the location in flash (like an address) where these calibration values are stored. Could you help me here how to locate these values and also how to load them into the ADC-Registers to use the calibration values?
If you got any further tips about calibrating the ADCs please write them below this post. 

Here is my init function of the first ADC:

 

 

 

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_DIV1;
  hadc1.Init.Resolution = ADC_RESOLUTION_10B;
  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc1.Init.LowPowerAutoWait = DISABLE;
  hadc1.Init.ContinuousConvMode = ENABLE;
  hadc1.Init.NbrOfConversion = 2;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;
  hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
  hadc1.Init.OversamplingMode = DISABLE;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }

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

  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_5;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_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();
  }

  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_15;
  sConfig.Rank = ADC_REGULAR_RANK_2;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC1_Init 2 */
  //ADC_ConfigureBoostMode(&hadc1);

  if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK) {
	  Error_Handler();
  }
  /* USER CODE END ADC1_Init 2 */

}

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

To calibrate linearity factors, pass ADC_CALIB_OFFSET_LINEARITY (instead of ADC_CALIB_OFFSET) to the HAL_ADCEx_Calibration_Start function.

To read the factors, see the reference manual. The process is involved. Partial excerpt here:

TDK_0-1722290426053.png

 

The RM does not mention storing these values to flash during manufacturing and suggests they can only be read after a calibration is done. I'd trust the RM over the AN, but I could be missing something.

 

For general ADC usage, nothing more is required beyond the calibration step above.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

To calibrate linearity factors, pass ADC_CALIB_OFFSET_LINEARITY (instead of ADC_CALIB_OFFSET) to the HAL_ADCEx_Calibration_Start function.

To read the factors, see the reference manual. The process is involved. Partial excerpt here:

TDK_0-1722290426053.png

 

The RM does not mention storing these values to flash during manufacturing and suggests they can only be read after a calibration is done. I'd trust the RM over the AN, but I could be missing something.

 

For general ADC usage, nothing more is required beyond the calibration step above.

If you feel a post has answered your question, please click "Accept as Solution".

Hi,

 

i have also found that section in the reference manual. When I call HAL_ADCEx_Calibration_Start with the parameter ADC_CALIB_OFFSET_LINEARITY do I need to match any specific conditions? The application note recommends a clock frequency of 10 MHz and a V_ref <= 2V but the reference manual does not give any recommendations. 

When I call the HAL_ADCEx_Calibration_Start function will the values for the offset and linearity correction be used automatically by the ADC or do I have to load it separately?

No specific conditions are needed.

After calibration, the calibration values will be used automatically.

If you feel a post has answered your question, please click "Accept as Solution".