Kevin O'Connor's Can2040 Brings a PIO-Powered CAN Bus to the Raspberry Pi Pico, Other RP2040 Boards

Running on the PIO and borrowing some cycles from one of the two Arm Cortex-M0+ cores, can2040 offers up to two CAN bus implementations.

Gareth Halfacree
2 years agoHW101 / Automotive

Developer Kevin O'Connor has brought the Raspberry Pi Pico family, and by extension other boards built around the same RP2040 microcontroller, a shiny new feature: CAN bus compatibility, implemented on the flexible programmable input/output (PIO) blocks.

"The can2040 project is a software CAN bus implementation for Raspberry Pi RP2040 microcontrollers," O'Connor writes by way of introduction. "It enables an RP2040 chip to implement [a] CAN bus using a standard CAN transceiver chip. The code supports reading and writing CAN 2.0B data frames at rates up to 1Mbit per second."

The project takes advantage of a surprisingly powerful feature of the RP2040: its programmable input/output (PIO) blocks, which allow up to eight simple real-time state machines to run separately to the two Arm Cortex-M0+ cores. O'Connor's CAN bus implementation doesn't run exclusively on the PIO blocks, however, but spreads across one of the RP2040's two Arm Cortex-M0+ cores too.

"The can2040 system is a software CAN bus implementation," O'Connor explains. "It utilizes the RP2040 PIO device as well as processing time on one of the RP2040 Arm cores. One may dedicate an ARM core to can2040. It is also possible for can2040 to share an Arm core with application code.

"The implementation uses one of the two RP2040 PIO hardware blocks," O'Connor continues. "It is possible for a single RP2040 chip to have two separate CAN bus interfaces by using both PIO blocks. [It] works with standard CAN bus transceivers. Any two RP2040 GPIO [General-Purpose Input/Output] pins may be used for the 'CAN RX' and 'CAN TX' wires."

The project's source code, and more details about its application programming interface (API), is available on O'Connor's GitHub repository under the reciprocal GNU General Public License 3.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles