I am developing an application for the ADuCM4050 microcontroller on a custom board in CrossCore Embedded Studio (v2.9.2), using the ICE-2000 emulator for debugging via SWD.
Initially this setup worked well. However, after some use, the board stopped allowing code to be written to flash via SWD. Whenever I try to debug or run code in CCES, the ICE-2000 is able to connect to the DAP, but the flash erase command fails. I get the following output from the debugger console:
Info : SWD IDCODE 0x6ba02477
Info : CHIPID 0x02a1
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00080020 msp: 0x20004000, semihosting
lr (/32): 0x00000000
Error: command ignored for attempted access of a protected or out of memory location)
Error: failed erasing sectors 0 to 9
Error: flash_erase returned -902
This matches the behavior seen here. Unfortunately, their suggestion of erasing over UART will not work for our board design.
We encountered a similar "bricking" issue on a different project which uses the ADuCM3029. This was resolved by using the JLink CLI to perform the following command sequence before loading code:
w4 0x40018020,0x676C7565 -> 'Write user key to FLCC_KEY, unlocking the flash
w4 0x40018008,0x7 -> Write mass erase command to FLCC_CMD
This seemed to consistently resolve the issue on that part.
So overall, three questions:
- Is there any understanding of what the root cause of this "bricking" behavior might be? Can the flash become persistently write protected?
- Is there any way to directly write ADuCM4050 memory locations using SWD via ICE-2000 (in the same manner as JLink CLI), to try this mass erase command?
- Is there any other way to force a mass flash erase in CCES? TCL script I can run? Note I have ADuCM4050_DFP installed (3.4.0)
Thanks for the help,