Page 10 of 33

Re: CAN controller

Posted: Sun Apr 14, 2013 11:10 am
by bertr2d2
Hi,

interesting pics nexulm. One thing seems to be still not solved from the SPI driver: during SPI transfer the CS line is still low a long time after the the last bit clock (1st pink -> CS , 2nd pink SCLK):

Image

There is a flag for the SPI-DMA transfer which should raise the CS line automatically after
last bit was transfered. Does the new SPI driver use DMA with this flag on?

The async MCP2515 code from Andre B. Olivera wasn't tested a lot. Do you see the same problems with the mcp251x.c from a brand new kernel ? The latest mcp251x driver was been fixed some time ago; don't know if this will fix your problem. The vanilla mcp251x driver may not be the fastest but the most tested version.

BTW: Do you use this version form Andre B. Olivera: http://lnxpps.de/rpie/mcp2515_mod.c ?
nexulm wrote:Two question from my side regarding the measurments are:
1. Why is there a delay of round about 30us between Interrupt Low of MCP2515 and SPI-Chip Enable?
IMO 30us is excellent, but you can't rely on this value. Plain vanilla Linux isn't a realtime system.
And the RaspberryPi needs to do lots of things in the background, e.g. the USB/Ethernet Bridge
generates 8000 interrupts per second. You don't see them because they are done with FIQ.
Zeta wrote:
nexulm wrote:For me that's not a problem of the "horse power" of BCM2835. Maybe it's more a general linux driver structure and interrupt priority questions, or? But I don't know th linux driver achitecture good enough so far. Furthermore IMO it doesn't depend directly on one-shot-irq because I've seen the same problem with Kernel 3.2.27 with Level-triggerd interrupt.
I agree the processing power is not the only problem here. Even if we miss some frames, which would be directly related to some "horse power" and architecture (our choice of using MCP2515 with only 2 buffers, and using 2 of them on the same SPI bus) limitations, it shouldn't simply stop working.
You are right: the missing system speed shouldn't break the functionality. There should be only missing frames.
Could you get the MCP2515 register values after the controller stopped transmitting frames ?
Would it be possible, that you adapt (vcanx -> canx and loopback the physical interfaces) my code above an try to run it with 1Mbps ? I'm interested which load this will generate on the CAN bus with the Olivera driver and the normal code.

Regards

Gerd

Re: CAN controller

Posted: Mon Apr 15, 2013 10:09 am
by nexulm
Hello Gerd,
bertr2d2 wrote: There is a flag for the SPI-DMA transfer which should raise the CS line automatically after
last bit was transfered. Does the new SPI driver use DMA with this flag on?
I think Martin (msperl) is the expert for his driver/patch!
bertr2d2 wrote: The async MCP2515 code from Andre B. Olivera wasn't tested a lot. Do you see the same problems with the mcp251x.c from a brand new kernel ? The latest mcp251x driver was been fixed some time ago; don't know if this will fix your problem. The vanilla mcp251x driver may not be the fastest but the most tested version.
I've seen the same fault with Kernel 3.2.27, SPI latency patch from msperl and the original mcp251x.c
included in the rpi-3.2.27 branch.
bertr2d2 wrote: BTW: Do you use this version form Andre B. Olivera: http://lnxpps.de/rpie/mcp2515_mod.c ?
First I've used the patched version of Andre B. Olivera from here...
http://clientes.netvisao.pt/anbadeol/li ... 8.patch.gz
...which was also mentioned here...
http://elinux.org/RPi_CANBus

