msperl
Posts: 353
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Tue Oct 29, 2013 6:40 pm

Problem has been found - it is 2 factors:

* 2D-DMA transfers are not 100% guaranteed to be always in the correct order, which makes them unreliable if one needs to configure an Register
* Resetting SPI RX/TX counters sometimes can take a bit longer, so I had to split the setting od CS+Reset+length now out to 3 DMAs to make it work

With both of these I have been able to run without this issue for 1.5 hours without issues.

You can find the latest code now on github - if you are interrested...

Now I rerun my testing with higher speeds over the night!

Martin

Zeta
Posts: 72
Joined: Wed Dec 12, 2012 9:51 pm

Re: CAN controller

Tue Oct 29, 2013 10:02 pm

bertr2d2 wrote:I didn't expected, that you would like to compile the kernel. I just thought, that you take the tar archive and
make a binary debian package of this. Did you took the exact kernel source as the Raspbian distribution ?
While looking at how to make a debian package (it is my first .deb, but already played with rpm before), it seemed the way to go. If I find how to directly make kernel package then, it will be easy to use in the future to follow the changes in raspbian (if martin's drivers are not upstreamed). And it is interesting to see how it works.

At first, I was thinking of compiling only the modules for can. But as you needed a patch kernel I have tried that first. When I get more knowledge and experience about this, I may adjust what really makes sense to build.

For my first try, I didn't apply any patch, only the last github version of the 3.6 branch (it is a pain to find the actual commit hash raspbian is built on, so I made the simplest and took the head, for testing purpose), and the config file of your last archive.
It proved to work, so now I can do it "correctly" :
  • Target the exact same kernel than stock raspbian
  • Apply the kernel patch (can be on a github fork or patches applied locally)
  • Add the missing drivers for can, and maybe package them separately (like a module_can, module_mcp2515 and module_bcm2835dma packages) if I find that it is something usual in debian
  • If I success the above, propose these packages to raspbian repo/build system. If they are not accepted, find a way to track raspbian and recompile to follow its change. I may even look at providing an APT repository.
For now I will start by creating a package with can that "works", and then look at the other steps...
bertr2d2 wrote:For reference take this one "How to build LPICP kernel modules for raspbian on the R-PI"
http://hg.kewl.org/pub/k8048/file/e9127 ... ADME.lpicp
Nice find ! Very interesting, I will follow it closely.
bertr2d2 wrote:I patched the kernel with this patch:

Code: Select all

@@ -584,6 +584,9 @@ struct platform_device bcm2708_powerman_device = {
   .id = 0,
   .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
   .resource = bcm2708_spi_resources,
+  .dev = {
+    .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
+  },
 };

 #ifdef CONFIG_SPI
Regards,
This will be useful.
msperl wrote:Problem has been found - it is 2 factors:

* 2D-DMA transfers are not 100% guaranteed to be always in the correct order, which makes them unreliable if one needs to configure an Register
* Resetting SPI RX/TX counters sometimes can take a bit longer, so I had to split the setting od CS+Reset+length now out to 3 DMAs to make it work

With both of these I have been able to run without this issue for 1.5 hours without issues.

You can find the latest code now on github - if you are interrested...

Now I rerun my testing with higher speeds over the night!

Martin
You are coding so fast, that seeing the time it takes me to create a debian package, you will have finished before me ;) Thanks again for your work and promising results !

I won't be available for some days, but will continue on this as soon as I am back. Hopefully it will be quick to have a first working version with all the patches in a way that it easy to update.

Zeta

msperl
Posts: 353
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Wed Oct 30, 2013 6:00 am

117M CAN messages and 10 hours later the system still works like a charm @8MHz SPI Bus without Packet loss.
Below that BUS Speed it produces overruns (and also overruns that are NOT detected...).

I will now go to get the mcp2515a driver working before working on the "pipelining" of DMA transfers...

Martin

rayhvh
Posts: 4
Joined: Mon Jan 23, 2012 12:04 am

Re: CAN controller

