How to program a MPC56xx to run without the debugger attached?

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

How to program a MPC56xx to run without the debugger attached?

Jump to solution
2,178 Views
yibbidy
Contributor V

Hi All,

 

I am using S32DS to flash program and debug a MPC5643L and all is fine.  What I want to do is program it so that it runs from reset without the debugger pod attached.  When I reset the microcontroller (through hardware) the firmware in flash doesn’t run, with or without the debugger attached.  I've recently migrated to S32DS from Codewarrior Classic and this was not the behaviour there.

 

I've tried making a new debug configuration and done the following:

 - under the Startup tab I've selected the the checkbox "Run On Reset" and deselected the checkbox "Set Breakpoint at Main()".

 - under the Main tab I've selected the "Release" build.

 - I've deleted all breakpoints.

 

I've not had any joy making any sense from the Run Configurations dialog.  I seem to be missing some fundamental concept here and can't find any documentation about this.

 

Alternatively, is there someway I can access the flash programmer application directly and point it to the .ELF file?

 

Thanks, Shaun

Labels (2)
1 Solution
1,762 Views
martin_kovar
NXP Employee
NXP Employee

Hi Shaun,

there is little bit different problem. In S32 Design Studio startup, there is disable watchdog code at the very beginning of this file. But at the moment you try to disable watchdog, MMU is not initialized, so you are not able to access the SWT addresses. This is the cause of your issue.

When you load the code to the microcontroller via debug probe (PE Micro debug probe), this probe place you to the start of the main function at first. But when you reset the microcontroller, it starts to execute instructions from entry point, which is 0x1000. Now MMU is not configured and only addresses from range 0x1000 to 0x1FFF are accessible. MMU configuration is the part of the startup.

So the solution is following. Delete the SWT disable code from startup (or delete the symbol DISABLE_SWT from project properties) and place the following function to your code, or change the order of MMU inititialization and disable watchdog code in the startup file. MMU initialization has to be done before disabling watchdog.

void DisableWatchdog(void)
{
    SWT.SR.R = 0x0000c520;     /* Write keys to clear soft lock bit */
    SWT.SR.R = 0x0000d928;
    SWT.CR.R = 0x8000010A;     /* Clear watchdog enable (WEN) */

    /* e200 Core Watchdog Timer */

     asm("e_li  %r3, 0");
     asm ("mtspr   340, %r3");

}

Call this function in the very beginning of your main function. Now it should work correct.

Please let me know, if it is OK on your side.

Regards,

Martin

View solution in original post

0 Kudos
2 Replies
1,763 Views
martin_kovar
NXP Employee
NXP Employee

Hi Shaun,

there is little bit different problem. In S32 Design Studio startup, there is disable watchdog code at the very beginning of this file. But at the moment you try to disable watchdog, MMU is not initialized, so you are not able to access the SWT addresses. This is the cause of your issue.

When you load the code to the microcontroller via debug probe (PE Micro debug probe), this probe place you to the start of the main function at first. But when you reset the microcontroller, it starts to execute instructions from entry point, which is 0x1000. Now MMU is not configured and only addresses from range 0x1000 to 0x1FFF are accessible. MMU configuration is the part of the startup.

So the solution is following. Delete the SWT disable code from startup (or delete the symbol DISABLE_SWT from project properties) and place the following function to your code, or change the order of MMU inititialization and disable watchdog code in the startup file. MMU initialization has to be done before disabling watchdog.

void DisableWatchdog(void)
{
    SWT.SR.R = 0x0000c520;     /* Write keys to clear soft lock bit */
    SWT.SR.R = 0x0000d928;
    SWT.CR.R = 0x8000010A;     /* Clear watchdog enable (WEN) */

    /* e200 Core Watchdog Timer */

     asm("e_li  %r3, 0");
     asm ("mtspr   340, %r3");

}

Call this function in the very beginning of your main function. Now it should work correct.

Please let me know, if it is OK on your side.

Regards,

Martin

0 Kudos
1,762 Views
yibbidy
Contributor V

Hi Martin,

Thanks so much for that, my problem is solved.  I don't know how I would have managed to find that myself :smileyhappy:

I ended up moving the disable watchdog code to be below the configure MMU code in the startup.S file.  That solved it.

I had a look back through my Codewarrior Classic project and found that there was a function similar to your DisableWatchdog(void) described above that was called from main().  I didn’t move it across to S32DS as it wouldn't compile (different GCC assembler semantics and BookE) and I noted that startup.S disabled the SWT anyway.  Well apparently not as you described it.

Thanks again for your help.

Regards, Shaun