Yesterday I've checked your version mcp2515_mod.c as I've seen that it differs from my patched version. Also your version shows the same fault that one CAN-Interface stops receiving CAN-frames.
bertr2d2 wrote: Could you get the MCP2515 register values after the controller stopped transmitting frames ?
Currently I don't know how it is possible? Is there any debugging stuff already in the driver code?
bertr2d2 wrote: Would it be possible, that you adapt (vcanx -> canx and loopback the physical interfaces) my code above an try to run it with 1Mbps ? I'm interested which load this will generate on the CAN bus with the Olivera driver and the normal code.
In general I've tested one CAN-Interface with Kernel 3.6.11, one-shot-IRQ, SPI low latency, MCP2515 up to 1Mbit/s and round about 60% busload (CAN-frames sends from CANalyzer/CANoe and are received by the MCP2515). I didn't see message losts here.
The only problem/fault for me is if a 2nd CAN-Interface is active that one of them stops receiving CAN frames after some time.
If I should test some specific behaviour for you I need a more detailed Howto for it as I'm not sure if I understand everything right, i.e. load (CPU load, CAN busload)!

Mike

Re: CAN controller

Posted: Mon Apr 15, 2013 8:35 pm
by bertr2d2
nexulm wrote:Hello Gerd,
bertr2d2 wrote: Could you get the MCP2515 register values after the controller stopped transmitting frames ?
Currently I don't know how it is possible? Is there any debugging stuff already in the driver code?
What does "ip -s -d link show can0; ip -s -d link show can1" say ?

Re: CAN controller

Posted: Mon Apr 15, 2013 9:30 pm
by nexulm
bertr2d2 wrote: What does "ip -s -d link show can0; ip -s -d link show can1" say ?
In fault case if CAN0 stops receiving the output of the commands is:

3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
link/can
can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
bitrate 500000 sample-point 0.833
tq 166 prop-seg 4 phase-seg1 5 phase-seg2 2 sjw 1
mcp2515: tseg1 2..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
clock 6000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 0 0 0
RX: bytes packets errors dropped overrun mcast
50208 6276 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
4: can1: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
link/can
can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
bitrate 500000 sample-point 0.833
tq 166 prop-seg 4 phase-seg1 5 phase-seg2 2 sjw 1
mcp2515: tseg1 2..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
clock 6000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 0 0 0
RX: bytes packets errors dropped overrun mcast
399160 49895 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0

Re: CAN controller

Posted: Tue May 14, 2013 11:51 am
by guyguy333
Currently, what is the best solution to use CAN bus with RPi and kernel 3.6 ? Which SPI drivers ?
Does http://elinux.org/RPi_CANBus is up to date ?

What works and what does not ?

Between the wiki and the forum there are confusions, we don't know what to use with the kernel 3.6

Thank you

Re: CAN controller

Posted: Tue May 14, 2013 5:40 pm
by Zeta
Hello guyguy333,

I think that out of the box mcp251x and spi drivers will work.
But if you need higher performances and bus load, then it is worth going to the spi driver will msperl's patch (https://github.com/raspberrypi/linux/pull/147). If no patch is available for your kernel version, simply extract the file from msperl's github and replace the one in your git tree, or better clone msperl's tree.

About the MCP2515 driver it allowed also some better performances (note that it can't work with MCP2510 controller, but MCP251x can).
guyguy333 wrote:Does http://elinux.org/RPi_CANBus is up to date ?
What works and what does not ?
Between the wiki and the forum there are confusions, we don't know what to use with the kernel 3.6
The wiki page has not been changed since the 2nd of February, but not much as changed since the beginning of the year, so the principle is still ok, only the patch linked may fail to apply.

If you try to compile it, please correct the wiki or list here the points that are not clear or not working, and I will update it.

Re: CAN controller

Posted: Tue Jul 16, 2013 7:19 am
by 123456
Hi,

is it important to consider the correct order of steps from: http://elinux.org/RPi_CANBus ?
Or is it impossible to install the MCP2515 Asynchronous Driver- and SPI low latency patch after the Kernel configuration but before compiling the kernel?

such as:
1. Kernel configuration
2. MCP2515 Asynchronous Driver patch
3. SPI low latency patch
4. compiling the kernel

thanks

Re: CAN controller

Posted: Tue Jul 16, 2013 10:03 am
by nexulm
Hello 123456 (nice name 8-) ),
123456 wrote: 1. Kernel configuration
2. MCP2515 Asynchronous Driver patch
3. SPI low latency patch
4. compiling the kernel
The correct order is:
1. MCP2515 Asynchronous Driver patch
2. Kernel configuration
3. SPI low latency patch
4. compiling the kernel