Thu Oct 31, 2013 3:20 pm

Afther more then an month of trying to get the raspberry pi work with can using this chip : http://www.skpang.co.uk/catalog/pican-c ... -1196.html

i didnt had any succes and im giving in...
i dont have much linux experience and this whas my school project but now it kinda failed. :?

maybe as an last resort. is theire anyone that can make it work FOR me???
make the raspberry pi work with that board and then make an backup image for me? that would be so awsome.. 8-)

i juist need to read out some can messages as my first step. AKA candump has to work..

tanks anyways


"NOTE : This PiCAN board requires user with advance Linux skills. Not suitable for beginners." i had better read that before trying haha

msperl
Posts: 353
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Thu Oct 31, 2013 4:22 pm

Take the ones that Gert has been providing and zeta is about to package.
Then it should work fine.

But I believe it is more of an issue of what is happening on the CAN-bus itself...

Do you have an oscilloscope available?
Connect our device to the CAN board and then look with your oscilloscope on the RX pin of the mcp2551 chip (pin 4 on the 8 pin chip) or mcp2515 (pin2 on the 18 bit chip).

This should show you some bit-pattern when there is traffic on the bus.
And from that you should be able to infer the Bus speed (bit length that you see) and start configuring it correctly.

From then on the receiving side should start to work.

If you do not see anything, then there is no activity on the CAN bus.

For testing transmits:
* disconnect RPI from CAN.
* restart CAN driver and configure it
* then send a single message with cansend

Now you can check with your oscilloscope on the TX pin of mcp2551 or mcp2515 (pin 1 on both chips) and you should see the bit pattern as well.

You could also check the differential between CANH and CANL or either versus ground

Ciao,
martin

Almaz
Posts: 7
Joined: Sun Oct 20, 2013 10:40 pm

Re: CAN controller

Fri Nov 01, 2013 9:22 pm

Hello)
I install this modules:

Code: Select all

# insmod spi-bcm2708.ko
# insmod can.ko 
# insmod can-dev.ko 
# insmod can-raw.ko 
# insmod can-bcm.ko 
# insmod mcp251x.ko
And try to see the result by command

Code: Select all

dmesg | egrep -i "can|spi|mcp"
I get this:

Code: Select all

bcm2708_spi bcm2708_spi.0: DMA channel 0 at address 0xf2007000 with irq 16
bcm2708_spi bcm2708_spi.0: DMA channel 4 at address 0xf2007400 with irq 20
bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80) 
bcm2708_spi bcm2708_spi.0: SPI Controller running in DMA mode 
can: controller area network core (rev 20120528 abi 9)
CAN device driver interface
can: raw protocol (rev 20120528)
can: broadcast manager protocol (rev 20120528 t)
And

Code: Select all

ifconfig can0"
:

Code: Select all

Device not found
It seems like mcp251x.ko not work ( not probe ). How to fix that?

bertr2d2
Posts: 98
Joined: Wed Aug 08, 2012 10:12 pm

Re: CAN controller

Fri Nov 01, 2013 11:16 pm

Almaz wrote: It seems like mcp251x.ko not work ( not probe ). How to fix that?
Please have a look at:
http://www.raspberrypi.org/phpBB3/viewt ... 53#p433553
but use http://lnxpps.de/rpie/rpi_can_3611_spi_dma.tar.xz instead.

The "glue" between the SPI interface and the MCP2515 is missing. Normally you have to change the board definition file and compile the kernel.
Martin was so kind to write a kernel module which make this boring step obvious:

Code: Select all

# MCP2515 with /INT on GPIO25 and 16MHz clock
modprobe spi-config devices=\
bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
rayhvh wrote:After more than a month of trying to get the raspberry pi work with can using this chip : http://www.skpang.co.uk/catalog/pican-c ... -1196.html
Did you shortened JP3 for the 120 Ohm termination ? I got the same interface these days (thx Sukkin :-) ) and its working fine here.

Regards

Gerd
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

danjperron
Posts: 3503
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: CAN controller

