Xanatos
Posts: 9
Joined: Tue Sep 24, 2013 12:27 pm

Re: CAN controller

Tue Oct 01, 2013 10:16 am

msperl, I just got a fresh 3.11.y branch and tried to add ypur patch. But I got rejects for the following code. What can be wrong?

Code: Select all

--- arch/arm/mach-bcm2708/bcm2708.c
+++ arch/arm/mach-bcm2708/bcm2708.c
@@ -552,19 +558,29 @@
        .resource = bcm2708_spi_resources,
        .dev = {
                .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
-       },
+       }, 
+};
+
+static struct mcp251x_platform_data mcp251x_info = {
+       .oscillator_frequency   = 16000000,
+       .board_specific_setup   = NULL,
+       .irq_flags              = IRQF_TRIGGER_FALLING|IRQF_ONESHOT,
+       .power_enable           = NULL,
+       .transceiver_enable     = NULL,
 };
 
 #ifdef CONFIG_BCM2708_SPIDEV
 static struct spi_board_info bcm2708_spi_devices[] = {
-#ifdef CONFIG_SPI_SPIDEV
        {
-               .modalias = "spidev",
-               .max_speed_hz = 500000,
+               .modalias = "mcp2515",
+               .max_speed_hz = 1000000,
+               .platform_data = &mcp251x_info,
                .bus_num = 0,
                .chip_select = 0,
                .mode = SPI_MODE_0,
-       }, {
+       }
+#ifdef CONFIG_SPI_SPIDEV
+       ,{
                .modalias = "spidev",
                .max_speed_hz = 500000,
                .bus_num = 0,
@@ -763,6 +786,7 @@
        system_serial_low = serial;
 
 #ifdef CONFIG_BCM2708_SPIDEV
+       bcm2708_mcp251x_init();
        spi_register_board_info(bcm2708_spi_devices,
                        ARRAY_SIZE(bcm2708_spi_devices));
 #endif
Regards,
Marco

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

Re: CAN controller

Tue Oct 01, 2013 10:22 am

Are you compiling on an RPI or are you cross-compiling?

I am only compiling on RPI - never tried to cross-compile...

Try to download the full source from the post above and see if that one compiles.

Martin

P.s: it may also be related to "tabs" that are pasted as multiple spaces - and that is why it may not apply cleanly...

Xanatos
Posts: 9
Joined: Tue Sep 24, 2013 12:27 pm

Re: CAN controller

Tue Oct 01, 2013 10:31 am

Martin,
saw to late your file before posting, sorry for that.

Yeah I'm doing cross compile as my PI is not at work 8-)

The file downloaded is spi-bcm2708.c do I need to replace the original bcm2708.c with that one?

Regards,
Marco

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

Re: CAN controller

Tue Oct 01, 2013 10:34 am

Xanatos wrote:Martin,
The file downloaded is spi-bcm2708.c do I need to replace the original bcm2708.c with that one?
Regards,
Marco
yes - replace the original spi-bcm2708.c with the downloaded version...

Martin

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

Re: CAN controller

Tue Oct 01, 2013 3:17 pm

Compiling the kernel to adpat the MCP2515 settings and connections is boring and for most users it's a challenge.
The best way would be a small module which could do the setup like this here (add_spike_device_to_bus):

https://github.com/scottellis/spike/blob/master/spike.c

The settings (especially MCP2515 frequency and GPIO Int) should be module params. Here is an example:

https://dev.openwrt.org/browser/trunk/p ... o-custom.c

Does somebody want's to get the credits ?

BTW: excellent writing here (SPI driver):

http://www.jumpnowtek.com/?option=com_c ... &Itemid=62

Regards

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

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

Re: CAN controller

Tue Oct 01, 2013 3:30 pm

bertr2d2 wrote: ...
The best way would be a small module which could do the setup like this here (add_spike_device_to_bus):
...
Does somebody want's to get the credits ?
working along these lines already...

probably would look like this:

Code: Select all

modprobe spi-boardconfig spi0=<driver>:[<speed>]:[<irq>]:[<driver specific data>] spi1=<driver>:[<speed>]:[<irq>]:[<driver specific data>]
in the long run it should support a certain set of drivers, like:
  • spidev
  • mcp251x
  • enc28j60
  • other
So far I got a kernel crash...

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

Re: CAN controller

Tue Oct 01, 2013 3:41 pm

Martin, you are faster than light ;-)

Many users appreciate you excellent work, as I do. Thx.

Regards

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

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

Re: CAN controller

Tue Oct 01, 2013 8:50 pm

Initial version is working - needs some code cleanup and better error-handling.

but basically I can now use:

Code: Select all

insmod spi-config.ko dev0=mcp2515:10000000:25:16000000 dev1=mcp2515:8000000:22:20000000
to configure to mcp2515 devices
  • one with 10MHz max SPI speed, GPIO25 as interrupt source and 16Mhz Crystal for MCP2515
  • one with 8MHz max SPI speed, GPIO22 as interrupt source and 20Mhz Crystal for MCP2515
The mcp2515 requires a bit more of setup effort, but things like mmc, spidev, enc28j60,... should work out of the box without special coding (as long as they only require an Interrupt line) - if you do NOT define anything then [email protected] is used...

Code to follow after some more cleanup - possibly moving to a separate thread...

Martin

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

Re: CAN controller

Wed Oct 02, 2013 4:15 pm

Updated version is available - now also on GIT-Hub: https://github.com/msperl/spi-config

Please also review the new thread: http://www.raspberrypi.org/phpBB3/viewt ... 44&t=57157 to handle this

Ciao,
Martin

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

Re: CAN controller

Sun Oct 06, 2013 7:06 pm

Thanks for your excellent work, Martin !

So, recompiling the kernel is not necessary anymore !
I have done a successful test on a fresh 2013-09-25-wheezy-raspbian with this modules+utils:
http://lnxpps.de/rpie/rpi_can.tar.xz
This archive provides vanilla kernel modules and can-utils.

Howto install:

Code: Select all

cd /
tar Jxvf /tmp/rpi_can.tar.xz
# resolve module dependecies
depmod -a
Test using loopback mode:

Code: Select all

rmmod spidev
modprobe spi_bcm2708

# 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

modprobe mcp251x

# doing loopback test
/sbin/ip link set can0 type can bitrate 500000 loopback on
/sbin/ifconfig can0 up

# first terminal
candump any,0:0,#FFFFFFFF

# second terminal
cansend can0 123#dead
If anything is going wrong, please provide the appropiate output from

Code: Select all

dmesg
cat /sys/bus/spi/devices/*/modalias
cat /proc/interrupts
ip -s -d link show can0
Regards

Gerd
Last edited by bertr2d2 on Tue Oct 08, 2013 6:44 am, edited 1 time in total.
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

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

Re: CAN controller

Mon Oct 07, 2013 8:31 pm

Hello,

Perfect ! Thanks for the work Martin and Gerd !

Works like a charm with an MCP2515 with a 20MHz crystal in loopback mode.
Next step for me is to find some CAN devices to plug it to and use it for real (not in loopback), maybe tomorrow. At this point I think I will need the MCP2515 driver, and not the MCP251x one if the hangup bug is still around.

Also what about the low-latency patch ? How does it fit here ?
What would be perfect would be to push the spi-config, the spi with low latency patch and both mcp2515 and mcp251x (as only the latter supports the old mcp2510) drivers in the stock raspbian. If they get into the kernel tree, then we will not have as much trouble following the kernel updates.

I don't know if this is be possible. What is your plan ? And how can we help ?

Also, what do you think is the best way to start automatically the can at startup ? A SysV init script, or is there "better" ?

Thanks again !!

Zeta

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

Re: CAN controller

Mon Oct 07, 2013 9:18 pm

For RPI-Config + raspbian - see: https://github.com/raspberrypi/linux/issues/391 - it might get there for the next stable section 3.10.y Also I try to get it into the main linux repository as well - in contact with the SPI-mailing-list,but no feedback yet...

For the SPI-bcm2708.c patch - there has been a pull request for a long time: https://github.com/raspberrypi/linux/pull/147 - it just never got pulled in... There is also an updated "patch" by notro converted to an out-of-tree module here: https://github.com/notro/spi-bcm2708 (but some assumptions in the later patches of his are wrong - especially the assumptions about DMA ranges bigger than 4096 bytes being adjacent are _not_necessarily_ correct.
Also - if I find time - I would like to improve the driver further...

Unfortunately mcp251x.c still has the "hickup" problem when running at higher CAN-bus-speeds and a saturated bus (say 5 consecutive frames without any gaps)
So you will need to compile the mcp2515.c as an additional module - see here if you look for a prepared version on git-hub: https://github.com/msperl/mcp2515

Maybe Gerd wants to add those 2 to the "package" of his (I have not been able to create modules that can get loaded with the stock--raspbian-kernel, but I assume it requires cross-compiling)...

As for startup:
  • for loading the spi-config module would be as simple as:
    • creating a file /etc/modprobe.d/spi-config.conf with the content:

      Code: Select all

      options spi-config devices=<your config>
    • testing that everything works fine by

      Code: Select all

      dmesg -C;rmmod spi-config;modprobe spi-config;dmesg
      to see that it loads correctly and does not hick up
    • adding spi-config to /etc/modules
    • reboot and hope that it works correctly...
  • configuring can:
    • I believe you can do it somehow by manipulating /etc/network/interfaces - you should be able to load can then on startup (not sure if the debian-scripts are up2date for that)
    • if not - create your own init-script
Ciao, Martin

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

Re: CAN controller

Tue Oct 08, 2013 9:10 am

Hi,

as Martin suggested, here is the 'new' version:

http://lnxpps.de/rpie/rpi_can_3611_spi_dma.tar.xz

It includes the advanced SPI driver from notro (which is based on Martin's Low Latency SPI Driver)
without the 64k DMA blast (only 4k DMA) and the mcp2515 async driver.
I had to include a new kernel (I used the same base as the actual Raspbian), because of the DMA.
CAN-Utils are included - based on the actual git source.

Please be aware loopback mode only works on the mcp251x - not in the mcp2515 async driver.

I would like if somebody else could make a debian package from this - I'm to lazy at the moment.

Please test the bin's.

Regards

Gerd

P.S.: loopback works fine here ...
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

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

Re: CAN controller

Tue Oct 08, 2013 12:03 pm

Created a pull request to get the DMA settings into the next release(s)...

Kernel works with the DMA-enabled bcm-2708 driver.

Martin

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

Re: CAN controller

Wed Oct 09, 2013 7:52 pm

Found a bug with spi-config, that can result in a crash when unloading the module, if the spi-bcm2708 driver has been removed first...

The new version on GitHub fixes this issue and tries to be more diligent avoiding such a situation - it will only remove a device it has assigned and only if it has not been changed since...

So beware...

@gerd: you may want to create a new binary release to avoid this situation...(but then, you typically would only remove the spi driver itself if you develop a new version on your own...)

Martin

P.s: as hinted above: working on a further improved driver that does only use dma...

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

Re: CAN controller

Wed Oct 09, 2013 8:30 pm

Updated:

http://lnxpps.de/rpie/rpi_can_3611_spi_dma.tar.xz

Code: Select all

[    5.061640] bcm2708_spi bcm2708_spi.0: DMA channel 0 at address 0xf2007000 with irq 16
[    5.247613] bcm2708_spi bcm2708_spi.0: DMA channel 4 at address 0xf2007400 with irq 20
[    5.385813] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
[    5.516291] bcm2708_spi bcm2708_spi.0: SPI Controller running in dma mode
...
[  104.055345] spi_config_register: device description: bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
[  104.055422]  spi_config_match_cs: SPI0: check CS=0 to be 0
[  104.055437]  spi_config_match_cs: SPI0.0: Found a device, but no driver...
[  104.055448] spi_config_register:spi0.0:mcp2515: found already registered device
[  104.055459]  spi_config_register:spi0.0:mcp2515: forcefully-releasing already registered device taints kernel
[  104.055467] Disabling lock debugging due to kernel taint
[  104.057853] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=10000000 mode=0 and gpio/irq=25/195
[  104.057893] spi_config_register:spi0.0:platform data:d9ecd140: 00 24 f4 00 02 20 00 00 00 00 00 00 00 00 00 00  .$... ..........
[  104.057909] spi_config_register:spi0.0:platform data:d9ecd150: 00 00 00 00                                      ....
[  104.109350] CAN device driver interface
[  104.140332] mcp251x spi0.0: CANSTAT 0x80 CANCTRL 0x07
[  104.142121] mcp251x spi0.0: probed
...
[  117.418622] mcp251x spi0.0: can0: bit-timing not yet defined
[  117.418656] mcp251x spi0.0: unable to set initial baudrate!
[  118.430871] mcp251x spi0.0: CNF: 0x00 0x91 0x01
[  192.353717] can: controller area network core (rev 20120528 abi 9)
[  192.353907] NET: Registered protocol family 29
[  192.372591] can: raw protocol (rev 20120528)

[email protected] /home/pi # cansend can0 123#deadbeefdead

[email protected] /home/pi # candump any,0:0,#FFFFFFFF    
  can0  123   [6]  DE AD BE EF DE AD
  can0  123   [6]  DE AD BE EF DE AD
Still searching for somebody who makes a Debian package ...

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

Wed Oct 09, 2013 10:11 pm

Hello,

Following your advices, Martin, I dug in the direction of autostarting the can interface using the spi-config module. It seems to work (not a lot of time and no can devices to test further on) with the following:

First, the modules need to be loaded. They can be given parameters too.
Edit the file /etc/modules:

Code: Select all

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835
# Can Modules follow :
spi_bcm2708
spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=20000000:pdu32-4=0x2002:force_release
mcp251x
Here it is configured for my setup (only one can device, 10MHz SPI & 20MHz crystal, GPIO 25 for interrupt), so it should be adapted to your hardware. Here I am still on the MCP251x for my tests, not yet switched to the last package that contains the MCP2515 driver.

Then, it can be started automatically by the network management. This works if you know at which frequency the bus will be used. It can probably also be changed at run-time, not yet looked how.
Edit the file /etc/network/interface to add the following:

Code: Select all

auto can0
iface can0 inet manual
        pre-up /sbin/ip link set can0 type can bitrate 125000 triple-sampling on
        up /sbin/ifconfig can0 up
        down /sbin/ifconfig can0 down
Here my setup is using 125kbps as the requested speed. It should work also if having two can interface by copying it for can1.

Hope this helps, and if someone can confirm this really works (I have only checked the modules are loaded and interface is up after restart) it would be great.

My next step would be to add all these data to eLinux's wiki. If I have some time next week (not yet sure...), I may also take a look at the .deb package (I have never made one so far, only RPM...). First I should find a package with source that provides some kernel modules, as a reference. I have not yet found where they are stored, I have only found the binaries...

Thanks again for your work ! (coding and providing pre-compiled binaries)

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

Re: CAN controller

Thu Oct 10, 2013 10:09 am

Great to hear that we were able to help.

As for the DMA driver: some rework is going to happen cleaning up code.
Also with this driver it came to my attention that it might be quite hard to get a raspberry-foundation" tainted driver (I got told there are no signoffs) into the linux mainline. So I will need to rewrite the SPI-bcm2708 taking the one that is already in the mainline as a base, so that we can document signoffs and get it upstream...

This applies also to the mcp2515.c driver that does not come with the stock - kernel. Getting any signoff on this will be very hard to get.
So my idea here is to implement another mcp2515.c, that is now making use of all the asyncronous SPI features to get the fastest possible thru-put at minimal CPU overhead (in conjunction with the above mentioned spi-bcm2708dma driver).

Give me some time to come up with something...

Martin

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

Re: CAN controller

Mon Oct 14, 2013 1:33 pm

Hello. im an total noobie to all of this.
now im struggeling with this for an while and i really want to fix it.
ive got an raspberry pi with : http://www.skpang.co.uk/catalog/pican-c ... -1196.html
the pican board.
now i had the files downloaded from : http://lnxpps.de/rpie/can-test.tar.bz2
and followed the following instructions provided

Code: Select all

The quickest way to try this board out is to use pre-compiled kernel image. 
Download the image from http://lnxpps.de/rpie/ and copy over to your Pi.

# cp can-test/kernel.img /boot
# cp -a can-test /home/pi

Reboot your Pi to let it come up with new kernel

# shutdown -r now

Go to the folder with the modules and install them
$ sudo su
# cd /home/pi/can-test
# insmod spi-bcm2708.ko
# insmod can.ko 
# insmod can-dev.ko 
# insmod can-raw.ko 
# insmod can-bcm.ko 
# insmod mcp251x.ko

Activate the interface with
# ip link set can0 up type can bitrate 500000

Connect the PiCAN to a CAN-bus network and monitor traffic by using command:

# ./candump can0

it gives no error. but also no messages from the can device.
now i got it connected @ 50,000 instead of 500,000.
(because the device im using uses 50 kb/s)
im juist in my internship so im an total noobie.
i connected the High and the Low straight from exension board to the CAN device.
ive tested the board with an windows pc and its sending messages.
my RPI is juist not reciving them.

now ive tryed to look at this forum pages. but i dont get any wiser how to fix it... :shock:
can anybody help me? maybe tell me in steps what i should download / copy where, and how to run it.
all i need is the RPI to recive some messages from the CAN device.

i would super appriciate your help. 8-) :oops:
(sorry for bad spelling)

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

Re: CAN controller

Wed Oct 16, 2013 9:56 am

rayhvh wrote:it gives no error. but also no messages from the can device.
now i got it connected @ 50,000 instead of 500,000.
(because the device im using uses 50 kb/s)
im juist in my internship so im an total noobie.
i connected the High and the Low straight from exension board to the CAN device.
ive tested the board with an windows pc and its sending messages.
my RPI is juist not reciving them.
It is quite hard to diagnose your problem remotely.
Essentially you might just be using the wrong parameters for configuring the communication with the device of your choice...
(Speed, Polarity,...)

As I had discussed (in private communication) with Gerd some time ago, we would recommend that there is an option on future boards to connect the RX/TX lines between the CAN-Controller and the CAN-Transciever to a GPO on the RPI (say via jumpers).

That alone would not give you much by itself, but if there ever was a GPIO based logic analyzer for the RPI, then we could easily check what is happening on the CAN-Bus itself. This would also allow estimating Bus parameters and such

Obviously this would require someone to write such a logic-analyzer - maybe we could use: http://www.raspberrypi.org/phpBB3/viewt ... =37&t=7696 (i did not check its functionality, as I use my logic8 board for analysis)
And based on this you can estimate the bus pattern to estimate bit speeds and such...

All this together would really help support CAN Bus devices - especially for the vendor of such boards, who need to support it...

But obviously you have a Revision-A or B board, that does not have such a facility.

The only thing I could think of to help, would be for you to get one of those MCP2551 chips (CAN Transcievers) in a DIP-package and put that on your breadboard and connect it to your RPI via one of the unused GPIO pins (for RX only).
Note that you will need to connect the chip to +5V and you will need a voltage divider setup for the RX Pin (so 10k coming from the Chips RX-PIN and 18k to Ground) to make the Output-Voltage level compatible with the 3V3 Levels of the RPI GPIO pins.
Obviously you woul

Then you can start to look at the "traffic pattern" in the RPI-logic-analyser by analyzing the pin in question and start estimating bit length of the pattern you see and then use that to estimate the settings for the configuration of the CAN bus...

As an alternative: If you have an oscilloscope at hand then you can also try to do this: - either pick up the signal on the RX pin (Pin 4 on U1 - either on the right or on the left side of R7) versus ground or just connect your oscilloscope to CanHigh and CanLow and look at the signal then.

That way you can check the waveforms you receive or transmit - for initial testing I would recommend that you run only with one side (RPI with CAN configured or the "client") connected...

Hope this helps you in debugging your problem...

Ciao,
Martin

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

Re: CAN controller

Sun Oct 20, 2013 11:42 pm

Hi,

I just did a fun project with a MPU6050 CANOpen module.

This little PIC18F26K80 cpu is quite capable. (CAN bus is not just for cars).

This is the info on this post.
http://www.raspberrypi.org/phpBB3/viewt ... 60#p440760


I really need full 1MBS rate.

Just wonder did somebody use one of this cpu instead of the MCP2515 to help the buffering issue.
Maybe I will try to emulate the MCP2515 with it.

Or use the FubarinoSD Pic32 http://www.seeedstudio.com/wiki/Fubarino_SD . It has 2 CAN bus and one usb. Usb will help a lot.

Daniel

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

Re: CAN controller

Mon Oct 21, 2013 6:42 am

In principle it works with a 2515 with 1MBit - the question here is primarily the issue of scheduling latencies and overhead of the linux kernel, which produce "delays" - especially with the original SPI and MCP2515 drivers.

That is why streamlined (and out of tree) drivers of both are needed to work without packet-loss.

Moving to a PIC to do the "heavy" lifting would be possible, but then you would need to write a separate CAN-bus driver, so that the limitations of the above drivers do not become your bottle-neck again... (especially for the transfer of RX-buffers)

I remember having had a similar talk with Gerd adding an AVR as a buffer between the RPI and the mcp2515 (because even with a 12MHz clock an AVR can read all the frames if you saturate the CAN bus.
The problem around the RPI drivers lies essentially around the fact that they have to rely on the scheduler to schedule the respective worker-threads and this can easily add 1-2 ms of delay until the "real driver" can respond - and that is PER SPI-Transfer!

So if you have to receive 7000 CAN-frames/s, you get easily saturated on the scheduling overheads alone - that is at least 14k context-switches/s.
Not to mention that the RPI would spend most of the time just handling the interrupts (from the mcp2515 as well as for the SPI-transfer-interrupts), which may result in >70% SYSTEM load on its own - not to mention the fact that your application needs to do some processing of the received data as well.

That is why am currently (again) rewriting the spi driver to a DMA only version (with streamlining of queued transfers without unnecessary interrupts) so that a subsequent rewrite of the mcp2515 driver may make use of heavy scheduling of SPI-transfers to get all the bytes across with a minimal amount of interrupts.

So If you want to do the PIC-approach, then I recommend that you write a dedicated linux-driver that can read all the states and all the existing transfers in just a few SPI-transaction to avoid those scheduling overheads.
Because just more (hidden) buffers to your simulation of the mcp2515 will not solve the other issues mentioned and would limit your implementation again unnecessarily.

Ciao,
Martin

cadsenthilkumar
Posts: 29
Joined: Wed Sep 25, 2013 11:09 am

Re: CAN controller

Mon Oct 21, 2013 8:30 am

HI

I am new to raspberry pi

As per ur post " I was starting with Raspbian "wheezy"
2012-07-15-wheezy-raspbian
on the SD-card and inital raspi-config done"


But i'm using "NOOBS_v1_3.zip" .shall i continue ur steps to implement can in my Raspberry pi.
Else please suggest me the best way or solution to implement CAN in my raspberry pi . :shock:

Previously i was using those steps that mentioned in "http://elinux.org/RPi_CANBus" to implement CAN in my Raspberry pi but once those steps completed my mouse and keyboard are not working. :D .

I think i'm going to learn new things

Thanks in advance



Regards
Senthilkumar R
maddin1234 wrote:Hi,
here is the description to enable a raspbian distribution
to communicate with the can controller mcp2515

I was starting with Raspbian "wheezy"
2012-07-15-wheezy-raspbian
on the SD-card and inital raspi-config done

1.) change user to root
$ sudo su
2.) update and upgrade
I was asked to keep or to overwrite one file, I choosed "N" to keep it
# apt-get update
# apt-get -y dist-upgrade

3.) install git and ncurses-dev
(If you want to "make menuconfig", ncurses-dev is needed)
# apt-get -y install git ncurses-dev
4.) download kernel sources
# cd /usr/src
# git clone --depth 1 git://github.com/raspberrypi/linux.git
# cd linux
5.) copy the compiletime configuration out of the intial kernel to
the sources for the new kernel
(do not use this line, if you want to have another configuration file)
# zcat /proc/config.gz > .config
6.) edit .config with make menuconfig
# make menuconfig
This shows how I set the configurations
[*] 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

....Device Drivers --->
........[*] SPI support --->
............<M> BCM2798 SPI controller driver (SPI0)
............<M> User mode SPI driver support
.......-*- GPIO Support --->
............[*] /sys/class/gpio/... (sysfs interface)
7.) patch the board definition bcm2708.c

Get a patchfile to the raspi with windows:
create a new txt-file and name it for example bcm2708.diff
copy the text of the posted patchfile from AlexB into that file
and save it on an usb-stick, if you have another clock frequency
change it in the patch-file or later in the patched bcm2708.c file

to mount a usb-stick follow
http://raspi.tv/2012/mount-a-usb-flash- ... erry-piebo

apply a patch to board-configuration
# cd /usr/src/linux/arch/arm/mach-bcm2708
# cp /media/usbstick/bcm2708.diff .
# patch -p0 <mcp2515_patch.diff
8.) make a new kernel
(put the three commands to one command-line, because it will take very long)
# cd /usr/src/linux
# make; make modules;make modules_install
9.) replacing the old kernel with the new one
# cp arch/arm/boot/Image /boot/kernel.img
10.) reboot and login again
# shutdown -r now
11.) install can-tools
$ sudo su
# cd /home/pi
# mkdir can
#cd can
get socketcan and compile/install it
# wget http://www.pengutronix.de/software/libs ... .8.tar.bz2
# tar xvjf libsocketcan-0.0.8.tar.bz2
# rm libsocketcan-0.0.8.tar.bz2
# cd libsocketcan-0.0.8
# .configure
# make
# make install
# cd ..
get can-util
# git clone git://gitorious.org/linux-can/can-utils.git can-util
# cd can-util
# make
# make install
# cd ..
now you are ready to use can

load the modules
# modprobe spi-bcm2708
# modprobe can
# modprobe can-dev
# modprobe can-raw
# modprobe can-bcm
# modprobe mcp251x
# ip link set can0 up type can bitrate 500000
to see if you are receiving messages
# candump can0
have fun

maddin1234

cadsenthilkumar
Posts: 29
Joined: Wed Sep 25, 2013 11:09 am

Re: CAN controller

Mon Oct 21, 2013 8:30 am

HI

I am new to raspberry pi

As per ur post " I was starting with Raspbian "wheezy"
2012-07-15-wheezy-raspbian
on the SD-card and inital raspi-config done"


But i'm using "NOOBS_v1_3.zip" .shall i continue ur steps to implement can in my Raspberry pi.
Else please suggest me the best way or solution to implement CAN in my raspberry pi . :shock:

Previously i was using those steps that mentioned in "http://elinux.org/RPi_CANBus" to implement CAN in my Raspberry pi but once those steps completed my mouse and keyboard are not working. :D .

I think i'm going to learn new things

Thanks in advance



Regards
Senthilkumar R
maddin1234 wrote:Hi,
here is the description to enable a raspbian distribution
to communicate with the can controller mcp2515

I was starting with Raspbian "wheezy"
2012-07-15-wheezy-raspbian
on the SD-card and inital raspi-config done

1.) change user to root
$ sudo su
2.) update and upgrade
I was asked to keep or to overwrite one file, I choosed "N" to keep it
# apt-get update
# apt-get -y dist-upgrade

3.) install git and ncurses-dev
(If you want to "make menuconfig", ncurses-dev is needed)
# apt-get -y install git ncurses-dev
4.) download kernel sources
# cd /usr/src
# git clone --depth 1 git://github.com/raspberrypi/linux.git
# cd linux
5.) copy the compiletime configuration out of the intial kernel to
the sources for the new kernel
(do not use this line, if you want to have another configuration file)
# zcat /proc/config.gz > .config
6.) edit .config with make menuconfig
# make menuconfig
This shows how I set the configurations
[*] 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

....Device Drivers --->
........[*] SPI support --->
............<M> BCM2798 SPI controller driver (SPI0)
............<M> User mode SPI driver support
.......-*- GPIO Support --->
............[*] /sys/class/gpio/... (sysfs interface)
7.) patch the board definition bcm2708.c

Get a patchfile to the raspi with windows:
create a new txt-file and name it for example bcm2708.diff
copy the text of the posted patchfile from AlexB into that file
and save it on an usb-stick, if you have another clock frequency
change it in the patch-file or later in the patched bcm2708.c file

to mount a usb-stick follow
http://raspi.tv/2012/mount-a-usb-flash- ... erry-piebo

apply a patch to board-configuration
# cd /usr/src/linux/arch/arm/mach-bcm2708
# cp /media/usbstick/bcm2708.diff .
# patch -p0 <mcp2515_patch.diff
8.) make a new kernel
(put the three commands to one command-line, because it will take very long)
# cd /usr/src/linux
# make; make modules;make modules_install
9.) replacing the old kernel with the new one
# cp arch/arm/boot/Image /boot/kernel.img
10.) reboot and login again
# shutdown -r now
11.) install can-tools
$ sudo su
# cd /home/pi
# mkdir can
#cd can
get socketcan and compile/install it
# wget http://www.pengutronix.de/software/libs ... .8.tar.bz2
# tar xvjf libsocketcan-0.0.8.tar.bz2
# rm libsocketcan-0.0.8.tar.bz2
# cd libsocketcan-0.0.8
# .configure
# make
# make install
# cd ..
get can-util
# git clone git://gitorious.org/linux-can/can-utils.git can-util
# cd can-util
# make
# make install
# cd ..
now you are ready to use can

load the modules
# modprobe spi-bcm2708
# modprobe can
# modprobe can-dev
# modprobe can-raw
# modprobe can-bcm
# modprobe mcp251x
# ip link set can0 up type can bitrate 500000
to see if you are receiving messages
# candump can0
have fun

maddin1234

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

Re: CAN controller

Mon Oct 21, 2013 11:18 am

Thanks Martin for your reply.


If I do a driver , I will try to use another road.

What about USB? Does anybody had some experience using the usb port for CAN bus.

Just bought a Faburino stamp from Microchip which has a PIC32MX795F512H cpu.
I will see what I could do with it. This will be , for me , a better approach since it has 2 CAN ports ,a lot of memories and 32 CAN fifo buffers. So I will see how the transfer via usb will go. (Couple month of work at least).

Again , a lots of night of fun learning new chip!


Daniel

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