Hi Fidel,
First of all, we provide this application note which describes ECC handling in detail:
https://www.nxp.com/docs/en/application-note/AN5200.pdf
https://www.nxp.com/docs/en/application-note-software/AN5200SW.zip
In short, ECC can occur when erase/program operation is terminated by unexpected reset; when you over-program non-erased double word; when too many erase cycles were performed on the flash…
Yes, the ECC can be injected also by software by overprogramming. This is described in the application note.
When core accesses corrupted flash or RAM (talking about double bit ECC error), an exception is triggered. See Table 4 in the AN5200. Core registers then show more details about the root cause (details also in AN5200). In addition, EER bit in CFLASH_MCR or in DFLASH_MCR is set.
If the problem is caused by ECC error, a debugger should be able to establish the connection. If the device is reset anyway each 10ms, the debugger is probably configured to run to main function after reset. The solution is to configure the debugger to not execute the code after reset. Then you should be able to check the content of memory or to step the code to see what is happening exactly in startup files.
For example, if you use Pemicro, go to Debug Configuration and then to Starup tab a uncheck Run on reset which is enabled by default:
lukaszadrapa_0-1669887509929.png
Regards,
Lukas