2026-03-16 5:48 AM
Hello,
We are currently working on STM32C542CCT6 from the STM32C5 series and developing custom Flash and Data Flash drivers.
Issue 1 – Hard Fault when accessing FLASH_SIZE
While executing code generated by STM32Cube, the following check causes the system to enter the Hard Fault handler:
if (FLASH_ADDR < (FLASH_BASE + FLASH_SIZE)) /* Main User Flash */
The FLASH_SIZE macro reads the value from the device information area. However, when the code attempts to access FLASH_SIZE, the system immediately enters the Hard Fault handler.
If we manually hardcode the flash size value, the code works correctly.
Our questions are:
Issue 2 – NMI when reading Data Flash
We have enabled Data Flash by setting: EDATA_EN = 1
We are trying to read from the Data Flash base address:0x09000000
using a pointer-based read method:
uint16_t data =(*(uint16_t *)0x09000000);
However, if the location has not been written previously, the system enters the NMI handler.
Observations:
Our questions are:
Thank you.
2026-03-16 5:51 AM
Have you tried debugging the Hard Fault - to see exactly what is causing it?
2026-03-16 5:57 AM
yes, macro which was used FLASH_SIZE is causing the hard fault.it is trying to read data from reserved memory address whenever it is trying that address it is end up with Hard fault handler and the code is completely generated by code generator, and it is in stm32C5xx_hal_flash.c