1 static int stm32_adc_init(void)
 2 {
 3     int result = RT_EOK;
 4     /* save adc name */
 5     char name_buf[5] = {'a', 'd', 'c', '0', 0};
 6     int i = 0;
 7 
 8     for (i = 0; i < sizeof(adc_config) / sizeof(adc_config[0]); i++)
 9     {
10         /* ADC init */
11         name_buf[3] = '0';
12         stm32_adc_obj[i].ADC_Handler = adc_config[i];
13 #if defined(ADC1)
14         if (stm32_adc_obj[i].ADC_Handler.Instance == ADC1)
15         {
16             name_buf[3] = '1';
17         }
18 #endif
19 #if defined(ADC2)
20         if (stm32_adc_obj[i].ADC_Handler.Instance == ADC2)
21         {
22             name_buf[3] = '2';
23         }
24 #endif
25 #if defined(ADC3)
26         if (stm32_adc_obj[i].ADC_Handler.Instance == ADC3)
27         {
28             name_buf[3] = '3';
29         }
30 #endif
31         if (HAL_ADC_Init(&stm32_adc_obj[i].ADC_Handler) != HAL_OK)
32         {
33             LOG_E("%s init failed", name_buf);
34             result = -RT_ERROR;
35         }
36         else
37         {
38             HAL_ADCEx_Calibration_Start(&stm32_adc_obj[i].ADC_Handler,ADC_SINGLE_ENDED);
39             /* register ADC device */
40             if (rt_hw_adc_register(&stm32_adc_obj[i].stm32_adc_device, name_buf, &stm_adc_ops, &stm32_adc_obj[i].ADC_Handler) == RT_EOK)
41             {
42                 LOG_D("%s init success", name_buf);
43             }
44             else
45             {
46                 LOG_E("%s register failed", name_buf);
47                 result = -RT_ERROR;
48             }
49         }
50     }
51 
52     return result;
53 }
54 INIT_BOARD_EXPORT(stm32_adc_init);

在drv_adc.c中增加红字即可将adc校准,增加采集精度