62
62
63
63
#define ADC_JSQR_FIELDS ((ADC_JSQR_JL | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN |\
64
64
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 */
67
66
68
67
/* Fixed timeout value for ADC calibration. */
69
68
/* 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
227
226
* @param CalibrationFactor Calibration factor (coded on 7 bits maximum)
228
227
* @retval HAL state
229
228
*/
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 )
231
231
{
232
232
HAL_StatusTypeDef tmp_hal_status = HAL_OK ;
233
233
uint32_t tmp_adc_is_conversion_on_going_regular ;
@@ -523,13 +523,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef *hadc, u
523
523
{
524
524
if (((HAL_GetTick () - tickstart ) > Timeout ) || (Timeout == 0UL ))
525
525
{
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 );
528
531
529
- /* Process unlocked */
530
- __HAL_UNLOCK (hadc );
532
+ /* Process unlocked */
533
+ __HAL_UNLOCK (hadc );
531
534
532
- return HAL_TIMEOUT ;
535
+ return HAL_TIMEOUT ;
536
+ }
533
537
}
534
538
}
535
539
}
@@ -885,6 +889,10 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t
885
889
/* Process locked */
886
890
__HAL_LOCK (hadc );
887
891
892
+ /* Temporary handle minimum initialization */
893
+ __HAL_ADC_RESET_HANDLE_STATE (& tmphadcSlave );
894
+ ADC_CLEAR_ERRORCODE (& tmphadcSlave );
895
+
888
896
/* Set a temporary handle of the ADC slave associated to the ADC master */
889
897
ADC_MULTI_SLAVE (hadc , & tmphadcSlave );
890
898
@@ -1000,6 +1008,10 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc)
1000
1008
/* Disable ADC peripheral if conversions are effectively stopped */
1001
1009
if (tmp_hal_status == HAL_OK )
1002
1010
{
1011
+ /* Temporary handle minimum initialization */
1012
+ __HAL_ADC_RESET_HANDLE_STATE (& tmphadcSlave );
1013
+ ADC_CLEAR_ERRORCODE (& tmphadcSlave );
1014
+
1003
1015
/* Set a temporary handle of the ADC slave associated to the ADC master */
1004
1016
ADC_MULTI_SLAVE (hadc , & tmphadcSlave );
1005
1017
@@ -1027,13 +1039,20 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc)
1027
1039
{
1028
1040
if ((HAL_GetTick () - tickstart ) > ADC_STOP_CONVERSION_TIMEOUT )
1029
1041
{
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 );
1032
1050
1033
- /* Process unlocked */
1034
- __HAL_UNLOCK (hadc );
1051
+ /* Process unlocked */
1052
+ __HAL_UNLOCK (hadc );
1035
1053
1036
- return HAL_ERROR ;
1054
+ return HAL_ERROR ;
1055
+ }
1037
1056
}
1038
1057
1039
1058
tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing ((& tmphadcSlave )-> Instance );
@@ -1484,6 +1503,10 @@ HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef *hadc)
1484
1503
/* Clear HAL_ADC_STATE_REG_BUSY bit */
1485
1504
CLEAR_BIT (hadc -> State , HAL_ADC_STATE_REG_BUSY );
1486
1505
1506
+ /* Temporary handle minimum initialization */
1507
+ __HAL_ADC_RESET_HANDLE_STATE (& tmphadcSlave );
1508
+ ADC_CLEAR_ERRORCODE (& tmphadcSlave );
1509
+
1487
1510
/* Set a temporary handle of the ADC slave associated to the ADC master */
1488
1511
ADC_MULTI_SLAVE (hadc , & tmphadcSlave );
1489
1512
@@ -1511,13 +1534,20 @@ HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef *hadc)
1511
1534
{
1512
1535
if ((HAL_GetTick () - tickstart ) > ADC_STOP_CONVERSION_TIMEOUT )
1513
1536
{
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 );
1516
1545
1517
- /* Process unlocked */
1518
- __HAL_UNLOCK (hadc );
1546
+ /* Process unlocked */
1547
+ __HAL_UNLOCK (hadc );
1519
1548
1520
- return HAL_ERROR ;
1549
+ return HAL_ERROR ;
1550
+ }
1521
1551
}
1522
1552
1523
1553
tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing ((& tmphadcSlave )-> Instance );
@@ -1957,19 +1987,23 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_I
1957
1987
{
1958
1988
/* Scan each offset register to check if the selected channel is targeted. */
1959
1989
/* 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 ))
1961
1992
{
1962
1993
LL_ADC_SetOffsetState (hadc -> Instance , LL_ADC_OFFSET_1 , LL_ADC_OFFSET_DISABLE );
1963
1994
}
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 ))
1965
1997
{
1966
1998
LL_ADC_SetOffsetState (hadc -> Instance , LL_ADC_OFFSET_2 , LL_ADC_OFFSET_DISABLE );
1967
1999
}
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 ))
1969
2002
{
1970
2003
LL_ADC_SetOffsetState (hadc -> Instance , LL_ADC_OFFSET_3 , LL_ADC_OFFSET_DISABLE );
1971
2004
}
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 ))
1973
2007
{
1974
2008
LL_ADC_SetOffsetState (hadc -> Instance , LL_ADC_OFFSET_4 , LL_ADC_OFFSET_DISABLE );
1975
2009
}
@@ -1990,7 +2024,9 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_I
1990
2024
if (sConfigInjected -> InjectedSingleDiff == ADC_DIFFERENTIAL_ENDED )
1991
2025
{
1992
2026
/* 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 );
1994
2030
}
1995
2031
1996
2032
}
@@ -2021,7 +2057,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_I
2021
2057
/* Note: Variable divided by 2 to compensate partially */
2022
2058
/* CPU processing cycles, scaling in us split to not */
2023
2059
/* 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 ));
2025
2061
while (wait_loop_index != 0UL )
2026
2062
{
2027
2063
wait_loop_index -- ;
@@ -2080,7 +2116,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_
2080
2116
{
2081
2117
HAL_StatusTypeDef tmp_hal_status = HAL_OK ;
2082
2118
ADC_Common_TypeDef * tmpADC_Common ;
2083
- ADC_HandleTypeDef tmphadcSlave ;
2119
+ ADC_HandleTypeDef tmphadcSlave ;
2084
2120
uint32_t tmphadcSlave_conversion_on_going ;
2085
2121
2086
2122
/* Check the parameters */
@@ -2095,6 +2131,10 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_
2095
2131
/* Process locked */
2096
2132
__HAL_LOCK (hadc );
2097
2133
2134
+ /* Temporary handle minimum initialization */
2135
+ __HAL_ADC_RESET_HANDLE_STATE (& tmphadcSlave );
2136
+ ADC_CLEAR_ERRORCODE (& tmphadcSlave );
2137
+
2098
2138
ADC_MULTI_SLAVE (hadc , & tmphadcSlave );
2099
2139
2100
2140
if (tmphadcSlave .Instance == NULL )
0 commit comments