Debugger and CAN

Discussion to talk about software related topics only.
Post Reply
dpursell
Posts: 20
Joined: Thu Aug 05, 2010 3:15 pm

Debugger and CAN

Post by dpursell »

I am running some code on a MOD5234 that uses CAN. I've noticed that when debugging through NBEclipse, the CAN works perfectly until the debugger stops the program, and then after continuing execution I won't receive any more CAN messages. When I use taskscan or pause the debugger again, it tells me that the code is always waiting on the CAN fifo. This behavior occurs both when hitting a breakpoint and when using the Suspend button to halt execution. The code is still running, I can interact over the the serial port and access the hosted webpage just fine. Has anyone else experienced this issue or have any ideas for troubleshooting?

Here is the relevant code if it helps. It runs in its own task (prio=49).

Code: Select all

J2[41].function( PIN_GPIO );
J2[44].function( PIN_GPIO );
J2[41].hiz();
J2[44].hiz();
J2[39].function( PINJ2_39_CAN0RX );
J2[42].function( PINJ2_42_CAN0TX );
if( CanInit(500000, 0, 4) != CAN_OK )
  std::cout << "Error: CAN Failed to intialize" << std::endl;
OS_FIFO fifo;
OSFifoInit(&fifo);
RegisterCanRxFifo(0, &fifo);

while (1)
{
  CanRxMessage canRaw(&fifo, 0);
  if( canRaw.IsValid() )
  {
    // Handle the CAN message
  }
}
Thanks,
David
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Debugger and CAN

Post by rnixon »

Does it vary depending on when you stop it? It may be that if the CAN is active when the halt occurs the h/w is in an undefined state.
v8dave
Posts: 333
Joined: Thu Dec 31, 2009 8:31 pm

Re: Debugger and CAN

Post by v8dave »

I get the same with a Philips SJA1000 device I am using with a Rabbit processor. If I hit a breakpoint and delay too long, the CAN stops working.

What is happening for me is that the bus eventually goes OFF BUS because of too many errors or in my case, overflow of the receive buffer. I detect this in code and then clear the errors and restart the bus and then it works again.

You may have to do something similar. Check the ERROR states of the CAN controller and you may find it has gone off bus. Simply reset the errors and the bus should work again.

Good to know this though as I am about to start the development of CAN on my MOD5234 based system in the next few weeks.

Dave....
dpursell
Posts: 20
Joined: Thu Aug 05, 2010 3:15 pm

Re: Debugger and CAN

Post by dpursell »

Thanks for the suggestions, it led me to a solution that's a bit strange, but seems to work. The status registers still appeared to contain valid values after the CAN stopped working, but just the act of reading the registers was enough to snap it back into a working state. I narrowed it down to the timer register specifically, so instead of waiting forever on incoming CAN, I do this:

Code: Select all

CanRxMessage canRaw(&fifo, TICKS_PER_SECOND);
int temp = sim.flexcan.timer; // kicks us back into run mode if we stopped during debug
if( canRaw.IsValid() )
{
  // process CAN message
}
and it seems to do the trick.

Thanks again,
David

Edit: for anyone else who tries this, you need to #include <sim5234.h> to access sim.flexcan.timer
Post Reply