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
USBUS: CDC ACM to UART functionality with example. #12268
Conversation
2a03f73
to
4f62f89
Compare
Rebased now that #11085 is merged, all dependencies are merged |
I'm getting: Should |
@leandrolanzieri That's probably the case. I have some time this evening to get this PR into proper shape again. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
4f62f89
to
9dfe772
Compare
Rebased and reworked into a better shape |
Also fixed this |
I've replaced the |
if (data == '\n') { | ||
usbus_cdc_acm_flush(&acmuart->cdcacm); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about transmit byte(s) as soon as they arrive in order to be more like a USB-to-UART adapter ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those send chunks of bytes too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Koen is there any timeout here, or would this essentially be line based?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something timeout-based would be better here indeed. I'll try to come up with something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would imagine you could receive bytes on the UART faster than you can submit USB packets.
So for the best performance, you would have double-buffering and
- fill the RX buffer in the UART callback
- in a thread, check if data is in the RX buffer, if so swap buffers and transfer the buffer over USB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it seems line based. Is it very inefficient to flush every byte? It probably is, so some timeout would be needed.
Somethink like:
- flush on every LF ('\r' instead of '\n', as terminals either send LF or CRLF).
- flush every N bytes (16, 32, ...)
- flush every M ms (with M being about the time it takes to transfer N bytes?)
maybe 3. is sufficient?
Chunking might cause problems, if the sender sends with a deliberate pause to not overload a shitty UART implementation, but the adapter sends full-speed N byte bursts...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer the flush after timeout and possible after every newline.
I've flashed that uart thingy on a particle xenon. my linux cannot enumerate it.
lsusb hangs |
I can reproduce this on the nRF52840dk, I'm trying to figure out if this is caused by this PR or if it is broken in general. |
The CDC ECM test ( |
I got a nucleo-f767zi. stlink uart and mcu usb connected. that should loopback. when I type into the terminal that's connected to the MCU, chars arrive at stlink terminal. but not the other way around. |
I think this is related to the flushing. I changed my terminal to convert cr to crlf, now on enter, data arrives on the other side. |
Fixed with the latest commit |
I flashed this on The Debug Adapter UART ( However, this only works in one direction:
|
I'm trying to add the arduino feature to the feather-m0 board but Reading the comments here it looks like I need this PR to get |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Contribution description
This PR adds integration for UART peripherals for the USBUS CDC ACM (serial over usb) functionality. It allows for transfering data over serial, configuring baud rate and parity bits of the UART peripheral from the host computer.
Testing procedure
Run
examples/usbus_uart_adapter
. When attached to a host computer, it should provide multiple (depending on the board) ttyACM devices of which the first one is connected to the RIOT shell and the others are proxied to the UART peripherals on the board.On a samr21-xpro, using
make list-ttys
this shows up as:In this case,
ttyACM3
is the first serial function and is connected to the RIOT shell.Issues/PRs references
Depends on #11085