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

Fix minor transmit stall race when in USB to CAN bridge mode #6823

Merged
merged 4 commits into from
Feb 28, 2025

Conversation

KevinOConnor
Copy link
Collaborator

There was a small race condition that could allow transmit "echo" frames to become briefly stalled when in USB to CAN bridge mode. This would likely only effect some controllers - potentially the stm32 usbotg (stm32f4 and stm32h7 devices).

The PR also contains a couple of commits intended to better organize the usb_canbus.c code.

-Kevin

@KevinOConnor KevinOConnor force-pushed the work-canbridge-20250214 branch from 6973749 to 6138a85 Compare February 15, 2025 21:50
@KevinOConnor
Copy link
Collaborator Author

FYI, I also added an additional change to this PR - the gs_usb "echo frames" will now be sent back to the host prior to processing those frames. This helps improve the output of candump debugging logs (it should not have an impact on klipper itself).

-Kevin

Don't limit the canbus_notify_tx() wakeup to cases where notify_local
is set - perform the wakeup whenever the host_status field indicates
the main task has work pending.

This fixes a small race condition where the main task could block
sending a usb echo frame, and the canbus_send() code gets called as
the usb bandwidth becomes available but before a usb wakeup
notification is sent.  In that situation, the usb code may not issue a
wake event and the echo frames may be delayed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Separate code in usbcan_task() to new drain_host_queue().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The Linux kernel reports a canbus message as transmitted when it gets
the echo frame back.  Processing the message prior to sending the echo
frame can lead to odd looking debugging logs (as the response messages
may appear to predate the request messages).  This doesn't impact the
Klipper code, but it does make analyzing logs harder.  Fix by sending
the echo frame prior to processing the frame.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
@KevinOConnor KevinOConnor force-pushed the work-canbridge-20250214 branch from 6138a85 to 941fb5a Compare February 27, 2025 18:34
@KevinOConnor KevinOConnor merged commit 941fb5a into master Feb 28, 2025
2 checks passed
@KevinOConnor KevinOConnor deleted the work-canbridge-20250214 branch February 28, 2025 03:48
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.

1 participant