Repository navigation
stm32: Fix Classic CAN issue where initialising CAN1 corrupts CAN2. - #18992
Conversation
|
@chrismas9 if you get a chance then I'd be interested to know if the new unit tests added here pass on your boards (can run with Still waiting for an F413Z board to arrive so I can finish this. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18992 +/- ##
==========================================
+ Coverage 98.46% 98.47% +0.01%
==========================================
Files 176 176
Lines 22811 22845 +34
==========================================
+ Hits 22460 22497 +37
+ Misses 351 348 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
eab0e62 to
1078d7d
Compare
|
Code size report: |
1078d7d to
6137e28
Compare
|
@projectgus I hope I built it properly. I haven't done this before. I cloned your repo, switched to |
|
Huh, thanks @chrismas9 that's interesting. Good that the results from your test code and the new unit test seem to agree that the problem on F413 is orderings 1,2 and 1,3. My F413 board should arrive soon, so I'll probably hold off on looking at this further until then. |
|
I have three CANbus drivers I can connect to the F413. I can do an external CAN test when you are ready. It sends on each port and listens on th eother two. |
6137e28 to
4890c6c
Compare
|
Received my NUCLEO-F413ZH board, and I think CAN3 is fixed now. @chrismas9 if you get a chance to confirm then it'd be much appreciated, thank you. The problem was that the init path called All CAN unit & multi-tests now passing, except one: It feels like a chip errata or a HAL bug but I can't see a "smoking gun" to confirm. Not fixing here as it's pre-existing issue that's not made worse by this fix. |
4890c6c to
505b16f
Compare
|
@chrismas9 will you get a chance to test this PR again? If not just let us know. |
|
For the 12 combinations of 2 or 3 CAN instances initialised in every order using my internal loopback test I get: Master 7/12 fail. I will set up external CAN buffers and run tests between channels in the next few days. |
|
The first test was with pyb.CAN in LOOPBACK. I have run the same 12 tests with external buffers with pyb.CAN and machine.CAN with no failures. The test sends on one channel and receives on all other channels. for pyb.CAN for machine.CAN |
|
@chrismas9 Thanks, appreciate you independently confirming this! |
|
@projectgus is this ready for final review/merging? |
I think so, yes |
- CAN1 init would clear all filters including CAN2 filter range. - CAN3 init would call can_clearfilter() with empty self->can values, the HAL layer interpreted this as clearing all CAN1 filters. To fix this clearing filter banks is moved to deinit, so they're already clean before the next init (they should be clear on initial init, due to peripheral reset). The only corner case is that if you initialise CAN1 and set too many filters, initialise CAN2, then some of the CAN1 filters may now apply to CAN2. However this would not have worked correctly in the current version either (the extra CAN1 filters would have been silently cleared). Includes expanded unit tests to cover arbitrary pairs of CAN instances. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
This turned out not to be needed for the bugfix in previous commit, but seems like a good practice anyway. Signed-off-by: Angus Gratton <[email protected]>
This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
505b16f to
f16bb6f
Compare
|
@dpgeorge Thanks for the review! I've rewritten both tests to count the number of received messages and then assert it's equal to 1, which is a lot less fiddly. Re-ran on the same set of boards, all still passing. |
dpgeorge
left a comment
There was a problem hiding this comment.
Looks good now, thanks for updating!
I did some basic tests on PYBV10 and everything passed.
Summary
Testing
ports/stm32/pyb_can*.py extmod_hardware/machine_can*.pyunit tests,multi_extmod/machine_can_*.py multi_pyb_can/*.pymulti-tests.Trade-offs and Alternatives
Generative AI
I did not use generative AI tools when creating this PR.