You must first apply the MCP2515 async driver patch to be able to enable the MCP2515 driver.
Step 2 and 3 doesn't matter as the SPI patch add only the missing functionalities (i.e. DMA) of the BCM2708 SPI driver.

Regards
Mike

Re: CAN controller

Posted: Thu Jul 18, 2013 3:40 pm
by feliks
Hello everybody,
first I want to say thank you for your work on getting SocketCAN runnig on the Pi.

I tried several times to activate CAN support for kernel 3.6. using Zeta´s tutorial (thank you for sharing).
After some failed installations I now have a running system with asynchron driver and kernel modules enabled:

lsmod shows:

Code: Select all

 
Module                  Size  Used by
mcp2515                 4448  0 
can_bcm                 9336  0 
can_raw                 4780  0 
can_dev                 5352  1 mcp2515
can                    18448  2 can_bcm,can_raw
snd_bcm2835            11420  0 
snd_pcm                53328  1 snd_bcm2835
snd_page_alloc          2680  1 snd_pcm
snd_seq                36932  0 
snd_seq_device          3628  1 snd_seq
snd_timer              14696  2 snd_pcm,snd_seq
snd                    36156  5 snd_bcm2835,snd_timer,snd_pcm,snd_seq,snd_seq_device
spidev                  3932  0 
leds_gpio               1516  0 
led_class               1816  1 leds_gpio
i2c_bcm2708             2848  0 
spi_bcm2708             3928  0 
i2c_core               13264  1 i2c_bcm2708
However CAN interface is not present after modprobe of kernel modules. wlan0 is also missing after this step.
Setting up can0 failes like this:
ip link set can0 type can bitrate 125000 loopback on

Code: Select all

RTNETLINK answers: Operation not supported
ifconfig can0 up gives:

Code: Select all

SIOCSIFFLAGS: Invalid argument
Log files are spamed with this message:

Code: Select all

mcp2515 spi0.0: can0: bit-timing not yet defined
I have no idea what I was doing wrong and how to get it running at last.
Did somebody has similar problems? I would be very graceful for some help.

Regards, Felix

Re: CAN controller

Posted: Thu Jul 18, 2013 9:55 pm
by bertr2d2
Hi feliks,
feliks wrote: However CAN interface is not present after modprobe of kernel modules. wlan0 is also missing after this step.
Setting up can0 failes like this:
ip link set can0 type can bitrate 125000 loopback on

Code: Select all

RTNETLINK answers: Operation not supported
IMHO bitrate is not supported in loopback mode in the async driver. Try:

Code: Select all

ip link set can0 type can loopback on
Regards

Gerd

Re: CAN controller

Posted: Fri Jul 19, 2013 8:18 am
by nexulm
Hello Felix, hello Gerd,
bertr2d2 wrote:Hi feliks,
feliks wrote: However CAN interface is not present after modprobe of kernel modules. wlan0 is also missing after this step.
Setting up can0 failes like this:
ip link set can0 type can bitrate 125000 loopback on

Code: Select all

RTNETLINK answers: Operation not supported
IMHO bitrate is not supported in loopback mode in the async driver. Try:

Code: Select all

ip link set can0 type can loopback on
Regards
Gerd
For me the loopback mode isn't supported by the async MCP2515 driver.
So it doesn't depend on the combination with bitrate. Gerd's proposal doesn't work aswell.
So, you have to try the command without "loopback on":
sudo ip link set up can0 type can bitrate 125000

If this command doesn't work a "dmesg"-output would be helpful to debug the problem!

Regards
Mike

Re: CAN controller

Posted: Fri Jul 19, 2013 10:09 am
by feliks
Hi,
thank you for your replies and you seem to be right that loopback and bitrate for mcp2515 are not supported together.
Trying the command without one of these options I get:

Code: Select all

Cannot find device "can0"
It´s also strange that wlan0 is missing after loading kernel modules. I think this has something to do with each other.

Re: CAN controller

