2023-09-21 01:46 PM - edited 2023-09-21 02:37 PM
Hello,
I am facing an issue when trying to calibrate the STM32U5.
I am using the API call `HAL_ADCEx_Calibration_Start()`, SDK Version: 1.3.0.
When I run the `HAL_ADCEx_Calibration_Start()` the board hangs and goes off into a limbo state. Even the debugger has a hard time reconnecting.
I've noticed the issue is directly related to the code snippet below in `HAL_ADCEx_Calibration_Start()`
# Original code at line 213 of `stm32u5xx_hal_adc_ex.c`
```
MODIFY_REG(hadc->Instance->CR, ADC_CR_CALINDEX, 0x9UL << ADC_CR_CALINDEX_Pos);
MODIFY_REG(hadc->Instance->CALFACT2, 0x00FF0000UL, 0x00020000UL);
SET_BIT(hadc->Instance->CALFACT, ADC_CALFACT_LATCH_COEF);
```
The code that works
```
MODIFY_REG(hadc->Instance->CR, ADC_CR_CALINDEX, 0x9UL << ADC_CR_CALINDEX_Pos);
HAL_Delay(1);
MODIFY_REG(hadc->Instance->CALFACT2, 0x00FF0000UL, 0x00020000UL);
HAL_Delay(1);
SET_BIT(hadc->Instance->CALFACT, ADC_CALFACT_LATCH_COEF);
HAL_Delay(1);
```
2023-09-21 02:19 PM - edited 2023-09-21 02:23 PM
2023-09-21 02:36 PM - edited 2023-09-22 02:30 PM
Everything in post 1 I am already doing:
```
static inline void enableVoltageScaling(void)
{
/*These have no effect if already enabled*/
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
HAL_PWREx_EnableVddA();
__HAL_RCC_LSI_ENABLE();
while (READ_BIT(RCC->BDCR, RCC_BDCR_LSIRDY) == 0){};
const HAL_StatusTypeDef rc = HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
assert(rc == HAL_OK);
}
void msp_clocksInit(void)
{
msp_updateSystemCoreClock();
HAL_Init();
enableVoltageScaling();
/* Require to active some clocks.
* Clocks running PORTG onwards require this.*/
HAL_PWREx_EnableVddIO2();
```
Post 2 is onto something however this has nothing with enabling and disable the ADC because if it did I could add a delay after line 209 when the ADC enables but before setting up the registers and it would work. But it doesn't.
The issue is I have delay between each one of the register setup that I illustrated above. Otherwise the board hangs and causes issues.
Please let me know the correct procedure for enabled extended calibration the reference manual is not clear as to all the prerequisites needed. Additionally the SDK code appears to be doing a few things differently than what is described in the reference manual.
2023-09-22 06:59 PM - edited 2023-09-22 07:00 PM