__LL_ADC_CALC_TEMPERATURE hardfaults / TS_CAL1 & TS_CAL2 read as zero
In trying to troubleshoot ADC DMA issues I have built the example code from:
STM32Cube\Repository\STM32Cube_FW_L1_V1.10.3\Projects\NUCLEO-L152RE\Examples_LL\ADC\ADC_MultiChannelSingleConversion
However, when it converts the results it hardfaults due to a divide-by-zero in __LL_ADC_CALC_TEMPERATURE() macro:
/* Computation of ADC conversions raw data to physical values */
/* using LL ADC driver helper macro. */
uhADCxConvertedData_VoltageGPIO_mVolt = __LL_ADC_CALC_DATA_TO_VOLTAGE(VDDA_APPLI, aADCxConvertedData[0], LL_ADC_RESOLUTION_12B);
uhADCxConvertedData_VrefInt_mVolt = __LL_ADC_CALC_DATA_TO_VOLTAGE(VDDA_APPLI, aADCxConvertedData[1], LL_ADC_RESOLUTION_12B);
hADCxConvertedData_Temperature_DegreeCelsius = __LL_ADC_CALC_TEMPERATURE(VDDA_APPLI, aADCxConvertedData[2], LL_ADC_RESOLUTION_12B); // This crashes
On closer inspection, *TEMPSENSOR_CAL1_ADDR and *TEMPSENSOR_CAL2_ADDR read back as zero, which is bourne out if I use the debugger to view memory at those locations.
For reference, the two defines are in stm32l1xx_ll_adc.h as follows:
/* Temperature sensor */
#if defined (TEMPSENSOR_CAL1_ADDR_CMSIS)
#define TEMPSENSOR_CAL1_ADDR ((uint16_t*) TEMPSENSOR_CAL1_ADDR_CMSIS) /* Internal temperature sensor, address of parameter TS_CAL1: On STM32L1, temperature sensor ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
#define TEMPSENSOR_CAL2_ADDR ((uint16_t*) TEMPSENSOR_CAL2_ADDR_CMSIS) /* Internal temperature sensor, address of parameter TS_CAL2: On STM32L1, temperature sensor ADC raw data acquired at temperature 110 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
#endif /* TEMPSENSOR_CAL1_ADDR_CMSIS */Which resolve to:
#define VREFINT_CAL_ADDR_CMSIS 0x1FF80078 /*!<Internal voltage reference, address of parameter VREFINT_CAL: VrefInt ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
#define TEMPSENSOR_CAL1_ADDR_CMSIS 0x1FF8007A /*!<Internal temperature sensor, address of parameter TS_CAL1: On STM32L1, temperature sensor ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
#define TEMPSENSOR_CAL2_ADDR_CMSIS 0x1FF8007E /*!<Internal temperature sensor, address of parameter TS_CAL2: On STM32L1, temperature sensor ADC raw data acquired at temperature 110 DegC (tolerance: +-5 DegC), Vref+ = 3.3 V (tolerance: +-10 mV). */In stm32l152xba.h
The micro in use is an STM32L152RET6
