-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
stm32: Improved CAN FD support. #8185
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
Conversation
e3a4441 to
09eb443
Compare
|
Can you fix extended frame mode too? |
2aed1cb to
9ee8afe
Compare
99af5fb to
5d1ea18
Compare
|
Changing the variable name that defines the type of CAN Address from extframe to extid does make it more clear. I have tested the non-can fd part of this code and it still functions as it did before. I can send and receive normal can frames both with simple and extended id's. I have not looked at the fdf=True type frames. Not striclty related to this change, but a note for testing this, receiving extid=False type frames on non can-fd interfaces still does not seem to work see #5508 |
I have not done any testing with the F4, although I have one if needed. Is this fixed in your PR #8206 ? Also have you seen this PR #8057 it fixes some IRQ issues and whatnot. If the issue is not fixed I can take a look, but this PR is mainly concerned with adding full CAN FD support. |
Can you tell me how to reproduce this issue ? I can test with of H7, F7 and F4. |
|
While writing down the steps to reproduce and looking at the code I realized, I should have used MASK16 instead of MASK32. |
|
That's great! Thanks for the feedback on the PR. |
|
Can you please rebase this on latest master to pick up the other merged FDCAN PR? |
Yes, I'll see what I can do, but I can't fix anything related to STM32G4. That said I documented the message ram usage very well and someone else would be able to fix it. |
5d1ea18 to
f4efec2
Compare
|
@dpgeorge rebased. I don't like setting the second set of bit timings (the BRS timings) in the |
|
After looking at the CAN specs and CAN FD specs I realized the specs refer to the extended (29-bit) ID as |
faf55b7 to
ccf0adf
Compare
|
Please see the updated notes in the first comment. |
0ac5a80 to
a2fb7af
Compare
a2fb7af to
2061103
Compare
|
@dpgeorge I've collected almost all? of the open CAN issues in this PR. All the linked issues should be fixed by this PR. I'm now working on the docs, the state of the CAN docs is really bad. Can you review & approve this so I can account for any API changes while I'm at it ? |
|
@dpgeorge docs updated. |
|
Thanks for updating. I'll take a look at this next. |
|
After an initial review of this PR, here are my comments:
|
16771b5 to
c7cfe83
Compare
The docs are clear about it and were updated to reflect the changes (removed the
I went with the 5-tuple option, docs/ code comments were both updated to reflect the changes.
This is possible, however it's not that simple. The main issue here is that the CAN FD RAM (which is shared between all sections including filtering) is currently configured/split statically (i.e. the number of filters, TX/RX FIFO sizes, etc.. per instance is set statically in EDIT: Maybe providing the CAN memory config would be a good feature for more advanced use cases. The needed args are the number of ext filters, number of standard filters, and the number of TX and RX FIFO elements. It would probably make more sense to rename |
|
ping @dpgeorge |
|
It looks like the only outstanding item here is what to do with Option 1
Option 2
Option 2 seems more in line with the rest of the machine API, eg specifying UART buffer size (which comes from the heap, but conceptually is the same as allocating general resources). |
* Enable CAN FD frame support and BRS. * Optimize the message RAM usage per FDCAN instance. * Document the usage and different sections of the Message RAM.
* A CAN bus can have mixed classic/FD nodes. Currently, CAN is configured for either standard or extended ID. * This patch allows extended IDs to be filtered and enabled on a per message basis, in send() and set/clearfilter.
* Define the maximum parameters for CAN/FDCAN nominal bit timing, and for FDCAN data bit timing, for bit timing calculations.
c7cfe83 to
73329dd
Compare
I went with option 2 and removed |
* Add keyword arg to configure the filter bank split.
73329dd to
0c52654
Compare
Fantastic!
Yes I agree, let's leave it static until someone requests for it to be configurable. |
|
Not sure why CI is failing, let me know if I need to fix something. |
|
There's so much CI, something is always going wrong... but in this case it is #8301 so nothing to worry about for this PR. |
|
Rebased and merged in ff287d0 through 5cdf964. And I updated the tests in 71344c1 Thank you @iabdalkader for your efforts on this, I think it is a good improvement to the API and good to have better FD CAN support! |
…es-functions Document optional types & functions
This PR does the following:
Example usage:
fdftrue:brs_baudrate(or brs timings), and setbrstrue, example:extframetrue, example:Testing:
I tested the following scenarios:
Notes:
I renamedextframetoextidbecause it never really enabled extended frames before, and classic CAN does Not support extended frames anyway.extended frameandextended formatrespectively. I still thinkextidis much better, and it is used in the HAL's CAN message structs, that said I reverted it.pyb_can_initfilterbanks()functions is problematic, to say the least. This function should Not be a class method for FDCAN because it can't be called before callingcan.init()first to initialize the number of standard and extended filters and their Message RAM addresses/offsets based on the Message RAM configuration, and set which type of filter is used (although I init both standard and extended filters but we can optimize this). As for classic CAN, this function callsHAL_CAN_ConfigFilter(NULL, &filter);fromcan.c. IfCAN3is defined,HAL_CAN_ConfigFilterwill dereference a NULL CAN handle pointer.extframekeyword argument tosend(),setfilter()andclearfilter(), and removed it frominit()because it's no longer needed. Also following comments on the same issue,recv()now returns a tuple for the matching filter ID, indicating the frame type (true for extended).