CANBUS gets flooded with tderror and rderror

Hello Wolfgang,

When the TEC (Transmitter Error Counter) of a CAN node overflows (exceeds 255), in order not to block the entire bus and the other healthy nodes, the node (CAN controller) shall change its state to “Bus-off”. If this happens the on-chip CAN controller also sets the BOFF (bus-off flag) to 1.
On the STM targets, depending on the ABOM (Automatic Bus-Off Management) bit in the CAN_MCR register, the CAN controller will recover from bus-off (become error active again) either automatically or on software request. But in both cases the CAN controller has to wait at least for the recovery sequence specified in the CAN standard (128 occurrences of 11 consecutive recessive bits monitored on CANRX).
If ABOM is enabled, the CAN controller will start the recovering sequence automatically after it has entered the bus-off state. If ABOM is disabled, the software must initiate the recovering sequence by requesting the CAN controller to enter and to leave initialization mode.

Unfortunately, in Mbed OS the ABOM is disabled by default. So you have two options:

  • Either to monitor the BOFF (bus-off flag) and when set initiate the recovering sequence by requesting the CAN controller to enter and to leave initialization mode by software.

  • Or to enable ABOM (Automatic Bus-Off Management) in the _can_init_freq_direct function. You can find it in the mbed-os/targets/TARGET_STM/can_api.c file. Just comment out the existing statement and add a new one as below:

...
static void _can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz)
{
...
    /*  Use default values for rist init */
    ...
    // obj->CanHandle.Init.ABOM = DISABLE;
    obj->CanHandle.Init.ABOM = ENABLE;
    ...
}
...

If the bus failure is only occasional and the bus is then capable to produce a recovery sequence (128 occurrences of 11 consecutive recessive bits monitored on CANRX) then this might help improve your system behavior.

Best regards, Zoltan