mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
[G4][ADC] Batch call DeInit() for all used devices
HAL_ADC_DeInit() initializes ADCx_COMMON registers, so it shouldn’t be called once device configuration starts.
This commit is contained in:
parent
575460ac52
commit
62878bd2fa
1 changed files with 19 additions and 18 deletions
|
@ -205,11 +205,7 @@ void adcInitDevice(adcDevice_t *adcdev, int channelCount)
|
||||||
|
|
||||||
hadc->Instance = adcdev->ADCx;
|
hadc->Instance = adcdev->ADCx;
|
||||||
|
|
||||||
if (HAL_ADC_DeInit(hadc) != HAL_OK)
|
// DeInit is done in adcInit().
|
||||||
{
|
|
||||||
// ADC de-initialization Error
|
|
||||||
handleError();
|
|
||||||
}
|
|
||||||
|
|
||||||
hadc->Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
|
hadc->Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
|
||||||
hadc->Init.Resolution = ADC_RESOLUTION_12B;
|
hadc->Init.Resolution = ADC_RESOLUTION_12B;
|
||||||
|
@ -231,19 +227,6 @@ void adcInitDevice(adcDevice_t *adcdev, int channelCount)
|
||||||
handleError();
|
handleError();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the ADC multi-mode
|
|
||||||
ADC_MultiModeTypeDef multimode = { 0 };
|
|
||||||
multimode.Mode = ADC_MODE_INDEPENDENT;
|
|
||||||
if (HAL_ADCEx_MultiModeConfigChannel(hadc, &multimode) != HAL_OK) {
|
|
||||||
handleError();
|
|
||||||
}
|
|
||||||
|
|
||||||
ADC_AnalogWDGConfTypeDef AnalogWDGConfig = { 0 };
|
|
||||||
AnalogWDGConfig.Channel = ADC_CHANNEL_1;
|
|
||||||
if (HAL_ADC_AnalogWDGConfig(hadc, &AnalogWDGConfig) != HAL_OK) {
|
|
||||||
handleError();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_ADCEx_Calibration_Start(hadc, ADC_SINGLE_ENDED) != HAL_OK) {
|
if (HAL_ADCEx_Calibration_Start(hadc, ADC_SINGLE_ENDED) != HAL_OK) {
|
||||||
handleError();
|
handleError();
|
||||||
}
|
}
|
||||||
|
@ -358,6 +341,24 @@ void adcInit(const adcConfig_t *config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeInit ADCx with inputs
|
||||||
|
// We have to batch call DeInit() for all devices as DeInit() initializes ADCx_COMMON register.
|
||||||
|
|
||||||
|
for (int dev = 0; dev < ADCDEV_COUNT; dev++) {
|
||||||
|
adcDevice_t *adc = &adcDevice[dev];
|
||||||
|
|
||||||
|
if (!(adc->ADCx && adc->channelBits)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
adc->ADCHandle.Instance = adc->ADCx;
|
||||||
|
|
||||||
|
if (HAL_ADC_DeInit(&adc->ADCHandle) != HAL_OK) {
|
||||||
|
// ADC de-initialization Error
|
||||||
|
handleError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Configure ADCx with inputs
|
// Configure ADCx with inputs
|
||||||
|
|
||||||
int dmaBufferIndex = 0;
|
int dmaBufferIndex = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue