On the MCU, please check if the ISP pin is activated (ie. pulled LOW). Otherwise, every time the JTAG / SWD is reset, the MCU will go into bootROM, instead of the user program.
If the ISP pin is not pulled LOW, please check the IDE's configuration. For Keil, the 'Connect' option in Project ->Options for xxx ->Debug->Settings must be set to 'with pre-reset'. For IAR, set Project->Options->Debugger->"JTAG Name"->Reset to "Normal". If your project is using an external JTAG configuration (*.ini in Keil and *.mac in IAR), please make sure that it is configured to point to internal Flash or SRAM.