Skip to main content
JU_it
Senior
April 7, 2022
Solved

__LL_ADC_CALC_TEMPERATURE hardfaults / TS_CAL1 & TS_CAL2 read as zero

  • April 7, 2022
  • 6 replies
  • 3883 views

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

This topic has been closed for replies.
Best answer by TDK
I mean, maybe. No offense, but I think it's more likely you picked the wrong MCU here. If you provide your IOC file I could replicate.

6 replies

TDK
April 7, 2022

Looks like the addresses it uses are not consistent with the user manual. Use STM32CubeProgrammer to verify the CAL factors are nonzero in memory in the datasheet locations.

0693W00000LxHoyQAF.png

"If you feel a post has answered your question, please click ""Accept as Solution""."
TDK
April 7, 2022

> In stm32l152xba.h

> The micro in use is an STM32L152RET6

That's not the correct include file for that chip.

The addresses in the current CMSIS include file stm32l152xe.h match those of the datasheet.

https://github.com/STMicroelectronics/STM32CubeL1/blob/master/Drivers/CMSIS/Device/ST/STM32L1xx/Include/stm32l152xe.h#L851

"If you feel a post has answered your question, please click ""Accept as Solution""."
JU_it
JU_itAuthor
Senior
April 8, 2022

Thanks TDK - So this looks like a bug in the STM32Cube then, since I picked the micro & set the project up through Cube IDE and those are the headers it pulled in >:(

TDK
TDKBest answer
April 8, 2022
I mean, maybe. No offense, but I think it's more likely you picked the wrong MCU here. If you provide your IOC file I could replicate.
"If you feel a post has answered your question, please click ""Accept as Solution""."