11/*
2- * Copyright (c) 2006-2023 , RT-Thread Development Team
2+ * Copyright (c) 2006-2025 , RT-Thread Development Team
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 *
@@ -199,19 +199,19 @@ static rt_err_t stm32_adc_enabled(struct rt_adc_device *device, rt_int8_t channe
199199 HAL_PWREx_EnableVddA ();
200200#endif /* defined(SOC_SERIES_STM32U5) */
201201
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+ }
207207
208208 /* perform an automatic ADC calibration to improve the conversion accuracy */
209209#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+ }
215215#elif defined(SOC_SERIES_STM32MP1 ) || defined(SOC_SERIES_STM32H7 ) || defined(SOC_SERIES_STM32U5 )
216216 /* Run the ADC linear calibration in single-ended mode */
217217 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
225225 else
226226 {
227227 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+ }
232232 }
233233
234234 return RT_EOK ;
@@ -277,19 +277,19 @@ static rt_err_t stm32_adc_get_value(struct rt_adc_device *device, rt_int8_t chan
277277 RT_ASSERT (value != RT_NULL );
278278
279279 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+ }
286286
287287 /* Wait for the ADC to convert */
288288 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+ }
293293
294294 /* get ADC value */
295295 * 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)
306306
307307 ADC_HandleTypeDef * stm32_adc_handler = device -> parent .user_data ;
308308
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 ;
312312 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 ;
315315 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 ;
318318
319319#ifdef SOC_SERIES_STM32U5
320320 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)
341341 int result = RT_EOK ;
342342 /* save adc name */
343343 char name_buf [5 ] = {'a' , 'd' , 'c' , '0' , 0 };
344- int i = 0 ;
344+ rt_uint32_t i = 0 ;
345345
346346 for (i = 0 ; i < sizeof (adc_config ) / sizeof (adc_config [0 ]); i ++ )
347347 {
0 commit comments