XU4 and can0 mcp251x

Post Reply
Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

XU4 and can0 mcp251x

Unread post by Zaren » Sun Dec 17, 2017 6:59 am

Hello,

I need start canbus on my XU4. Do I have to recompile kernel with patches from here http://mdrjr.net/mcp2515_patchs.tar ?

Thanks,
Zaren

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Sun Dec 17, 2017 6:07 pm

Here is can plate what I use https://www.ebay.com/itm/Arduino-MCP251 ... 1841404580

I bought XU4 shifter shield and turned on 5v there.

Here are options on my XU4:

Code: Select all

>  lsmod
Module                      Size  Used by
fuse                            75334  3
cpufreq_conservative     2955  0
cpufreq_userspace        1799  0
cpufreq_powersave        878  0
spidev                    6446  0
spi_s3c64xx            11643  0
exynos_gpiomem    3162  0
mcp251x                 8610  0
can_dev                 8667  1 mcp251x
ipv6                       341356  40

Code: Select all

> ls -d /sys/bus/spi/drivers/mcp251x
/sys/bus/spi/drivers/mcp251x

Code: Select all

> uname -a
Linux odroid 4.9.58-71 #1 SMP PREEMPT Wed Oct 25 21:02:48 UTC 2017 armv7l armv7l armv7l GNU/Linux

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Sun Dec 17, 2017 6:35 pm

Code: Select all

> dmesg | less
[  117.694049] CAN device driver interface
I got nothing from following commands

Code: Select all

> dmesg | grep mcp
> dmesg | grep can
> dmesg | grep spi

User avatar
odroid
Site Admin
Posts: 32281
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 135 times
Been thanked: 312 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by odroid » Mon Dec 18, 2017 10:41 am

We have no experience of CAN bus driver implementation.

Anyway, there must be "/dev/spidev1.0" if SPI driver is loaded well.

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Mon Dec 18, 2017 3:59 pm

Thank you for your replay!

Yes, "/dev/spidev1.0" is present. I would be very appreciate you if you push me in right direction. As far I understand I need to load mcp251x driver to get can0 device to have data from that hardware. Or I can get the data just from spidev1.0?
I understand that you don't have experience with canbus and I don't expect from you clear recipe for this question. I just will be appreciate of some your hints and thoughts about how might it can be. If it's you have of course. =)

Thanks,
Zaren
Last edited by Zaren on Mon Dec 18, 2017 4:33 pm, edited 1 time in total.

User avatar
odroid
Site Admin
Posts: 32281
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 135 times
Been thanked: 312 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by odroid » Mon Dec 18, 2017 4:32 pm

MCP251x driver was included in our latest 4.14 kernel as a module.
https://github.com/hardkernel/linux/blo ... nfig#L1454
If the device tree file is properly modified to enable it as a spi subdev, the CAN bus should be accessible.

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Mon Dec 18, 2017 4:40 pm

Thanks!
Do I have to upgrade the kernel according by wiki page https://wiki.odroid.com/odroid-xu4/soft ... ing_kernel ?

User avatar
odroid
Site Admin
Posts: 32281
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 135 times
Been thanked: 312 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by odroid » Mon Dec 18, 2017 5:00 pm

Yes, upgrade to 4.14 from 4.9 first.
https://wiki.odroid.com/odroid-xu4/os_i ... st-upgrade
And build the kernel on the board as explained in the WiKi.

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Thu Dec 21, 2017 7:22 am

Hello,

I updated kernel. Right now I have 4.14.7+

