When running the code after the download, it never reaches the main function. FLASH programming doesn’t report any verify error.
Simple manual Mass erase via Hardware | FLASH | Mass Erase before debug download may solve the problem already.
Most probably the application remains in the BAM program because specific “startup” parameters were not programmed properly in the internal FLASH or left in the BAM area from an old (different) application. After the reset, the CPU starts executing a so called BAM (Boot Assist Module) program.
The BAM searches the internal FLASH memory for a valid reset configuration halfword (RCHW). A valid RCHW is a 16-bit value that contains a fixed 8-bit boot identifier and some configuration bits, which define the location of the boot code and boot configuration options. If the BAM program does find a valid RCHW, the watchdog is enabled, the BAM program fetches the reset vector from the address of the BOOT_BLOCK_ADDRESS + 0x4, and branches to the reset boot vector. Check if valid RCHW and valid reset vector are set in the user application and programmed through the debug download. Refer to CPU reference manual for more details on BAM.