|
22 | 22 | #include <zephyr/pm/device.h> |
23 | 23 | #include <zephyr/pm/policy.h> |
24 | 24 | #include <stm32_ll_adc.h> |
| 25 | +#include <stm32_ll_system.h> |
25 | 26 | #if defined(CONFIG_SOC_SERIES_STM32U5X) |
26 | 27 | #include <stm32_ll_pwr.h> |
27 | 28 | #endif /* CONFIG_SOC_SERIES_STM32U5X */ |
@@ -535,6 +536,24 @@ static void adc_stm32_calibration_start(const struct device *dev) |
535 | 536 | defined(CONFIG_SOC_SERIES_STM32WBAX) |
536 | 537 | LL_ADC_StartCalibration(adc); |
537 | 538 | #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 | + } |
538 | 557 | LL_ADC_StartCalibration(adc, LL_ADC_CALIB_OFFSET); |
539 | 558 | #elif defined(CONFIG_SOC_SERIES_STM32H7X) |
540 | 559 | LL_ADC_StartCalibration(adc, LL_ADC_CALIB_OFFSET, LL_ADC_SINGLE_ENDED); |
|
0 commit comments