Fri Nov 01, 2013 11:48 pm

Gert,

I think you put one zero to much speed=1000000 for 1mHz. I never seen 10Mhz CAN bus yet.

Also you need an other 120 ohm resistor on the other end. (Only 2 resistors at each end). They are needed to cancel echo.

Daniel

bertr2d2
Posts: 98
Joined: Wed Aug 08, 2012 10:12 pm

Re: CAN controller

Fri Nov 01, 2013 11:59 pm

danjperron wrote:Gert,
I think you put one zero to much speed=1000000 for 1mHz. I never seen 10Mhz CAN bus yet.
Daniel
The 10Mhz is the max speed for the SPI interface of the MCP2515. A more detailed description could be found at:
https://github.com/msperl/spi-config
The CAN speed itself is set by the 'ip" command.

And yes, you need 120 Ohm on the other end of the CAN bus which is normally done by another interface.

Regards

Gerd
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

Almaz
Posts: 7
Joined: Sun Oct 20, 2013 10:40 pm

Re: CAN controller

Sat Nov 02, 2013 1:11 pm

Gerd,
thank you for answer) I try to follow by instruction of linked topic:
1. I create fresh Raspbian sd card.
2. Expand filesystem, reboot
3. download "rpi_can_3611_spi_dma.tar.xz"
4. Unpack the archive:

Code: Select all

tar Jxvf /tmp/rpi_can.tar.xz
and get the many strings like:

Code: Select all

lib/modules/3.6.11+/kernel/net/can/
.....
usr/bin/canbusload
...
5.

Code: Select all

depmod -a
nothing show me

6.

Code: Select all

rmmod spidev
and get the answer:

Code: Select all

Error:Module spidev is not currently loaded
And "lsmod" do not show me any spidev module.

7.

Code: Select all

modprobe spi_bcm2708
And "lsmod" show me loaded "spidev" and "spi_bcm2708" modules.

8.

Code: Select all

modprobe spi-config devices=\
bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
and get error:

Code: Select all

FATAL: Module spi-config not found
9.

Code: Select all

modprobe mcp251x 
show me same error

Were i mistaken?
Jumper J3 is used) I use http://www.skpang.co.uk/catalog/pican-c ... -1196.html too. And when i follow to instruction i get worked can interface, but my mouse stop to work after that)

Mayco
Posts: 2
Joined: Sat Nov 02, 2013 3:49 pm

Re: CAN controller

Sat Nov 02, 2013 4:11 pm

Almaz, do you extract the archive in your filesystem root ("/")? That's the mistake I made at first, I extracted the archive in another directory and then copied over the data to "/", but that didn't seem to work for some reason.

Anyway, I also have a question of my own. I've purchased the "PICAN shield" (http://www.skpang.co.uk/catalog/pican-c ... -1196.html) for one of my Raspberry Pi's and installed the support using the method(s) provided by Gerd.

I also purchased a cable like this: Image.

After preparing my Raspberry Pi and connecting JP3 for the 120 ohm resistor ending, I hooked up this cable between my PICAN and a cars OBDII interface (I'm pretty sure it's a Opel Corsa D, which should have the following CAN specifications: CAN 11bit @ 500kb/s). I initialize the PICAN shield using:

Code: Select all

rmmod spidev
modprobe spi_bcm2708
modprobe spi-config devices=\
bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pd$
modprobe mcp251x
/sbin/ip link set can0 type can bitrate 500000
/sbin/ifconfig can0 up
Then, I connect the cable, start the candump (and/or cansniffer), start the car... and nothing happens.

Now I have some pretty in-depth knowledge about the CAN standard, but I clearly don't know as much about car diagnostics OBDII as I would like. I didn't expect any data I could make sense of, but I at least expected to see a lot of (seemingly random) CAN frames scroll by in the sniffer/dump program. Are OBDII and CAN seperate things or do I need to send some "data request" frame before the car starts "talking"?

Can anyone tell me what I'm doing wrong here?

Thanks in advance!

