klipper_canbus

systemd-networkd

Is a newer networking system daemon used by Debian and Ubuntu amongst others At this time its not known if/when the raspbian stack will move to this standard.

Am I using systemd-networkd

You can check by running the following.

sudo systemctl status systemd-networkd

If you see the following then you can leave this page :)

[

otherwise continue

Check your version of systemd supports CAN interfaces

Run

systemctl --version

If it reports a systemd version number of 239 or higher you are fine to continue.

creating a CAN network for systemd-networkd

Run

ls /etc/systemd/network/

If you see 80-can.network check its blank before you blindly overwrite anything (its probably blank)

Running the below will open the existing file for editing, OR if none exist it will create a new file.

sudo nano /etc/systemd/network/80-can.network

Populate the file

[Match]
Name=can0

[CAN]
BitRate=1000000

and press Ctrl+X to save. (You can overwrite)

Next up we can create a .link file which will allow setting of the txqueuelen and network type.

Again we can run the below to create an empty file.

sudo nano /etc/systemd/network/80-can.link

Populate the file

[Match]
Type=can

[Link]
TransmitQueueLength=256

and press Ctrl+X to save. (You can overwrite)

Restarting the network stack

The following commands will restart the stack incoporating your new network settings

sudo systemctl restart systemd-networkd

You can check the status after with

sudo systemctl status systemd-networkd

Bringing the network online.

Note: this step may be suplurfious depending on your order of operations.

Ensure your USB CAN adapter is connected and visible via lsusb

It will present with an id of 1d50:606f for most Candlelight_Fw devices, but may present differently if you have SLCAN firmware.

check if the network is up

ip -details link show can0

If you see a warning about the device not existing you need to check that your OS is seeing the device.

If you dont see a network but your USB device is connected and visible, run the following to force the nework up.

sudo networkctl up can0

Double check the network came up

ip -details link show can0

A good network will look like this (for now)

can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0 
    can state ERROR-ACTIVE restart-ms 0 
          bitrate 500000 sample-point 0.875 
          tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
          gs_usb: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..1024 brp-inc 1
          clock 48000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 parentbus usb parentdev 1-2:1.0

Transmit queue length through udev (optional)

The transmit queue length setting isn’t available in all systemd-networkd versions. If the transmit queue length isn’t applied from your networkd configuration you can set up transmit queue length through udev instead.

To verify that your queue length value has been applied, you can run:

ip link show can0

The queue length is the value after qlen. In this example queue length is 10 instead of the expected 256:

can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0 

To fix this add a udev rule:

sudo nano /etc/udev/rules.d/99-canbus.rules

Enter the contents:

# set tx queue size for canbus
SUBSYSTEM=="net", ACTION=="add|change", KERNEL=="can0" ATTR{tx_queue_len}="256"

and press Ctrl+X to save. (You can overwrite)

Finally you need to restart the system.


references:

Continue along with the rest of this guide to setup your toolhead and the rest :)

Return to Main