-
Notifications
You must be signed in to change notification settings - Fork 3k
STM32 ADC update #6987
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
STM32 ADC update #6987
Changes from all commits
cb579cb
d7932c2
743a812
5f21c3f
e438bd6
06bca28
4d3a544
881a8e3
7fd4203
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5660,12 +5660,6 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf | |
/* Set handle of the other ADC sharing the same common register */ | ||
ADC_COMMON_ADC_OTHER(hadc, &tmphadcSharingSameCommonRegister); | ||
|
||
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. why is it removed ? Is it a patch that we have added previously ? 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. yes, same kind of patch as #6412 |
||
/* Software is allowed to change common parameters only when all ADCs */ | ||
/* of the common group are disabled. */ | ||
if ((ADC_IS_ENABLE(hadc) == RESET) && | ||
( (tmphadcSharingSameCommonRegister.Instance == NULL) || | ||
(ADC_IS_ENABLE(&tmphadcSharingSameCommonRegister) == RESET) ) ) | ||
{ | ||
/* If Channel_16 is selected, enable Temp. sensor measurement path */ | ||
/* Note: Temp. sensor internal channels available on ADC1 only */ | ||
if ((sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) && (hadc->Instance == ADC1)) | ||
|
@@ -5694,17 +5688,6 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf | |
{ | ||
SET_BIT(tmpADC_Common->CCR, ADC_CCR_VREFEN); | ||
} | ||
} | ||
/* 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 | ||
{ | ||
/* Update ADC state machine to error */ | ||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); | ||
|
||
tmp_hal_status = HAL_ERROR; | ||
} | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,6 +269,18 @@ extern "C" { | |
/* ADC registers bits positions */ | ||
#define ADC_CR1_RES_BITOFFSET_POS (24U) /* Value equivalent to POSITION_VAL(ADC_CR1_RES) */ | ||
#define ADC_TR_HT_BITOFFSET_POS (16U) /* Value equivalent to POSITION_VAL(ADC_TR_HT) */ | ||
|
||
/* ADC internal channels related definitions */ | ||
/* Internal voltage reference VrefInt */ | ||
#define VREFINT_CAL_ADDR ((uint16_t*) (0x1FFF7A2AU)) /* Internal voltage reference, address of parameter VREFINT_CAL: VrefInt ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.3 V (tolerance: +-10 mV). */ | ||
#define VREFINT_CAL_VREF ( 3300U) /* Analog voltage reference (Vref+) value with which temperature sensor has been calibrated in production (tolerance: +-10 mV) (unit: mV). */ | ||
/* Temperature sensor */ | ||
#define TEMPSENSOR_CAL1_ADDR ((uint16_t*) (0x1FFF7A2CU)) /* Internal temperature sensor, address of parameter TS_CAL1: On STM32F4, temperature sensor ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.3 V (tolerance: +-10 mV). */ | ||
#define TEMPSENSOR_CAL2_ADDR ((uint16_t*) (0x1FFF7A2EU)) /* Internal temperature sensor, address of parameter TS_CAL2: On STM32F4, temperature sensor ADC raw data acquired at temperature 110 DegC (tolerance: +-5 DegC), Vref+ = 3.3 V (tolerance: +-10 mV). */ | ||
#define TEMPSENSOR_CAL1_TEMP (( int32_t) 30) /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL1_ADDR (tolerance: +-5 DegC) (unit: DegC). */ | ||
#define TEMPSENSOR_CAL2_TEMP (( int32_t) 110) /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL2_ADDR (tolerance: +-5 DegC) (unit: DegC). */ | ||
#define TEMPSENSOR_CAL_VREFANALOG ( 3300U) /* Analog voltage reference (Vref+) voltage with which temperature sensor has been calibrated in production (+-10 mV) (unit: mV). */ | ||
|
||
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. Why did you add this ? 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. To align with other STM32 families, |
||
/** | ||
* @} | ||
*/ | ||
|
@@ -1654,6 +1666,64 @@ typedef struct | |
/ __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \ | ||
) | ||
|
||
/** | ||
* @brief Helper macro to calculate the temperature (unit: degree Celsius) | ||
* from ADC conversion data of internal temperature sensor. | ||
* @note Computation is using temperature sensor calibration values | ||
* stored in system memory for each device during production. | ||
* @note Calculation formula: | ||
* Temperature = ((TS_ADC_DATA - TS_CAL1) | ||
* * (TS_CAL2_TEMP - TS_CAL1_TEMP)) | ||
* / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP | ||
* with TS_ADC_DATA = temperature sensor raw data measured by ADC | ||
* Avg_Slope = (TS_CAL2 - TS_CAL1) | ||
* / (TS_CAL2_TEMP - TS_CAL1_TEMP) | ||
* TS_CAL1 = equivalent TS_ADC_DATA at temperature | ||
* TEMP_DEGC_CAL1 (calibrated in factory) | ||
* TS_CAL2 = equivalent TS_ADC_DATA at temperature | ||
* TEMP_DEGC_CAL2 (calibrated in factory) | ||
* Caution: Calculation relevancy under reserve that calibration | ||
* parameters are correct (address and data). | ||
* To calculate temperature using temperature sensor | ||
* datasheet typical values (generic values less, therefore | ||
* less accurate than calibrated values), | ||
* use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(). | ||
* @note As calculation input, the analog reference voltage (Vref+) must be | ||
* defined as it impacts the ADC LSB equivalent voltage. | ||
* @note Analog reference voltage (Vref+) must be either known from | ||
* user board environment or can be calculated using ADC measurement | ||
* and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE(). | ||
* @note On this STM32 serie, calibration data of temperature sensor | ||
* corresponds to a resolution of 12 bits, | ||
* this is the recommended ADC resolution to convert voltage of | ||
* temperature sensor. | ||
* Otherwise, this macro performs the processing to scale | ||
* ADC conversion data to 12 bits. | ||
* @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV) | ||
* @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal | ||
* temperature sensor (unit: digital value). | ||
* @param __ADC_RESOLUTION__ ADC resolution at which internal temperature | ||
* sensor voltage has been measured. | ||
* This parameter can be one of the following values: | ||
* @arg @ref LL_ADC_RESOLUTION_12B | ||
* @arg @ref LL_ADC_RESOLUTION_10B | ||
* @arg @ref LL_ADC_RESOLUTION_8B | ||
* @arg @ref LL_ADC_RESOLUTION_6B | ||
* @retval Temperature (unit: degree Celsius) | ||
*/ | ||
#define __LL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\ | ||
__TEMPSENSOR_ADC_DATA__,\ | ||
__ADC_RESOLUTION__) \ | ||
(((( ((int32_t)((__LL_ADC_CONVERT_DATA_RESOLUTION((__TEMPSENSOR_ADC_DATA__), \ | ||
(__ADC_RESOLUTION__), \ | ||
LL_ADC_RESOLUTION_12B) \ | ||
* (__VREFANALOG_VOLTAGE__)) \ | ||
/ TEMPSENSOR_CAL_VREFANALOG) \ | ||
- (int32_t) *TEMPSENSOR_CAL1_ADDR) \ | ||
) * (int32_t)(TEMPSENSOR_CAL2_TEMP - TEMPSENSOR_CAL1_TEMP) \ | ||
) / (int32_t)((int32_t)*TEMPSENSOR_CAL2_ADDR - (int32_t)*TEMPSENSOR_CAL1_ADDR) \ | ||
) + TEMPSENSOR_CAL1_TEMP \ | ||
) | ||
|
||
/** | ||
* @brief Helper macro to calculate the temperature (unit: degree Celsius) | ||
|
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.
I don't understand how this macro can determine if the calibration has been done or not ?
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.
Check RM:
ADC data register (ADC_DR)
Just after a calibration is complete, DATA[6:0] contains the calibration factor
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.
ok