MQX BSP Port CodeWarrior Debug Issue

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

MQX BSP Port CodeWarrior Debug Issue

814 Views
smrakshit
Contributor I

Hi All,

twrk60n512

I have a custom board with the K60n512. I ported the BSP for twrk60n512 using the BSP Porting Wizard. My custom board uses a 4 MHz external crystal as the source and use the PEE mode at 96 MHz. I have a SampleMQX project which uses this BSP and I have used the PE settings to select the 4 MHz external crystal and PEE mode at 96 MHz.

I see the following behavior when I try to debug:

Execution starts at the program entry point in boot.S. The following lines of code are stepped through:

        /* disable interrupts and clear pending flags */

        ldr r0, =0xe000e180     /* NVIC_ICER0 - Interrupt Clear-Enable Registers */

        ldr r1, =0xe000e280     /* NVIC_ICPR0 - Interrupt Clear-Pending Registers */

        ldr r2, =0xffffffff

        mov r3, #8

ASM_LABEL(_boot_loop)

        cbz r3, _boot_loop_end

        str r2, [r0], #4        /* NVIC_ICERx - clear enable IRQ register */

        str r2, [r1], #4        /* NVIC_ICPRx - clear pending IRQ register */

        sub r3, r3, #1

        b _boot_loop

ASM_LABEL(_boot_loop_end)

        /* prepare process stack pointer */

        mrs r0, MSP

        msr PSP, r0

        /* switch to proccess stack (PSP) */

        mrs r0, CONTROL

        orr r0, r0, #2

        msr CONTROL, r0

        isb #15

After line 20 in the above segment code jumps to line 3 in the following:

#if defined(__CODEWARRIOR__)

        ASM_EXTERN(__thumb_startup)

        b ASM_PREFIX(__thumb_startup)

#elif defined(TOOLCHAIN_GCC_CW)

        /* call startup from EWL library */

        ASM_EXTERN(__thumb_startup)

        b ASM_PREFIX(__thumb_startup)

#elif defined(__IAR_SYSTEMS_ICC__)  || defined (__IASMARM__)

        ASM_EXTERN(__iar_program_start)

        b ASM_PREFIX(__iar_program_start)

After this the execution jumps to startup.c inside asm void __thumb_startup(void). The _bl_init_registers fall through fine. After that the call to _bl_init_hardware takes the control to comp.c __init_hardware(void) and from there to init_hw.c and from there to CPU.c __pe_hardware_initialize(void). The following lines of code execute there:

void __pe_initialize_hardware(void)

{

  /*** !!! Here you can place your own code before PE initialization using property "User code before PE initialization" on the build options tab. !!! ***/

  /*** ### MK60DN512ZVMD10 "Cpu" init code ... ***/

  /*** PE initialization code after reset ***/

  /* SIM_SCGC6: RTC=1 */

  SIM_SCGC6 |= (uint32_t)0x20000000UL;                    

  if ((RTC_CR & RTC_CR_OSCE_MASK) == 0u) { /* Only if the OSCILLATOR is not already enabled */

    /* RTC_CR: SC2P=0,SC4P=0,SC8P=0,SC16P=0 */

    RTC_CR &= (uint32_t)~0x3C00UL;                   

    /* RTC_CR: OSCE=1 */

    RTC_CR |= (uint32_t)0x0100UL;                    

    /* RTC_CR: CLKO=0 */

    RTC_CR &= (uint32_t)~0x0200UL;                   

  }

  /* Disable the WDOG module */

  /* WDOG_UNLOCK: WDOGUNLOCK=0xC520 */

  WDOG_UNLOCK = (uint16_t)0xC520U;     /* Key 1 */

At line 18 of the above segment on trying to step through it the control goes back to the first line of the boot.S segment of code given above and execution follows the same chain infinitely from there.

It will be great if somebody could point out what I am doing wrong for which the execution does not proceed further. I am using MQX 4.0.1 on CodeWarrior 10.2.

Thanks and with best regards,

Sushanta.

0 Kudos
1 Reply

333 Views
c0170
Senior Contributor III

Hello Sushanta Mohan Rakshit,

I had similar problem with K60 and Watchdog the last week, still has not solved it, only ported one example project and code works :-) If I did same code with created CW code, it got reset constantly.

Back to your issue, what happens if you do not single step program but set breakpoint after line 18 in __pe_initialize_hardware ?

What's the value of SRSL in MC register? The address 0x4007e001 ? That could indicate how did you get back to reset vector. There's 5 bit which is COP.  Check System Reset Status Register Low (MC_SRSL) in K60's reference manual for more information.

Regards,

c0170

0 Kudos