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

canio: implement for stm32f405 #3505

Merged
merged 9 commits into from
Oct 7, 2020
Merged

canio: implement for stm32f405 #3505

merged 9 commits into from
Oct 7, 2020

Conversation

jepler
Copy link
Member

@jepler jepler commented Oct 2, 2020

The has successfully run my loopback self-test program for CAN, which tests transmission, reception, and filtering. The 1M baud rate setting was also verified on a saleae to be accurate.

I also verified that I could exchange packets with Adafruit_CircuitPython_MCP2515 at baudrate=250_000.

@jepler
Copy link
Member Author

jepler commented Oct 2, 2020

I implemented a send-and-receive program that operates on both built in canio and adafruit_mcp2515: https://gist.github.com/ffc169a73954e02ab9f18f9c53fa4618

It's a bit fiddly to get it started because if you don't start them close to the same time each one concludes the CAN bus is not functioning properly.

@tannewt tannewt self-requested a review October 2, 2020 22:56
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions but nothing major. Please fix up lib/tinyusb as well.

ports/stm/common-hal/canio/Listener.h Outdated Show resolved Hide resolved
ports/stm/common-hal/canio/CAN.c Outdated Show resolved Hide resolved
@jepler
Copy link
Member Author

jepler commented Oct 6, 2020

This PR has been rebased. I believe there's no longer an unintended change to tinyusb. I've attempted to address all review comments.

Testing performed (today): sending to a Feather M4 CAN prototype board

@jepler jepler requested review from hierophect and tannewt October 6, 2020 15:35
@hierophect hierophect added the stm label Oct 6, 2020
@tannewt
Copy link
Member

tannewt commented Oct 6, 2020

I still see a TinyUSB change in the first commit: c46cf85

Everything else looks good.

jepler added 7 commits October 6, 2020 20:11
The has successfully run my loopback self-test program for CAN,
which tests transmission, reception, and filtering.  The 1M baud rate setting
was also verified on saleae to be accurate.
.. also add the 8ms wait for transmission that the atmel sam port
has
.. it's necessary to wait for a cancellation request to actually free
the respective Tx mailbox
@jepler
Copy link
Member Author

jepler commented Oct 7, 2020

Thanks for the patience, I've tried again to correct it.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

@tannewt tannewt merged commit 0775e2b into adafruit:main Oct 7, 2020
@hierophect
Copy link
Collaborator

Shoot, didn't get a chance to test. My CAN stuff is coming in late. I'll open an issue if I have any issues once I get them.

@jepler jepler deleted the canbus-stm branch November 3, 2021 21:09


void common_hal_canio_listener_construct(canio_listener_obj_t *self, canio_can_obj_t *can, size_t nmatch, canio_match_obj_t **matches, float timeout) {
if (!can->fifo0_in_use) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the expectation that a canio stm32f405 user will always need to create 2 listeners?

Copy link
Member

@anecdata anecdata Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is what you're asking, but I believe the bus needs two devices to function in active mode adafruit/Adafruit_CircuitPython_MCP2515#21 (comment)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this repo, if I understand this correctly, a separate listener object is required to use FIFO1. I was comparing this implementation with another library (Rust), and noticed that in their receive handler, they check both FIFOs in one check.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear to me which listener will get which messages when there is no matching/filtering setup. I suppose the likely recommendation is to use message id filtering.

Aka, incorrect usage (that will lead to weird behavior):

listenerFIFO0 = can.listen(timeout=.1)
listenerFIFO1 = can.listen(timeout=.1)

Correct usage:

listenerFIFO0 = can.listen(matches=[<list of message ids>], timeout=.1)
listenerFIFO1 = can.listen(matches=[<list of message ids different than FIFO0>], timeout=.1)

I have not tested this though.

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

Successfully merging this pull request may close these issues.

5 participants