cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Fault when reading flash

sivaram
Associate III

I am working to generate the CRC for the flash memory, During this I am facing hard fault when the CRC module tries to read from certain flash locations, to debug it I made a small loop which assigns the value of each 4 byte. I found that reading at certain locations results in hardfault.

I tried with different starting address, I found that

when starting address is 0x08000000 hardfault occurred at 0x08000440

when starting address is 0x08001000 hardfault occurred at 0x0800144c

when starting address is 0x08004000 hardfault occurred at 0x080044cc

uint32_t *d1 = 0x08000000;
while(length){
      uint32_t temp = *d1;
      d1++;
      length -= 4;
}

Any Idea of what is causing this issue?

23 REPLIES 23

It seems to be caused after writing to the sector.

I'm flashing the same way every time but apparently, in some cases, the write results in an (ECC?) error, that generates hard-faults if read. STM32CubeProgrammer will also fail to read the sector, and must be erased in order to recover. HAL always returns OK.

HAL_FLASH_Unlock();
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, 0x081E0000 + (32*fw), (uint32_t)(pSrcBuffer)) != HAL_OK)
{
		// ERROR!
               while ( 1 );
}
HAL_FLASH_Lock();

fb
Associate III

I had the same hard fault from random flash addresses when reading. It happened, when I wrote a flash word (32 bytes) with HAL_FLASH_Program, to an address in flash to which I already wrote, but with erasing the sector first with HAL_FLASHEx_Erase. Then the next read caused the hard fault. But not necessary at the location where I wrote. I guess something related to ECC. Tested with a NUCLEO-H723ZG board.

Hello,

same issue. Even the STM32CubeProgrammer fail to read. Do you find a solution?

Gary_Zhang
Associate

Hi, 

Did you fix this issue?

I also have the same situation recently. Read the Flash sector after writing will end up with a hard fault. 

It seems many folks see this kind of issue, any one from ST to look into it?