6262
6363#define ADC_JSQR_FIELDS ((ADC_JSQR_JL | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN |\
6464 ADC_JSQR_JSQ1 | ADC_JSQR_JSQ2 |\
65- ADC_JSQR_JSQ3 | ADC_JSQR_JSQ4 )) /*!< ADC_JSQR fields of parameters that can be updated anytime
66- once the ADC is enabled */
65+ ADC_JSQR_JSQ3 | ADC_JSQR_JSQ4 )) /*!< ADC_JSQR fields of parameters that can be updated anytime once the ADC is enabled */
6766
6867/* Fixed timeout value for ADC calibration. */
6968/* Values defined to be higher than worst cases: low clock frequency, */
@@ -227,7 +226,8 @@ uint32_t HAL_ADCEx_Calibration_GetValue(ADC_HandleTypeDef *hadc, uint32_t Single
227226 * @param CalibrationFactor Calibration factor (coded on 7 bits maximum)
228227 * @retval HAL state
229228 */
230- HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue (ADC_HandleTypeDef * hadc , uint32_t SingleDiff , uint32_t CalibrationFactor )
229+ HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue (ADC_HandleTypeDef * hadc , uint32_t SingleDiff ,
230+ uint32_t CalibrationFactor )
231231{
232232 HAL_StatusTypeDef tmp_hal_status = HAL_OK ;
233233 uint32_t tmp_adc_is_conversion_on_going_regular ;
@@ -523,13 +523,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef *hadc, u
523523 {
524524 if (((HAL_GetTick () - tickstart ) > Timeout ) || (Timeout == 0UL ))
525525 {
526- /* Update ADC state machine to timeout */
527- SET_BIT (hadc -> State , HAL_ADC_STATE_TIMEOUT );
526+ /* New check to avoid false timeout detection in case of preemption */
527+ if ((hadc -> Instance -> ISR & tmp_Flag_End ) == 0UL )
528+ {
529+ /* Update ADC state machine to timeout */
530+ SET_BIT (hadc -> State , HAL_ADC_STATE_TIMEOUT );
528531
529- /* Process unlocked */
530- __HAL_UNLOCK (hadc );
532+ /* Process unlocked */
533+ __HAL_UNLOCK (hadc );
531534
532- return HAL_TIMEOUT ;
535+ return HAL_TIMEOUT ;
536+ }
533537 }
534538 }
535539 }
@@ -885,6 +889,10 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t
885889 /* Process locked */
886890 __HAL_LOCK (hadc );
887891
892+ /* Temporary handle minimum initialization */
893+ __HAL_ADC_RESET_HANDLE_STATE (& tmphadcSlave );
894+ ADC_CLEAR_ERRORCODE (& tmphadcSlave );
895+
888896 /* Set a temporary handle of the ADC slave associated to the ADC master */
889897 ADC_MULTI_SLAVE (hadc , & tmphadcSlave );
890898
@@ -1000,6 +1008,10 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc)
10001008 /* Disable ADC peripheral if conversions are effectively stopped */
10011009 if (tmp_hal_status == HAL_OK )
10021010 {
1011+ /* Temporary handle minimum initialization */
1012+ __HAL_ADC_RESET_HANDLE_STATE (& tmphadcSlave );
1013+ ADC_CLEAR_ERRORCODE (& tmphadcSlave );
1014+
10031015 /* Set a temporary handle of the ADC slave associated to the ADC master */
10041016 ADC_MULTI_SLAVE (hadc , & tmphadcSlave );
10051017
@@ -1027,13 +1039,20 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc)
10271039 {
10281040 if ((HAL_GetTick () - tickstart ) > ADC_STOP_CONVERSION_TIMEOUT )
10291041 {
1030- /* Update ADC state machine to error */
1031- SET_BIT (hadc -> State , HAL_ADC_STATE_ERROR_INTERNAL );
1042+ /* New check to avoid false timeout detection in case of preemption */
1043+ tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing ((& tmphadcSlave )-> Instance );
1044+ if ((LL_ADC_REG_IsConversionOngoing (hadc -> Instance ) == 1UL )
1045+ || (tmphadcSlave_conversion_on_going == 1UL )
1046+ )
1047+ {
1048+ /* Update ADC state machine to error */
1049+ SET_BIT (hadc -> State , HAL_ADC_STATE_ERROR_INTERNAL );
10321050
1033- /* Process unlocked */
1034- __HAL_UNLOCK (hadc );
1051+ /* Process unlocked */
1052+ __HAL_UNLOCK (hadc );
10351053
1036- return HAL_ERROR ;
1054+ return HAL_ERROR ;
1055+ }
10371056 }
10381057
10391058 tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing ((& tmphadcSlave )-> Instance );
@@ -1484,6 +1503,10 @@ HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef *hadc)
14841503 /* Clear HAL_ADC_STATE_REG_BUSY bit */
14851504 CLEAR_BIT (hadc -> State , HAL_ADC_STATE_REG_BUSY );
14861505
1506+ /* Temporary handle minimum initialization */
1507+ __HAL_ADC_RESET_HANDLE_STATE (& tmphadcSlave );
1508+ ADC_CLEAR_ERRORCODE (& tmphadcSlave );
1509+
14871510 /* Set a temporary handle of the ADC slave associated to the ADC master */
14881511 ADC_MULTI_SLAVE (hadc , & tmphadcSlave );
14891512
@@ -1511,13 +1534,20 @@ HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef *hadc)
15111534 {
15121535 if ((HAL_GetTick () - tickstart ) > ADC_STOP_CONVERSION_TIMEOUT )
15131536 {
1514- /* Update ADC state machine to error */
1515- SET_BIT (hadc -> State , HAL_ADC_STATE_ERROR_INTERNAL );
1537+ /* New check to avoid false timeout detection in case of preemption */
1538+ tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing ((& tmphadcSlave )-> Instance );
1539+ if ((LL_ADC_REG_IsConversionOngoing (hadc -> Instance ) == 1UL )
1540+ || (tmphadcSlave_conversion_on_going == 1UL )
1541+ )
1542+ {
1543+ /* Update ADC state machine to error */
1544+ SET_BIT (hadc -> State , HAL_ADC_STATE_ERROR_INTERNAL );
15161545
1517- /* Process unlocked */
1518- __HAL_UNLOCK (hadc );
1546+ /* Process unlocked */
1547+ __HAL_UNLOCK (hadc );
15191548
1520- return HAL_ERROR ;
1549+ return HAL_ERROR ;
1550+ }
15211551 }
15221552
15231553 tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing ((& tmphadcSlave )-> Instance );
@@ -1957,19 +1987,23 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_I
19571987 {
19581988 /* Scan each offset register to check if the selected channel is targeted. */
19591989 /* If this is the case, the corresponding offset number is disabled. */
1960- if (__LL_ADC_CHANNEL_TO_DECIMAL_NB (LL_ADC_GetOffsetChannel (hadc -> Instance , LL_ADC_OFFSET_1 )) == __LL_ADC_CHANNEL_TO_DECIMAL_NB (sConfigInjected -> InjectedChannel ))
1990+ if (__LL_ADC_CHANNEL_TO_DECIMAL_NB (LL_ADC_GetOffsetChannel (hadc -> Instance , LL_ADC_OFFSET_1 ))
1991+ == __LL_ADC_CHANNEL_TO_DECIMAL_NB (sConfigInjected -> InjectedChannel ))
19611992 {
19621993 LL_ADC_SetOffsetState (hadc -> Instance , LL_ADC_OFFSET_1 , LL_ADC_OFFSET_DISABLE );
19631994 }
1964- if (__LL_ADC_CHANNEL_TO_DECIMAL_NB (LL_ADC_GetOffsetChannel (hadc -> Instance , LL_ADC_OFFSET_2 )) == __LL_ADC_CHANNEL_TO_DECIMAL_NB (sConfigInjected -> InjectedChannel ))
1995+ if (__LL_ADC_CHANNEL_TO_DECIMAL_NB (LL_ADC_GetOffsetChannel (hadc -> Instance , LL_ADC_OFFSET_2 ))
1996+ == __LL_ADC_CHANNEL_TO_DECIMAL_NB (sConfigInjected -> InjectedChannel ))
19651997 {
19661998 LL_ADC_SetOffsetState (hadc -> Instance , LL_ADC_OFFSET_2 , LL_ADC_OFFSET_DISABLE );
19671999 }
1968- if (__LL_ADC_CHANNEL_TO_DECIMAL_NB (LL_ADC_GetOffsetChannel (hadc -> Instance , LL_ADC_OFFSET_3 )) == __LL_ADC_CHANNEL_TO_DECIMAL_NB (sConfigInjected -> InjectedChannel ))
2000+ if (__LL_ADC_CHANNEL_TO_DECIMAL_NB (LL_ADC_GetOffsetChannel (hadc -> Instance , LL_ADC_OFFSET_3 ))
2001+ == __LL_ADC_CHANNEL_TO_DECIMAL_NB (sConfigInjected -> InjectedChannel ))
19692002 {
19702003 LL_ADC_SetOffsetState (hadc -> Instance , LL_ADC_OFFSET_3 , LL_ADC_OFFSET_DISABLE );
19712004 }
1972- if (__LL_ADC_CHANNEL_TO_DECIMAL_NB (LL_ADC_GetOffsetChannel (hadc -> Instance , LL_ADC_OFFSET_4 )) == __LL_ADC_CHANNEL_TO_DECIMAL_NB (sConfigInjected -> InjectedChannel ))
2005+ if (__LL_ADC_CHANNEL_TO_DECIMAL_NB (LL_ADC_GetOffsetChannel (hadc -> Instance , LL_ADC_OFFSET_4 ))
2006+ == __LL_ADC_CHANNEL_TO_DECIMAL_NB (sConfigInjected -> InjectedChannel ))
19732007 {
19742008 LL_ADC_SetOffsetState (hadc -> Instance , LL_ADC_OFFSET_4 , LL_ADC_OFFSET_DISABLE );
19752009 }
@@ -1990,7 +2024,9 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_I
19902024 if (sConfigInjected -> InjectedSingleDiff == ADC_DIFFERENTIAL_ENDED )
19912025 {
19922026 /* Set sampling time of the selected ADC channel */
1993- LL_ADC_SetChannelSamplingTime (hadc -> Instance , (uint32_t )(__LL_ADC_DECIMAL_NB_TO_CHANNEL ((__LL_ADC_CHANNEL_TO_DECIMAL_NB ((uint32_t )sConfigInjected -> InjectedChannel ) + 1UL ) & 0x1FUL )), sConfigInjected -> InjectedSamplingTime );
2027+ LL_ADC_SetChannelSamplingTime (hadc -> Instance ,
2028+ (uint32_t )(__LL_ADC_DECIMAL_NB_TO_CHANNEL ((__LL_ADC_CHANNEL_TO_DECIMAL_NB ((uint32_t )sConfigInjected -> InjectedChannel )
2029+ + 1UL ) & 0x1FUL )), sConfigInjected -> InjectedSamplingTime );
19942030 }
19952031
19962032 }
@@ -2021,7 +2057,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_I
20212057 /* Note: Variable divided by 2 to compensate partially */
20222058 /* CPU processing cycles, scaling in us split to not */
20232059 /* exceed 32 bits register capacity and handle low frequency. */
2024- wait_loop_index = ((LL_ADC_DELAY_TEMPSENSOR_STAB_US / 10UL ) * (SystemCoreClock / (100000UL * 2UL )));
2060+ wait_loop_index = ((LL_ADC_DELAY_TEMPSENSOR_STAB_US / 10UL ) * ((( SystemCoreClock / (100000UL * 2UL )) + 1UL ) + 1UL ));
20252061 while (wait_loop_index != 0UL )
20262062 {
20272063 wait_loop_index -- ;
@@ -2080,7 +2116,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_
20802116{
20812117 HAL_StatusTypeDef tmp_hal_status = HAL_OK ;
20822118 ADC_Common_TypeDef * tmpADC_Common ;
2083- ADC_HandleTypeDef tmphadcSlave ;
2119+ ADC_HandleTypeDef tmphadcSlave ;
20842120 uint32_t tmphadcSlave_conversion_on_going ;
20852121
20862122 /* Check the parameters */
@@ -2095,6 +2131,10 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_
20952131 /* Process locked */
20962132 __HAL_LOCK (hadc );
20972133
2134+ /* Temporary handle minimum initialization */
2135+ __HAL_ADC_RESET_HANDLE_STATE (& tmphadcSlave );
2136+ ADC_CLEAR_ERRORCODE (& tmphadcSlave );
2137+
20982138 ADC_MULTI_SLAVE (hadc , & tmphadcSlave );
20992139
21002140 if (tmphadcSlave .Instance == NULL )
0 commit comments