can2040 project adds software CAN bus to Raspberry Pi RP2040

The can2040 project is a software CAN bus implementation for the Raspberry Pi RP2040 microcontroller that leverages programmable I/Os (PIO) to achieve reading and writing CAN 2.0B data frames at rates up to 1Mbit per second.

Kevin O’Connor, the developer of the project, further explains the implementation uses only one of the two RP2040 PIO hardware blocks, so it is possible for a single Raspberry Pi RP2040 chip to have two separate CAN bus interfaces.

Raspberry Pi RP2040 can2040 software CAN Bus

Some processing also happens on one of the Arm Cortex-M0+ cores of the microcontroller with the processing time dependent on the amount of bus traffic, and a fully saturated CAN bus at the fastest supported rate of 1Mbit/s may use up to around 30% of that core when clocked at 125MHz, so that should still leave plenty of room for other tasks that may run on the system. I could not find any information about RAM and storage footprint.

We’ve previously seen hardware-based CAN implementations with the Raspberry Pi RP2040 microcontroller, such as CANPico and CanBed RP2040, using a MCP2515 or MCP2518FD CAN controller and MCP2551 or MCP2562FD CAN transceiver, and as I understand it, the can2040 code removes the need for the CAN controller, so you’d just need to connect a CAN receiver the Raspberry Pi Pico or other RP2040 board. That way, the software CAN bus implementation for RP2040 should be able to interoperate with other (hardware-based) CAN bus implementations, and a bus may consist of a mixture of can2040 and non-can2040 nodes. Note there are limitations that may impact the CAN bus:

The CAN bus specification defines three error handling states: “error active” (ie, normal state), “error passive”, and “bus off”. Automatic transition between these states is not implemented. The can2040 code does not transmit “error frames”. The can2040 code will not automatically enter a “bus off” state. In this regard, the can2040 code may be thought of as always being in the “error passive” state.

You’ll find more details about the project on Github with the C source code, Python testing scripts, and application programming interface (API) documentation released under a GPLv3 license.


Support CNX Software! Donate via PayPal or cryptocurrencies, become a Patron on Patreon, or buy review samples

ROCK Pi 4C Plus