1
1
/*
2
- * Copyright (c) 2006-2023 , RT-Thread Development Team
2
+ * Copyright (c) 2006-2025 , RT-Thread Development Team
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*
@@ -199,19 +199,19 @@ static rt_err_t stm32_adc_enabled(struct rt_adc_device *device, rt_int8_t channe
199
199
HAL_PWREx_EnableVddA ();
200
200
#endif /* defined(SOC_SERIES_STM32U5) */
201
201
202
- if (HAL_ADC_ConfigChannel (stm32_adc_handler , & ADC_ChanConf ) != HAL_OK )
203
- {
204
- LOG_E ("Failed to configure ADC channel %d" , channel );
205
- return - RT_ERROR ;
206
- }
202
+ if (HAL_ADC_ConfigChannel (stm32_adc_handler , & ADC_ChanConf ) != HAL_OK )
203
+ {
204
+ LOG_E ("Failed to configure ADC channel %d" , channel );
205
+ return - RT_ERROR ;
206
+ }
207
207
208
208
/* perform an automatic ADC calibration to improve the conversion accuracy */
209
209
#if defined(SOC_SERIES_STM32L4 ) || defined (SOC_SERIES_STM32WB )
210
- if (HAL_ADCEx_Calibration_Start (stm32_adc_handler , ADC_ChanConf .SingleDiff ) != HAL_OK )
211
- {
212
- LOG_E ("ADC calibration error!\n" );
213
- return - RT_ERROR ;
214
- }
210
+ if (HAL_ADCEx_Calibration_Start (stm32_adc_handler , ADC_ChanConf .SingleDiff ) != HAL_OK )
211
+ {
212
+ LOG_E ("ADC calibration error!\n" );
213
+ return - RT_ERROR ;
214
+ }
215
215
#elif defined(SOC_SERIES_STM32MP1 ) || defined(SOC_SERIES_STM32H7 ) || defined(SOC_SERIES_STM32U5 )
216
216
/* Run the ADC linear calibration in single-ended mode */
217
217
if (HAL_ADCEx_Calibration_Start (stm32_adc_handler , ADC_CALIB_OFFSET_LINEARITY , ADC_ChanConf .SingleDiff ) != HAL_OK )
@@ -225,10 +225,10 @@ static rt_err_t stm32_adc_enabled(struct rt_adc_device *device, rt_int8_t channe
225
225
else
226
226
{
227
227
if (HAL_ADC_Stop (stm32_adc_handler ) != HAL_OK )
228
- {
229
- LOG_E ("Stop ADC conversion failed!\n" );
230
- return - RT_ERROR ;
231
- }
228
+ {
229
+ LOG_E ("Stop ADC conversion failed!\n" );
230
+ return - RT_ERROR ;
231
+ }
232
232
}
233
233
234
234
return RT_EOK ;
@@ -277,19 +277,19 @@ static rt_err_t stm32_adc_get_value(struct rt_adc_device *device, rt_int8_t chan
277
277
RT_ASSERT (value != RT_NULL );
278
278
279
279
stm32_adc_handler = device -> parent .user_data ;
280
-
281
- if (HAL_ADC_Start (stm32_adc_handler ) != HAL_OK )
282
- {
283
- LOG_E ("Start ADC conversion error!\n" );
284
- return - RT_ERROR ;
285
- }
280
+
281
+ if (HAL_ADC_Start (stm32_adc_handler ) != HAL_OK )
282
+ {
283
+ LOG_E ("Start ADC conversion error!\n" );
284
+ return - RT_ERROR ;
285
+ }
286
286
287
287
/* Wait for the ADC to convert */
288
288
if (HAL_ADC_PollForConversion (stm32_adc_handler , 100 ) != RT_EOK )
289
- {
290
- LOG_E ("ADC conversion error!\n" );
291
- return - RT_ERROR ;
292
- }
289
+ {
290
+ LOG_E ("ADC conversion error!\n" );
291
+ return - RT_ERROR ;
292
+ }
293
293
294
294
/* get ADC value */
295
295
* value = (rt_uint32_t )HAL_ADC_GetValue (stm32_adc_handler );
@@ -306,15 +306,15 @@ static rt_int16_t stm32_adc_get_vref (struct rt_adc_device *device)
306
306
307
307
ADC_HandleTypeDef * stm32_adc_handler = device -> parent .user_data ;
308
308
309
- ret = stm32_adc_enabled (device , RT_ADC_INTERN_CH_VREF , RT_TRUE );
310
- if (ret != RT_EOK )
311
- return 0 ;
309
+ ret = stm32_adc_enabled (device , RT_ADC_INTERN_CH_VREF , RT_TRUE );
310
+ if (ret != RT_EOK )
311
+ return 0 ;
312
312
ret = stm32_adc_get_value (device , RT_ADC_INTERN_CH_VREF , & vref_value );
313
- if (ret != RT_EOK )
314
- return 0 ;
313
+ if (ret != RT_EOK )
314
+ return 0 ;
315
315
ret = stm32_adc_enabled (device , RT_ADC_INTERN_CH_VREF , RT_FALSE );
316
- if (ret != RT_EOK )
317
- return 0 ;
316
+ if (ret != RT_EOK )
317
+ return 0 ;
318
318
319
319
#ifdef SOC_SERIES_STM32U5
320
320
vref_mv = __LL_ADC_CALC_VREFANALOG_VOLTAGE (stm32_adc_handler -> Instance , vref_value , stm32_adc_handler -> Init .Resolution );
@@ -341,7 +341,7 @@ static int stm32_adc_init(void)
341
341
int result = RT_EOK ;
342
342
/* save adc name */
343
343
char name_buf [5 ] = {'a' , 'd' , 'c' , '0' , 0 };
344
- int i = 0 ;
344
+ rt_uint32_t i = 0 ;
345
345
346
346
for (i = 0 ; i < sizeof (adc_config ) / sizeof (adc_config [0 ]); i ++ )
347
347
{
0 commit comments