Jump to content

Recommended Posts

Posted

Hi all,

 

I'm trying to put my orange pi zero to talk with a CAN BUS via mcp2515 chip. 

The chip is SPI controlled.

The actual image does not have support for SocketCAN enabled, so I'm compiling the kernel with SocketCan following the kernel configuration shown here

https://developer.ridgerun.com/wiki/index.php/How_to_configure_and_use_CAN_bus

 

I'm using the cross-compiler tool from the armian website.

 

After the image is burned to the sdcard and the orange pi zero is booted, I can see the image has can support enabled, but when I load the mcp251x driver it does nothing. I'm sure I'm missing some detail on spi side in order to have the mcp driver pointing to the proper spi.

 

Any hints?

 

Thanks in advance

 

Amauri

Posted
  On 2/19/2017 at 4:46 AM, amauri said:

After the image is burned to the sdcard and the orange pi zero is booted, I can see the image has can support enabled, but when I load the mcp251x driver it does nothing. I'm sure I'm missing some detail on spi side in order to have the mcp driver pointing to the proper spi.

 

Any hints?

For the dev/mainline kernel you would need DT bindings in form of a patch or an overlay: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt

For the default/legacy - you'll have to init the driver manually in the board setup code - see comments in the driver source: https://github.com/igorpecovnik/linux/blob/sun8i/drivers/net/can/mcp251x.c#L36-L57

Posted

Thanks Zador,

 

I'm a bit stuck here. The kernel compilation seems not to support overlays. I was looking at raspian for raspberry pi and they have the /boot/config.txt and the overlays at /boot/overlays. The overlay configuration defines the device can0 attached to the mcp251x driver.

https://github.com/raspberrypi/linux/blob/rpi-4.4.y/arch/arm/boot/dts/overlays/mcp2515-can0-overlay.dts

 

The information on the mcp251x.c shows some configuration for compiling time, but does not specify how to create the device can0.

 

The socketCan are used through the can devices.

 

Any documentation on how to set the DT with or without overlay? 

I see in the armbian path userpatches/overlay directory. Is it here to put the overlay file?

 

Regards,

 

Amauri

Posted
  On 2/21/2017 at 7:39 AM, amauri said:

I was looking at raspian for raspberry pi and they have the /boot/config.txt and the overlays at /boot/overlays.

This applies only to Raspberry Pi boards.

 

  On 2/21/2017 at 7:39 AM, amauri said:

The overlay configuration defines the device can0 attached to the mcp251x driver.

https://github.com/raspberrypi/linux/blob/rpi-4.4.y/arch/arm/boot/dts/overlays/mcp2515-can0-overlay.dts

It attaches to spi0 bus and disables spidev before that. In case of Orange Pi Zero you don't need to disable spidev as it is not activated by default, but you need to attach to spi1 instead of spi0. Also bindings for the interrupt pin will be different.

 

  On 2/21/2017 at 7:39 AM, amauri said:

I see in the armbian path userpatches/overlay directory. Is it here to put the overlay file?

No. You can put a patch that adds the overlay to the kernel compilation process, or you can put a patch that modifies the Orange Pi Zero device tree file, and you need to use patch userpatches/kernel/sun8i-dev/ in this case. Alternatively you can compile overlay on the board itself if you get dtc with overlay support.

Posted

Thanks,

 

Just made some more readings about the dts in linux and found the dts for the orangepi boards in the igor's toolchain at sources/u-boot/v2017.01/arch/arm/dts

 

I think I can try to make changes here and compile the kernel. Is it right?

 

I could not find a documentation on how to implement the dtc overlay in the kernel.

 

The boot.cmd has reference to the /boot/dts and /boot/overlay

Posted
  On 2/22/2017 at 10:08 AM, amauri said:

Just made some more readings about the dts in linux and found the dts for the orangepi boards in the igor's toolchain at sources/u-boot/v2017.01/arch/arm/dts

You've found DT files in u-boot sources that are used only by u-boot. For the kernel they are located in sources/linux-sun8i-mainline/orange-pi-4.10/arch/arm/boot/dts, but for OPi Zero it's slightly more complicated since its DT file is not present upstream yet and it is added with a patch.

 

  On 2/22/2017 at 10:08 AM, amauri said:

I think I can try to make changes here and compile the kernel. Is it right?

Not exactly. You can make a patch that will apply after lib/patch/kernel/sun8i-dev/add-opi-zero-dts-with-wireless.patch to change sun8i-h2plus-orangepi-zero.dts

 

  On 2/22/2017 at 10:08 AM, amauri said:

I could not find a documentation on how to implement the dtc overlay in the kernel.

 

The boot.cmd has reference to the /boot/dts and /boot/overlay

