cancel
Showing results for 
Search instead for 
Did you mean: 

Test for EDATA FLASH ECC code on STM32H563

L_P
Associate II

Hello All,

We are looking into testing our code that access the EDATA and handle FLASH ECCC (single bit error) and ECCD (double bit error).

How can we simulate those errors?

Is it possible to insert single bit or double bit errors using a JTAG? It would useful to test the code without modifying it.

Any alternatives?

1 ACCEPTED SOLUTION

Accepted Solutions

The solution is to write to FLASH at least twice using different data for every cycle without erasing. This will trigger an ECC error on the next read attempt.

View solution in original post

7 REPLIES 7
Saket_Om
ST Employee

Hello @L_P 

Please refer to the AN5342, it explains how you can trigger an ECC error. 

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

The solution is to write to FLASH at least twice using different data for every cycle without erasing. This will trigger an ECC error on the next read attempt.

What method did you use to write to flash? I am also trying to simulate ECC errors in flash, and have tried the above method of writing to flash at least twice with different data without erasing, and then reading. This has not worked for me though.

 

Here's my code:

  if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, Address, ((uint32_t)FlashWordB)) != HAL_OK)
  {
	  Error_Handler();
  }
  if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, Address, ((uint32_t)FlashWordA)) != HAL_OK)
  {
	  Error_Handler();
  }
  uint64_t readData[4];

  for (int i = 0; i < 4; i++) {
	  readData[i] = *((uint64_t *)(Address + i * 8)); // Read 64 bits at a time
  }

 FlashWordB is all 0's, and FlashWordA is all 1's. What's weird though is that when I check the memory afterwards with the cubeProgrammer, that address in memory is still all 0's. When I step through this code with the debugger, the HAL_FLASH_Program function runs without any errors, and it seems that for whatever reason it is just not writing the second time it is called.

@Amel NASRI Do you have any ideas?

 

Thank you!

Did you call HAL_FLASH_Unlock() before writing to flash?

 

Also, if you are writing to EDATA flash, I believe you need to use FLASH_TYPEPROGRAM_HALFWORD_EDATA.

Yes, before writing I call HAL_FLASH_Unlock(), and then after both writes and the read I call HAL_FLASH_lock(). Did you use HAL_FLASH_Program() to write to flash or did you do it differently? 

 

I am not sure what you mean by EDATA flash. I am writing to sector 2 bank 1, specifically at address 0x08040000. I also tried using FLASH_TYPEPROGRAM_HALFWORD_EDATA and it was not recognized.

 

Here is the data I am writing to flash:

uint64_t FlashWordA[4] = { 0x1111111111111111,
						   0x1111111111111111,
		                   0x1111111111111111,
		                   0x1111111111111111
                        };

uint64_t FlashWordB[4] = { 0x0000000000000000,
							0x0000000000000000,
							0x0000000000000000,
							0x0000000000000000
                        };

I write FlashWordB first, then FlashWordA. 

 

Thanks again for your help and for the prompt response, I appreciate it.

EDATA is also called "Flash high-cycle data". According to the manual for stm32h563 section 7.3.10, "The embedded flash memory offers up to 96 Kbytes (maximum) memory area with high cycling capability (100 kcycles) to store data and emulate EEPROM". If you want to use it, you need to enable it via the option bytes.

 

This is my code:

 

uint32_t writeAddr =  0x08000000 + 0x40000 + 0x200;
uint32_t buffer[4] = {0x12341234, 0x56785678, 0x43214321, 0x87658765};
FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
for(int k = 0; k < 0x100 ; k+=16)
{
    HAL_FLASH_Program(FLASH_TYPEPROGRAM_QUADWORD, writeAddr + k, ((uint32_t)buffer));
    buffer[0]++;
    HAL_FLASH_Program(FLASH_TYPEPROGRAM_QUADWORD, writeAddr + k, ((uint32_t)buffer));
    buffer[0]++;
}
HAL_FLASH_Lock();

 

I ended up getting flash ECC figured out, thank you so much for your help! I'm now working on testing RAM ECC, but am having trouble triggering ECC errors. Is this something you have encountered?

Thanks again!