I found a partial workaround by adding the flashing batch file that uses the jlink script as a post-build step. I have two versions of jlink scripts. The first flashes both internal and external flash parts. The second one only flashes the external part.
The reason that I have two scripts is an attempt to see what I can get to work by flashing both or just the external in the post-build step.
The ideal situation is to be able to flash both flashes myself in post-build, and just have the debugger load symbols and run (by *unchecking* the "Load Image" box on the "Startup" tab). But this does not work. When it runs, the code goes into the weeds every time when I do this.
So instead, I flash either one or both flashes in post-build and then allow the debug configuration to re-flash the internal one again (by *checking* the "Load Image" box on the "Startup" tab). This appears to work for some unknown reason.
Interestingly, I can flash both flashes using the same batch and jlink files on a command line and run the device, so I am fairly confident that there is nothing wrong with the flash script. Although after flashing it, I then perform a reset.
Here is the version for flashing both internal and external flashes. The one that only does the external one is identical without the first loadbin. The way that the external flashing works is that we load the image into upper RAM and a flashing utility into lower RAM and let it run.
The batch file sets up this config:
set JLINK_ARGS=-ExitOnError 1 -device MK81FN256XXX15 -if JTAG -speed 4000 -jtagconf "-1,-1" -autoconnect 1
set JLINK_COMMAND_SCRIPT=-CommanderScript %SCRIPT_PATH%
%JLINK_PATH%\JLink %JLINK_ARGS% %JLINK_COMMAND_SCRIPT%
The jlink script is this:
RSetType 3
r
loadbin C:\xxx\internal_firmware_image.bin, 0x0000
loadbin C:\xxx\external_firmware_image.bin, 0x20000000
loadbin C:\yyy\tools\qspi_192K.bin, 0x1FFF0000
wreg msp, 0x20030000
wreg psp, 0x20030000
setpc 0x1fff0400
halt
exit
I should note that in post-build, before running the flashing batch file, we run another batch file that calls a python script to process the axf/elf file into two binary files, and it is these files that get flashed into the two flash parts.