It's not documented because it is not implemented officially in mainline u-boot and kernel, and as for Armbian - we don't provide official images with mainline kernel for H3 boards yet, and by the time we start to provide them we hopefully will have some overlays for the hardware that we own and that was tested.

Posted
  Quote

It's not documented because it is not implemented officially in mainline u-boot and kernel, and as for Armbian - we don't provide official images with mainline kernel for H3 boards yet, and by the time we start to provide them we hopefully will have some overlays for the hardware that we own and that was tested.

Expand  

It's working with mcp2515 ? 

Posted
  On 3/3/2017 at 11:43 AM, IgZero said:

It's working with mcp2515 ? 

Expand  

It should work but it requires patching the kernel for legacy and creating a DT overlay for mainline.

Edit: Does your CAN board have any kind of documentation or references? Driver requires information about onboard oscillator frequency (i.e. it can be 8MHz or 16MHz)

Edit 2: For example on this board you can clearly see 8.000 on the oscillator, so there it would be 8MHz.

Posted

I'm using the same board as above, but I couldn't make it work. 

On raspberry pi I have the same board working.

I need to do more configuration, but in overall without the overlay out of the box it is a pain. Specially with the amount of boards outside.

 

Regards,

 

Amauri

Posted
  On 3/6/2017 at 9:37 AM, amauri said:

I'm using the same board as above, but I couldn't make it work. 

On raspberry pi I have the same board working.

I need to do more configuration, but in overall without the overlay out of the box it is a pain. Specially with the amount of boards outside.

Expand  

I can add some overlays for testing, but compared to RPi overlay parameters are not supported, so for now if CAN boards have different oscillator frequency they'll have to use different overlays, and the interrupt pin will be hardcoded too.

Also on most boards exposed SPI bus will be SPI0, but on OPi Zero and OPi PC2 it will be SPI1, so this doubles the number of overlay files too.

 

If you can test MCP2515 with 8MHz oscillator I'll add overlays for it for testing later.

Posted
  On 3/6/2017 at 10:25 AM, IgZero said:

Hi! I am ready to test MCP2515 with 8 MHz oscillator. I wait for an example of your overlay.

Expand  

Code (requires DT compiler with overlays support):

  Reveal hidden contents

 

Precompiled overlay (zipped): sun8i-h3-spi0-mcp2515.zip

Needs to be unzipped to /boot/dtb/overlay/ directory on a recent nightly image, then 

overlays=sun8i-h3-spi0-mcp2515

needs to be added to /boot/armbianEnv.txt (these should be only one "overlays" line there, no other overlays are needed for this test). Reboot is required to apply these changes.

 

Wiring details:

  • CS - Chip Select 0 (SPI-CE0,  Pin 24 of 40-pin header)
  • INT - PA7 (Pin 29 of 40-pin header)

 

Please provide dmesg log as a result of your test

 

Posted
  On 3/6/2017 at 11:36 AM, zador.blood.stained said:

Precompiled overlay (zipped): sun8i-h3-spi0-mcp2515.zip

Needs to be unzipped to /boot/dtb/overlay/ directory on a recent nightly image, then 

overlays=sun8i-h3-spi0-mcp2515

needs to be added to /boot/armbianEnv.txt (these should be only one "overlays" line there, no other overlays are needed for this test). Reboot is required to apply these changes.

 

Wiring details:

  • CS - Chip Select 0 (SPI-CE0,  Pin 24 of 40-pin header)
  • INT - PA7 (Pin 29 of 40-pin header)
Expand  

Thanks. Overlay works!!!

 

  Quote

root@orangepipc:~# dmesg | grep can0
[    9.388553] mcp251x spi0.0 can0: MCP2515 successfully initialized.
root@orangepipc:~#
 

Expand  

Has loaded can and can-dev modules:

  Quote

root@orangepipc:~# modprobe can

root@orangepipc:~# modprobe can-dev

root@orangepipc:~# dmesg

...SKIP...

[   57.137872] can: controller area network core (rev 20120528 abi 9)
[   57.138018] NET: Registered protocol family 29
 

Expand  

There was a can0 interface:

  Quote