Almaz
Posts: 7
Joined: Sun Oct 20, 2013 10:40 pm

Re: CAN controller

Sat Nov 02, 2013 4:41 pm

understood. Here's what worked for me:
1. download this - http://lnxpps.de/rpie/rpi_can_3611_spi_dma.tar.xz
2. unpack in /home/pi/can
3. then run this:

Code: Select all

cd /home/pi/can/boot
cp kernel.img /boot
reboot
after rebooting run this:

Code: Select all

cd /home/pi/can/lib/modules/3.6.11+/kernel/drivers/spi
insmod spi-bcm2708.ko
insmod spi-config.ko devices=\bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
cd /home/pi/can/lib/modules/3.6.11+/kernel/net/can
insmod can.ko
cd /home/pi/can/lib/modules/3.6.11+/kernel/drivers/net/can
insmod can-dev.ko
cd /home/pi/can/lib/modules/3.6.11+/kernel/net/can
insmod can-raw.ko
insmod can-bcm.ko
cd /home/pi/can/lib/modules/3.6.11+/kernel/drivers/net/can
insmod mcp251x.ko
ifconfig can0
ip link set can0 up type can bitrate 1000000
Use jumper j3 on skpang's hardware.
Thanks for help to bertr2d2)

bertr2d2
Posts: 98
Joined: Wed Aug 08, 2012 10:12 pm

Re: CAN controller

Sat Nov 02, 2013 5:01 pm

Almaz,

you could avoid the copying if you extract the archive in the right path:

Code: Select all

cd /
tar Jxvf /tmp/rpi_can_3611_spi_dma.tar.xz 
depmod -a
will put all things in the right place. Load the modules with modprobe.
The depmod -a will resolve dependencies and you don't need to give a path anymore.

Regards

Gerd
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

danjperron
Posts: 3503
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: CAN controller

Sat Nov 02, 2013 8:17 pm

I prefer to have it more automatic,

This is the best method I found so far,

P.S. I'm log as root. If you are not , use the sudo command.

1- from a stock raspbian we need to change the kernel

Code: Select all

cd /tmp
wget http://lnxpps.de/rpie/rpi_can_3611_spi_dma.tar.xz
cd /
tar Jxvf /tmp/rpi_can_3611_spi_dma.tar.xz 
depmod -a
reboot

2- We need to update the /etc/modprobe.d/raspi-blacklist.conf file
Enable the spi-bcm2708 driver and blacklist the mcp251x driver

Code: Select all

#blacklist spi-bcm2708
blacklist mcp251x
3- Let's add the spi-config and the new mcp2515 modules in file /etc/modules

Code: Select all

# MCP2515 configuration with /INT on GPIO25 and 16MHz clock
spi-config devices=\
bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release

#and of course the mcp2515 driver 
mcp2515
4- And now the network can0 auto connect. Add these in the /etc/network/interfaces

Code: Select all

auto can0
iface can0 inet manual
     pre-up /sbin/ip link set can0 type can bitrate 125000
     up /sbin/ifconfig can0 up
     down /sbin/ifconfig can0 down
and reboot!

if everything is ok , the command ifconfig should report something like

Code: Select all

root@RpiTest:~# ifconfig
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:6674 errors:0 dropped:0 overruns:0 frame:0
          TX packets:58915 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 lg file transmission:10 
          RX bytes:6695 (6.5 KiB)  TX bytes:176745 (172.6 KiB)
I don't know if this is the best method but it is working fine for me.

Daniel

floeckschlager
Posts: 5
Joined: Sun Nov 03, 2013 4:23 pm

Re: CAN controller

Sun Nov 03, 2013 4:31 pm

Hey!

I have installed the CAN interface with Gerds rpi_can_3611_spi_dma.tar.xz archive, but I have skipped the "rmmod spidev"-command to keep access to /dev/spidev0.1.

Now sending messages via can0 works fine until I try to send some character over spidev0.1. The character is transmitted correctly, but when I try to send some can-messages after that, the device begins to send this message several times one after an other.

