Arm Cortex-M: Application does not run correctly after download into Flash

01-Aug-2024

Two different applications (A and B) are added into a winIDEA workspace. Application A is debugged and then Application B is downloaded and debugged.

Once the Application B is downloaded the core is not stopped on the correct reset vector. Running the core from this state results in Hard Fault exception. Resetting the core after download but before running, fixes the issue. Further on, Application B runs OK when the device is running standalone or is in reset after download.


Possible solution

1.  Open Hardware | CPU Options | Reset page.

2. Enable the option Reset CPU after Download.


Immediately after reset, the Cortex-M device loads stack pointer (SP) and program counter (PC) registers with values from Flash (usually address 0x0000’0000 and 0x0000’0004 respectively). winIDEA proceeds with programming Application B, the SP and PC are still loaded with the values from Application A. After programming operation completes, the Flash now contains changed stack pointer value and reset vector. However, for the core to correctly execute the new Application B  the change values must be updated into respective core registers. This can be done multiple ways in winIDEA, but, for this specific use case, it is recommended that you configure an automatic reset of the device after programming (Download).

Was this answer helpful?