New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STM32L4 ADC correct internal channel management #6412
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2312,7 +2312,6 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf | |
/* Parameters update conditioned to ADC state: */ | ||
/* Parameters that can be updated only when ADC is disabled: */ | ||
/* - Single or differential mode */ | ||
/* - Internal measurement channels: Vbat/VrefInt/TempSensor */ | ||
if (ADC_IS_ENABLE(hadc) == RESET) | ||
{ | ||
/* Set mode single-ended or differential input of the selected ADC channel */ | ||
|
@@ -2325,71 +2324,56 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf | |
LL_ADC_SetChannelSamplingTime(hadc->Instance, __LL_ADC_DECIMAL_NB_TO_CHANNEL(__LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfig->Channel) + 1), sConfig->SamplingTime); | ||
} | ||
|
||
/* Management of internal measurement channels: Vbat/VrefInt/TempSensor. */ | ||
/* If internal channel selected, enable dedicated internal buffers and */ | ||
/* paths. */ | ||
/* Note: these internal measurement paths can be disabled using */ | ||
/* HAL_ADC_DeInit(). */ | ||
|
||
/* Configuration of common ADC parameters */ | ||
/* If the requested internal measurement path has already been enabled, */ | ||
/* bypass the configuration processing. */ | ||
if (( (sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) && | ||
((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0U)) || | ||
( (sConfig->Channel == ADC_CHANNEL_VBAT) && | ||
((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_VBAT) == 0U)) || | ||
( (sConfig->Channel == ADC_CHANNEL_VREFINT) && | ||
((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_VREFINT) == 0U)) | ||
) | ||
} | ||
|
||
/* Management of internal measurement channels: Vbat/VrefInt/TempSensor. */ | ||
/* If internal channel selected, enable dedicated internal buffers and */ | ||
/* paths. */ | ||
/* Note: these internal measurement paths can be disabled using */ | ||
/* HAL_ADC_DeInit(). */ | ||
|
||
/* Configuration of common ADC parameters */ | ||
/* If the requested internal measurement path has already been enabled, */ | ||
/* bypass the configuration processing. */ | ||
if (( (sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) && | ||
((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0U)) || | ||
( (sConfig->Channel == ADC_CHANNEL_VBAT) && | ||
((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_VBAT) == 0U)) || | ||
( (sConfig->Channel == ADC_CHANNEL_VREFINT) && | ||
((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_VREFINT) == 0U)) | ||
) | ||
{ | ||
/* Configuration of common ADC parameters (continuation) */ | ||
|
||
if (sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) | ||
{ | ||
/* Configuration of common ADC parameters (continuation) */ | ||
|
||
/* Software is allowed to change common parameters only when all ADCs */ | ||
/* of the common group are disabled. */ | ||
if ((ADC_IS_ENABLE(hadc) == RESET) && | ||
(ADC_ANY_OTHER_ENABLED(hadc) == RESET) ) | ||
if (ADC_TEMPERATURE_SENSOR_INSTANCE(hadc)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this imply that ADC parameters can now be changed without all ADCs needing to be in reset (per the deleted comment)? |
||
{ | ||
if (sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) | ||
{ | ||
if (ADC_TEMPERATURE_SENSOR_INSTANCE(hadc)) | ||
{ | ||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_TEMPSENSOR | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance))); | ||
|
||
/* Delay for temperature sensor stabilization time */ | ||
/* Wait loop initialization and execution */ | ||
/* Note: Variable divided by 2 to compensate partially */ | ||
/* CPU processing cycles. */ | ||
wait_loop_index = (LL_ADC_DELAY_TEMPSENSOR_STAB_US * (SystemCoreClock / (1000000 * 2))); | ||
while(wait_loop_index != 0) | ||
{ | ||
wait_loop_index--; | ||
} | ||
} | ||
} | ||
else if (sConfig->Channel == ADC_CHANNEL_VBAT) | ||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_TEMPSENSOR | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance))); | ||
|
||
/* Delay for temperature sensor stabilization time */ | ||
/* Wait loop initialization and execution */ | ||
/* Note: Variable divided by 2 to compensate partially */ | ||
/* CPU processing cycles. */ | ||
wait_loop_index = (LL_ADC_DELAY_TEMPSENSOR_STAB_US * (SystemCoreClock / (1000000 * 2))); | ||
while(wait_loop_index != 0) | ||
{ | ||
if (ADC_BATTERY_VOLTAGE_INSTANCE(hadc)) | ||
{ | ||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VBAT | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance))); | ||
} | ||
} | ||
else if (sConfig->Channel == ADC_CHANNEL_VREFINT) | ||
{ | ||
if (ADC_VREFINT_INSTANCE(hadc)) | ||
{ | ||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VREFINT | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance))); | ||
} | ||
wait_loop_index--; | ||
} | ||
} | ||
/* If the requested internal measurement path has already been */ | ||
/* enabled and other ADC of the common group are enabled, internal */ | ||
/* measurement paths cannot be enabled. */ | ||
else | ||
} | ||
else if (sConfig->Channel == ADC_CHANNEL_VBAT) | ||
{ | ||
if (ADC_BATTERY_VOLTAGE_INSTANCE(hadc)) | ||
{ | ||
/* Update ADC state machine to error */ | ||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); | ||
|
||
tmp_hal_status = HAL_ERROR; | ||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VBAT | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance))); | ||
} | ||
} | ||
else if (sConfig->Channel == ADC_CHANNEL_VREFINT) | ||
{ | ||
if (ADC_VREFINT_INSTANCE(hadc)) | ||
{ | ||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VREFINT | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance))); | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. So configuration of the internal channels doesn't require that the ADC be in RESET mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, ADC driver team explained me that restriction is no more valid since last reference manual version.
Official correction will come in the next cube release.