Debug only works after chip erase in ST-LINK utility
Another fun update:
I was digging through the documentation on the flash option bytes and it occurred to me that when I assembled my custom board I had forgotten to install the pull-down resistor on the BOOT0 pin. I installed the resistor, and was able to debug my program yay!
I tried it again, and I got the same disconnected error. Boo!
Tried it again, and it still didn't work. Boo!
Erased the chip with the utility, and was able to debug! Yay!
Tried to re-launch the debugger again, and I got the unplugged error again. Boo!
Erased the chip with the utility, and was able to debug! Yay!
Erased the chip with the utility, and was able to debug! Yay!
Tried to re-launch the debugger again, and I got the unplugged error again. Boo!
Erased the chip with the utility, and was able to debug! Yay!
So it appears that fixing the boot0 pull-down resistor makes it at least act consistently in that something in the flash from the previously-loaded program prevents a successful debug launch. I notice that when debugging works, it gets past the breaking point with the warning: "Warn : couldn't use loader, falling back to page memory writes".
I just tried making it fail by re-launching the debugger without first erasing the chip, and the debugger worked. This time I had accidentally tried re-launching without terminating the previous debug, and once I terminated the last debug session, I re-launched and to my surprise, the debug session started successfully. Terminated and tried re-launching and it failed again. When it in place of the "Warn : couldn't use loader, falling back to page memory writes" message, I get:
Error: jtag status contains invalid mode value - communication failure
Info : Previous state query failed, trying to reconnect
Error: error writing to flash at address 0x08000000 at offset 0x00000000
Maybe when the flash has the previous program, the program also installs some kind of flash loader that fails when it runs?