Skip to content

Commit c93d6b8

Browse files
gautierg-stnashif
authored andcommitted
drivers: adc: stm32: apply extended calibration on u5
Some STM32U5 can apply an extended calibration to enhance the ADC performance. Signed-off-by: Guillaume Gautier <[email protected]>
1 parent aa670f7 commit c93d6b8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

drivers/adc/adc_stm32.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <zephyr/pm/device.h>
2323
#include <zephyr/pm/policy.h>
2424
#include <stm32_ll_adc.h>
25+
#include <stm32_ll_system.h>
2526
#if defined(CONFIG_SOC_SERIES_STM32U5X)
2627
#include <stm32_ll_pwr.h>
2728
#endif /* CONFIG_SOC_SERIES_STM32U5X */
@@ -535,6 +536,24 @@ static void adc_stm32_calibration_start(const struct device *dev)
535536
defined(CONFIG_SOC_SERIES_STM32WBAX)
536537
LL_ADC_StartCalibration(adc);
537538
#elif defined(CONFIG_SOC_SERIES_STM32U5X)
539+
if (adc != ADC4) {
540+
uint32_t dev_id = LL_DBGMCU_GetDeviceID();
541+
uint32_t rev_id = LL_DBGMCU_GetRevisionID();
542+
543+
/* Some U5 implement an extended calibration to enhance ADC performance.
544+
* It is not available for ADC4.
545+
* It is available on all U5 except U575/585 (dev ID 482) revision X (rev ID 2001).
546+
* The code below applies the procedure described in RM0456 in the ADC chapter:
547+
* "Extended calibration mode"
548+
*/
549+
if ((dev_id != 0x482UL) && (rev_id != 0x2001UL)) {
550+
adc_stm32_enable(adc);
551+
MODIFY_REG(adc->CR, ADC_CR_CALINDEX, 0x9UL << ADC_CR_CALINDEX_Pos);
552+
MODIFY_REG(adc->CALFACT2, 0xFFFFFF00UL, 0x03021100UL);
553+
SET_BIT(adc->CALFACT, ADC_CALFACT_LATCH_COEF);
554+
adc_stm32_disable(adc);
555+
}
556+
}
538557
LL_ADC_StartCalibration(adc, LL_ADC_CALIB_OFFSET);
539558
#elif defined(CONFIG_SOC_SERIES_STM32H7X)
540559
LL_ADC_StartCalibration(adc, LL_ADC_CALIB_OFFSET, LL_ADC_SINGLE_ENDED);

0 commit comments

Comments
 (0)