Skip to main content
ingwmeier
Senior
April 26, 2025
Solved

Hardfault, when reading TEMPSENSOR_CAL1_ADDR with STM32H56x

  • April 26, 2025
  • 3 replies
  • 593 views
#define TEMPSENSOR_CAL1_ADDR ((uint16_t*) (0x08FFF814UL)) /* Address of parameter TS_CAL1: On STM32H5,
 temperature sensor ADC raw data acquired at temperature 30 DegC
 (tolerance: +-5 DegC), Vref+ = 3.3 V (tolerance: +-10 mV). */

uint16_t regval = *TEMPSENSOR_CAL1_ADDR;

as soon as this address is read, the CPU goes into Hardfault. I double checked the Address in the Datasheet..

also restarts the CPU, when I try to show this Memory with the debugger.

also tested it with a Nucleo-H563ZI.

the same access with other STM32 CPUs (U5, L4 etc) work with no problems.

This topic has been closed for replies.
Best answer by AScha.3

Hi,

its a problem with the cache : disable cache, then see:

	 int flsz = FLASH_SIZE;
	 printf("size : %d \n", flsz);

	 int regval = *TEMPSENSOR_CAL1_ADDR;

	 printf("tempcal1 %ld C : %d \n", TEMPSENSOR_CAL1_TEMP, regval);

 

AScha3_0-1745660782921.png

To be able to read into system flash you need to disable the cache associated to this area.

This can be done by setting non cacheable attribute this this region.

You have an example for accessing this UID in the STM32CubeH5 here:

STM32Cube_FW_H5_V1.3.0\Projects\NUCLEO-H563ZI\Examples_LL\UTILS\UTILS_ReadDeviceInfo\

(by Jocelyn R.)

 

3 replies

AScha.3
AScha.3Best answer
Super User
April 26, 2025

Hi,

its a problem with the cache : disable cache, then see:

	 int flsz = FLASH_SIZE;
	 printf("size : %d \n", flsz);

	 int regval = *TEMPSENSOR_CAL1_ADDR;

	 printf("tempcal1 %ld C : %d \n", TEMPSENSOR_CAL1_TEMP, regval);

 

AScha3_0-1745660782921.png

To be able to read into system flash you need to disable the cache associated to this area.

This can be done by setting non cacheable attribute this this region.

You have an example for accessing this UID in the STM32CubeH5 here:

STM32Cube_FW_H5_V1.3.0\Projects\NUCLEO-H563ZI\Examples_LL\UTILS\UTILS_ReadDeviceInfo\

(by Jocelyn R.)

 

If you feel a post has answered your question, please click on " Best Answer ".
ingwmeier
ingwmeierAuthor
Senior
April 26, 2025

Thank you so much! 

ingwmeier
ingwmeierAuthor
Senior
April 28, 2025
 /* Disable MPU before perloading and config update */
 LL_MPU_Disable();

 /* Define Not cacheable memory via MPU */
 LL_MPU_ConfigAttributes(LL_MPU_ATTRIBUTES_NUMBER1, LL_MPU_NOT_CACHEABLE);

 /* BaseAddress-LimitAddress configuration for RO area*/
 LL_MPU_EnableRegion(LL_MPU_REGION_NUMBER1);
 LL_MPU_ConfigRegion(LL_MPU_REGION_NUMBER1,LL_MPU_REGION_ALL_RO,LL_MPU_ATTRIBUTES_NUMBER1, 0x08FFF800UL, 0x08FFFFFFUL);

 /* Enable MPU */
 LL_MPU_Enable(LL_MPU_CTRL_HFNMI_PRIVDEF);

Why not add these lines of code through CubeMX if cache is enabled?
Would prevent some hardfaults