Unfortunately it's can't help me =(

There is my modules right now:

Code: Select all

 > lsmod
Module                  Size  Used by
spi_config             20480  0
fuse                   86016  3
cpufreq_conservative    16384  0
cpufreq_userspace      16384  0
cpufreq_powersave      16384  0
spidev                 20480  0
spi_s3c64xx            20480  0
exynos_gpiomem         16384  0
can_bcm                24576  0
can_gw                 20480  0
can_raw                20480  0
can_dev                20480  0
can                    20480  3 can_raw,can_bcm,can_gw
ipv6                  380928  40
I compiled the spi-config kernel module to load mcp251x. It looks like this:

Code: Select all

sudo modprobe spi-config devices=bus=1:cs=0:modalias=mcp2515:speed=125000:force_release
But CAN is still not present. In dmesg I found that:

Code: Select all

spi_config: loading out-of-tree module taints kernel.
[   73.809684] spi_config_register: device description: bus=1:cs=0:modalias=mcp2515:speed=125000:force_release
[   73.809696]  spi_config_match_cs: SPI1: check CS=0 to be 0
[   73.809702]  spi_config_match_cs: SPI1.0: Found a device with modinfo spidev
[   73.809707] spi_config_register:spi1.0:mcp2515: found already registered device
[   73.815585]  spi_config_register:spi1.0:mcp2515: forcefully-releasing already registered device taints kernel
[   73.825816] spi spi1.0: No CS for SPI(0)
[   73.829373] s3c64xx-spi 12d30000.spi: can't setup spi1.0, status -19
[   73.835724] spi_config_register:spi1.0:mcp2515: failed to register device
Maybe you know what it can be?

cap00k
Posts: 88
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID
Has thanked: 0
Been thanked: 9 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by cap00k » Thu Dec 21, 2017 12:29 pm

Apply those patchs to the kernel source and let me know if it works.
Before applying the patch, you must add spidev to the /etc/modprobe.d/blacklist-odroid.conf file.

Code: Select all

blacklist spidev
I don't have a mcp2515 module and could not test it.
On my system, I saw the following message:

Code: Select all

odroid@odroid:~$ lsmod
Module                  Size  Used by
joydev                 20480  0
fuse                   86016  3
cpufreq_conservative    16384  0
cpufreq_userspace      16384  0
cpufreq_powersave      16384  0
mcp251x                20480  0
can_dev                20480  1 mcp251x
spi_s3c64xx            20480  0
exynos_gpiomem         16384  0
ipv6                  380928  40
odroid@odroid:~$ dmesg | grep mcp
[    9.116305] mcp251x spi1.0: Cannot initialize MCP2515. Wrong wiring?
[    9.123578] mcp251x spi1.0: Probe failed, err=19
odroid@odroid:~$ 
Maybe, according to the patch, the connection should be as follows.
mcp2515 ------ shifter-shield ------ odroid-30pin
int ---------------------------------------- pin 5
scl ---------------------------------------- pin 10
si ----------------------------------------- pin 9
so ---------------------------------------- pin 7
cs ---------------------------------------- pin 11
Attachments
can_bus_patch.zip
(513 Bytes) Downloaded 105 times

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Thu Dec 21, 2017 4:46 pm

Thanks for your suggestion!
I will try it today.

Right now I have connection according by wiki.odroid:
mcp2515 ----shifter-shield
int ---------- wiringPi 7 (gpio #18)
sci ---------- wiringPi 14 (#189)
si ------------ wiringPi 12 (#192)
so ------------ wiringPi 13 (#191)
cs ------------ wiringPi 10 (#190)

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Fri Dec 22, 2017 5:39 am

After patch and rebuild the kernel I got can0 device =) Next step I will try to use it.
But I leave wires as I plugged in before. Only int plug in to pin #25.

Code: Select all

[    7.810041] mcp251x spi1.0 can0: MCP2515 successfully initialized.

Code: Select all

ifconfig -a
can0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          UP RUNNING 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)
Thank you very much!

PS: where did you get this patch? Did you make it? Where did you get documentation to do this patch? I want to know how to do this. I need the same for my ODROID C1+. I saw the meson8b_odroidc.dts file for C1+ but can't find the same section with spidev

cap00k
Posts: 88
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID
Has thanked: 0
Been thanked: 9 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by cap00k » Fri Dec 22, 2017 11:40 am

Hi Zaren,
Thanks for the test.

This patch is based on a schematic, I made.
To connect int-pin to GPX1.2(gpio #18), you can modify the dts file like this:

Code: Select all

	can0: mcp2515@0 {
		reg = <0>;
		compatible = "microchip,mcp2515";
		spi-max-frequency = <10000000>;
		interrupt-parent = <&gpx1>;
		interrupts = <2 IRQ_TYPE_EDGE_FALLING>;
		clocks = <&clock CLK_SCLK_SPI1>;
		controller-data {
			cs-gpio = <&gpa2 5 GPIO_ACTIVE_HIGH>;
			samsung,spi-feedback-delay = <0>;
		};
	};
Then, let me know the results.
And I will have review the device tree in C1.

cap00k
Posts: 88
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID
Has thanked: 0
Been thanked: 9 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by cap00k » Fri Dec 22, 2017 12:07 pm

I have reviewed the C1 kernel, but linux-3.10.y does not have a spi can driver.
After apply the mcp2515_patch you attached, then review the device tree.
It takes more time.

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Fri Dec 22, 2017 2:40 pm

Hey, a lot of thanks !
About spi can driver... I started on my c1+ following kernel modules: can, can_gw, can_raw, mcp251x. There are same modules as in xu4. And I got the same output messages in dmesg. Is it not enough for started can0 after patching dts file?

cap00k
Posts: 88
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID
Has thanked: 0
Been thanked: 9 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by cap00k » Tue Dec 26, 2017 10:33 am

Hi, Zaren.
The spi configuration of xu4 and c1+ is different, and the interrupt handling is different, applying the xu4 dts patch to the c1+ kernel will not work.

Can you attach a driver patch to the c1+ kernel?
This will help you review the dts file in the c1+.

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Thu Dec 28, 2017 10:18 pm

Hey,

I compiled the kernel for c1+ according by https://wiki.odroid.com/odroid-c1/os_images/ubuntu/v2.2
There are my stages:
0. Buckup my eMmc flash drive to file on my desktop by dd command.
1. Clone by git the kernel for c1
2. Apply patch files for spi ( apart from 0008-ARM-dts-enable-mcp2515-for-XU3-XU4.patch this file)
3. Compile following the instruction.

Right now I have patched kernel

Code: Select all

> uname -a
Linux odroid 3.10.107 #3 SMP PREEMPT Tue Dec 26 23:30:40 UTC 2017 armv7l armv7l armv7l GNU/Linux
But previous kernel was 3.10.107-109 . I done something wrong? Where is the 109?

Here are my dmesg:

Code: Select all

dmesg | grep mcp
odroid@odroid:~/workspace$ dmesg | grep spi
[    6.453153] spicc spicc: device_id = 0
[    6.455887] spicc spicc: pinctrl_name = default
[    6.460444] spicc spicc: num_chipselect = 2
[    6.464873] spicc spicc: cs_gpios[0] = GPIOX_20(117)
[    6.469927] spicc spicc: cs_gpios[1] = GPIOX_21(118)
[    6.475049] spicc spicc: regs = fe108d80
[    6.479315] spicc spicc: master is unqueued, this is deprecated
[    6.495666] spi spi0.0: spicc_setup : spi->bits_per_word = 8, spi->max_spped_hz = 2000000, spi->chip_select = 0, spi->mode = 0x00
[    6.523683] spi spi0.1: spicc_setup : spi->bits_per_word = 8, spi->max_spped_hz = 1000000, spi->chip_select = 1, spi->mode = 0x00
[    6.552102] ads7846 spi0.1: touchscreen, irq 96
[    6.558849] input: ADS7846 Touchscreen as /devices/platform/spicc/spi_master/spi0/spi0.1/input/input1
[    6.571134] spicc spicc: SPICC init ok
odroid@odroid:~/workspace$ dmesg | grep can
[    6.592149] can: controller area network core (rev 20120528 abi 9)
[    6.600428] can: netlink gateway (rev 20130117) max_hops=1
[    6.608488] can: raw protocol (rev 20120528)
I hope patches are work. But I have no idea how to change dts file =(
I try to insert the same code into dts c1 file but in vain... yet

Code: Select all

dtc -O dtb -o ./meson8b_odroidc.dtb ./meson8b_odroidc.dts
Error: ./meson8b_odroidc.dts:38.17-18 syntax error
FATAL ERROR: Unable to parse input tree
Do you have some notions how to change dts file for c1+ ?
I would be appreciate for any idia. Since I have buckuped my emmc I am ready for any experiments )))

User avatar
odroid
Site Admin
Posts: 32281
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 135 times
Been thanked: 312 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by odroid » Fri Jan 19, 2018 7:01 pm

Try this WiKi guide and let me know the result.
https://wiki.odroid.com/odroid-c1/appli ... io/can-bus

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Mon Jan 22, 2018 3:50 am

Hi,
Good news! Unfortunately I can't get the some pictures on the wiki.odroid site because the permission denied.
It is the "can_bus" "mcp2515", "circuit", "T-board", "C1+ CAN" and both of the "can-bus link". Could you fix it, please?

Thanks a lot

User avatar
odroid
Site Admin
Posts: 32281
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 135 times
Been thanked: 312 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by odroid » Mon Jan 22, 2018 11:14 am

It must be fine now.

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Mon Jan 22, 2018 5:04 pm

Just for clarify. In your circuit Niren plugged in into +5V and to T-board as is without any level shifter. Why it is not harm Odroid pins? As far I understand Odroid pins work with 3.3V
And also I found in patch file that you remove from meson8b_odroidc.dts the SPI Touch Screen section. Whether would works my ODROID-VU5 display in that case?

Thanks!

cap00k
Posts: 88
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID
Has thanked: 0
Been thanked: 9 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by cap00k » Tue Jan 23, 2018 11:46 am

If the module is not supplied with 5V, the transceiver does not signal.
This is a temporary code for testing can-bus.
To use the touch screen, you need a spi touch screen section.
The vu5 touchscreen uses USB interface.
You must delete the spidev section and modify the irq number.

Code: Select all

    spi@c1108d80 {
        #address-cells = <1>;
        #size-cells = <0>;
        compatible = "amlogic,spicc";
        dev_name = "spicc";
        status = "okay";
        reg = <0xc1108d80 0x28>;
        pinctrl-names="default";
        pinctrl-0=<&aml_spicc_pins>;
        device_id = <0>;
        num_chipselect = <2>;
        cs_gpios = "GPIOX_20", "GPIOX_21";

        can0: mcp2515@0 {
            compatible = "microchip,mcp2515";
            reg = <0>;
            spi-max-frequency = <5000000>;
            irq-falling = <1>;
            irq-gpio = "GPIOY_3";
        };

		/* SPI Touch Screen Define */
		ads7846@1 {
			spi-max-frequency = <1000000>;

            /*
			    Driver Select : "ti,tsc2046", "ti,ads7843", "ti,ads7845", "ti,ads7846", "ti,ads7873"
			        kernel/drivers/hardkernel/ads7846.c
			*/
			compatible = "ti,ads7846";

            /*
                SPI Chip Select : (0 ~ 1)
                    Chip Select = GPIOX_21 (CS1)
            */
			reg = <1>;

            /* AMLogic Interrupt Define */
            /*
                IRQ Source : (GPIO_IRQ0(0) ~ GPIO_IRQ7(7))
            */
            irq-source = <0>;

            /*
                IRQ Filter Select : (0 ~ 7)
                    Value 0 : No Filtering, Value 1 ~ 7 : value * 3 * 111nS(delay)
            */
            irq-filter = <7>;   /* 258.741us Delay */

            /*
                IRQ Trigger Select : (0 ~ 3)
                    GPIO_IRQ_HIGH = 0, GPIO_IRQ_LOW = 1, GPIO_IRQ_RISING = 2, GPIO_IRQ_FALLING = 3
            */
            irq-trigger = <3>;  /* GPIO_IRQ_FALLING (Trigger Interrupt) */

            /* Used Pen Down GPIO(IRQ GPIO) Select */
            pendown-gpio = "GPIOY_8";

	    ti,moving-average = <1>;
	    ti,mv-avg-length = <20>;
	    ti,swap-xy = <1>;
            ti,x-min = <0>;
            ti,x-max = <8000>;
            ti,y-min = <0>;
            ti,y-max = <4800>;
            ti,x-plate-ohms = <40>;
            ti,pressure-min = <0>;
            ti,pressure-max = <255>;

            linux,wakeup;
		};
    };

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Sat Feb 17, 2018 7:09 pm

Hello! :)

I tested different approaches to join Odroid and my car. Right now it is looks like no so good.
I done all changes with my C1+ kernel and tested with loopback interface and it's works.
Unfortunatelly XU4 with patched kernel loopback test did not pass. Although XU4 has a can0 device.
In this way I can't check whether both Odroids can communicate with each other through CAN :(
I plugged in my C1+ to ODB of my car and I got nothing. I used candump utility which is in loopback case works prefectly. I know that the speed of ODB in my car is the 500kbps and I changed speed also in can0 interface.

Farther I bought the Arduino nano and used https://github.com/Seeed-Studio/CAN_BUS_Shield (I just made some changes according my hardware - 8mhz oscillator) library for the test speed and so on. Arduino got the can messages prefectly from my car. I connected C1+ and Arduino to tests transfer canbus messages between them. Unfortunatelly they don't see each other. I use cansend to try send some message to Arduino and vice versa. I tried 125Kbps and 500Kbps. But no luck.

I tried to change SPI mode in kernel module. It uses 0 by default and I changed it 1,2,3. In case of 1,2 mcp2515 can't started at all. In case of mode 3 it works like with mode 0 with no result. But I can't find the crystal oscilliator frequency in source of mcp kernel module. I bought the osciloscope and compared the shape of waves when I send message from Arduino and send it from C1+. It looks different. I have impression that the C1+ has a highest frequency than the Arduino.

How I can change oscilliator frequincy parameter in kernel module?

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Sat Feb 24, 2018 9:01 pm

I manage to work the can bus between C1+ and Arduino. The value oscillator frequency in kernel module should be in two times of the crystal oscillator frequincy. I found the place in mcp251x.c and changed it from 10000000 to 16000000 because the crystal oscilliator on Niren has 8000000 Hz. And it is works.
Is there any options change the this parameter in dts file?
Last edited by Zaren on Sun Feb 25, 2018 4:01 am, edited 1 time in total.

User avatar
odroid
Site Admin
Posts: 32281
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 135 times
Been thanked: 312 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by odroid » Sat Feb 24, 2018 9:59 pm

I couldn't find how to change the default SPI clock frequency.
https://github.com/hardkernel/linux/blo ... c.dts#L574

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Sun Feb 25, 2018 3:59 am

I changed value here:
https://github.com/hardkernel/linux/blo ... 1x.c#L1138

As far I understand it is not frequence of spi bus but it is a value of mcp2515 crystal frequence multiplied by two. It needs for kernel to calculate right value of frequence.

I tried something like this:
https://github.com/raspberrypi/linux/issues/848
But it did not work out.

What the max frequence of spi on C1+? I soldered the 16Mhz crystal to Niren instead of 8Mhz and kernel can't recognize it right now.

User avatar
odroid
Site Admin
Posts: 32281
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 135 times
Been thanked: 312 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by odroid » Sun Feb 25, 2018 11:38 am

When we tested our 3.2inch LCD via SPI connection, it was around ~22Mhz even the device driver set it 32Mhz due to limited internal clock controller/divider.
https://wiki.odroid.com/accessory/displ ... d/c1/start

Do you have an oscilloscope to measure the actual frequency?

Also refer the S805 datasheet in this link. http://www.hardkernel.com/main/products ... &tab_idx=2
(sclk will be divided by system clock with equation: 2^(data_rate+2), Example: if system clock = 128MHz and data_rate=2, sclk's frequency equals 8MHz)

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Mon Mar 05, 2018 3:22 am

Hello, it seems I was wrong about working C1+ canbus =) Right now it is not works. I don't know what happend before. But it worked couple of times. I postpone my straggle with 16Mhz and come back to 8Mhz crystal.
I connect the oscilloscope to Adruino CANL CANH miso mosi slk and C1+ the same gpio's.
There is an image from Arduino:
75A5FBC3-7437-4F66-A196-A3183A20250C.png
Arduino canl canh miso mosi slk
75A5FBC3-7437-4F66-A196-A3183A20250C.png (69.51 KiB) Viewed 6062 times
There is an image from C1+
0860A7C1-5D13-416A-A1C3-CB831D24D867.png
C1+ staff
0860A7C1-5D13-416A-A1C3-CB831D24D867.png (66.11 KiB) Viewed 6062 times
If you look at the miso mosi and slk bits you can the differences. On Adruino there are moving bits but on C1+ no any signals. I don't know it is the normal or not.
There is the dmesg:

Code: Select all

[    6.412046] spicc spicc: device_id = 0 
[    6.414297] spicc spicc: pinctrl_name = default
[    6.417241] spicc spicc: num_chipselect = 2
[    6.421582] spicc spicc: cs_gpios[0] = GPIOX_20(117)
[    6.426753] spicc spicc: cs_gpios[1] = GPIOX_21(118)
[    6.431864] spicc spicc: regs = fe108d80
[    6.436286] spicc spicc: master is unqueued, this is deprecated
[    6.454236] CAN device driver interface
[    6.464934] spi spi0.0: spicc_setup : spi->bits_per_word = 8, spi->max_spped_hz = 10000000, spi->chip_select = 0, spi->mode = 0x00
[    6.489488] mcp251x spi0.0: probed
[    6.496368] systemd[1]: Starting Remount Root and Kernel File Systems...
[    6.507630] spicc spicc: chipselect 0 already in use
[    6.510266] spi_master spi0: spi_device register error /spi@c1108d80/spidev@0
[    6.533193] EXT4-fs (mmcblk0p2): re-mounted. Opts: errors=remount-ro
[    6.543932] spi spi0.1: spicc_setup : spi->bits_per_word = 8, spi->max_spped_hz = 1000000, spi->chip_select = 1, spi->mode = 0x00
[    6.555148]  reg:2620,clearmask=10001,setmask=10001
[    6.557612] reg:2621,clearmask=ff,set pin=88
[    6.562015] reg:2623,clearmask=7,setmask=7
[    6.566437] ads7846 spi0.1: touchscreen, irq 96
[    6.571297] input: ADS7846 Touchscreen as /devices/platform/spicc/spi_master/spi0/spi0.1/input/input1
[    6.583222] spicc spicc: SPICC init ok 

[   30.609121] mcp251x spi0.0: CNF: 0x00 0xf5 0x01
[   34.267459] can: controller area network core (rev 20120528 abi 9)
[   34.267658] NET: Registered protocol family 29
[   34.280710] can: raw protocol (rev 20120528)
C1+ has the can0 . But steel there is no connections. Could you give me some hints what can it would be? It seems can0 works and spi bus also. C1+ with loopback works fine. If can shield constantly registering and loopback is working it means spi is ok but why spi gpio's are silent?

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Wed Mar 07, 2018 3:22 pm

I'm still experimenting, trying to make to speak my canbus shield.
I use some trick to make level shifter : https://www.raspberrypi.org/forums/view ... p?t=141052
Made some changes in mcp251x.c file. I replaced 160000000 to 8000000 value of oscillator.
Arduino and C1+ can speak with each other right now. Also I have some motion of bits of mosi/miso/slk on my C1+.
It is possible to have more than one spi device on C1+. I want to have two spi devices. One of them it is a canbus shield another one it is the NRF radio spi module. Having of loaded mcp251x driver I have no any of /dev/spidev*. In which way I can turn on spi dev?

callum91
Posts: 6
Joined: Fri Feb 16, 2018 8:20 pm
languages_spoken: english
ODROIDs: XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by callum91 » Thu Mar 08, 2018 8:33 pm

Hi Zaren,

I am trying to achieve a similar setup to what you mentioned here with an arduino talking to an Odroid XU4 through mcp2515. Currently I am able to get arduino to arduino communication correctly working so am happy the MCP2515 boards are working correctly. On the odroid I am able to load the mcp251x.c library with the spiconfig as you have done earlier and the can0 device is available. Using the Can-Utils package the mcp2515 board passes a loopback test with no problems. However when i set the odroid can0 interface back to loopback off mode and try attaching the CAN-BUS to the working arduino sender, there is no response from the Odroid MCP2515. Just wanting to confirm that you changed the value in the mcp251x.c file and are using the same patch file from cap00k above? and following this change did you need to rebuild the kernel or do any other steps?

and to confirm you are able to send messages from the arduino to the odroid over can bus correctly now?

Thanks Callum
Zaren wrote:I'm still experimenting, trying to make to speak my canbus shield.
I use some trick to make level shifter : https://www.raspberrypi.org/forums/view ... p?t=141052
Made some changes in mcp251x.c file. I replaced 160000000 to 8000000 value of oscillator.
Arduino and C1+ can speak with each other right now. Also I have some motion of bits of mosi/miso/slk on my C1+.
It is possible to have more than one spi device on C1+. I want to have two spi devices. One of them it is a canbus shield another one it is the NRF radio spi module. Having of loaded mcp251x driver I have no any of /dev/spidev*. In which way I can turn on spi dev?

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Fri Mar 09, 2018 1:41 pm

Hi, Callum
I play around with C1+ and its mcp2551 frequency value here:
https://github.com/hardkernel/linux/blo ... 1x.c#L1138
Original value was 10000000. I recompiled kernel module with 8000000 and it is worked out. At first I recompiled entire kernel with that patch but after, making changes in module, I recompiling constantly just the one module and install it.

Code: Select all

make -j4 modules && make modules_install
Unfortunatelly, my XU4 didn't pass the loopback test (as I mentioned before in this forum) and I switched to my C1+. But I'm going to appply that to XU4 due to having the working canbus setup.
I tested can shield yesterday with my car and at last I got the can messages from car can bus! =) And yes, The arduino and odroid right now can send and recieve messages perfectly between each other. You mentioned that your XU4 passed the loopback test. What the version of kernel do you have?
Which can shield do you use? Is it Niren?

callum91
Posts: 6
Joined: Fri Feb 16, 2018 8:20 pm
languages_spoken: english
ODROIDs: XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by callum91 » Fri Mar 09, 2018 4:19 pm

Thanks for your reply Zaren,

Before making that frequency change was the odroid c1+ able to pass a loopback test?
Thats perfect hopefully I can get my arduino and odroid talking too. On our setup we are on kernel 4.14.20+ (found from running uname -r) and have followed the same steps as above with applying the kernel patch. However looking at the source that we are using to build the kernel I can seem to find the mcp251x.c file that you are modifying above? The source we are using is the from https://github.com/hardkernel/linux -b odroidxu4-4.14.y

On the odroid the mcp2515 is able to pass the loopback test correctly but will not read any messages in normal mode.
We are using the Niren can bus shields but I think we have a problem with them as the interrupt pin from the mcp2515 does not change with any incoming data. I have tested this on the arduino setup aswell using two different libraries. One waits for the interrupt pin to go low before reading and the other just attempts to read the rx buffer constantly.

From my understanding the mcp251x.c module waits for the interrupt pin and then tries to read the register. Could you confirm that on your mcp2515 boards the interrupt pin does change when receiving a message on the CAN bus?

Thanks Callum

EDIT****

Just noticed that the Arduino mcp2515 library with interrupts I was attempting to use wasnt setting the speed to 8MHZ correctly and now that I have corrected that I can use the library with the interrupts, now just need to try setting the odroid clock to 8 Mhz and hopefully everything will be all go.
Last edited by callum91 on Fri Mar 09, 2018 5:46 pm, edited 1 time in total.

callum91
Posts: 6
Joined: Fri Feb 16, 2018 8:20 pm
languages_spoken: english
ODROIDs: XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by callum91 » Fri Mar 09, 2018 5:41 pm

Im confident now that they issue is with the spi clock speed on the odroid xu4. Im attempting to build from this source here https://github.com/hardkernel/linux/tre ... xu4-4.14.y but am not able to find the similar line to what you adjusted on your c1+ in the mcp251x.c file.

Looking in the mcp251x.c file it is reading the frequency from the &spi->dev clock. found here https://github.com/hardkernel/linux/blo ... 1037-L1045

Does anyone know where to change the speed of the spi clock to 8Mhz?

Thanks,
Callum

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Fri Mar 09, 2018 6:11 pm

Odroid c1+ has passed the loopback test before I change frequency in mcp251x.c
It seems worked but didn't connect to arduino. It looked similiar as your case with XU4.

Just try to change

Code: Select all

freq = pdata->oscillator_frequency;
to

Code: Select all

freq = 8000000;
In case of C1+ that value is hardcoded - 10000000.

As far I understand you can change spi clock speed on the odroid xu4 at the dts file.

Code: Select all

can0: mcp2515@0 {
      reg = <0>;
      compatible = "microchip,mcp2515";
      spi-max-frequency = <10000000>;
      interrupt-parent = <&gpx1>;
      interrupts = <2 IRQ_TYPE_EDGE_FALLING>;
      clocks = <&clock CLK_SCLK_SPI1>;
      controller-data {
         cs-gpio = <&gpa2 5 GPIO_ACTIVE_HIGH>;
         samsung,spi-feedback-delay = <0>;
      };
   };
Or maybe here in mcp251x.c

Code: Select all

spi->max_speed_hz = spi->max_speed_hz ? : 10 * 1000 * 1000;

callum91
Posts: 6
Joined: Fri Feb 16, 2018 8:20 pm
languages_spoken: english
ODROIDs: XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by callum91 » Fri Mar 09, 2018 8:06 pm

Hi Zaren,
Have just been able to successfully connect the odroid and the arduino through the can bus! Thank you for your help in getting this to work.

To outline the process I used on a clean Odroid XU4

Run the following lines of code:

Code: Select all

sudo apt install git gcc g++ build-essential
git clone --depth 1 https://github.com/hardkernel/linux -b odroidxu4-4.14.y
cd linux
Apply the can bus patch file from cap00k above to the source.
On this line here https://github.com/hardkernel/linux/blo ... 1x.c#L1046 I have added:

Code: Select all

freq = 8000000;
Then run the rest of the kernel source build from this link https://wiki.odroid.com/odroid-xu4/soft ... ing_kernel

Code: Select all

make odroidxu4_defconfig
$ make -j8
$ sudo make modules_install
$ sudo cp -f arch/arm/boot/zImage /media/boot
$ sudo cp -f arch/arm/boot/dts/exynos5422-odroidxu3.dtb /media/boot
$ sudo cp -f arch/arm/boot/dts/exynos5422-odroidxu4.dtb /media/boot
$ sudo cp -f arch/arm/boot/dts/exynos5422-odroidxu3-lite.dtb /media/boot
$ sync
$ sudo cp .config /boot/config-`make kernelrelease`
$ sudo update-initramfs -c -k `make kernelrelease`
$ sudo mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n uInitrd -d /boot/initrd.img-`make kernelrelease` /boot/uInitrd-`make kernelrelease`
$ sudo cp /boot/uInitrd-`make kernelrelease` /media/boot/uInitrd
$ sync
$ sudo sync
$ sudo reboot
For anyone else following this thread the change to the mcp251x.c file is required when using Niren mcp2515 boards or other similar boards that have a 8Mhz clock installed. I do not have a 16Mhz version currently to test but this may work with just the standard driver code. If it doesnt try setting the freq value to 16000000.

Thanks for your help and let me know if i can help anymore with getting yoru XU4 onto the CAN BUS.

Callum
Last edited by callum91 on Fri Mar 09, 2018 10:27 pm, edited 1 time in total.

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Fri Mar 09, 2018 9:54 pm

Hi Callum,
glad to hear that! =)

I resoldered the 8Mhz crystall to 16Mhz in one of my Niren's. But unfortunatelly I don't get any success attemps to make work that on my C1+. But I did't tested it on arduino yet.

This is the link which you can see the worked resoldered same shield:
https://www.youtube.com/watch?v=xEt6RGq ... v&index=46
But it is a french language and I don't understand what about this video )

As far I understand, according datasheet http://ww1.microchip.com/downloads/en/D ... 01801H.pdf (page 56) I will have to resoldered also two capacitors due to changed crystall.

Thanks!

janmoravec
Posts: 6
Joined: Tue Apr 10, 2018 9:19 pm
languages_spoken: english
ODROIDs: Odroid XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by janmoravec » Tue Apr 10, 2018 9:59 pm

Hi,
I'm trying to connect the NiRen MCP2415 to Odroid XU4. I have followed the instructions from callum91, but I can not get the driver to work. These are the dmesg messages:

[ 8.233112] s3c64xx-spi 12d30000.spi: chipselect 0 already in use
[ 8.240624] spi_master spi1: spi_device register error /soc/spi@12d30000/spidev@0
[ 8.255063] spi_master spi1: Failed to create SPI device for /soc/spi@12d30000/spidev@0
[ 8.512509] random: crng init done
[ 8.916715] CAN device driver interface
[ 8.928297] mcp251x spi1.0: Cannot initialize MCP2515. Wrong wiring?
[ 8.935680] mcp251x spi1.0: Probe failed, err=19


