Code: Select all
/sbin/ip link set can0 type can bitrate 500000 <possibly add other args for loopback,...>
ifconfig can0 up
the spi-config module has the modalias set to mcp2515, however it seems it loads the mcp251x driver when loaded manually.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
mcp2515
Code: Select all
[ 12.692143] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=10000000 mode=0 and gpio/irq=25/195
[ 12.726909] spi_config_register:spi0.0:platform data:c9e6db20: 00 2d 31 01 02 20 00 00 00 00 00 00 00 00 00 00 .-1.. ..........
[ 12.744642] spi_config_register:spi0.0:platform data:c9e6db30: 00 00 00 00 ....
[ 12.767685] CAN device driver interface
[ 12.818466] mcp251x spi0.0: CANSTAT 0x80 CANCTRL 0x07
[ 12.820147] mcp251x spi0.0: probed
[ 20.970478] mcp251x spi0.0: CNF: 0x04 0xb5 0x01
Code: Select all
Module Size Used by
can_raw 6148 0
can 23604 1 can_raw
mcp2515 6109 0
mcp251x 9494 0
can_dev 9485 2 mcp2515,mcp251x
spi_config 9384 0
spidev 5248 0
spi_bcm2708 7453 0
snd_bcm2835 16432 0
snd_pcm 77728 1 snd_bcm2835
snd_page_alloc 5169 1 snd_pcm
snd_seq 53482 0
snd_seq_device 6462 1 snd_seq
snd_timer 20110 2 snd_pcm,snd_seq
snd 58744 5 snd_bcm2835,snd_timer,snd_pcm,snd_seq,snd_seq_device
joydev 9356 0
evdev 9450 3
hid_sunplus 1491 0
leds_gpio 2243 0
led_class 3570 1 leds_gpio
The interrupt list, the interrupt is linked to mcp251x:spi:mcp2515
spi:spidev
Code: Select all
CPU0
3: 4451 ARMCTRL BCM2708 Timer Tick
16: 0 ARMCTRL bcm2708_spi.0
32: 106154 ARMCTRL dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1
52: 2 ARMCTRL BCM2708 GPIO catchall handler
65: 225 ARMCTRL ARM Mailbox IRQ
66: 1 ARMCTRL VCHIQ doorbell
75: 1 ARMCTRL
77: 5829 ARMCTRL bcm2708_sdhci (dma)
80: 30 ARMCTRL bcm2708_spi.0
83: 19 ARMCTRL uart-pl011
84: 9127 ARMCTRL mmc0
195: 2 GPIO mcp251x
FIQ: usb_fiq
Err: 0
Code: Select all
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
link/can
can state ERROR-PASSIVE restart-ms 0
bitrate 125000 sample-point 0.875
tq 500 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
clock 10000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 1 1 0
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0 Yes, that was that !msperl wrote:When the linux SPI subsystem detects a driver matching pair of driver/device based on the modinfo it will use that and try to initiate that driver. But if there are multiple drivers in memory that can handle the same modinfo, then the first one loaded wins.
So this was your case...
Code: Select all
# grep mcp251 /lib/modules/3.6.11+/modules.alias
alias spi:mcp2515 mcp251x
alias spi:mcp2510 mcp251x
That is not much of a problem, as it only fills the dmesg output but doesn't prevent anything to work then. But it would be better to remove it.msperl wrote:As for the message showing up regularly: I guess that there is a feature in the kernel that tries to configure a CAN device every few seconds if it has not been configured yet. The problem here is that the driver itself just complains that it has not been configured and ads a message to the dmesg buffer. This was possibly a change somewhere in the lower parts of the CAN infrastructure that was changed after the driver got written, and the driver never got updated to remove that fact.
I need to finish to make my setup starting autonomously first, then I will be able to spend some time to help you testing this (probably not on the coding side, as I am far behind you on linux driver concepts...).msperl wrote:Anyway: both drivers are old and have issues, so as soon as I finish my spi-DMA driver I will start a new mcp2515 driver that tries to be as efficient as possible (making use of all the spi-DMA-driver features) so that we can transfer a message with minimal overhead delay and interrupts. Obviously it ideally would also be able to handle a 1MBit CAN-bus which is saturated with 0 byte length frames (that would be 15385 messages/second), but I might not be able to achive that...
This works. The other way is to simply remove the mcp251x driver and updating the system with "depmod -a". The blacklist is still better as it allows to activate it later on without having to move back some files.msperl wrote:you can add the mcp251x driver to /etc/modprobe.d/raspi-blacklist.conf so that it does not get automatically loaded and then the mcp2515 might get loaded instead...
Code: Select all
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
link/can
can state STOPPED restart-ms 0
bitrate 125000 sample-point 0.875
tq 500 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
mcp2515: tseg1 2..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
clock 10000000
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
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0 Code: Select all
spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=20000000:pdu32-4=0x2002:force_releaseCode: Select all
// Enumeration of all devices supported by this driver.
// There is only one device for the mcp2515, but I kept the principle of the enum to be easier to make it evolve
enum mcp2515_model {
CAN_MCP2515 // Could be assigning a value using "= xxx" if needed, but zero value is enough
};
// Construct the table containing the modinfo text, and the corresponding value
// This value is used by the driver to know which device it has been loaded for,
// in case several are supported
static const struct spi_device_id mcp2515_id_table[] = {
{ "mcp2515", CAN_MCP2515 },
{ },
};
// Register the modinfo structure to the kernel
// As it is related to "spi", the name will appear as "spi:mcp2515" in the modules.alias file
MODULE_DEVICE_TABLE(spi, mcp2515_id_table);
Code: Select all
// With "spi" of type "struct spi_device *spi"
switch(spi_get_device_id(spi)->driver_data)
{
case CAN_MCP2515:
// Some device specific code
// ...
}I think for me it would still be okay. Of course keeping the absolute sequencing would be better, but if this is the only trade-off to be able to do it...msperl wrote:Do we need to send out CAN-messages in correct sequence under any circumstances?
The question why I ask is because it should normally work "fine" if you send up to 3 CAN messages in a row, but as soon as you exceed that you may run into reordering issues due to the way that the HW works.
If this is a hard requirement, then the driver would need to sacrifice potential thru-put for this (under some circumstances).
A similar situation applies to receiving, but there I am not sure yet if I can achieve this under ALL circumstances - there might be some tricky race-conditions between HW and SW to make it work - especially if the linux side is very busy and the system comes closer to "loosing packets" due to long delays in scheduling. But then in such a situation we would come already close to loosing some packet, which would be even worth...
Great ! Well done !msperl wrote:From my current plans for the driver, it should be possible to handle:with just 1 IRQ plus 2 SPI-callbacks.
- up to 2 receives of a CAN message
- up to 3 transmits of a CAN message
- all error handling (missed packets, BUS-error conditions,...)
Code: Select all
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:1237913 errors:2 dropped:0 overruns:0 frame:2
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:9877777 (9.4 MiB) TX bytes:0 (0.0 B)
Code: Select all
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 324412 23468 91832 0 0 0 0 17031 22978 3 69 28 0
0 0 0 324380 23468 91832 0 0 0 0 16597 22959 3 65 32 0
0 0 0 324316 23468 91832 0 0 0 0 16812 23350 0 69 31 0
0 0 0 324220 23468 91832 0 0 0 0 16712 22787 0 71 29 0
0 0 0 324220 23468 91832 0 0 0 0 17030 23033 1 69 30 0
1 0 0 324284 23468 91832 0 0 0 0 16698 22918 0 71 29 0
0 0 0 324348 23468 91832 0 0 0 0 16813 23416 1 70 28 0
0 0 0 324316 23468 91832 0 0 0 0 16587 23014 1 68 31 0
0 0 0 324284 23468 91832 0 0 0 0 16805 23330 1 68 31 0
0 0 0 324284 23468 91832 0 0 0 0 16599 22966 1 68 31 0
0 0 0 324284 23468 91832 0 0 0 0 17025 23063 1 73 26 0
Code: Select all
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 3.6.11-can-1+ #1 PREEMPT Sun Oct 27 15:39:51 UTC 2013 armv6l GNU/LinuxI would definitly say yes to this question. I do have an application which could run into trouble ifmsperl wrote: What about absolute sequencing of messages?
Do we need to send out CAN-messages in correct sequence under any circumstances?
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_SPIThe driver works fine - if you only have low traffic. This is probably the reason why you haven't seen any problem yet.danjperron wrote:Hi Bertr2d2,
you don't even need that board to program the PIC18F26K80. The Rpi alone will do.
Check this post http://www.raspberrypi.org/phpBB3/viewt ... 43#p430643
I Know I'm a little bit off track but does anybody have knowledge about libcanopen from
https://github.com/rscada/libcanopen. I'm trying to figure out how to send raw TPDO in python 2.7.
SDO works fine but I don't have a clue on how to use the library TPDO method.
B.T.W. looks like that I won't need to do a driver since the mcp2515 driver I got from here works like a charm.
The mcp2515 code is from Andre B. Oliveira, with some SocketCAN team cleaning ...This is my current project http://www.raspberrypi.org/phpBB3/viewt ... 38#p444938
Thanks for the driver!
Daniel