root@orangepipc:~# ifconfig -a
can0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          NOARP  MTU:16  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth0      Link encap:Ethernet  HWaddr 02:81:f0:b5:ba:37
          inet addr:10.45.255.145  Bcast:10.45.255.255  Mask:255.255.255.0
          inet6 addr: fe80::81:f0ff:feb5:ba37/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2843 errors:0 dropped:0 overruns:0 frame:0
          TX packets:964 errors:0 dropped:0 overruns:0 carrier:0
          collisions:5 txqueuelen:1000
          RX bytes:244712 (244.7 KB)  TX bytes:207383 (207.3 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

root@orangepipc:~#
 

Expand  

 

Posted

I can confirm that this works for the OrangePi Zero (the SPI1 version since there is no SPI0 on the Zero). I had to change the pin to PA2 to fit my board but everything else was as the code published above.

Posted

Hi johlin, can you confirm you see CAN messages using the board? 

The build above is working setting the can0, but when using candump (sudo apt-get install can-utils) to inspect the messages on a CAN BUS I get nothing.

I can assert that there are CAN traffic using another board. I tried the INT PA02 and PA07 and nothing. On both cases the can0 interface is created but no traffic.

 

Looking at the decompiled sun8i-h3-spi1-mcp2515.dtbo 

I see the entry below. The frequency is correct to 8MHz, but the reference to the clock seems strange (clocks = <0x2>;)

The same for the irq, but it might be correct.

 

/dts-v1/;

/ {
       compatible = "allwinner,sun8i-h3";

       fragment@0 {
               target-path = "/aliases";

               __overlay__ {
                       spi1 = "/soc/spi@01c69000";
               };
       };

       fragment@1 {
               target-path = "/clocks";

               __overlay__ {
                       #address-cells = <0x1>;
                       #size-cells = <0x1>;

                       can0_osc_fixed {
                               compatible = "fixed-clock";
                               #clock-cells = <0x0>;
                               clock-frequency = <0x7a1200>;
                               linux,phandle = <0x2>;
                               phandle = <0x2>;
                       };
               };
       };

       fragment@2 {
               target = <0xffffffff>;

               __overlay__ {

                       can0_pin_irq@0 {
                               allwinner,pins = "PA7";
                               allwinner,function = "irq";
                               allwinner,drive = <0x0>;
                               allwinner,pull = <0x1>;
                               linux,phandle = <0x1>;
                               phandle = <0x1>;
                       };
               };
       };

       fragment@3 {
               target = <0xffffffff>;

               __overlay__ {
                       status = "okay";
                       #address-cells = <0x1>;
                       #size-cells = <0x0>;

                       mcp2515@0 {
                               reg = <0x0>;
                               compatible = "microchip,mcp2515";
                               pinctrl-names = "default";
                               pinctrl-0 = <0x1>;
                               spi-max-frequency = <0x989680>;
                               interrupt-parent = <0xffffffff>;
                               interrupts = <0x0 0x7 0x2>;
                               clocks = <0x2>;
                               status = "okay";
                               linux,phandle = <0x3>;
                               phandle = <0x3>;
                       };
               };
       };

       __symbols__ {
               can0_osc_fixed = "/fragment@1/__overlay__/can0_osc_fixed";
               can0_pin_irq = "/fragment@2/__overlay__/can0_pin_irq@0";
               can0 = "/fragment@3/__overlay__/mcp2515@0";
       };

       __fixups__ {
               pio = "/fragment@2:target:0", "/fragment@3/__overlay__/mcp2515@0:interrupt-parent:0";
               spi1 = "/fragment@3:target:0";
       };

       __local_fixups__ {

               fragment@3 {

                       __overlay__ {

                               mcp2515@0 {
                                       pinctrl-0 = <0x0>;
                                       clocks = <0x0>;
                               };
                       };
               };
       };
};


 

 

Posted
  On 3/10/2017 at 10:42 AM, amauri said:

I see the entry below. The frequency is correct to 8MHz, but the reference to the clock seems strange (clocks = <0x2>;)

Expand  

You are looking at decompiled overlays, so 0x2 is a phandle reference, and, as you can see, can0_osc_fixed has phandle 0x2.

 

  On 3/10/2017 at 10:42 AM, amauri said:

I tried the INT PA02 and PA07 and nothing. On both cases the can0 interface is created but no traffic.

Expand  

Please note that you have to change "interrupts" property too if you want to change the interrupt pin. Can you confirm (i.e. with a oscilloscope if you have one) that interrupt line is going low?

 

  On 3/10/2017 at 10:42 AM, amauri said:

I can assert that there are CAN traffic using another board.

Expand  

Does it use the same mcp2515 board and Device Tree overlays?

Posted
  On 3/10/2017 at 10:42 AM, amauri said:

Hi johlin, can you confirm you see CAN messages using the board? 

The build above is working setting the can0, but when using candump (sudo apt-get install can-utils) to inspect the messages on a CAN BUS I get nothing.

I can assert that there are CAN traffic using another board. I tried the INT PA02 and PA07 and nothing. On both cases the can0 interface is created but no traffic.
 

 

Expand  

 

I do indeed see messages using the board. I ran a test with the Zero and a Raspberry Pi, each with their own (custom) CAN board, using MCP2551 for the Orange Pi and MCP2562 for the Raspberry Pi. At 500 000 bps everything was bit-perfect for the nearly 24 hours I ran the test.

Posted

Very strange here.

root@orangepizero:~# cat /proc/net/can/stats

       3 transmitted frames (TXF)
   97889 received frames (RXF)
       0 matched frames (RXMF)

 

The kernel stack see some frames coming, but the candump can see them.

 

Researching a bit more here.

Posted

This is also very strange, see the clock value:

 

root@orangepizero:~# ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
   link/can  promiscuity 0  
   can state ERROR-ACTIVE restart-ms 1000  
         bitrate 125000 sample-point 0.875  
         tq 500 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
         mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
         clock 4000000

 

 

Can anyone also do this command just to check the clock value?

 

Regards,

 

Amauri

 

Posted

Hi, I got it working, there was a problem in the CAN board. 

 

Now I can send and receive CAN messages. But there is still an issue: missing frames.

 

The orangepi stack is not retrieving all the CAN messages and the missing rate is high. I wonder if the SPI kernel module is not working properly. Is there any other configuration that could be done?

 

Best regards,

 

Amauri

Posted

Hello.
I tried to do the same with mcp2515.
Distr : Armbian 5.27.170416 nightly
Kernel : 4.10.3-sun8i
My board: Orange Pi plus 2.
Error:
[   11.874772] mcp251x spi0.0: Cannot initialize MCP2515. Wrong wiring?
[   11.885334] mcp251x spi0.0: Probe failed, err=19

Pin connect:

  Reveal hidden contents

I tried that too

  Reveal hidden contents


VCC = 5 V


MCP2515<->SPI 9a29e38b-f47a-5475-5745-739694f7a6bf.jpg

Posted
  On 4/16/2017 at 8:35 AM, Igor said:
Expand  

Yes.
 

armbianEnv.txt
3 version:
1)

  Quote

