Skip to content

New machine.CAN driver #12337

@projectgus

Description

@projectgus

Summary

Planned cross-platform machine.CAN driver for Micropython.

Background

MicroPython currently only has one driver for a CAN bus controller, the pyb.CAN driver on STM32. Various folks have contributed functional and useful pull requests with CAN drivers for other ports. Many implement a machine.CAN interface. Quite sensibly, these drivers have all based their new APIs on the pyb.CAN driver. These efforts are hugely appreciated 🙏.

@jimmo, @dpgeorge, and I discussed this recently. We all agree MicroPython should have a cross-platform machine.CAN interface. None of us want to use the pyb.CAN API for this:

  • The conventions used by pyb.CAN don't match the best conventions of machine APIs.
  • It's not very ergonomic, compared to libraries such as CircuitPython canio or python-can.
  • Some functions assume behaviour of the ST CAN hardware peripheral that is not common across platforms. Trying to adapt these to each port in turn is messy and difficult for both users and maintainers.

Goals

MicroPython should have a machine.CAN interface which is:

  • Similar to other cross-platform machine APIs.
  • Relatively easy to use.
  • Still fast and light on resource usage.
  • Easy to implement on new hardware platforms.
  • Easy to extend for use with asyncio.
  • Easy to integrate with higher-level CAN-based driver layers such as canopen.

Also:

  • The interface should be easy for the existing un-merged driver PRs to adapt to.

Plan

We plan to do the following:

  1. Write a machine.CAN API as a docs PR, discuss with other maintainers and the community. See docs: Add machine.CAN low-level API docs. #13149
  2. Implement common cross-port interface helpers as extmod/machine_can.c (similar to extmod/machine_pwm.c, etc).
  3. Create a compliant machine.CAN implementation on STM32 (this will be a thin wrapper around pyb.CAN, which will remain for legacy compatibility.)
  4. Work with the existing PR authors as needed/wanted to merge machine.CAN drivers for new ports.

GitHub sponsor funds have been allocated for the first three steps, and I plan to work on it. Currently other work (USB device driver functionality) is the priority, but this is the next priority after that.

This issue post will be updated with overall status of this effort.

Metadata

Metadata

Assignees

Labels

driversenhancementFeature requests, new feature implementations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy