-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
stm32: Add machine.CAN low-level driver #18572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| .. note:: Not all modes are supported by all CAN controller hardware. | ||
| Passing an unsupported mode value will raise ``ValueError``. | ||
|
|
||
| .. class:: CAN.Mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were so many flags associated with CAN that I thought it might useful to scope some of them to enum classes, i.e. CAN.Mode.NORMAL rather than CAN.MODE_NORMAL. This does take up a little more code size, and it's not the common pattern for machine drivers, so maybe it should be swapped back to the "normal" API pattern.
1547a8d to
fc11501
Compare
| // include is a no-op (as the file is included directly into | ||
| // extmod/machine_can.c). However, including it anyway means that Language | ||
| // Servers and IDEs can correctly analyse the machine_can.c file while the | ||
| // developer is writing it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other extmod/machine_*.c files don't have a _port.h shared header like this, but I found it very useful when writing the stm32 implementation using clangd for IDE-style checks.
I also think it's generally a useful pattern as it encourages explicitly writing out the interface between the extmod source file and the port-specific source file, even though they get compiled together. So I'd like to implement it for the other extmod machine drivers, eventually.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18572 +/- ##
=======================================
Coverage 98.38% 98.38%
=======================================
Files 171 171
Lines 22300 22300
=======================================
Hits 21939 21939
Misses 361 361 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Code size report: |
API is different to the original machine.CAN proposal, as numerous shortcomings were found during initial implementation. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Partially working, some API still unimplemented. Adds new multi_can tests which pass when testing between NUCLEO_H723ZG and PYBDV11. This work was mostly funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
fc11501 to
3b52285
Compare
|
Thanks for keeping at this! I've been using the previous branch for a while. |
Summary
This work follows on from #13149 and closes #12337. The goal is to have a
machine.CANAPI that can be used on multiple ports, and an implementation that works on stm32 port. The existing pyb.CAN API is being kept alongside this.The
machine.CANAPI has changed substantially from the draft submitted in #13149. See comment with more explanation about what happened.Status
I'm afraid this PR is still not complete, although TX and RX functionality work and the supplied new tests all pass. Remaining items:
CAN.recv()error flags and add test coverage.CAN.get_state(),CAN.Stateenum,CAN.IRQ_STATEinterrupt trigger.CAN.get_counters()CAN.get_timings()CAN.reset()andCAN.restart(), and/or simplify the API to remove one of these.CAN.mode()and add test coverage.pyb.CANstill works, usingmulti_pyb_cantests.Future PRs
can&aiocanmodules in micropython-lib. The goal ofmachine.CANis to only implement the bare bones needed to make a higher level "Pythonic" CAN library on top.Testing
NUCLEO_H723ZGboard (fdcan peripheral) and aPYBDV11(bxCAN peripheral).pyb.CANyet.Trade-offs and Alternatives
micropython-liblibraries, but it should be easier to implement all of it in Python now the Python-C interface is simpler.