usbus: Add CDC-ACM (Serial console) function#11085
Conversation
@cladmi that simplifies our job, right? 😉 |
|
Seems like a dependency to "auto_init_usbus" is missing, just adding stdio_cdc_acm doesn't work. |
|
rebased! |
|
Currently in a broken state, I've neglected this PR a bit while reworking the USBUS API. |
|
release status ping, should I change the milestone? |
|
@MrKevinWeiss This might be merged before the end of the month. |
|
@dylad Rebased on top of master. It should compile and work again. There is still a lot of missing docs and some magic constants scattered here and there. |
|
Also added a test application as demonstrator |
dylad
left a comment
There was a problem hiding this comment.
First round, just some basic stuff
| int fd; | ||
| fd = vfs_bind(STDIN_FILENO, O_RDONLY, &uart_stdio_vfs_ops, (void *)STDIN_FILENO); | ||
| if (fd < 0) { | ||
| /* How to handle errors on init? */ |
There was a problem hiding this comment.
Not my question though, I've copied it from other stdio implementation, the question remained unanswered so far…
There was a problem hiding this comment.
Reworked the vfs bits to mimick the implementation from stdio_uart closely.
|
note to other maintainers: I won't be the one to ACK this PR as I authored some part of this code. |
aabadie
left a comment
There was a problem hiding this comment.
Maybe add a README to the test application like for CDC ECM?
Also I'm wondering how USB stdio is selected over UART (which is the default on samr21-xpro for example). Is this done magically by the build system ?
sys/usb/usbus/cdc/acm/cdc_acm.c
Outdated
| #include "usb/usbus/cdc/acm.h" | ||
| #include "usb/usbus/control.h" | ||
|
|
||
| #include <string.h> |
There was a problem hiding this comment.
This should be the first include
Yeah, should definitely be included.
Somewhat magically, by only selecting I've reworked some small aspects of the code here over the weekend to get line control working. I'll push the changes asap. |
miri64
left a comment
There was a problem hiding this comment.
Potpourri review (a little of everything: style, clarification questions, ...). Not much to say about the code quality. From what I see it looks correct.
|
Ping @bergzand? |
Added |
|
I think I've addressed all the comments here. Anybody willing to give it a last review or give it an ACK? |
|
What about the dependency on
|
It needs some initialization, and AFAICT there's no idiom in the dependencies system yet for "pull it in unless the application wants to do it manually", short of which there's no way to do manual initialization once a module pulls in auto_init. (Proposed in #11085 (comment) but probably exceeds this PR). I'd suggest asking applications to take in |
|
Ok, fair enough. If a board requires Now just replace that |
benpicco
left a comment
There was a problem hiding this comment.
Code looks good, tested successfully on both Linux and Windows with nrf52.
Please squash!
4a0fa5b to
325cc4e
Compare
Squashed! |
benpicco
left a comment
There was a problem hiding this comment.
One more nit - just squash directly.
325cc4e to
1ecb165
Compare
1ecb165 to
4b7feb1
Compare
|
Rebased to master while I'm at it |
4b7feb1 to
c6447b7
Compare
|
Run a quick test on SAME54-XPRO, shell is working but early printf aren't display. Looks like there is some garbage |
|
@dylad Not sure I can reproduce your issue, this is what I get on a samr21-xpro: > ps
2019-09-30 21:31:18,232 # ps
2019-09-30 21:31:18,234 # pid | name | state Q | pri | stack ( used) | base addr | current
2019-09-30 21:31:18,235 # - | isr_stack | - - | - | 512 ( 148) | 0x20000000 | 0x200001b8
2019-09-30 21:31:18,236 # 1 | idle | pending Q | 15 | 256 ( 156) | 0x200004f8 | 0x2000055c
2019-09-30 21:31:18,237 # 2 | main | running Q | 7 | 1536 ( 788) | 0x200005f8 | 0x200008e4
2019-09-30 21:31:18,238 # 3 | usbus | bl anyfl _ | 1 | 1024 ( 448) | 0x20000bf8 | 0x20000efc
2019-09-30 21:31:18,238 # | SUM | | | 3328 ( 1540)
> reboot
2019-09-30 21:31:20,986 # Serial port disconnected, waiting to get reconnected...
2019-09-30 21:31:22,009 # Try to reconnect to /dev/ttyACM2 again...
2019-09-30 21:31:22,010 # Reconnected to serial port /dev/ttyACM2
2019-09-30 21:31:22,011 # rebootmain(): This is RIOT! (Version: 2019.10-devel-1127-gc6447b-pr/usb/cdcacm)
2019-09-30 21:31:22,012 # RIOT USB CDC ACM shell test
> ps
2019-09-30 21:31:23,192 # ps
2019-09-30 21:31:23,194 # pid | name | state Q | pri | stack ( used) | base addr | current
2019-09-30 21:31:23,195 # - | isr_stack | - - | - | 512 ( 148) | 0x20000000 | 0x200001b8
2019-09-30 21:31:23,196 # 1 | idle | pending Q | 15 | 256 ( 156) | 0x200004f8 | 0x2000055c
2019-09-30 21:31:23,197 # 2 | main | running Q | 7 | 1536 ( 788) | 0x200005f8 | 0x200008e4
2019-09-30 21:31:23,198 # 3 | usbus | bl anyfl _ | 1 | 1024 ( 448) | 0x20000bf8 | 0x20000efc
2019-09-30 21:31:23,198 # | SUM | | | 3328 ( 1540)I expect the semi-garbled reboot at |
|
@bergzand I had the same output using minicom so I don't think it is related to pyterm. |
|
The output looks good with Can't really test the reset behavior as PuTTY will just exit with an error when the device gets disconnected. But for garbled output during early boot I'd rather blame some unstable clock. |
|
As discussed on IRC, let's just go ahead with this. |
|
Thanks everyone! |
|
Thank to you, Koen. Great work |

Contribution description
This PR extends the USBUS stack with RIOT serial console over USB.
Output from
stdio_writeis buffered until a host opens the serial device. This can be configured withUSBUS_CDCACM_BUFFER_FOR_DTE. In practice this means that no output produced bystdio_writeis discarded.Testing procedure
Add
USEMODULE += stdio_cdc_acmto a project.Issues/PRs references
depends on #11075
Todo
Prevent hangs when the
tsrbis full