Debugging nRF54 (w/ TFM), TFM halts after any breakpoint in app

When trying to debug my non-secure app, I can hit the break point once, but after that, any stepping or continuing results in tfm_hal_system_halt via MPC_Handler(). I'm using Cortex Debug extension with JLink gdb server.

I tracked down the issue to flash read, which I think the debugger is doing. Although it's unclear why it's trying to read anything in the TFM secure area. For reference, we had the same application running on nrf91 w/ tfm and never had this issue.

I was able to get passed this issue by setting .gdbinit with

set mem inaccessible-by-default on
# Secure flash (TF-M) - no touch!
mem 0x0000d000 0x0002d000 wo
# Non-secure flash (app)
mem 0x0002d000 0x0016a000 rw

to prevent read access of TFM flash. However, this seems like a duct tape solution. Is there some Kconfig or other I can use to prevent this issue?

My launch.json config:

{
"name": "Cortex Debug nRF54",
"type": "cortex-debug",
"request": "attach",
"cwd": "${workspaceFolder}",
"servertype": "jlink",
"toolchainPrefix": "arm-zephyr-eabi",
"device": "cortex-m33",
"executable": "./agmuster/build/agmuster/zephyr/zephyr.elf",
"rtos": "/Applications/SEGGER/JLink/GDBServer/RTOSPlugin_Zephyr.dylib",
"preAttachCommands": [
"source ${workspaceFolder}/agmuster/.gdbinit",
]
},

Thanks,

Konstantin

Related