‎2022-04-07 06:52 AM
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
Solved! Go to Solution.
‎2022-04-08 07:05 AM
‎2022-04-07 12:11 PM
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.
‎2022-04-07 12:14 PM
> 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.
‎2022-04-08 12:49 AM
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 >:(
‎2022-04-08 07:05 AM
‎2022-04-11 01:18 AM
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:
So, yay :squinting_face_with_tongue:
‎2022-04-11 05:47 AM
@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