Is there some way to get the can0 and spidev0.1 working correctly the same time?

I am working with real hardware and not in loopback mode. For receiving I use an at90can128 and a shift-register (74HC595).


Flo

BTW: Sending messages always in the right order is necessary for me. For example when doing some firmware-update via can-bus.

msperl
Posts: 353
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Mon Nov 04, 2013 1:35 pm

To get mcp2515 + SPIDEV working, you will have to configure the second SPI device as SPIDEV device with your preferred speed, mode,...

For that you need to add the following to the Parameter of spi-config typically: ",bus=0:cs=1:speed=500000:modalias=spidev"

You can also configure an SD Card(mmc), ADC, Display (fbXX),... that way - choose the right modalias and other optional parameters to get it configured correctly... so that the corresponding drivers can get matched and used.

See also: the documentation here on what parameters are available: https://github.com/msperl/spi-config
With that you can configure "exotic" devices with a bit of "black magic"...

Ciao, Martin

msperl
Posts: 353
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Mon Nov 04, 2013 1:45 pm

SPI-Driver update:

Driver has been updated with a "future" feature from the 3.14 kernel called spi_prepare_messages.

This result in a drop of CPU utilization from 88% down to 80% CPU Utilization.
Also with the new interface only 57 out of 3283 packets are delivered from the 2nd hardware buffer.
While "without prepares" I see 1528 out of 3438 packets get delivered from the 2nd HW buffer. So in about 44% of all cases both buffers are full.
If we get closer to 50%, then we start getting packet-loss!

Note that all this is based on a new pair of drivers: spi-bcm2835dma and mcp2515a, both of which are available on git-hub...

Please see main thread for details: http://www.raspberrypi.org/phpBB3/viewt ... 33#p448233

Ciao, Martin

floeckschlager
Posts: 5
Joined: Sun Nov 03, 2013 4:23 pm

Re: CAN controller

Tue Nov 05, 2013 8:11 pm

Hi,
thanks for the instructions. But there are still problems when I try sending some CAN-msg after I transmitted some bytes per spidev.
I don't have a scope here at the moment, but now it looks like the bcm2515 begins to spam the bus even more than before (I've build in a message counter on the at90can to check this).
The spamming stops first when I send an other byte per SPI. Only then the message appears in candump (once) and the TX packets counter in ifconfig is increased. Sending bytes per spidev works fine all the time. But when I try to send the next CAN-Message the spamming starts over again...

msperl
Posts: 353
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Tue Nov 05, 2013 9:50 pm

Seems as if there is an issue with acknowledging the packet due to different bit-timings - missing BUS-termination?

