can2040 project adds software CAN bus to Raspberry Pi RP2040 microcontroller

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.

Via Hackster.io

Share this:
FacebookTwitterHacker NewsSlashdotRedditLinkedInPinterestFlipboardMeWeLineEmailShare

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX RK3588 mini-ITX motherboard

4 Replies to “can2040 project adds software CAN bus to Raspberry Pi RP2040 microcontroller”

  1. We’ve received an additional comment with regards to the lack of error frames (on LinkedIn):

    Worth noting it doesn’t generate error frames. This has a lot of consequences, because much of the protocol relies on the error confinement rules. In particular, atomic broadcast. This is a key feature of CAN that separates it from other protocols like Ethernet (which also just drop frames) and is a major reason it is so robust in practice.

  2. Are you saying it does not need a CAN driver chip, and can connect directly to the CAN bus?

    1. That’s my understanding that this acts as a CAN controller, but you’d still need a CAN transceiver like MCP2551 or MCP2562FD to handle 12 or 24V signals.

Leave a Reply

Your email address will not be published. Required fields are marked *

Boardcon Rockchip and Allwinner SoM and SBC products
Boardcon Rockchip and Allwinner SoM and SBC products