Posted: Fri Jul 19, 2013 10:38 am
by nexulm
feliks wrote:Hi,

Code: Select all

Cannot find device "can0"
It´s also strange that wlan0 is missing after loading kernel modules. I think this has something to do with each other.
I don't think that can0 and wlan0 depends on each other. My USB-WLAN interface is working with the MCP2515 in parallel.
For me it seems that the mcp2515 probe doesn't find any hardware.
Please provide the missing "dmesg" output which shows the mcp2515 probing if you load the module with "sudo modprobe mcp2515".
My working module load script is:

Code: Select all

#!/bin/bash
#start moduls
sudo modprobe mcp251x
sudo modprobe spi-bcm2708
sudo modprobe can
sudo modprobe can-dev
sudo modprobe can-raw
sudo modprobe can-bcm
sudo ip link set up can0 type can bitrate 500000
Regards
Mike

Re: CAN controller

Posted: Fri Jul 19, 2013 12:22 pm
by feliks
I´m sorry, it was my fault. I forgot loading kernel modules before. Now everything works fine. I just had to leave out the loopback option. Thank you very much for help.
Here some additions to zeta´s tutorial for kernel 3.6.:
  • the current trunk version is now 3.6. so fetching the additional branch is not necessary anymore
  • for executing imagetool-uncompressed.py python2 was not found. To resolve this issue the correct link has to be set:

    Code: Select all

    ln -s /usr/bin/python /usr/local/bin/python2
  • arch/arm/mach-bcm2708/bcm2708.c is different to the version in the tutorial, so the patch did not work. I attached my version after applying the patch manually.
  • for me, the SPI low latency patch results in errors during kernel compilation, so I had to leave this out. Using bitrates <=500kBit I had no frame losts so far (I did no tests with higher rates)
  • it´s important to use an image with more than 2GB partition.
Regards, Felix

Re: CAN controller

Posted: Wed Jul 24, 2013 3:32 pm
by opentronic
Hi Guys,
I want suggest you www.industrialberry.com. There, you can find several open hardware projects from which there is CanBarry board. It is based on mcp2515 and mcp2551. Moreover, that project contain an on board I2C real time clock too.

Re: CAN controller

Posted: Mon Jul 29, 2013 6:44 pm
by frezende
Hi guys!

Where can I find the zeta´s tutorial for kernel 3.6 that I have seen many references in this forum?

Regards, Frezende

Re: CAN controller

Posted: Mon Jul 29, 2013 7:04 pm
by feliks
Hi Frezende,
I referred to this one: http://elinux.org/RPi_CANBus
Regards

Re: CAN controller

Posted: Mon Jul 29, 2013 7:13 pm
by Zeta
Hello Frezende,

feliks already given the link, but I wanted to add that it is not really 'my' tutorial. I only put on the elinux wiki what other already presented here and in the related SPI discussion.

I have not rebuilt my kernel since January, so the wiki is a bit out of date if you try to blindly copy/paste it to your command line. However the principle didn't changed, and only small changes should be needed (like the fact the master is at version 3.6, whereas it was a branch back then, or a commit broke a patch so the patch has to be regenerated with the current version).

As it is a wiki, anyone can change it, so if anyone of you have some time to update it to the current state of the kernel, I (and other probably) will be grateful.

Thanks !

Re: CAN controller

Posted: Tue Jul 30, 2013 10:26 pm
by medy2
Hi all,
I'm quite new to RPi + mcp2515, and like maddin1234, I've also built this configuration:
I have a setup with two mcp2515, one connected to SPI_CE0_N and GPIO17 for interrupt
and the other connected to SPI_CE1_N and GPIO18 for interrupt.
I use kernel 3.6, the mcp2515 patch and the spi latency patch.
The mcp2515 attached to CE0 works well, but what I have to configure to probe and use the second mcp2515, attached on the CE1?

Thanks
Matteo

Re: CAN controller

Posted: Mon Aug 26, 2013 6:30 pm
by KingAlex1985
Hello everybody,

I have some problems with compiling the linux kernel with Zeta's tutorial.

