2024-09-05 10:00 AM
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?
Solved! Go to Solution.
2024-09-10 05:03 AM
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.
2024-09-09 08:33 AM
2024-09-10 05:03 AM
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.
2024-09-18 01:37 PM
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!
2024-09-19 05:46 AM
Did you call HAL_FLASH_Unlock() before writing to flash?
2024-09-19 07:16 AM
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.
2024-09-19 09:38 AM
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.
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();
2024-09-20 12:12 PM
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!