verbosity=7
console=both
machid=1029
bootm_boot_mode=sec
rootdev=UUID=4dfb914e-4904-424e-a0fb-2eb01eef10ae
rootfstype=ext4
overlays=sun8i-h3-spi0-mcp2515 sun8i-h3-spi-add-cs1
param_mcp2515_spi_bus=0
param_mcp2515_spi_cs=0
param_mcp2515_max_freq=10000000
param_mcp2515_clk_freq=8000000
param_mcp2515_int_pin=PA7

Expand  

2)

  Quote

verbosity=7
console=both
machid=1029
bootm_boot_mode=sec
rootdev=UUID=4dfb914e-4904-424e-a0fb-2eb01eef10ae
rootfstype=ext4
overlays=sun8i-h3-spi-mcp2515 sun8i-h3-spi-add-cs1
param_mcp2515_spi_bus=0
param_mcp2515_spi_cs=0
param_mcp2515_max_freq=10000000
param_mcp2515_clk_freq=8000000
param_mcp2515_int_pin=PA7

Expand  

3)

  Quote

verbosity=7
console=both
machid=1029
bootm_boot_mode=sec
rootdev=UUID=4dfb914e-4904-424e-a0fb-2eb01eef10ae
rootfstype=ext4
overlays=sun8i-h3-spi0-mcp2515

Expand  

 

version 2, not working, no error,no drivers mcp2515

version 1 and 2:
[   10.378603] mcp251x spi0.0: Cannot initialize MCP2515. Wrong wiring?
[   10.388743] mcp251x spi0.0: Probe failed, err=19

Posted
  On 4/16/2017 at 9:22 AM, zador.blood.stained said:

More like "no".

You are not using a fresh enough nightly image (implied by

  • Latest versions of the u-boot and the boot script is required

Please start with a fresh image (this also means not old image updated with apt) and try again

 

Expand  

I installed everything today.

Posted

Download image: https://www.armbian.com/orange-pi-plus-2/ .
Next:

sed -i "s/apt/beta/" /etc/apt/sources.list.d/armbian.list
apt-get update
apt-get upgrade

Next:
To make sure you won’t run into conflicts within newly installed packages, remove them all before upgrade:

 

 

1
2
aptitude remove ~nlinux-dtb ~nlinux-u-boot ~nlinux-image ~nlinux-headers
aptitude remove ~nlinux-firmware ~narmbian-firmware ~nlinux-$(lsb_release -cs)-root

Proceed with install:

1
2
3
4
apt-get install linux-image-dev-sun8i linux-dtb-dev-sun8i linux-headers-dev-sun8i
apt-get install linux-u-boot-orangepiplus-dev linux-$(lsb_release -cs)-root-dev-orangepiplus
apt-get install armbian-firmware sunxi-tools swconfig a10disp
reboot

===================

I do not know from where else you can download

Posted (edited)

Log loading board:
 

  Reveal hidden contents

 

Edited by user_357

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines