drivers: adc: stm32: Fix race condition with internal channels
When using one of the internal channels (die_temp, vbat, vref) the channels are enabled in the individual drivers and disabled again whenever an adc conversion is complete. This creates a race condition if the ADC is used from multiple threads. This commit moves the disabling of the channels to the individual drivers. Signed-off-by: Brian Juel Folkmann <bju@trackunit.com>
This commit is contained in:
parent
768ed26010
commit
06b57926a2
4 changed files with 24 additions and 7 deletions
|
@ -38,6 +38,7 @@ static int stm32_vbat_sample_fetch(const struct device *dev, enum sensor_channel
|
|||
struct stm32_vbat_data *data = dev->data;
|
||||
struct adc_sequence *sp = &data->adc_seq;
|
||||
int rc;
|
||||
uint32_t path;
|
||||
|
||||
if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_VOLTAGE) {
|
||||
return -ENOTSUP;
|
||||
|
@ -52,14 +53,19 @@ static int stm32_vbat_sample_fetch(const struct device *dev, enum sensor_channel
|
|||
goto unlock;
|
||||
}
|
||||
|
||||
path = LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(data->adc_base));
|
||||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(data->adc_base),
|
||||
LL_ADC_PATH_INTERNAL_VBAT);
|
||||
LL_ADC_PATH_INTERNAL_VBAT | path);
|
||||
|
||||
rc = adc_read(data->adc, sp);
|
||||
if (rc == 0) {
|
||||
data->raw = data->sample_buffer;
|
||||
}
|
||||
|
||||
path = LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(data->adc_base));
|
||||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(data->adc_base),
|
||||
path &= ~LL_ADC_PATH_INTERNAL_VBAT);
|
||||
|
||||
unlock:
|
||||
k_mutex_unlock(&data->mutex);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue