Hard Fault when accessing FLASH_SIZE and NMI while reading Data Flash (EDATA) on STM32C542
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:
- Is there any specific register configuration or initialization required before accessing FLASH_SIZE on this device?
- Is this region restricted due to Trust Zone or privileged access on STM32C5 devices?
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:
- If we erase and write data first, the read operation works correctly.
- If we read from a blank location, it enters the NMI handler.
Our questions are:
- Is this behavior expected due to ECC protection in the Data Flash region?
- Is there any recommended HAL API to safely read Data Flash?
- Is there any API available to read from data flash?
- Is there any API available to check whether a Data Flash page is blank before performing a read operation?
Thank you.
