CAN bus interface configuring fails

[ 5.871990] mcp251x spi0.1 can0: MCP2515 successfully initialized.
[ 5.883830] mcp251x spi0.0 can1: MCP2515 successfully initialized.
[ 45.757812] can: controller area network core (rev 20170425 abi 9)
[ 45.793194] can: raw protocol (rev 20170425)

Running balenaOS 2.27.0+rev1 on Raspberry Pi 3+ with PiCAN (dual) interface. The CAN interfaces get initialized correctly but configuring them via /sbin/ip produces error:

root@xxxxxx:~# /sbin/ip link set can0 up type can bitrate 250000 restart-ms 100
ip: either “dev” is duplicate, or “type” is garbage

Hello ! Could you DM me a link to the device in the dashboard so that we can take a look ? Thanks ! :slight_smile:

https://dashboard.balena-cloud.com/devices/10eaf12ecd212d8d64a61ba2f7938607/summary

Thank you for the device link :slight_smile: It seems that the device needs custom dtoverlay settings which you set via the device settings page - this looks good :slight_smile: The /resin-boot/config.txt file does not contain the overlay settings though, would it be okay if I rebooted the device to see if it gets regenerated ?

Yes, please do, it’s only testing environment at this point.

I somehow have the feeling that the “ip link” program was working at some point but not anymore, strange…

T: Janne

root@xxxxxxx:/mnt/boot# cat config.txt
avoid_warnings=1
disable_splash=1
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=24
dtoverlay=spi-bcm2835-overlay
dtparam=i2c_arm=on
dtparam=spi=on
dtparam=audio=on
gpu_mem=16

The dtoverlay settings are found under /mnt/boot, and…

root@xxxxxx:/# ip link show can0
3: can0: mtu 16 qdisc noop qlen 10
link/[280]

So the device actually is there and is type CAN [280]. Could it be that the ip software is just outdated and unable to handle CAN type of devices? How can it be upgraded on host os?

// Janne

Hello ! Thank you for this additional data, we are still looking into this and will let you know when we will have more information.

Hey, @janne_kjellman
can you check if support access is enabled for the device, and enable it if its not.

https://dashboard.balena-cloud.com/devices/79940fe48f27f460f1fae264d2fdc7b9/summary

It should be enabled.

Hi @janne_kjellman,

I checked your device and it seems okay. I mean the configuration looks good, kernel module is loaded, devices are visible, … It seems that ip can’t handle the can device. Unfortunately, I don’t have a can around to try it locally. I tried to find more info, like this one https://community.nxp.com/thread/462448, and it probably confirms my findings. Will continue with this investigation.

Hi,

Same hardware with Raspbian runs flawlessly…

I installed iproute2 to one of the Docker sub systems and run the command in Host OS:

root@79940fe:/mnt/data# ./ip link set can0 type can

root@79940fe:/mnt/data# ./ip link set can0 bitspeed 250000

Error: either “dev” is duplicate, or “bitspeed” is a garbage.

root@79940fe:/mnt/data# ./ip link set can0 up

RTNETLINK answers: Invalid argument

root@79940fe:/mnt/data#

So it feels that even with iproute2 the device is not working properly. Even this iproute2 does not support setting speed on device but even UP command does not return reasonable answer from the can0 device?

// Janne

Can you please try running the ip commands from a container, and not the host OS. The ip command in the host OS is provided by busybox, which is a smaller single binary implementation of many standard Linux tools.

Since you are in a multi-container environment please enable in your docker-compose.yml file network_mode: "host" and privileged: true for the container you are going to run the commands from.

root@79940fe:/usr# ip -d link show can0
2: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
link/can promiscuity 0
can state STOPPED restart-ms 0
mcp251x: tseg1 3…16 tseg2 2…8 sjw 1…4 brp 1…64 brp-inc 1
clock 8000000
root@79940fe:/usr# ip link set can0 bitspeed 250000
Error: either “dev” is duplicate, or “bitspeed” is a garbage.
root@79940fe:/usr# ip link set can0 up
RTNETLINK answers: Invalid argument

Can you please run it in a Stretch container, since I think the default one is Jessie. This will bring us closer to Raspbian. resin/raspberrypi3-debian:stretch.

Also just in case can you run ip link set can0 bitspeed 250000 as ip link set can0 type can bitspeed 250000. And also with a different speed, e.g. 1000000.

Setting the container to run FROM resin/raspberrypi3-debian:stretch

root@79940fe:/# ip link set can0 type can bitrate 250000
root@79940fe:/# ip link set can0 up
root@79940fe:/# ip link show can0
2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 10
link/can

-> Seems to work.
-> Also candump shows packets.

Is there way to get this working in the raspberry3-node container as well?

Hi @janne_kjellman, if you need node.js and stretch, you can try our new set of base images, I would try balenalib/raspberrypi3-debian-node:8-stretch-build which will give you node.js 8 with debian stretch for the raspberry pi 3.

This set of images is going to be released officially in the coming week and you can read a bit more about them on this Docs pull request