We have developed own SWD + GPIO bitbang SW to program onboard S32K118 MCU.
After performing SWD connection steps we have executed MassErase commands. Then the system left in some state that MDM-AP-CTRL registershows always 0x00000001 - MassErase is ongoing and memory access through AHB-AP is failing.
## 0. DP Init
SWDReadDP 0x00 # returned 0x0BC11477
SWDWriteDP 0x00 0x0000001E
SWDWriteDP 0x01 0x00000000
SWDWriteDP 0x01 0x50000000
SWDReadDP 0x01 # returned 0xF0000040
## Reading ID's
SWDWriteDP 0x02 0x010000F0
SWDReadAP 0x03 # returned 0x00000000
SWDReadDP 0x03 # returned 0x001C0020
SWDWriteDP 0x02 0x000000F0
SWDReadAP 0x03 # returned 0x00000000
SWDReadDP 0x03 # returned 0x04770031
#DP_ID = 0x0BC11477
#AP_ID = 0x001C0020
#AHB_ID = 0x04770031
1. AN12130 MassErase
SWDReadAP 0x00 # returned 0x00000000
SWDReadDP 0x03 # returned 0x00000034
# MDM-AP Mass erase enabled
SWDWriteAP 0x01 0x00000009 #MDM_AP_CTRL_MASS_ERASE | MDM_AP_CTRL_SYSTEM_RESET
SWDReadAP 0x01 # returned 0x00000001
SWDReadDP 0x03 # returned 0x00000001
SWDReadAP 0x01 # returned 0x00000001
SWDReadDP 0x03 # returned 0x00000001
## AN12130 SWD connection steps
SWDWriteDP 0x02 0x01000000
SWDWriteAP 0x01 0x00000008
SWDReadAP 0x00 # returned 0x00000001
SWDReadDP 0x03 # returned 0x00000034
...
SWDReadAP 0x00 # returned 0x00000000
SWDReadDP 0x03 # returned 0x0000003E # Flash is initialized
SWDReadAP 0x01 # returned 0x00000000
SWDReadDP 0x03 # returned 0x00000001
#MDM-AP ctrl: 0x00000001 # MassErase is ON???
#MDM-AP reset + debug request
SWDWriteAP 0x01 0x0000000C
#MDM-AP Clearing Reset
SWDWriteAP 0x01 0x00000004
SWDReadDP 0x01 # returned 0xF0000040
#DP_CTRL: 0xF0000040
#DP_CTRL_READOK bit set
SWDWriteDP 0x02 0x01000000
SWDReadAP 0x00 # returned 0x00000000
SWDReadDP 0x03 # returned 0x00000034
#MDM-AP Status: 0x00000034
#System is secured.
#System is in RESET
#System can be mass erased
SWDReadAP 0x01 # returned 0x00000000
SWDReadDP 0x03 # returned 0x00000001
#MDM-AP Ctrl: 0x00000001
#Mass erase is ON ???
Hello Pauli,
In the following section explains a reason why this bit is asserted in the MDM-AP register:
If the MCU is not secured it could be possible to recover from this state writing o the FSEC register but if this is the case it will be impossible to program again this MCU.
Best regards,
Alexis Andalon