Project runs with debugger, but will not run without debugger

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Project runs with debugger, but will not run without debugger

1,693 Views
Kratz
Contributor IV

What kind of set up problem is this?  The MKE02Z64VLD2 M0+ processor operates 2 SPI modules and PWM inverter output operate just fine when the debugger (Universal Multilink) is attached. If the debugger is removed with power on, the project works fine.  However, if the power is removed discharging the supply completely, upon power up the project will not run with no debugger attached).  Processor Expert was used to generate the projects inits.  The external 32.768 KHz crystal runs at frequency at high gain with a beautiful sine-wave.  The Kinetis Design Studio (Version: 3.2.0) is used for this project.

Kinetis Microcontrollers‌@@@##

Here is the Processor Expert clock initialization code:

/* System clock initialization */
/* ICS_C2: BDIV|=1 */
ICS_C2 |= ICS_C2_BDIV(0x01); /* Update system prescalers */
/* SIM_BUSDIV: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,BUSDIV=0 */
SIM_BUSDIV = 0x00U; /* Update system prescalers */
/* Switch to FEE Mode */
/* ICS_C2: BDIV=1,LP=0 */
ICS_C2 = (uint8_t)((ICS_C2 & (uint8_t)~(uint8_t)(
ICS_C2_BDIV(0x06) |
ICS_C2_LP_MASK
)) | (uint8_t)(
ICS_C2_BDIV(0x01)
));
/* OSC_CR: OSCEN=1,??=0,OSCSTEN=0,OSCOS=1,??=0,RANGE=0,HGO=1,OSCINIT=0 */
OSC_CR = (OSC_CR_OSCEN_MASK | OSC_CR_OSCOS_MASK | OSC_CR_HGO_MASK);
/* ICS_C1: CLKS=0,RDIV=0,IREFS=0,IRCLKEN=0,IREFSTEN=0 */
ICS_C1 = (ICS_C1_CLKS(0x00) | ICS_C1_RDIV(0x00));
while((ICS_S & ICS_S_IREFST_MASK) != 0x00U) { /* Check that the source of the FLL reference clock is the external reference clock. */
}
while((ICS_S & 0x0CU) != 0x00U) { /* Wait until output of the FLL is selected */
}
/*** End of PE initialization code after reset ***/

Manual: https://www.nxp.com/docs/en/reference-manual/MKE02Z64M20SF0RM.pdf  Clock section begins on page 263.

Labels (1)
4 Replies

1,393 Views
Kratz
Contributor IV

In this case,  I collaborated on a project with another person. The processor Flash size was increased, but the memory starting point did not change, so somehow the code would run on the debugger, but fail without the debugger.  

0 Kudos

1,393 Views
BlackNight
NXP Employee
NXP Employee

Another reason why an application might run with the debugger, but not without it (beside semihosting):

the debugger initializes some registers/peripherals used for debug, especially the ARM, e.g. the DWT block (see Cycle Counting on ARM Cortex-M with DWT | MCU on Eclipse ). So if your application is using such a functionality, you have to initialize stuff from your application too. For the case in that article I have to initialize the DWT clocks to get it running without the debugger, because the debugger is otherwise doing this.

I hope this helps,

Erich

1,393 Views
davidsherman
Senior Contributor I

I have seen similar behavior on a KE06.  Is the debug console enabled?  I had to disable that in order to get it to run from flash properly.

1,393 Views
BlackNight
NXP Employee
NXP Employee

Hi Kevin,

you might check two possible reasons:

- ezPort (see Disabling EzPort on NXP Kinetis to Solve Power-On Issues | MCU on Eclipse ), but I believe the KE does not have that hardware, so this might not be the case

- are you doing any printf() (semihosting)? They can be blocking without a debugger attached.

- does it run to main()? Use a LED or a GPIO pin to check to which point the application runs.

I hope this helps,

Erich