Page 1 of 1

CAN overflow not reset?

Posted: Sat Mar 12, 2016 11:34 am
by avrhack
I've got an issue with error handling on CAN receives. If I end up with an overflow error, the only way to fix things is to re-power the STM32. I presume a software reset would work but haven't tried it yet.

I note the following very old thread viewtopic.php?f=16&t=1361&hilit=overflow+can but that's a throughput issue whereas the one I'm having is that the overflow flag is not reset.

Looking at the driver code the error is flagged as one would expect here:

Code: Select all

canp->can->RF0R = CAN_RF0R_FOVR0;
osalSysLockFromISR();
osalEventBroadcastFlagsI(&canp->error_event, CAN_OVERFLOW_ERROR);
osalSysUnlockFromISR();

Looking at the data sheet it's clear that the overflow flag is only reset by software, but the only place I can see that happening is in can_lld_receive. It does not appear to be done by stopping/starting the CAN peripheral. In my case that's what I do when I get errors.

As a suggestion, when stopping the peripheral would it not be better to use the software reset bit in the MCR? At the moment the code resets the MCR to its power-on default of 0x00010002 whereas a setting of 0x0008000 would cause a 'proper' reset of CAN and that would automatically return the MCR to 0x00010002 as well as all the other CAN registers to default.

I have done this 'hack' on my version of ChibiOS to try it but as the fault I'm seeing can take days or even weeks to appear it's not going to be a quick confirmation that this is the fix.

Anyone else seen this?

Re: CAN overflow not reset?

Posted: Sat Mar 12, 2016 11:39 am
by Giovanni
Please let me know if that change solves the problem for you. If so then it will be included.

Giovanni

Re: CAN overflow not reset?

Posted: Sun Mar 13, 2016 6:15 pm
by avrhack
Managed to replicate the problem and it wasn't specifically this reset. The change I suggested didn't make anything worse but nor did it solve anything so I guess no point in changing it.

What I did for my specific case was just loop around reading frames after an overflow error as it's clear from the driver code that will reset the overflow error flag.

Still getting CAN errors but this is expected when I flood/stress the bus and the USB gateway I have is unable to keep up - will need to be more intelligent about how I pack CAN frames into USB as I'm using one per bulk frame which is a waste. Will also need to put some buffering into the mix as well I suspect.

However at least now, once the bus traffic backs off the whole thing recovers whereas before it needed a press of the big red button so that's progress of sorts!