cancel
Showing results for 
Search instead for 
Did you mean: 

__LL_ADC_CALC_TEMPERATURE hardfaults / TS_CAL1 & TS_CAL2 read as zero

JU
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
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".

View solution in original post

6 REPLIES 6
TDK
Guru

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
Guru

> 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
Associate III

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 >:(

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".
JU
Associate III

You're right - I had picked the wrong MCU, although it turns out there' still a bug in CubeIDE that I discovered whilst trying to change MCU:

https://community.st.com/s/question/0D53W00001U4XFhSAN/cubeide-190-has-a-heart-attack-on-loading-compatible-mcus-out-of-memory-huge-delay-nonresponsive

So, yay :squinting_face_with_tongue:

JU
Associate III

@TDK​ further to my comment above - it looks like a variant of the original bug is still in the generated code having switched to the correct micro... I'll start yet another thread for it! :D