First thing, I can't find the entry "Microchip MCP251x SPI CAN controllers" in the menuconfig. It should looks like this:
=======================================================
[*] Networking support --->
....<M> CAN bus subsystem support --->
........<M> Raw CAN Protocol (raw access with CAN-ID filtering)
........<M> Broadcast Manager CAN Protocol (with content filtering)
............CAN Device Drivers --->
................<M> Platform CAN drivers with Netlink support
................[*] CAN bit-timing calculation
................<M> Microchip MCP251x SPI CAN controllers
................[*] CAN devices debugging messages
========================================================

But it looks like this:
Image

Why is it different? Or why is the "<M> Microchip MCP251x SPI CAN controllers"-line in the menuconfig not visible for me?

The second things is, that when i start to compile the kernel, I get this error-message ("command not found"):
===================================================
alex@alex-desktop:/opt/raspberrypi/linux$ make ARCH=arm CROSS_COMPILE=arm-rpi-linux-gnueabi- -j3
make: arm-rpi-linux-gnueabi-gcc: Kommando nicht gefunden
scripts/kconfig/conf --silentoldconfig Kconfig
make: arm-rpi-linux-gnueabi-gcc: Kommando nicht gefunden
WRAP arch/arm/include/generated/asm/auxvec.h
WRAP arch/arm/include/generated/asm/bitsperlong.h
WRAP arch/arm/include/generated/asm/cputime.h
WRAP arch/arm/include/generated/asm/emergency-restart.h
WRAP arch/arm/include/generated/asm/errno.h
WRAP arch/arm/include/generated/asm/ioctl.h
WRAP arch/arm/include/generated/asm/irq_regs.h
WRAP arch/arm/include/generated/asm/kdebug.h
WRAP arch/arm/include/generated/asm/local.h
WRAP arch/arm/include/generated/asm/local64.h
WRAP arch/arm/include/generated/asm/percpu.h
WRAP arch/arm/include/generated/asm/poll.h
WRAP arch/arm/include/generated/asm/resource.h
WRAP arch/arm/include/generated/asm/sections.h
WRAP arch/arm/include/generated/asm/siginfo.h
WRAP arch/arm/include/generated/asm/sizes.h
CHK include/linux/version.h
UPD include/linux/version.h
CHK include/generated/utsrelease.h
UPD include/generated/utsrelease.h
HOSTCC scripts/genksyms/genksyms.o
SHIPPED scripts/genksyms/lex.lex.c
SHIPPED scripts/genksyms/keywords.hash.c
SHIPPED scripts/genksyms/parse.tab.h
SHIPPED scripts/genksyms/parse.tab.c
HOSTCC scripts/genksyms/lex.lex.o
Generating include/generated/mach-types.h
CC scripts/mod/empty.o
/bin/sh: 1: arm-rpi-linux-gnueabi-gcc: not found
make[2]: *** [scripts/mod/empty.o] Fehler 127
make[1]: *** [scripts/mod] Fehler 2
make[1]: *** Warte auf noch nicht beendete Prozesse...
HOSTCC scripts/genksyms/parse.tab.o
CC kernel/bounds.s
/bin/sh: 1: arm-rpi-linux-gnueabi-gcc: not found
make[1]: *** [kernel/bounds.s] Fehler 127
make: *** [prepare0] Fehler 2
make: *** Warte auf noch nicht beendete Prozesse...
HOSTLD scripts/genksyms/genksyms
make: *** [scripts] Fehler 2
===================================================

I also tried use the same command, but with a blank between "-j3":
"make ARCH=arm CROSS_COMPILE=arm-rpi-linux-gnueabi- -j 3"
But I get still error-messages.

I used the "bcm2708.c"-file from "feliks".

Does anyone has any solution for my problems?
Thank you in advance.

Greetings.
Alex

Re: CAN controller

