cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Fault when accessing FLASH_SIZE and NMI while reading Data Flash (EDATA) on STM32C542

koteswara_roa
Associate

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:

  1. Is this behavior expected due to ECC protection in the Data Flash region?
  2. Is there any recommended HAL API to safely read Data Flash?
  3. Is there any API available to read from data flash?
  4. Is there any API available to check whether a Data Flash page is blank before performing a read operation?

Thank you.

 

2 REPLIES 2
Andrew Neil
Super User

Have you tried debugging the Hard Fault - to see exactly what is causing it?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

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