Debug only works after chip erase in ST-LINK utility
I have a custom board that I am trying to debug from an ST-Link devleopment board. After much experimentation, I found that I can successfully load and debug a program, but only if the chip had previously been erased with the STM32 ST-LINK utility application. Otherwise, I always get a message of "unplugged target during debug session"
Here's the console log from a failed launch:
Open On-Chip Debugger 0.10.0-dev-00278-ga53935e-dirty (2017-05-09-09:25)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 4000 kHz
adapter_nsrst_delay: 100
Info : clock speed 4000 kHz
Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED
Info : STLINK v2 JTAG v27 API v2 M v15 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 77.475003
Info : STM32L082CZYx.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : accepting 'gdb' connection on tcp/3333
STM32L082CZYx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x08003cb4 msp: 0x20005000
STM32L0: Enabling HSI16
Info : Device: STM32L0xx (Cat.5)
Info : STM32L flash has dual banks. Bank (0) size is 96kb, base address is 0x8000000
Info : Device: STM32L0xx (Cat.5)
Info : STM32L flash has dual banks. Bank (1) size is 96kb, base address is 0x8018000
STM32L082CZYx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x08003cb4 msp: 0x20005000
STM32L082CZYx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x08003cb4 msp: 0x20005000
STM32L0: Enabling HSI16
Error: jtag status contains invalid mode value - communication failure
Info : Previous state query failed, trying to reconnect
STM32L082CZYx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x20000004 msp: 0x20005000
Error: error writing to flash at address 0x08000000 at offset 0x00000000
STM32L082CZYx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x1ff00404 msp: 0x200014d0
Info : dropped 'gdb' connection
After a chip erase, the console log from a successful launch looks like this:
Open On-Chip Debugger 0.10.0-dev-00278-ga53935e-dirty (2017-05-09-09:25)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
none separate
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 4000 kHz
adapter_nsrst_delay: 100
Info : clock speed 4000 kHz
Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED
Info : STLINK v2 JTAG v27 API v2 M v15 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.257482
Info : STM32L082CZYx.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : accepting 'gdb' connection on tcp/3333
STM32L082CZYx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0xf0000000 pc: 00000000 msp: 00000000
STM32L0: Enabling HSI16
Info : Device: STM32L0xx (Cat.5)
Info : STM32L flash has dual banks. Bank (0) size is 96kb, base address is 0x8000000
Info : Device: STM32L0xx (Cat.5)
Info : STM32L flash has dual banks. Bank (1) size is 96kb, base address is 0x8018000
STM32L082CZYx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0xf0000000 pc: 00000000 msp: 00000000
STM32L082CZYx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0xf0000000 pc: 00000000 msp: 00000000
STM32L0: Enabling HSI16
Warn : couldn't use loader, falling back to page memory writes
STM32L082CZYx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x1ff00404 msp: 0x200014d0
I'm also getting the same behavior when I use a Nucleo STM32L073 board.
After searching some other problems and responsese I've tried several combinations of the settings of the reset_config (can someone point me to a source for what they mean?) in the Debug.cfg file, but I'm getting the same behavior.