Posted: Mon Aug 26, 2013 7:02 pm
by feliks
KingAlex1985 wrote: First thing, I can't find the entry "Microchip MCP251x SPI CAN controllers" in the menuconfig
....
You have to enable the SPI support at fist, then MCP entry should be visible.
KingAlex1985 wrote: make: arm-rpi-linux-gnueabi-gcc: Kommando nicht gefunden
To cross compile for arm/rpi, you have to build you own compiler. For me it was easier to do all this directly on the Pi. Just leave out all the ARCH and CROSS_COMPILE options in the tutorial. However, the kernel compilation takes some hours doing it that way.

Regards and good luck

Re: CAN controller

Posted: Mon Aug 26, 2013 7:20 pm
by Zeta
feliks wrote:To cross compile for arm/rpi, you have to build you own compiler. For me it was easier to do all this directly on the Pi. Just leave out all the ARCH and CROSS_COMPILE options in the tutorial. However, the kernel compilation takes some hours doing it that way.
It has to be noted that for the desktop Ubuntu and ArchLinux distribution, a compiler compatible with the raspberry pi exists in the official packages, and so doesn't require bulding our own (At least that's what says the wiki, I never tried it myself) :
http://elinux.org/RPi_Kernel_Compilation#Ubuntu (other follow)

Re: CAN controller

Posted: Mon Aug 26, 2013 8:11 pm
by KingAlex1985
feliks wrote: You have to enable the SPI support at fist, then MCP entry should be visible.
@feliks: It still doesn't show me the "Microchip MCP251x SPI CAN controllers"-entry in the menuconfig, although the SPI support is checked. See the picture:
Image
What else can I do?

Edit:
Sorry, my fault. Now I can see the MCP entry. Tank you very much.
Now I will go on with the other steps.

Re: CAN controller

Posted: Mon Aug 26, 2013 8:23 pm
by Zeta
KingAlex1985 wrote:@feliks: It still doesn't show me the "Microchip MCP251x SPI CAN controllers"-entry in the menuconfig, although the SPI support is checked.
It seems you are mixing two menus.

The MCP251x driver should be shown under the Networking/CAN part of the menu, as you wrote in your previous message :
=======================================================
[*] Networking support --->
....<M> CAN bus subsystem support --->
........<M> Raw CAN Protocol (raw access with CAN-ID filtering)
........<M> Broadcast Manager CAN Protocol (with content filtering)
............CAN Device Drivers --->
................<M> Platform CAN drivers with Netlink support
................[*] CAN bit-timing calculation
................<M> Microchip MCP251x SPI CAN controllers
................[*] CAN devices debugging messages
===========================================

But as this drivers needs SPI, the menuconfig tool don't show it unless SPI is activated.

So you have to go to the SPI menu and activate it, and then go back to the CAN menu and it should be visible.

The MCP251x is a CAN driver that needs SPI, not a SPI driver.

I hope this is clearer !

Re: CAN controller

Posted: Mon Aug 26, 2013 8:45 pm
by KingAlex1985
Ok, thank you feliks. Now the MCP entry will be shown.

But my second problem is still there. It's the "command not found"-error-message.
=============================================================
alex@alex-desktop:/opt/raspberrypi/linux$ make ARCH=arm CROSS_COMPILE=arm-rpi-linux-gnueabi- -j 3
make: arm-rpi-linux-gnueabi-gcc: command not found
scripts/kconfig/conf --silentoldconfig Kconfig
make: arm-rpi-linux-gnueabi-gcc: command not found
CHK include/linux/version.h
CHK include/generated/utsrelease.h
CC scripts/mod/empty.o
/bin/sh: 1: arm-rpi-linux-gnueabi-gcc: not found
make[2]: *** [scripts/mod/empty.o] Fehler 127
make[1]: *** [scripts/mod] Fehler 2
make[1]: *** Warte auf noch nicht beendete Prozesse...
make: *** [scripts] Fehler 2
make: *** Warte auf noch nicht beendete Prozesse...
alex@alex-desktop:/opt/raspberrypi/linux$
=============================================================

I used this command for cross-compiling from Linux (in my case: Kubuntu 13.04):
"sudo apt-get install gcc-arm-linux-gnueabi make ncurses-dev"