Allwinner A10-A20 CAN bus is working and with mainline drivers!


58_can_bus_2

CAN (controlled area network) bus is communication protocol bus standard widely used in Automotive industry. It uses only two wires for communication and is very robust and noise immune. This is why it also is used in industrial robotics and other areas where reliable communication for small amounts of data is needed.

A10 and A20 SoCs are known to have CAN bus controller inside but few years ago when we started the A10/A20 OLinuXino design nobody knew what is this CAN driver neither how to use it.

This is why when I read message on Twitter –

can1

I reply: “indeed, but on purpose, as no one has used this CAN or know how to use it, this would be just waste of components ”

Obviously things changed for the last couple of years as we have been feed with info about A20 CAN driver!

There is mainline CAN driver for A10/A20: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/net/can/sun4i_can.c?id=refs/tags/v4.4-rc8

CAN is documented http://linux-sunxi.org/images/f/f5/Sun7i-CANbus.pdf in fact it’s same as NXP SJA1000.

Sunxi-Can-Driver is on Github: https://github.com/btolfa/sunxi-can-driver

Linux-Sunxi mainlining efforts: http://linux-sunxi.org/Linux_mainlining_effort#Merged_into_4.4

Can4Linux is available also.

We quickly setup test with CAN transciever from AM3352-SOM-EVB and A20-OLinuXino-MICRO and build kernel with CAN support. Everything works!

Now we work on small board with CAN transciever on it which will enable CAN to be used on A20-OLinuXino-MICRO, A20-SOM-EVB, A10/20-OLinuXino-LIME and A20-OLinuXino-LIME2.

Fortunately when we made the board we kept same GPIO pin numbering on all boards so the CAN signals are on same places on all these boards and this makes the extension CAN board easy to route.

This will allow all our A10/A20 OLinuXinos to be used in CAN applications.

19 Comments (+add yours?)

  1. Gergely Imreh
    Jan 19, 2016 @ 16:34:03

    Well done, very thoughtful development methods!

    Reply

  2. eduardo
    Jan 19, 2016 @ 16:35:27

    Please bring one to Fosdem. We want to support it by our icoBoard.

    Reply

  3. Christian
    Jan 19, 2016 @ 17:32:35

    Great News – is there already a release date for the CAN extension board?

    Reply

  4. Kees Zagers
    Jan 19, 2016 @ 18:40:55

    Nice. Already used the Olimex Duinomite (also PIC-T795) products very succesfully in CAN projects. It would be very nice to have also the Linux platforms with CAN from Olimex.

    Reply

  5. Heinz
    Jan 20, 2016 @ 00:45:46

    @Kees, hope you will use can4linux 🙂 it’s much more performing and easier to use

    Reply

    • Gerd
      Jan 25, 2016 @ 00:57:57

      How did you measure the performance can4linux vs SocketCAN on A10/A20 ?
      Why is can4linux easier than SocketCAN ?

      Reply

      • Heinz
        Jan 26, 2016 @ 11:42:13

        Measuring the processor usage time when receiving messages with high speed and high bus load.
        “easier to use”? look at the simple example at https://en.wikipedia.org/wiki/Can4linux or the examples directory at the SourceForge project page. can4linux is a so-called character driver, with handling like a UART.

      • Heinz
        Jan 26, 2016 @ 11:59:21

        Additional to the default C API, using the LInux standard calls open(), read(), write(), Phyton and Tcl bindings are available.

  6. Stupido
    Jan 25, 2016 @ 09:53:04

    Very good news – still can’t remove the grin out of my face!

    Reply

  7. Bghes
    Feb 02, 2016 @ 22:13:05

    Could you give the DTS can device definition ?

    Reply

  8. Тенгиз Шарафиев
    Feb 25, 2016 @ 16:43:24

    Patch for A10-OLinuXino-LIME dts that add binding for canbus


    From 102e17cff416395aa70d4f423e72a354cd778308 Mon Sep 17 00:00:00 2001
    From: Tengiz Sharafiev <btolfa@gmail.com>
    Date: Thu, 25 Feb 2016 17:36:38 +0300
    Subject: [PATCH] Add dts binding for sun4i_can
    Based on https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/net/can/sun4i_can.txt
    arch/arm/boot/dts/sun4i-a10-olinuxino-lime.dts | 6 ++++++
    arch/arm/boot/dts/sun4i-a10.dtsi | 15 +++++++++++++++
    2 files changed, 21 insertions(+)
    diff –git a/arch/arm/boot/dts/sun4i-a10-olinuxino-lime.dts b/arch/arm/boot/dts/sun4i-a10-olinuxino-lime.dts
    index b350448..900962a 100644
    — a/arch/arm/boot/dts/sun4i-a10-olinuxino-lime.dts
    +++ b/arch/arm/boot/dts/sun4i-a10-olinuxino-lime.dts
    @@ -136,6 +136,12 @@
    };
    };
    +&can0 {
    + pinctrl-names = "default";
    + pinctrl-0 = <&can0_pins_a>;
    + status = "okay";
    +};
    +
    &mdio {
    status = "okay";
    diff –git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
    index aa90f31..7da378c 100644
    — a/arch/arm/boot/dts/sun4i-a10.dtsi
    +++ b/arch/arm/boot/dts/sun4i-a10.dtsi
    @@ -969,6 +969,13 @@
    allwinner,drive = <SUN4I_PINCTRL_10_MA>;
    allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
    };
    +
    + can0_pins_a: can0@0 {
    + allwinner,pins = "PH20","PH21";
    + allwinner,function = "can";
    + allwinner,drive = <SUN4I_PINCTRL_10_MA>;
    + allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
    + };
    };
    timer@01c20c00 {
    @@ -1172,5 +1179,13 @@
    clocks = <&apb1_gates 7>;
    status = "disabled";
    };
    +
    + can0: can@01c2bc00 {
    + compatible = "allwinner,sun4i-a10-can";
    + reg = <0x01c2bc00 0x400>;
    + interrupts = <26>;
    + clocks = <&apb1_gates 4>;
    + status = "disabled";
    + };
    };
    };
    2.7.1

    Reply

  9. Christian
    Mar 26, 2016 @ 16:21:12

    Have you made any progress or an ETA?

    Reply

  10. Jussi Saarijoki
    May 17, 2016 @ 09:59:04

    Any news on this?

    Reply

  11. vvk
    Nov 09, 2016 @ 07:31:55

    can you please provide guide to use can4linux c drivers with banana pro?
    can you please include all steps from compiling to execution

    Reply

  12. Stephan
    Nov 23, 2016 @ 13:43:50

    We experienced some problems regarding the A20s CAN interface getting out of step after receiving huger amounts of CAN frames. It was reproducibly appearing after several minutes. First some false frames appeared (candump), then none were received anymore. (I also double checked, that they are still on the bus). Though, the controller still acked them. Turning the controller down and up again brought it back to live.
    I could trace this back to the frequency scaling. Setting the governor from ondemand to performance made the problem disappear completely until heat protection kicked in.
    We didn’t find a final solution yet – just telling in case anyone might run into similar problems.

    Reply

  13. Heinz (@heinz_hjo)
    Nov 24, 2016 @ 20:45:41

    @Stephan we need to get your complete code. pleas provide an download-able example for testing the hardware.
    Thanks

    Reply

  14. Bert
    Dec 14, 2016 @ 19:56:00

    Hello everybody,
    I have an A20-OLinuXino-LIME2 board with an A20-CAN adapter board and now want build a kernel from scratch for this configuration.
    Can anybody give me a short but detailed example on what to load down from where, and what to configure.
    Thanks Bert

    Reply

Leave a comment