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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

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

633 次查看
kai_liu
Senior Contributor I

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

         while(1);

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.

标记 (1)
1 回复

392 次查看
kai_liu
Senior Contributor I

By moving boot_app() to very first place before pll_init() of bootloader, the dowloaded image works.

It seems the setup of MCG order really makes sense. It can not be setup twice?