-
-
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
1547a8d to
fc11501
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18572 +/- ##
==========================================
- Coverage 98.38% 98.33% -0.05%
==========================================
Files 171 171
Lines 22300 22309 +9
==========================================
- Hits 21939 21937 -2
- Misses 361 372 +11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Code size report: |
fc11501 to
3b52285
Compare
|
Thanks for keeping at this! I've been using the previous branch for a while. |
|
Thanks for putting this PR up! I tested with 2x PYBV10 connected through some CAN tranceivers and the new tests added here all pass. Testing the existing I noticed there's not a simple multitest that just sends and recv's a few frames, without using IRQs. I managed to get something simple working with a poll on |
| @@ -0,0 +1,74 @@ | |||
| from machine import CAN | |||
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.
Maybe these tests can go in tests/multi_extmod/ and be prefixed with machine_can_? Tests in that directory most likely require hardware connections anyway, and if you just want to run CAN tests then can do:
$ ./run-multitests.py -t a0 -t a1 multi_extmod/machine_can_*.py
| .. note:: Specific controller hardware may accept additional optional | ||
| parameters for hardware-specific features such as oversampling. | ||
|
|
||
| .. method:: CAN.init_fd(bitrate, sample_point=None, sjw=None, tseg1=None, tseg2=None) |
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.
Does it make sense to combine this into .init() but with additional keyword arguments to set the timing?
I'm just thinking it's a little awkward to init FD mode with:
can = machine.CAN(1, 500_000, CAN.Mode.SILENT)
can.init_fd(1_000_000)
can.mode(CAN.Mode.NORMAL)Or maybe make it so the mode defaults to SILENT?
Not sure, just some ideas.
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.
Another option could be to require calling init_fd() first, then init() (although that does require constructing via just CAN(1)).
Simplifies the pattern of an optional arg which can be a list of at least a certain length, otherwise one is lazily initialised. Signed-off-by: Angus Gratton <[email protected]>
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 <[email protected]>
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 <[email protected]>
3b52285 to
eb7affc
Compare
|
Still quite a bit to do (next year now), but it's coming along! Also have some tests written for error state transitions and restart, but they need a little bit of tidying up. |
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.