@@ -421,13 +421,25 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
421
421
}
422
422
#endif
423
423
424
+ #ifdef __HAL_RCC_ADC_CLK_ENABLE
425
+ __HAL_RCC_ADC_CLK_ENABLE ();
426
+ #endif
427
+ #ifdef __HAL_RCC_ADC_CONFIG
428
+ /* ADC Periph interface clock configuration */
429
+ __HAL_RCC_ADC_CONFIG (RCC_ADCCLKSOURCE_SYSCLK );
430
+ #endif
431
+
424
432
/* Enable GPIO clock ****************************************/
425
433
port = set_GPIO_Port_Clock (STM_PORT (g_current_pin ));
426
434
427
435
/*##-2- Configure peripheral GPIO ##########################################*/
428
436
/* ADC Channel GPIO pin configuration */
429
437
GPIO_InitStruct .Pin = STM_GPIO_PIN (g_current_pin );
438
+ #ifdef GPIO_MODE_ANALOG_ADC_CONTROL
439
+ GPIO_InitStruct .Mode = GPIO_MODE_ANALOG_ADC_CONTROL ;
440
+ #else
430
441
GPIO_InitStruct .Mode = GPIO_MODE_ANALOG ;
442
+ #endif
431
443
GPIO_InitStruct .Pull = GPIO_NOPULL ;
432
444
HAL_GPIO_Init (port , & GPIO_InitStruct );
433
445
}
@@ -573,7 +585,11 @@ uint16_t adc_read_value(PinName pin)
573
585
}
574
586
575
587
AdcChannelConf .Channel = get_adc_channel (pin ); /* Specifies the channel to configure into ADC */
588
+ #ifdef STM32L4xx
589
+ if (!IS_ADC_CHANNEL (& AdcHandle , AdcChannelConf .Channel )) return 0 ;
590
+ #else
576
591
if (!IS_ADC_CHANNEL (AdcChannelConf .Channel )) return 0 ;
592
+ #endif
577
593
AdcChannelConf .Rank = ADC_REGULAR_RANK_1 ; /* Specifies the rank in the regular group sequencer */
578
594
#ifndef STM32L0xx
579
595
AdcChannelConf .SamplingTime = SAMPLINGTIME ; /* Sampling time value to be set for the selected channel */
@@ -585,7 +601,7 @@ uint16_t adc_read_value(PinName pin)
585
601
return 0 ;
586
602
}
587
603
588
- #ifdef STM32F3xx
604
+ #if defined ( STM32F3xx ) || defined ( STM32L4xx )
589
605
/*##-2.1- Calibrate ADC then Start the conversion process ####################*/
590
606
if (HAL_ADCEx_Calibration_Start (& AdcHandle , ADC_SINGLE_ENDED ) != HAL_OK )
591
607
{
0 commit comments