Author Topic: uTasker & problems reseting FlexCan  (Read 16550 times)

Offline izzz

  • Newbie
  • *
  • Posts: 4
    • View Profile
uTasker & problems reseting FlexCan
« on: March 31, 2010, 03:12:42 PM »
Hello,

I'm working with uTasker and MCF52235 microcontroller and I have problems when I try to SoftReset FlexCAN.

When I try to send/receive CAN messages, CAN_OTHER_INTERRUPT in uTasker is awaken. When that happens I try to reset FlexCAN, but often an unhandled exception (0x40602000) occurs when doing so the program enter in the while(1) defined inside de handler undef_int(void) in M5223X.c and stands there forever.

All the CAN interrupts are initialized (_CAN_buf_Interrupt0 to 15, _CAN_bus_off_Interrupt and _CAN_error_Interrupt) so every one has a handler.

I'm having problems when I use long cables between two boards communicated by CAN bus. I have the termination resistors at the end and at the begin of the cables.

This is my SoftReset FlexCAN code:

void fnResetCAN(void){
    unsigned int counter;
    if (CAN_ERRSTAT & (CAN_BUS_IDLE|CAN_ERROR_PASSIVE)){
    unsigned int imask = CAN_IMASK;
    unsigned int canmcr = CANMCR;
        CANMCR |= CAN_SOFTRST;
        for (counter=0; counter<500, (CANMCR & CAN_SOFTRST);counter++){}
          CAN_IMASK = imask;
       CANMCR |= canmcr;
       CANMCR &= ~(CAN_FRZ | CAN_HALT);

    }
}

Hope you can help me,

Ivan

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3243
    • View Profile
    • uTasker
Re: uTasker & problems reseting FlexCan
« Reply #1 on: March 31, 2010, 08:33:23 PM »
Hi Ivan

I would first try solving the problem that you are having when performing a soft reset.
Also an exception error will result in the undefined interrupt being called (this is more likely than an undefined interrupt from a peripheral source).

Follow the instructions here to try to identify the code that is causing this:
http://www.utasker.com/forum/index.php?topic=123.msg468#msg468

Generally only the CAN_ACK_ERROR (either CAN_TX_REMOTE_ERROR or CAN_TX_ERROR) are expected during normal operation when a destination doesn't respond. Other error sources are (BIT1ERROR | BIT0ERROR | CAN_CRC_ERR | CAN_FRM_ERR | CAN_STF_ERR), which generate the warning error event that is occurring. You can identify the actual error in more detail if you look at the variable ulError (copied from CAN_ERRSTAT) when the event is generated (in the _CAN_error_Interrupt() interrupt handler) - this may help identify the source of un-reliability.

Regards

Mark
« Last Edit: March 31, 2010, 10:59:52 PM by mark »

Offline izzz

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: uTasker & problems reseting FlexCan
« Reply #2 on: April 01, 2010, 09:55:47 AM »
I tried what you said and here's the results:

1- The Stack Pointer is 0x20007F6C



2- I opened a View Memory window and found:
   + Exception 0x40602000:
      Format = 0x4
      Status Reg = 0x2000
      Vector = 0x18 (Reserved)
      Fault Status = 0x0 (Reserved)
   + Program Counter: 0x00020B9C



I don't know where's the problem, the vector and fault status are reserved.

3- Using the call stack I can't not found nothing interesting except that the exception is fired when accessing fnCAN



4- It seems that's a problem setting the SOFT_RESET bit, isn't it?



I replaced the for loop for a while loop but is always the same, it seems that the exception is fired always before entering in the wait-for-softreset-done loop

Any idea?

Regards,

Ivan
« Last Edit: April 01, 2010, 10:00:25 AM by izzz »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3243
    • View Profile
    • uTasker
Re: uTasker & problems reseting FlexCan
« Reply #3 on: April 01, 2010, 12:49:43 PM »
Hi Ivan

The vector 0x18 is 24, which is a spurious interrupt.

This suggests that the setting of the CAN_SOFTRST is causing a spurious interrupt to be generated. I don't know why this is at the moment but check first than no CAN interrupt priorities (level/priority) collide with any other interrupts in the system (see app_hw_m5223x.h). Such a collision is one possible cause of spurious interrupts.

I will do some thinking on how such an event can be possible - at the moment such an occurrence is new to me...

Regards

Mark

PS: Try disabling interrupt before executing the soft reset and enabling them again afterward. Maybe there is a difference which may help explain something.


Offline izzz

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: uTasker & problems reseting FlexCan
« Reply #4 on: April 01, 2010, 02:02:41 PM »
I checked the interrupt priorities. There was a non-CAN interrupt (RXFRAME_INTERRUPT_PRIORITY) with same level/priority as CAN_interrupt_15. I changed it to level 4, priority 2 (because that lvl/pri was free) but still gets stuck.

I tried disabling and enabling the interrupts before and after softreset and seems that works. That can explain why and spurious interrupt is fired?

Regards,

Ivan