Never seen such a behavior - unless you have only one device on the bus or two, but one is in "listen only mode" and the transmitting one is not set for one-shot mode. (Note: one-shot-mode means it will not try to redeliver the message if it was not acknowledged (by any peers) when it was sent out, but normally you would want to make sure it gets sent so it will retry until there is a peer acknowledging it. And the ATMega - you have not configured it for listen only?
The counter only increasing once would indicate this "retransmit" behaviour.

Also: I would guess that while this "broadcast storm" is happening, the interrupts for the MCP2515 do not increase - nor the ones for the SPI driver. Check via cat /proc/interrupts - it this is what you are observing, then no packets get delivered via SPI and CAN and you have triggered the CAN-bus transmit issue due to missing ACK.

Then give the mcp251x driver a chance and configure one-shot mode via the ip link command when configuring baud-rate and see if you can reproduce it...

Other idea:
Your second device you communicate with via SPIDEV - does it have reverse CS polarity by chance? Or do you have CS inverted for the MCP2515 via an opto-coupler or similar?
Because there is a bug in the spi-driver that does not fully support that - it does not show with a single device on the SPI bus.

That is all that comes to my mind right now...

Martin

P.s: oscilloscope/logic-analyzer would be the best approach - and as I have mentioned some time ago, maybe we should have the TX/RX pins between the Can-Controller exposed to a GPIO pin on the RPI and then sample this pin to see what is really happening on the CAN-bus...

Zeta
Posts: 72
Joined: Wed Dec 12, 2012 9:51 pm

Re: CAN controller

Tue Nov 05, 2013 11:34 pm

Hi,

WARNING : What follows is work in progress, which is not yet an acceptable solution for me as it is now. If you don't know what you are doing, then follow the instructions some messages above to extract Gerd's archive directly, which we know works well (and is as easy).

Quick status of my new trial with .deb. To gain some time before having the full kernel package done correctly, I tried to convert Gerd's archive to .deb using alien (I first needed to convert from tar.xz to tar.gz).
Then you can install it like that :

Code: Select all

wget http://sagittarii.fr/rpi/rpi-can-3611-spi-dma_1-2_all.deb
sudo dpkg --force-overwrite -i rpi-can-3611-spi-dma_1-2_all.deb
The "--force-overwrite" option is needed as this package replace some files already provided by other packages, creating conflicts, like shown in the trace:

Code: Select all

dpkg: warning: overriding problem because --force enabled:
 trying to overwrite '/lib/modules/3.6.11+/kernel/drivers/spi/spi-bcm2708.ko', which is also in package raspberrypi-bootloader 1.20130902-1
dpkg: warning: overriding problem because --force enabled:
 trying to overwrite '/usr/bin/cancel', which is also in package cups-client 1.5.3-5
dpkg: warning: overriding problem because --force enabled:
 trying to overwrite '/boot/kernel.img', which is also in package raspberrypi-bootloader 1.20130902-1
dpkg: error processing rpi-can-3611-spi-dma_1-2_all.deb (--install):
 unable to make backup link of `./boot/kernel.img' before installing new version: Operation not permitted
Errors were encountered while processing:
 rpi-can-3611-spi-dma_1-2_all.deb
It seems the "cancel" program was copied to this archive by error (copy of can* ?), so I should remove it from the archive before creating the .deb, and it will be ok.
But for the two other, there is a conflict. The spi driver is replaced giving only a warning, so it is ok as a temporary solution, but the kernel update fails with an error.
"Backup link" ? not sure what it is trying to do, but if it tries a symbolic link, it will fail as the /boot partition is formated as FAT with doesn't support it. Maybe it is something else ?
If I rename the kernel before, so that it doesn't exist anymore, then only a warning is shown and the file is created.

If you have some comments on this, I can make some changes, otherwise I will return tomorrow to packaging correctly everything, to allow making updates without warnings or need of force options, and by packaging separately the kernel, the can tools (candump, cansend, ...) and maybe the modules (as spi-config can be used separately than the mcp2515, I will see when at this point).

Zeta.

bertr2d2
Posts: 98
Joined: Wed Aug 08, 2012 10:12 pm

Re: CAN controller

Wed Nov 06, 2013 1:07 am

Hi Zeta,
Zeta wrote: ...
It seems the "cancel" program was copied to this archive by error (copy of can* ?), so I should remove it from the archive before creating the .deb, and it will be ok.
thanks for the hint: cancel was added by accident (wildcard can*). Fixed it - /usr/bin/cancel removed from archive.

Regards

Gerd
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

Zeta
Posts: 72
Joined: Wed Dec 12, 2012 9:51 pm

Re: CAN controller

Thu Nov 07, 2013 11:22 pm

Hello,

Good news, my Pi finally managed to compile a kernel this night and package it to a deb file.

I have only made a quick test of it now, so I am still not sure everything works correctly. So far, it boots and loads the modules for the can0 and a Wifi dongle. I can use it correctly from ssh, so I think it is okay, but I will make some more tests tomorrow with real can hardware (I have nothing connected now, not even a termination resistor...), and will let you know.

What is in the debian package ? This:
  • The same kernel as raspbian is using (3.6.11, from the same git hash), at least for the last september version
  • The mcp2515 driver with a patch so that it provides the modinfo (see my post about this in the previous pages) and all the CAN modules it depends on
  • The spi low latency patch (I used the "old" version on my PC, as I did not found where the last one is), it involves the patch in the kernel as Gerd shown, for the DMA
  • The spi-config module to allow on the fly configuration of the SPI without recompiling the kernel
  • the .config file from Gerd's archive, with slight changes for the lines above (I should have done it from the raspbian default .config file, but this time I forgot I was on Gerd's kernel while extracting it)
This kernel and its module are completely independent on the default one, so both can be installed at the same time and the bootloader configured to launch the one you want.

The mcp251x is not in it, as it was more a pain to have both (like additional configuration to be sure which module was loaded). The only missing thing in the mcp2515 is the loopback mode which was handy for tests (and mcp2510 support if someone still has one), otherwise it does everything better.

The can utils (cansend, candump and friends) are not in this package either. I will make a dedicated package for them after, but for now if you don't already have them you can use the ones in Gerd's archive.

Using the modinfo patch in the mcp2515, it is loaded automatically when loading the module spi-config. So this is easier than before.

People who don't care to brick their pi and need to reflash it can give it a try there (you've been warned ! ;) ) : http://sagittarii.fr/rpi/linux-image-3. ... _armhf.deb

Code: Select all

# download the package
wget http://sagittarii.fr/rpi/linux-image-3.6.11-can-2+_3.6.11_armhf.deb

# install it
sudo dpkg -i linux-image-3.6.11-can-2+_3.6.11_armhf.deb

# backup your config.txt file so that it is easy to go back to the stock kernel in case of problem
sudo cp /boot/config.txt /boot/config.txt.bak

# add a custom kernel line to config.txt so that it load the new kernel and not the default one
# you must check before if there is not already a "kernel=" line in this file, and if there is remove it before or replace it by hand
sudo su -c 'echo "kernel=vmlinuz-3.6.11-can-2+" >> /boot/config.txt'

# reboot the pi, and check if it works !
# in the previous messages, you can see how to autostart the can line by tuning /etc/modules and /etc/network/interfaces
So my next step is to check if it really works by connecting it to real CAN devices. If everything is ok, then I will have to document a bit more what I have done, and make this in a more "debian way".
There is another topic on the forum about the sources uses for the kernel package and they said it was not part of raspbian but hacked by the foundation. Maybe they would also be interested in this discussion, which should happen in that other topic and not here : http://www.raspberrypi.org/phpBB3/viewt ... 1&p=449660

Please let me know your results if you test this package !

Zeta

Zeta
Posts: 72
Joined: Wed Dec 12, 2012 9:51 pm

Re: CAN controller

Fri Nov 08, 2013 8:30 pm

I let my rpi run the whole afternoon with the kernel for which I provided the debian package in the message above with success.

I am looking at the can-utils package right now (which contains cansend, ...). It has already been started but it seems it never reached the debian distribution:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=568303
and : http://lists.debian.org/debian-mentors/ ... 00078.html

I am trying to compile it to see if it is still working, or need to be updated.

Zeta

Sully
Posts: 2
Joined: Tue Nov 19, 2013 5:13 pm

Re: CAN controller

Tue Nov 19, 2013 7:30 pm

Hi,

Noob here with respect to linux and the raspberry pi but learning a lot from all the info in this forum. Thanks for all the help!

I finally got my RPI to read a CAN message that I'm sending from another controller as I can see the messages through candump. Now I would like to take that CAN message and do something useful with it via a Python script. I've been looking for some example python scripts utilizing SPI and CAN but haven't found anything that I could use to get started. An example script or a point in the right direction would be much appreciated.

Thanks,
Sully

msperl
Posts: 353
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Wed Nov 20, 2013 3:18 pm

Look here: https://libbits.wordpress.com/2012/05/2 ... in-python/

But the problem is that raspbian only ships with python 2.7 and 3.2, while you would need 3.3 (+patch)...

You may compile the latest version of python yourself - not that complicated - and then you can probably use it.
It will require a bit of experimentation...

Martin

Return to “Interfacing (DSI, CSI, I2C, etc.)”