How to check ECC for flash corruption?

Hello,
I’m using Flash_WriteBuffer() for writing and Sys_Flash_Copy() for reading.
Sys_Flash_Copy() doesn’t seem to do ECC check. Is that right?

If so, I think I need the example code for the “safe method” in the below link.

And then, how to determine if a read corrupted in the example code?

Thanks,
Calvin

@Calvin

Sys_Flash_Copy() uses the flash copy command. From the Hardware Reference Manual, section 7.4.1 item 6:

In copier mode, the flash memory is read with or without ECC, depending on the COPIER_ECC_CTRL bit of the FLASH_ECC_CTRL register.

So one way to tell if there are any uncorrected errors using Sys_Flash_Copy() would be:

FLASH_ECC_CTRL->CMD_ECC_CTRL_ALIAS = FLASH_CMD_ECC_ENABLE_BITBAND;

/* clear uncorrected error counter */
FLASH_ECC_STATUS->ECC_UNCOR_ERROR_CNT_CLEAR_ALIAS = FLASH_ECC_UNCOR_ERROR_CNT_CLEAR_BITBAND;

/* perform the copy */
Sys_Flash_Copy(src_addr, dest_addr, length, COPY_TO_MEM_BITBAND);

/* read uncorrected error counter */
uint32_t UncorrectedErrors = FLASH->ECC_UNCOR_ERROR_CNT; 

Thank you for using our community forum!

Thank you, Martin.

If UncorrectedErrors is greater than 0, ERROR_ALIAS should be COPY_ERROR right?
(FLASH_COPY_CTRL->ERROR_ALIAS == COPY_ERROR)

@martin.bela The customer is correct. Also, please remember to remove the follow-up tag from the earlier post.

@Calvin

If UncorrectedErrors is greater than 0, ERROR_ALIAS should be COPY_ERROR right?
(FLASH_COPY_CTRL->ERROR_ALIAS == COPY_ERROR)

Yes, you are correct.