@@ -421,13 +421,25 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
421421 }
422422#endif
423423
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+
424432 /* Enable GPIO clock ****************************************/
425433 port = set_GPIO_Port_Clock (STM_PORT (g_current_pin ));
426434
427435 /*##-2- Configure peripheral GPIO ##########################################*/
428436 /* ADC Channel GPIO pin configuration */
429437 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
430441 GPIO_InitStruct .Mode = GPIO_MODE_ANALOG ;
442+ #endif
431443 GPIO_InitStruct .Pull = GPIO_NOPULL ;
432444 HAL_GPIO_Init (port , & GPIO_InitStruct );
433445}
@@ -573,7 +585,11 @@ uint16_t adc_read_value(PinName pin)
573585 }
574586
575587 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
576591 if (!IS_ADC_CHANNEL (AdcChannelConf .Channel )) return 0 ;
592+ #endif
577593 AdcChannelConf .Rank = ADC_REGULAR_RANK_1 ; /* Specifies the rank in the regular group sequencer */
578594#ifndef STM32L0xx
579595 AdcChannelConf .SamplingTime = SAMPLINGTIME ; /* Sampling time value to be set for the selected channel */
@@ -585,7 +601,7 @@ uint16_t adc_read_value(PinName pin)
585601 return 0 ;
586602 }
587603
588- #ifdef STM32F3xx
604+ #if defined ( STM32F3xx ) || defined ( STM32L4xx )
589605 /*##-2.1- Calibrate ADC then Start the conversion process ####################*/
590606 if (HAL_ADCEx_Calibration_Start (& AdcHandle , ADC_SINGLE_ENDED ) != HAL_OK )
591607 {
0 commit comments