AnsweredAssumed Answered

The user app doesn't run with USB MSD bootloader, but it works in a debugger

Question asked by Kai Liu on Oct 28, 2013
Latest reply on Oct 28, 2013 by Kai Liu

With my USB MSD bootloader, I can download S-rec file successfully. The image file is located at correct address (0x8000) with right content. That could be verified in IAR memory Window.


But it doesn't run as my expectation.


Since IAR supports debug without download. And obviously, both bootloader and user code are already programmed into flash memory. So I can debug different program with same flash image.


The main() of user code is not startup code. So I using two breakpoints to enforce debugger to stop at __startup, not _main. It will complain there are too many breakpoints, choose stop to prevent it going to main. By this means, I can debug user code starts at 0x8000.


So I load MSD bootloader in debugger, I found the function boot_app() works. The SP/PC are setup via R0/R1, and it jumps to user application code, runs through regular __startup, and common_startup, and stops at following step.


       mcg_clk_hz = pll_init(CLK0_FREQ_HZ,  /* CLKIN0 frequency */

                             LOW_POWER,     /* Set the oscillator for low power mode */

                             CLK0_TYPE,     /* Crystal or canned oscillator clock input */

                             PLL0_PRDIV,    /* PLL predivider value */

                             PLL0_VDIV,     /* PLL multiplier */

                             MCGOUT);       /* Use the output from this PLL as the MCGOUT */



       /* Check the value returned from pll_init() to make sure there wasn't an error */

       if (mcg_clk_hz < 0x100)     // It returns as 0x01, presents as FEI



BTW, the user code is FRDM_KL25ZDemo, which comes from FRDM, linked with modified icf.


I double checked my init code in bootloader, it seems pll_init() has been called for USB clock setup before jumping to user code.


Is that make sense?


Maybe we should take care SP/PC/SCB_VTOR as well as MCG and their setup orders?

I can share my sources if anyone wants to help.