Hi @dmiv
Thank you for your patience.
By default, when a LPC55 boots with the flash erased, it will enter to the ROM bootloader or ISP mode.
According to the UM11295, section 51.6 Debug session protocol :
On LPC55S1x/LPC551x parts, when program control is in ROM memory context (i.e.,
instructions are fetched from the ROM memory address range during the boot process),
the debug access port (AP) of CPU0 is disabled irrespective of device life-cycle state or
DCFG_SOCU settings. This mechanism is referred to as 'Boot-ROM protection' in this
manual.
Therefore, what you are probably facing is the Boot-ROM protection, which disables access to the Core 0 DAP . However, there are several ways to start a debug session for different scenarios .The section 51.6.1 Debug session with uninitialized/invalid flash image or ISP mode (that we mentioned before ) describes is one of those ways that fits your scenario with the erased flash.
In other words, the Debug mailbox , or DM-AP, is the AP that can help to get out of the Boot-ROM protection and start a debug session , gaining access to the Core 0 AP. The APSEL = 2 is the index for the DM-AP, as this AP its NXP implementation.
Regarding the pseudocode and your situation of not being follow our Debug mailbox script further, unfortunately, we are not able to test with the same tools. However, the DM-AP access should be granted by the LPC55, as it comes out of fabric or does not have any other modification.
To develop low level SWD algorithms you may refer to the ARM Cortex M33 Processor Technical Reference manual and the ARM Debug Interface Architecture Specification ADIv5.0 to ADIv5.2 ( as the M33 follow Arm debug interface (ADI) 5.0 to 5.2 spec).
Additionally, If you would like to get more support on the develop of your own programmer you may contact our Professional Engineering services Team, who can evaluate your request, or any other of our partners who develop similar algorithms. As this labor is out of the scope of our support team at this community.
Please accept my apologies for the delay, and any inconvenience.
Diego.