CERB40 II crashes when errors on CANBus (NETMF 4.3)

When a problem occurs on the CANBus the ErrorReceived event of ControllerAreaNetwork is never hit. Instead the CERB40 crashes (debugger detached and watchdog restart if enabled).

The problem can be easily reproduced by shortening the canbus for a short time.
It is not clear if Reset should be called in error handling code. Anyway the error handling code is never called!

Test code used

public static void Main()
{
    ControllerAreaNetwork  canChannel;
    // just private timings, but use any for test
    var timings = new ControllerAreaNetwork.Timings(3, 12, 8, 64, 1, true);
    canChannel = new ControllerAreaNetwork(ControllerAreaNetwork.Channel.One, timings);

    canChannel.ErrorReceived += (s, e) =>
    {
        Debug.Print("Error on CAN: " + e.Error.ToString());
        s.Reset();
    };

    canChannel.MessageAvailable += (s, e) =>
    {
        var m = s.ReadMessage();
        Debug.Print("Message received id: " + m.ArbitrationId.ToString());
    };

    canChannel.Enabled = true;

    while (true)
    {
        canChannel.SendMessage(new ControllerAreaNetwork.Message() {
            ArbitrationId = 11,
            Data = new Byte[] { 1, 2, 3, 4, 5, 6, 7, 8 },
            Length = 8 });
        Thread.Sleep(200);
    }

}

@ LGOR - We’ll take a look and see if we can reproduce the issue.

@ LGOR - This should be fixed for the next release.

Thanks for feedback. Any timeframe for next release ?

@ LGOR - Likely within the next few days.

CERB40 || seems to crash again when upgrading from SDK version 4.3.7.9 (SDK 2015 prerelease) to version 4.3.7.10 (2015 Release)

After upgrading my device my code (which runs fine on 4.3.7.9) crashes after a few seconds. I was able to isolate the problem in the canbus SendMessage function which crashes the module after some successful sends.

Some remarks:

  • Canbus runs fine when only receiving, though I receive from time to time a canbus 3 error
  • When sending I get canbus 1 errors and the module crashes after some sends (from time to time SendMessage throws a System.Exception (stack trace NativeSendMessage)
  • I did not find an explanation of the error codes 1 and 3 in the documentation

My test code

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.Pins;
using System.Threading;
using GHI.IO;

namespace CanTest
{
public class Program
{
static OutputPort LED; // led to check running
static bool sendCan = false;
static int cntr = 0;

    private static void TimerTick100mS()
    {
        LED.Write((cntr++ % 5) == 0);       // toggle led every 500 mSec
        sendCan = true;                     // send message every 100 mSec
    }


    public static void Main()
    {
        LED = new OutputPort(FEZCerb40II.Gpio.PB5, false);
        var timer = new Timer(callback => TimerTick100mS(), null, 500, 100);

        // Set some private timings and create canbus network
        int PhaseSegment1 = 12;
        int PhaseSegment2 = 8;
        int BaudRatePrescaler = 4*16;
        int propagation = 3;
        var timings = new ControllerAreaNetwork.Timings(propagation, PhaseSegment1, PhaseSegment2, BaudRatePrescaler, 1, true);
        var canChannel = new ControllerAreaNetwork(ControllerAreaNetwork.Channel.One, timings);

        Byte[] outputData = new Byte[8];

        // Handle error event
        canChannel.ErrorReceived += (s, e) =>
        {
            Debug.Print("Error on CAN: " + e.Error.ToString());
            s.Reset();
        };

        // Handle receiver event
        canChannel.MessageAvailable += (s, e) =>
        {
            var m = s.ReadMessage();
            try
            {
                var module = m. ArbitrationId >> 6;
                var messageType = m.ArbitrationId & 0x1f; 
                Debug.Print("Message " + messageType.ToString() + " from " + module.ToString());
            }
            catch (Exception err)
            {
                Debug.Print("Error handling CAN message: " + err.ToString());
            }
        };

        // enable controller
        canChannel.Enabled = true;

        while (true)
        {
            if (sendCan)
            {
                sendCan = false;

                // Create some message
                uint moduleNr = 2;
                uint messageID = (moduleNr << 6) + 1;
                var message = new ControllerAreaNetwork.Message() { ArbitrationId = messageID, Length = 8, Data = new Byte[8], IsExtendedId = false, IsRemoteTransmissionRequest = false };
                
                try
                {
                    bool ok = canChannel.SendMessage(message);      // Crashed Cerb40 after some successfull sends !!!
                    Debug.Print(ok ? "Send ok" : "Send NOK");
                }
                catch (Exception err)
                {
                    // From time to time we get a System.Exception ????
                    Debug.Print("Exception on sendmessage " + err.Message);
                }
            }
            Thread.Sleep(10);
        }
    }
}

}

Debug output

Loading start at 8079dd4, end 809fd60

Assembly: mscorlib (4.3.1.0) Assembly: Microsoft.SPOT.Native (4.3.1.0) Assembly: Microsoft.SPOT.Hardware (4.3.1.0)
Assembly: Microsoft.SPOT.Graphics (4.3.1.0) Assembly: Microsoft.SPOT.TinyCore (4.3.1.0)
Assembly: Microsoft.SPOT.IO (4.3.1.0) Assembly: System.IO (4.3.1.0) Assembly: Microsoft.SPOT.Hardware.Usb (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.3.1.0) Assembly: Microsoft.SPOT.Hardware.PWM (4.3.1.0)
Loading Deployment Assemblies.

Attaching deployed file.

Assembly: CanTest (1.0.0.0) Attaching deployed file.

Assembly: GHI.Pins (4.3.7.10) Attaching deployed file.

Assembly: GHI.Hardware (4.3.7.10) Resolving.

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Native.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Graphics.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.TinyCore.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.Usb.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.PWM.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\NETMF v4.3 SDK\Libraries\le\GHI.Hardware.dll’
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘c:\users\luc\documents\visual studio 2013\Projects\CanTest\CanTest\bin\Debug\le\CanTest.exe’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.12.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\NETMF v4.3 SDK\Libraries\le\GHI.Pins.dll’
The thread ‘’ (0x2) has exited with code 0 (0x0).
Send ok
Error on CAN: 1
Error on CAN: 1
Error on CAN: 1
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Send ok
Send ok
Send ok
Send ok
Error on CAN: 3
Error on CAN: 3
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Message 11 from 2
Send ok
Send ok
Send ok

Module crashes after some successful sends !!!

Is 4.3.7.10 behaving different ?
Is this a bug ? In error handling ?
Am I doing something wrong ?

Thx for help