-
Notifications
You must be signed in to change notification settings - Fork 19
Enabling CAN on Raspberry Pi Yocto
As per the wiki page for yocto, the CAN protocol support was not available for the yocto build. As CAN is one of the important protocols used for communication between two different devices, students can build their user application code that establishes communication between two CAN devices.
The changes can be made in build.sh which can be found here
The following lines are added in the local.conf file
- To enable CAN module, add,
ENABLE_CAN = 1
or the local.conf can also be modified - To autoload the CAN module, add,
KERNEL_MODULE_AUTOLOAD:rpi += mcp251x flexcan
- To add CAN tools support,
IMAGE_INSTALL:append = can-utils iproute2
- By default, the frequency of the crystal oscillator is set to 16 Mhz. Since in the MCP2515 module, the crystal oscillator is 8 Mhz, the following
variable also needs to be setCAN_OSCILLATOR = 8000000
- To reflect the changes in local.conf, we have to verify whether the changes are already made in local.conf. The code can be found here
After booting, the following commands can verify whether the CAN module is installed properly
lsmod | grep can
dmesg | grep -i can
This section has not been tested/verified yet. We have to verify whether the CAN bus is established by connecting it with a CAN device or establishing CAN communication between two raspberry pi's. The Raspberry Pi does not have an inherent CAN support, due to the Raspberry Pi’s Broadcom SoCs (System on a Chip) do not have a CAN controller, but it can be added using USB or CAN adapters. Thus we require an MCP2515 module which is a CAN bus board module that uses SPI interface of raspberry pi and convert it into a CAN interface. Thus we added mcp251x to autoload the CAN module.
1.To verify the CAN bus is established, we need to check the following commands modprobe mcp251x
2. Setting the baudrate: ip link set can0 up type can bitrate 125000
3. Once the driver is installed and the bitrate is set, the CAN interface can be started by giving the following command: ifconfig can0 up
4. To dump all the messages in the bus: candump can0
5. To send a message in the CAN bus: cansend can0 610#000000
6. When CAN bus is no longer needed, the CAN bus is brought down: ip link set can0 down
References
- https://elinux.org/R-Car/Boards/CAN
- https://forums.raspberrypi.com/viewtopic.php?t=141052
- https://linuxjedi.co.uk/2021/12/01/making-a-can-bus-module-work-with-a-raspberry-pi/
- https://meta-raspberrypi.readthedocs.io/en/latest/extra-build-config.html
- https://forums.raspberrypi.com/viewtopic.php?t=141052