I use following Ubuntu: Linux odroid 4.14.32+ #1 SMP PREEMPT Tue Apr 10 10:27:05 UTC 2018 armv7l armv7l armv7l GNU/Linux

And connection:
int ---------------------------------------- pin 24
scl ---------------------------------------- pin 10
si ----------------------------------------- pin 9
so ---------------------------------------- pin 7
cs ---------------------------------------- pin 11

I have attached a photo of connection. Could you please help me?
Best regards,
Jan Moravec
Attachments
img.jpg
Photo of connection.
img.jpg (379.38 KiB) Viewed 5547 times

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Thu Apr 12, 2018 6:04 pm

Hello, Jan !

As far as I know GPIO of XU4 works only with 1.8V . You have to buy XU4 levelshifter which can allows to plug in logic which works with 3.3V or 5V. Niren consumes the 5V and that means logic of Niren works with 5V
http://www.hardkernel.com/main/products ... 3556253995
You can damage XU4 GPIO's in this way that you show in photo! =(

janmoravec
Posts: 6
Joined: Tue Apr 10, 2018 9:19 pm
languages_spoken: english
ODROIDs: Odroid XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by janmoravec » Fri May 04, 2018 10:15 pm

Hello Zaren,

thank you, you are of course correct. I tried it with the level-shifter and the driver works!

