Questions about the frequent interruptions to crash

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

Questions about the frequent interruptions to crash

Jump to solution
1,650 Views
jinchengxie
Contributor I

    I there was a problem in the application MC9S12XET256 chip:When the CPU has frequently CAN interrupt and a serial port interrupt occurs, the program will occasionally in crash situation.When back to normal after close the COP, is there a better handle this suggestion?

    And why the program crashes, does not automatically produce watchdog reset? whether you need to do in watchdog interrupt processing can trigger watchdog reset

 

Regards,

xjc

Labels (1)
0 Kudos
Reply
1 Solution
1,429 Views
RadekS
NXP Employee
NXP Employee

Hi XJC,

I am glad that it works now.

The problem is that the COP do not cause any watchdog interrupt and CopInterrupt() isn’t an interrupt routine (ISR).

When COP is not triggered properly, it will reset MCU. If COP is detected as reset source, vector at address 0xFFFA will be fetched. This vector points to your CopInterrupt() routine.

Similar is valid also for CM reset (vector at 0xFFFC).

POR/External/Illegal Address resets will fetch reset vector at address 0xFFFE.

So, the CopInterrupt() routine is executed as first code after MCU reset (while the stack is not initialized yet) and RTI instruction at end of routine doesn’t have sense (there isn’t any context which might be restored). The CopInterrupt() (CMInterrupt()) routine must end by jump into some code. For example:

asm jmp _Startup;

If you do not want different behavior/code for POR/CM/COP resets, you may define _Startup() routine for all three vectors inside prm file. For example:

VECTOR 0 _Startup //Power On, External, Illegal Address resets

VECTOR 1 _Startup //Clock Monitor reset

VECTOR 2 _Startup //COP Watchdog reset

In that case you don’t need to define CopInterrupt()/CMInterrupt() routines.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
9 Replies
1,429 Views
RadekS
NXP Employee
NXP Employee

Hi XJC,

It is hard to say what could be a reason for that crash. We need more details about that topic.

For example, what means “crash situation” (endless loop, code run away, stop communication, ….)?

The problem might be in stack overflow, unhandled interrupt, collision in access to peripherals, memory lack, …

But, this is just shooting from the hip.

Do you use XGATE? If yes, do you use semaphores? Do you use interrupt nesting? Did you handle all interrupts? Did you try to increase the stack? Did you use any other data type than int in shared memory?

If the COP is correctly initialized and the code “crash” without COP reset, the CPU (XGATE) must execute some code which continues in COP triggering.

In fact, you should trigger watchdog only in main code (the interrupts may work fine while main code hangs in some dead loop). However, this expects that ISR will be shortest as possible without any wait loops. If the ISR length in cycles cannot be determined, we have to trigger watchdog also inside these ISR routines and this might be the source is a potential danger.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,429 Views
jinchengxie
Contributor I

Hi Radek,

    After debugging found out the problem:Program to jump to the watchdog interrupt, and did not back out of the interruption, and does not cause watchdog reset.

    But,When inside the watchdog interrupt execution JMP statements(asm{jmp $C000;};) , program can trigger watchdog reset properly;If you do not execute the statement,Will not trigger watchdog reset,And the program crashes(code run away), all not output pin.What's the problem?

{A46274AA-909C-4DC5-85A6-C1B6580B21B6}.bmp

Regards,

xjc

0 Kudos
Reply
1,429 Views
jinchengxie
Contributor I

    Add the instructions above:while main code hangs in some dead loop,Can cause watchdog reset.

    But,while interrupt(timer/serial/CAN interrupt) hangs in long delay (the COP timeout),The program will enter the watchdog interrupt,but can not cause watchdog reset;unless,When inside the watchdog interrupt execution JMP statements(asm{jmp $C000;};) , program can trigger watchdog reset properly;

Regards,

xjc

0 Kudos
Reply
1,430 Views
RadekS
NXP Employee
NXP Employee

Hi XJC,

I am glad that it works now.

