Here a quote from: Documentation/networking/can.txt line 908.Webo wrote:So, do there exist solutions to support the hardware filtering? Or does this require an own implementation/modification![]()
Code: Select all
... The high efficient filter sets inside the PF_CAN core allow
to set different multiple filters for each socket separately.
Therefore the use of hardware filters goes to the category 'handmade
tuning on deep embedded systems'. The author is running a MPC603e
@133MHz with four SJA1000 CAN controllers from 2002 under heavy bus
load without any problems ...
tz1 wrote:github.com/tz1/pikernomatic has been updated to the latest rpi-update kernel binary.
Attached are the can specific modules built with pikernomatic.
msperl wrote:ad 2): Sending receiving messages:
http://en.wikipedia.org/wiki/SocketCAN
and also the definite documentation directly from the kernel:
http://lxr.free-electrons.com/source/Do ... ng/can.txt
Code: Select all
modprobe mcp2515a use_dummy_complete=0
Code: Select all
#! /bin/sh
CS=8
test -z "$1" || CS=$1
SCLK=11
MOSI=10
MISO=9
#config SPI Pins and Directions
CONFIG_PINS() {
(while read gpio dir level; do
test -f /sys/class/gpio/gpio$gpio/value || echo $gpio > /sys/class/gpio/export
echo $dir > /sys/class/gpio/gpio$gpio/direction
test -z "$level" || echo $level > /sys/class/gpio/gpio$gpio/value
done) <<EOF
$CS out 1
$MISO in
$MOSI out 0
$SCLK out 0
EOF
}
UNCONFIG_PINS() {
(while read gpio dir level; do
test -f /sys/class/gpio/gpio$gpio/value || echo $gpio > /sys/class/gpio/unexport
done) <<EOF
$CS
$MISO
$MOSI
$SCLK
EOF
}
CS() {
echo "$1" > /sys/class/gpio/gpio$CS/value
}
MOSI() {
echo "$1" > /sys/class/gpio/gpio$MOSI/value
}
SCLK() {
echo "$1" > /sys/class/gpio/gpio$SCLK/value
}
spi_send() {
echo "$1" \
| awk '{X=$1;for(i=128;i>=1;i/=2){B=0;if (X>=i){ B=1;X-=i;}print i,B}}' \
| while read bit v; do
MOSI $v
SCLK 1
echo -n "$bit "
cat /sys/class/gpio/gpio$MISO/value
SCLK 0
done \
| awk 'BEGIN{C=0}{if ($2){C+=$1}}END{printf "%-20s %3i 0x%02x\n","'$2'",C,C;}'
}
CONFIG_PINS
# reset mcp2515
echo "Resetting MCP2515"
CS 0
spi_send 192 RESET
CS 1
# wait some time
sleep 1
# and read the registers
echo "Reading MCP2515 config-registers"
CS 0
spi_send 3 CMD-READ
spi_send 40 REG-CNF3
spi_send 0 CNF3
spi_send 0 CNF2
spi_send 0 CNF1
spi_send 0 INTE
spi_send 0 INTF
spi_send 0 EFLG
spi_send 0 CANSTAT
spi_send 0 CANCTRL
CS 1
UNCONFIG_PINS
Code: Select all
root@raspberrypi:~# sh test-mcp2515.sh 8
Resetting MCP2515
RESET 192 0xc0
Read MCP2515 registers
CMD-READ 3 0x03
REG-CNF3 40 0x28
CNF3 0 0x00
CNF2 0 0x00
CNF1 0 0x00
INTE 0 0x00
INTF 0 0x00
EFLG 0 0x00
CANSTAT 128 0x80
CANCTRL 135 0x87
Code: Select all
dmesg -C
modprobe spi-bcm2708
modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pdu32-0=16000000:pdu32-4=0x2002:force_release
modprobe mcp251x
dmesg
Code: Select all
[90600.903092] bcm2708_spi bcm2708_spi.0: master is unqueued, this is deprecated
[90600.903139] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
[90609.232778] spi_config_register: device description: bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pdu32-0=16000000:pdu32-4=0x2002:force_release
[90609.237435] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=10000000 mode=0 and gpio/irq=25/195
[90609.237481] spi_config_register:spi0.0:platform data:da103da0: 00 24 f4 00 02 20 00 00 00 00 00 00 00 00 00 00 .$... ..........
[90609.237501] spi_config_register:spi0.0:platform data:da103db0: 00 00 00 00 ....
[90615.416805] CAN device driver interface
[90615.436830] mcp251x spi0.0: probed
[90615.548927] mcp251x spi0.0 can0: bit-timing not yet defined
[90615.548967] mcp251x spi0.0: unable to set initial baudrate!
Code: Select all
[90721.827524] bcm2708_spi bcm2708_spi.0: master is unqueued, this is deprecated
[90721.827573] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
[90728.508529] spi_config_register: device description: bus=0:cs=1:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pdu32-0=16000000:pdu32-4=0x2002:force_release
[90728.512329] spi_config_register:spi0.1: registering modalias=mcp2515 with max_speed_hz=10000000 mode=0 and gpio/irq=25/195
[90728.512377] spi_config_register:spi0.1:platform data:dbbfe4c0: 00 24 f4 00 02 20 00 00 00 00 00 00 00 00 00 00 .$... ..........
[90728.512395] spi_config_register:spi0.1:platform data:dbbfe4d0: 00 00 00 00 ....
[90739.396232] CAN device driver interface
[90740.406161] mcp251x spi0.1: MCP251x didn't enter in conf mode after reset
[90740.406321] mcp251x spi0.1: probe failed
Code: Select all
pdu32-0=<12000000|16000000|20000000|...>
Code: Select all
/sbin/ip link set can0 up type can bitrate <1000000|500000|250000|125000|100000|...>
Code: Select all
pi@pi~ $ candump any,0:0,#FFFFFFFF
can0 20000004 [8] 00 10 00 00 00 00 00 00 ERRORFRAME
Code: Select all
sudo modprobe spi-config devices=\bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=22:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
sudo ip link set can0 up type can bitrate 125000
Code: Select all
candump any,0:0,#FFFFFFFF
Code: Select all
candump can0
Code: Select all
candump
Code: Select all
Usage: candump [options] <CAN interface>+
(use CTRL-C to terminate candump)
Options: -t <type> (timestamp: (a)bsolute/(d)elta/(z)ero/(A)bsolute w date)
-c (increment color mode level)
-i (binary output - may exceed 80 chars/line)
-a (enable additional ASCII output)
-S (swap byte order in printed CAN data[] - marked with '`' )
-s <level> (silent mode - 0: off (default) 1: animation 2: silent)
-b <can> (bridge mode - send received frames to <can>)
-B <can> (bridge mode - like '-b' with disabled loopback)
-u <usecs> (delay bridge forwarding by <usecs> microseconds)
-l (log CAN-frames into file. Sets '-s 2' by default)
-L (use log file format on stdout)
-n <count> (terminate after receiption of <count> CAN frames)
-r <size> (set socket receive buffer to <size>)
-d (monitor dropped CAN frames)
-e (dump CAN error frames in human-readable format)
Up to 16 CAN interfaces with optional filter sets can be specified
on the commandline in the form: <ifname>[,filter]*
Comma separated filters can be specified for each given CAN interface:
<can_id>:<can_mask> (matches when <received_can_id> & mask == can_id & mask)
<can_id>~<can_mask> (matches when <received_can_id> & mask != can_id & mask)
#<error_mask> (set error frame filter, see include/linux/can/error.h)
CAN IDs, masks and data content are given and expected in hexadecimal values.
When can_id and can_mask are both 8 digits, they are assumed to be 29 bit EFF.
Without any given filter all data frames are received ('0:0' default filter).
Use interface name 'any' to receive from all CAN interfaces.
Examples:
candump -c -c -ta can0,123:7FF,400:700,#000000FF can2,400~7F0 can3 can8
candump -l any,0~0,#FFFFFFFF (log only error frames but no(!) data frames)
candump -l any,0:0,#FFFFFFFF (log error frames and also all data frames)
candump vcan2,92345678:DFFFFFFF (match only for extended CAN ID 12345678)
candump vcan2,123:7FF (matches CAN ID 123 - including EFF and RTR frames)
candump vcan2,123:C00007FF (matches CAN ID 123 - only SFF and non-RTR frames)
Code: Select all
$ ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
link/can
can state STOPPED restart-ms 100
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 8000000
Code: Select all
$ cat /etc/modules
# /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
i2c-bcm2708
i2c-dev
# MCP2515 configuration with /INT on GPIO25 and 16MHz clock
spi-bcm2708
can
can-dev
can-raw
can-bcm
spi-config devices=\
bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002
:force_release
mcp2515
Code: Select all
$ cat /etc/modprobe.d/raspi-blacklist.conf
# blacklist spi and i2c by default (many users don't need them)
#blacklist spi-bcm2708
blacklist i2c-bcm2708
blacklist mcp251x
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
Code: Select all
$ 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:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Code: Select all
candump any,0:0,#FFFFFFFF
Code: Select all
cansend can0 7DF#0201050000000000
Code: Select all
sudo ifconfig can0 up
Code: Select all
mcp2515 spi0.0 can0: writing CNF: 0x03 0xb5 0x01
Code: Select all
$ lsmod | grep 'mcp\|can\|spi\|i2c'
mcp2515 6494 0
spi_config 9367 0
can_bcm 11643 0
can_raw 6183 0
can_dev 9987 1 mcp2515
can 23714 2 can_bcm,can_raw
i2c_dev 5557 0
i2c_bcm2708 3997 0
regmap_i2c 1645 3 snd_soc_pcm512x,snd_soc_wm8804,snd_soc_core
regmap_spi 1897 3 snd_soc_pcm512x,snd_soc_wm8804,snd_soc_core
spi_bcm2708 4728 0
msperl wrote:Everything that you shared indicates that:
a) the communication with the MCP2515 chip is working
b) the interface is up
My guess is that you have NOT added another device on the CAN bus.
Unless this is added your packet will not get delivered anywhere (as there isn't a single recipient to acknowledge it) and that is probably why it does not show up in candump - packet is still pending.
Please also share the output of "lsmod" to see which modules(=drivers) you have actually loaded.
Martin
Code: Select all
rmmod mcp2515
modprobe mcp251x
msperl wrote:if you load the mcp251x driver instead of the mcp2515:Then you can add: "one-shot on" to your /sbin/ip command - this way the mcp2515 will only try to send the message once possibly also sending an error frame that it was not acknowledged...Code: Select all
rmmod mcp2515 modprobe mcp251x
With that you should see the message you send even without a peer.
The driver named mcp2515 does not support this, but the mcp251x does - but it is buggy in other ways, so that the recommended driver until now is still the mcp2515.
Code: Select all
$ ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 1
0
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 8000000
Code: Select all
$ dmesg | grep 'mcp\|can\|spi\|i2c'
[ 5.126427] bcm2708_spi bcm2708_spi.0: master is unqueued, this is deprecated
[ 5.291836] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
[ 13.675599] bcm2708_i2c_init_pinmode(0,0)
[ 13.683758] bcm2708_i2c_init_pinmode(0,1)
[ 13.692170] bcm2708_i2c bcm2708_i2c.0: BSC0 Controller at 0x20205000 (irq 79) (baudrate
100000)
[ 13.703920] bcm2708_i2c_init_pinmode(1,2)
[ 13.709311] bcm2708_i2c_init_pinmode(1,3)
[ 13.720134] bcm2708_i2c bcm2708_i2c.1: BSC1 Controller at 0x20804000 (irq 79) (baudrate
100000)
[ 13.880667] i2c /dev entries driver
[ 14.090734] can: controller area network core (rev 20120528 abi 9)
[ 14.266949] can: raw protocol (rev 20120528)
[ 14.343973] can: broadcast manager protocol (rev 20120528 t)
[ 14.445220] spi_config_register: device description: bus=0:cs=0:modalias=mcp2515:speed=1
0000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
[ 14.462336] spi_config_match_cs: SPI0: check CS=0 to be 0
[ 14.469274] spi_config_match_cs: SPI0.0: Found a device with modinfo spidev
[ 14.477908] spi_config_register:spi0.0:mcp2515: found already registered device
[ 14.486750] spi_config_register:spi0.0:mcp2515: forcefully-releasing already registered
device taints kernel
[ 14.502484] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=1
0000000 mode=0 and gpio/irq=25/195
[ 14.534402] spi_config_register:spi0.0:platform data:d6bd9020: 00 24 f4 00 02 20 00 00 0
0 00 00 00 00 00 00 00 .$... ..........
[ 14.550812] spi_config_register:spi0.0:platform data:d6bd9030: 00 00 00 00
....
[ 14.845864] mcp2515 spi0.0 can0: device registered (cs=0, irq=195)
[ 22.337042] mcp2515 spi0.0 can0: writing CNF: 0x03 0xb5 0x01
msperl wrote:No idea - I use my self-compiled kernel, so I do not know the package you are using is included.
But, yes - the mcp2515 driver does not support all the features:
* one-shot
* loopback
* listen-only
* triple-sampling
the mcp251x driver supports all of those (but is buggy in other ways...).
msperl wrote:Cable polarity?
Code: Select all
can state STOPPED
msperl wrote:Cable polarity?
Code: Select all
can state ERROR-ACTIVE restart-ms 100
Code: Select all
ip -s -d link show can0
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 100
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 8000000
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
mikexu wrote:So... I have recompiled kernel, butis still the same....Code: Select all
can state STOPPED
I wanted to test the mcp2515x module for loopback, but I forgot to enable mcp2515x module before recompile. Do you know how to install this module alone really quick? Thanks a lot!
msperl wrote:Cable polarity?