STM32G4xx firmware written in Rust using the Embassy framework that bridges CAN-FD buses to Linux via USB using the gs_usb driver and socketCAN interface.
- 3x CAN-FD channels
- configurable 120Ω termination resistor
Install Rust via rustup.rs.
Set nSWBOOT0 to 0 using STM32CubeProgrammer for the first time, then connect the debugger and flash the device:
$ cargo run --releaseThree socketCAN interfaces will appear, for example as can0, can1, and can2.
You can configure them using ip command:
$ sudo ip link set can0 type can bitrate 500000
$ sudo ip link set can0 upAfter that, you can start sending and receiving CAN frames:
$ candump can0
$ cansend can0 123#abcdAll configurations must be done while the interface is in the down state.
$ sudo ip link set can0 downAfter the configuration, bring the interface up.
Set CAN to 500 Kbps and CAN-FD to 1 Mbps:
$ sudo ip link set can0 type can bitrate 500000 fd on dbitrate 1000000Termination resistor can be enabled in configuration mode via:
$ sudo ip link set can0 down
$ sudo ip link set can0 type can bitrate 500000 termination 120
$ sudo ip link set can0 upConfigure udev rules (/etc/udev/rules.d/91-scan.rules) for persistent interface names:
SUBSYSTEM=="net", ENV{ID_SERIAL}=="trnila_STM32_CAN_LIN_1", ATTR{dev_id}=="0x0", NAME="scan0"
SUBSYSTEM=="net", ENV{ID_SERIAL}=="trnila_STM32_CAN_LIN_1", ATTR{dev_id}=="0x1", NAME="scan1"
SUBSYSTEM=="net", ENV{ID_SERIAL}=="trnila_STM32_CAN_LIN_1", ATTR{dev_id}=="0x2", NAME="scan2"
and then reload sudo udevadm control --reload-rules and re-plug the device.
Install following dependencies:
- uv
- can-utils
Next, connect the DUT's can0 interface to the tester's can1_0 interface, and so on. Then run:
$ CAN_IFACES=0:can0:can1_0,1:can1:can1_1,2:can2:can0_0 ./hw_test.py