The problem is that the COP do not cause any watchdog interrupt and CopInterrupt() isn’t an interrupt routine (ISR).

When COP is not triggered properly, it will reset MCU. If COP is detected as reset source, vector at address 0xFFFA will be fetched. This vector points to your CopInterrupt() routine.

Similar is valid also for CM reset (vector at 0xFFFC).

POR/External/Illegal Address resets will fetch reset vector at address 0xFFFE.

So, the CopInterrupt() routine is executed as first code after MCU reset (while the stack is not initialized yet) and RTI instruction at end of routine doesn’t have sense (there isn’t any context which might be restored). The CopInterrupt() (CMInterrupt()) routine must end by jump into some code. For example:

asm jmp _Startup;

If you do not want different behavior/code for POR/CM/COP resets, you may define _Startup() routine for all three vectors inside prm file. For example:

VECTOR 0 _Startup //Power On, External, Illegal Address resets

VECTOR 1 _Startup //Clock Monitor reset

VECTOR 2 _Startup //COP Watchdog reset

In that case you don’t need to define CopInterrupt()/CMInterrupt() routines.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,429 Views
jinchengxie
Contributor I

Add the instructions above:The main and the PRM file inside the key code as shown.

33.bmp

0 Kudos
Reply
1,429 Views
RadekS
NXP Employee
NXP Employee

Hi XJC,

You set COPCTL=0x47. So, the watchdog will reset MCU after 16 million of OSC cycles.

Are you sure, that your “for” loops are longer than this interval?

Note: you cannot debug COP reset by BDM. The BDM connection is interrupted in case of any reset.

Since the MODC and BKGD signals share the same pin, the MCU will be reset into special/normal mode randomly.

Note: The CopInterrupt() routine without any jump don’t have any sense. You may add here a loop and LED signalization of COP reset.

For example:

//function prototype of _Startup function (Start12.c)

void _Startup(void);

//******************************************************************************

// COP interurpt

//******************************************************************************

#pragma CODE_SEG NON_BANKED

interrupt 2 void COP_ISR(void)

{

    DDRA = 0xff;

    PORTA = 0x00;          //LEDs on - show we entered the COP_ISR

    

    for(i=0; i<60000; i++)  //delay

    {

        asm nop;

    }

    PORTA = 0xff;

    asm jmp _Startup;      //jump to power-on reset vector

    // !!! RTI instruction cannot be executed because this is not interrupt !!!

}

#pragma CODE_SEG DEFAULT

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,429 Views
jinchengxie
Contributor I

Hi Radek,

When adding notes, not careful comments of the code.I'm sure the “for” loops is long enough,And the program has jumped to the CopInterrupt(),And all the pins have no output.as shown in the figure,Why is the difference between two things?

I have understood you said the other.Thanks!

44.bmp

Regards,

xjc

0 Kudos
Reply
1,429 Views
RadekS
NXP Employee
NXP Employee

Hi XJC,

It hard to say what exactly happened in this extreme situation. Theoretically, it might be debugged on assembler level.

It is like a jump from the window. Sometimes you may fall on your legs, sometimes on your head. It might depend left or right leg used for the jump start. And always it depends on floor level from which you jumped.

Since, the CopInterrupt() is not ended properly by asm JMP command, the RTI will restore some data from the stack. I suppose that the difference will be just in stack content or stack pointer during MCU reset.

The Situation 2 is a just happy coincidence where RTI instruction will fill program counter by some valid data.

I suppose that i and j variables are probably not static and they exist on the stack. This may cause different stack pointer value and the program counter is filed by invalid data after the watchdog reset.

Anyway, it is code runaway in both situations with happy end only in one case.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,429 Views
jinchengxie
Contributor I

Hi Radek,

According to what you have said, After I define _Startup() routine for all three vectors inside prm file,problem has been solved.But,I have a question:Why while main code hangs in some dead loop,Can cause watchdog reset.I think:In this case, also jumped to the CopInterrupt().

Regards,

xjc

0 Kudos
Reply