mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #809 from bcostm/master
NUCLEO_F334R8 - Fix issue with multiple ADC initializationpull/837/head
commit
2acefb66eb
|
@ -37,10 +37,11 @@
|
|||
|
||||
ADC_HandleTypeDef AdcHandle;
|
||||
|
||||
int adc_inited = 0;
|
||||
|
||||
void analogin_init(analogin_t *obj, PinName pin)
|
||||
{
|
||||
static int adc1_inited = 0;
|
||||
static int adc2_inited = 0;
|
||||
|
||||
// Get the peripheral name from the pin and assign it to the object
|
||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||
MBED_ASSERT(obj->adc != (ADCName)NC);
|
||||
|
@ -51,30 +52,30 @@ void analogin_init(analogin_t *obj, PinName pin)
|
|||
// Save pin number for the read function
|
||||
obj->pin = pin;
|
||||
|
||||
// The ADC initialization is done once
|
||||
if (adc_inited == 0) {
|
||||
adc_inited = 1;
|
||||
// Check if ADC is already initialized
|
||||
if ((obj->adc == ADC_1) && adc1_inited) return;
|
||||
if ((obj->adc == ADC_2) && adc2_inited) return;
|
||||
if (obj->adc == ADC_1) adc1_inited = 1;
|
||||
if (obj->adc == ADC_2) adc2_inited = 1;
|
||||
|
||||
// Enable ADC clock
|
||||
if (obj->adc == ADC_1) __ADC1_CLK_ENABLE();
|
||||
if (obj->adc == ADC_2) __ADC2_CLK_ENABLE();
|
||||
// Enable ADC clock
|
||||
__ADC12_CLK_ENABLE();
|
||||
|
||||
// Configure ADC
|
||||
AdcHandle.Instance = (ADC_TypeDef *)(obj->adc);
|
||||
AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
|
||||
AdcHandle.Init.Resolution = ADC_RESOLUTION12b;
|
||||
AdcHandle.Init.ScanConvMode = DISABLE;
|
||||
AdcHandle.Init.ContinuousConvMode = DISABLE;
|
||||
AdcHandle.Init.DiscontinuousConvMode = DISABLE;
|
||||
AdcHandle.Init.NbrOfDiscConversion = 0;
|
||||
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
|
||||
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
AdcHandle.Init.NbrOfConversion = 1;
|
||||
AdcHandle.Init.DMAContinuousRequests = DISABLE;
|
||||
AdcHandle.Init.EOCSelection = DISABLE;
|
||||
HAL_ADC_Init(&AdcHandle);
|
||||
}
|
||||
// Configure ADC
|
||||
AdcHandle.Instance = (ADC_TypeDef *)(obj->adc);
|
||||
AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
|
||||
AdcHandle.Init.Resolution = ADC_RESOLUTION12b;
|
||||
AdcHandle.Init.ScanConvMode = DISABLE;
|
||||
AdcHandle.Init.ContinuousConvMode = DISABLE;
|
||||
AdcHandle.Init.DiscontinuousConvMode = DISABLE;
|
||||
AdcHandle.Init.NbrOfDiscConversion = 0;
|
||||
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
|
||||
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
AdcHandle.Init.NbrOfConversion = 1;
|
||||
AdcHandle.Init.DMAContinuousRequests = DISABLE;
|
||||
AdcHandle.Init.EOCSelection = DISABLE;
|
||||
HAL_ADC_Init(&AdcHandle);
|
||||
}
|
||||
|
||||
static inline uint16_t adc_read(analogin_t *obj)
|
||||
|
|
Loading…
Reference in New Issue