Now I face another issue - I want to connect to CAN bus with 1 000 000 bps. The problem is following:
sudo ip link set can0 type can bitrate 1000000
mcp251x cpi1.0 can0: bitrate error 33.3% too high


I'm sure that the mcp2515 should support bitrate 1000000, but the driver does not allow me to set it.
Do you have any idea how to solve it, please?

Thank you.

Zaren
Posts: 53
Joined: Wed Nov 08, 2017 7:12 am
languages_spoken: english
ODROIDs: ODROID C1+, XU4
Location: Poland
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by Zaren » Sat May 05, 2018 5:32 am

Hi, Jan.
I think it can be solved by 16Mhz crystall. Niren has a 8Mhz.
Guys on this video https://www.youtube.com/watch?v=xEt6RGq ... v&index=46
somehow manage to work Niren with resoldered crystall. But I'm not sure on 100% . We have to try it. =)

ajal
Posts: 3
Joined: Fri Apr 12, 2019 7:15 pm
languages_spoken: english
ODROIDs: XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by ajal » Fri Apr 12, 2019 10:08 pm

Hi,
I have tried applying the patch from cap00k and was able to get the can0 to show up. But as I followed the instructions to send/receive data (https://magazine.odroid.com/article/con ... droid-xu4/), I also loaded 'spi_s3c64xx' instead of 'spicc'. The can was not sending data in either triple sampling mode nor in loopback mode. I tried sending data with an arduino Uno and was not able to receive data. I also tried CAN sniffer tool from PEAK. What I observed is that as soon as I send the data from odroid XU4 , the status in the PEAK application goes to ERROR-PASSIVE. Also I noted that when I check for device file with 'root@odroid:~# ls /dev/spidev*' . I dont get any device file. Could somebody please help me? Thanks.

mdgramma
Posts: 1
Joined: Mon Jan 22, 2018 3:49 am
languages_spoken: english
ODROIDs: XU3 (1), XU4 (30)
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by mdgramma » Tue Apr 16, 2019 1:48 am

Is it feasible to connect two different CAN devices on Odroid XU4, and use the XU4 as gateway to control the networks (can0 and can1) independently using Linux CAN sendMsg/dump functions? If so, how should the device tree source be changed (two separate entries?). I am using Ubuntu 18.04 on xu4, Linux kernel version 4.14.57.

ajal
Posts: 3
Joined: Fri Apr 12, 2019 7:15 pm
languages_spoken: english
ODROIDs: XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: XU4 and can0 mcp251x

Unread post by ajal » Wed Apr 24, 2019 6:51 pm

update:

Solution from callum91 worked for me. The wiring for the interrupt pin was wrong. It works for me with pin #174 on the shifter shield. Thank you for the help!

User avatar
odroid
Site Admin
Posts: 32281
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 135 times
Been thanked: 312 times
Contact:

Re: XU4 and can0 mcp251x

Unread post by odroid » Thu Apr 25, 2019 8:46 am

Glad to hear that you made it work.
I've added this nice thread link to the WiKi page.
https://wiki.odroid.com/odroid-c1/appli ... _xu4_users

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: Google [Bot] and 2 guests