1 /* 2 * Copyright (c) 2021 STMicroelectronics 3 * SPDX-License-Identifier: Apache-2.0 4 */ 5 6 #include <zephyr/kernel.h> 7 #include <zephyr/init.h> 8 #include <stm32_ll_adc.h> 9 #include <zephyr/devicetree.h> 10 enable_adc_reference(void)11static int enable_adc_reference(void) 12 { 13 uint8_t init_status; 14 /* VREF+ is not connected to VDDA by default */ 15 /* Use 2.5V as reference (instead of 3.3V) for internal channels 16 * calculation 17 */ 18 __HAL_RCC_SYSCFG_CLK_ENABLE(); 19 20 /* VREF_OUT2 = 2.5 V */ 21 HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE1); 22 HAL_SYSCFG_VREFBUF_HighImpedanceConfig( 23 SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE); 24 25 init_status = HAL_SYSCFG_EnableVREFBUF(); 26 __ASSERT(init_status == HAL_OK, "ADC Conversion value may be incorrect"); 27 28 return init_status; 29 } 30 31 SYS_INIT(enable_adc_reference, POST_KERNEL, 0); 32