Skip to content
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

Lots of improvements, FDCAN preparation #45

Merged
merged 51 commits into from
Jan 23, 2025
Merged

Conversation

duckylotl
Copy link
Contributor

I implemented FDCAN support for this library (see FDCAN branch in my fork). During this I implemented a few new features.

This PR only includes the changes that apply to the current CAN peripheral (bxCAN). The FDCAN implementation essentially uses this as a base.

This PR includes quite a lot of changes:

  • Define CAN interface by Tx and Rx pins
    • allows all possible combinations of Tx/Rx pins
    • checks if alternate functions are correctly grouped on the F1 platform (special case)
    • old style still supported
  • setters for additional options
    • IRQ Priority, AutoBusOff, AutoRetransmission, ...
  • expanded filter api
    • current filter function is bugged. Added fixed version and extra functions for ease of use
  • allow setBaudRate to be called before or after begin()
    • also while running to switch baudrate
  • complete lifecycle functions
    • added end() to tear down CAN and free resources
  • changed how instances reserve CAN instances
    • class objects contain peripheral handler, no risk of writing into non valid memory
    • register in global to claim peripheral once peripheral will be started
    • IRQ can retrieve STM32_CAN instances from global by "container_of" magic
    • inspired by Arduino core Hardware Timer implementation
  • IRQ mapping of all platforms
    • added special handling for F0 for shared CEC IRQ
    • workaround for F1 and F3 for shared IRQ with USB

The current API should be untouched. Old projects should work as before. I tried to only expand the API.

Tested on Nucleo-F303K8, Nucleo-F767ZI. Loopback only, no CAN Transceiver.

This fixes the following issues:

Inspired by how Arduino core does it for shared FDCAN+TIM IRQ on G0 Platform in HardwareTimer implementation
…O1 instead of 0. Need to call polling function for TX event handling.
…to self. Now always has a valid object to configure. Register pointer to it in global canObj list once CAN is actually started.
… in setMBFilter(bank_num) and setMBFilter(bank_num, input)
…eep FlexCan compat value as false for success
… re-mapped, CAN IRQs are not blocked by USB anymore.
…Peripheral when no peripheral has been allocated.
@pazi88
Copy link
Owner

pazi88 commented Jan 23, 2025

Thanks! Sounds really good and something that I have been meaning to do for long time. I'll check and pull in, if everything checks out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants