Open clembo1 opened 4 days ago
Appreciate the info. This network management issue has been known for a bit, but I don't have any CB1/BTT Pi to test with so I wasn't confident in adding any info without personally testing. I've only really seen this issue crop up a few times, and unfortunately each time we try to go down to an actual fix the user ends up jsut installing the latest CB1 image from BTT which 'fixes' it.
The following link has some additional instructions on using Systemd/Network to configure CAN.
https://www.pragmaticlinux.com/2021/07/automatically-bring-up-a-socketcan-interface-on-boot/
Background:
Instructions that worked for me section systemd-networkd (netplan) | copied in part from the url
Pre-req's -- you have already got your mainboard flashed. CAN shows up in lsusb. In my case it is: Bus 002 Device 004: ID 1d50:606f OpenMoko, Inc. Geschwister Schneider CAN adapter
Complete the 10-can.link and 25-can.network configurations in the original instructions. Note: I added an additional line on 25-can.network to included RestartSec=100ms. [Match] Name=can* [CAN] BitRate=1M RestartSec=100ms
Load the SocketCAN kernel modules Before we can bring the can0 SocketCAN network interface in the UP state, we need to first load the SocketCAN related kernel modules. Open up the terminal again and run these commands:
sudo modprobe can sudo modprobe can_raw To verify that the SocketCAN related kernel modules loaded properly, you can run lsmod | grep "can".
Should get something like this: voron@bigtreetech-cb1:~$ lsmod | grep "can" can_dev 36864 1 gs_usb can_raw 20480 0 can 20480 1 can_raw
With the USB-to-CAN adapter plugged in and the SocketCAN kernel modules loaded, we continue with configuring the can0 SocketCAN network interface. note: you may or may not need the canbus cable plugged into the toolhead board. It was not necessary for me with the M8P v2.0 board. The command for this is:
Note: the default with current instructions does not set the restart timeout, not sure if 100 milliseconds is needed or not This configures the can0 network interface for a CAN communication speed of 1,000,000 bits/second. Feel free to adjust this to match the CAN communication speed on your CAN bus. Furthermore, it configures can0 to automatically re-initialize the CAN controller in case of a CAN bus off event, after 100 milliseconds. Feel free to adjust this if needed, but 100 milliseconds works fine in most cases.
With the can0 SocketCAN network interface configured, we can continue with the last step, which is bringing it in the UP state:
At this point you can run the command below to confirm the state ip -s -d link show can0 Result should be something like this (bold is mine):
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1024 link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0 can state ERROR-ACTIVE restart-ms 100 bitrate 1000000 sample-point 0.750 tq 62 prop-seg 5 phase-seg1 6 phase-seg2 4 sjw 2 brp 3 gs_usb: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..1024 brp_inc 1 clock 48000000 re-started bus-errors arbit-lost error-warn error-pass bus-off 0 0 0 0 0 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 parentbus usb parentdev 2-1.4:1.0 RX: bytes packets errors dropped missed mcast 0 0 0 0 0 0 TX: bytes packets errors dropped carrier collsns 0 0 0 0 0 0
Note: If you restart, the CAN will be in state "down."To solve this, we need to take an additional step to automatically put state UP on reboot
Next, enter the can and can_raw kernel modules each on their own line: can can_raw
exit and save changes
Before we move on with the configuration of our SocketCAN network interface, we need to first activate the systemd-networkd service. Run the following two commands from the terminal:
This starts the systemd-networkd service and makes sure it also starts the next time your boot your Linux system.
To enable this configuration file for our can0 SocketCAN network interface, we just need to restart the systemd-networkd service:
Run the command below to confirm the state "UP" ip -s -d link show can0 (optional, "sudo reboot" then run the above command to confirm state is "UP"