Skip to content

Conversation

bergzand
Copy link
Member

Contribution description

This PR extends the USBUS stack with RIOT serial console over USB.

Output from stdio_write is buffered until a host opens the serial device. This can be configured with USBUS_CDCACM_BUFFER_FOR_DTE. In practice this means that no output produced by stdio_write is discarded.

Testing procedure

Add USEMODULE += stdio_cdc_acm to a project.

Issues/PRs references

depends on #11075

image

Todo

Prevent hangs when the tsrb is full

@bergzand bergzand added Type: new feature The issue requests / The PR implemements a new feature for RIOT State: waiting for other PR State: The PR requires another PR to be merged first labels Feb 28, 2019
@bergzand bergzand requested review from kaspar030 and dylad February 28, 2019 20:51
@kaspar030
Copy link
Contributor

Output from stdio_write is buffered until a host opens the serial device.

@cladmi that simplifies our job, right? 😉

@kaspar030
Copy link
Contributor

Seems like a dependency to "auto_init_usbus" is missing, just adding stdio_cdc_acm doesn't work.

@bergzand bergzand added the Area: USB Area: Universal Serial Bus label Mar 18, 2019
@MrKevinWeiss MrKevinWeiss added this to the Release 2019.07 milestone Jun 3, 2019
@dylad dylad removed the State: waiting for other PR State: The PR requires another PR to be merged first label Jun 5, 2019
@bergzand
Copy link
Member Author

bergzand commented Jun 6, 2019

rebased!

@bergzand
Copy link
Member Author

bergzand commented Jun 6, 2019

Currently in a broken state, I've neglected this PR a bit while reworking the USBUS API.

@MrKevinWeiss
Copy link
Contributor

release status ping, should I change the milestone?

@dylad
Copy link
Member

dylad commented Jun 13, 2019

@MrKevinWeiss This might be merged before the end of the month.

@bergzand
Copy link
Member Author

@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.

@bergzand
Copy link
Member Author

Also added a test application as demonstrator

dylad
dylad previously requested changes Jun 15, 2019
Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

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

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? */
Copy link
Member

Choose a reason for hiding this comment

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

Good question tough...

Copy link
Member Author

Choose a reason for hiding this comment

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

Not my question though, I've copied it from other stdio implementation, the question remained unanswered so far…

Copy link
Member Author

Choose a reason for hiding this comment

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

Reworked the vfs bits to mimick the implementation from stdio_uart closely.

@dylad
Copy link
Member

dylad commented Jun 15, 2019

note to other maintainers: I won't be the one to ACK this PR as I authored some part of this code.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

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 ?

#include "usb/usbus/cdc/acm.h"
#include "usb/usbus/control.h"

#include <string.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be the first include

@bergzand
Copy link
Member Author

Maybe add a README to the test application like for CDC ECM?

Yeah, should definitely be included.

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 ?

Somewhat magically, by only selecting stdio_uart if neither of stdio_rtt and stdio_cdc_acm is selected

I've reworked some small aspects of the code here over the weekend to get line control working. I'll push the changes asap.

@dylad dylad dismissed their stale review June 18, 2019 12:02

Comments were address. I leave it to you.

miri64
miri64 previously requested changes Jun 20, 2019
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

Potpourri review (a little of everything: style, clarification questions, ...). Not much to say about the code quality. From what I see it looks correct.

@miri64
Copy link
Member

miri64 commented Jul 30, 2019

Ping @bergzand?

@miri64 miri64 self-assigned this Jul 30, 2019
@bergzand
Copy link
Member Author

Maybe add a README to the test application like for CDC ECM?

Added

@bergzand
Copy link
Member Author

I think I've addressed all the comments here. Anybody willing to give it a last review or give it an ACK?

@benpicco
Copy link
Contributor

What about the dependency on auto_init_usbus ?

stdio_cdc_acm is not very useful without it.

@chrysn
Copy link
Member

chrysn commented Sep 30, 2019

What about the dependency on auto_init_usbus ?

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 auto_init_usbus in their modules list explicitly until such a mechanism exists (as is done with most other auto_inits)

@benpicco
Copy link
Contributor

Ok, fair enough. If a board requires stdio_cdc_acm we can just add both to Makefile.dep anyway.

Now just replace that 64 by a define and you'll have my ACK - those magic numbers make me nervous.

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Code looks good, tested successfully on both Linux and Windows with nrf52.

Please squash!

@bergzand
Copy link
Member Author

Please squash!

Squashed!

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 30, 2019
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

One more nit - just squash directly.

@bergzand
Copy link
Member Author

Rebased to master while I'm at it

@dylad
Copy link
Member

dylad commented Sep 30, 2019

Run a quick test on SAME54-XPRO, shell is working but early printf aren't display.
If a reboot (using a reset or reboot command from shell), the line gets disconnect then reconnect but nothing is print from the early boot.

Looks like there is some garbage

> reboot
2019-09-30 21:23:31,648 # Serial port disconnected, waiting to get reconnected...
2019-09-30 21:23:32,653 # Try to reconnect to /dev/ttyACM1 again...
2019-09-30 21:23:32,655 # Reconnected to serial port /dev/ttyACM1
ps
2019-09-30 21:23:36,115 #  rps
2019-09-30 21:23:36,121 # 	pid | name                 | state    Q | pri | stack  ( used) | base addr  | current     
2019-09-30 21:23:36,124 # 	  - | isr_stack            | -        - |   - |    512 (  108) | 0x20000000 | 0x200001c8
2019-09-30 21:23:36,125 # 	  1 | idle                 | pending  Q |  15 |    256 (  156) | 0x200004f8 | 0x20000574 
2019-09-30 21:23:36,127 # 	  2 | main                 | running  Q |   7 |   1536 (  692) | 0x200005f8 | 0x20000944 
2019-09-30 21:23:36,129 # 	  3 | usbus                | bl anyfl _ |   1 |   1024 (  392) | 0x20000bf8 | 0x20000f0c 
2019-09-30 21:23:36,130 # 	    | SUM                  |            |     |   3328 ( 1348)
> reboot
2019-09-30 21:23:38,423 # Serial port disconnected, waiting to get reconnected...
2019-09-30 21:23:39,429 # Try to reconnect to /dev/ttyACM1 again...
2019-09-30 21:23:39,431 # Reconnected to serial port /dev/ttyACM1
ps
2019-09-30 21:23:42,140 #  rebooThis is RSBps
2019-09-30 21:23:42,142 # shell: command not found: main():
> 

@bergzand
Copy link
Member Author

@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 2019-09-30 21:31:22,011 to be caused by buffering by pyterm.

@dylad
Copy link
Member

dylad commented Sep 30, 2019

@bergzand I had the same output using minicom so I don't think it is related to pyterm.

@benpicco
Copy link
Contributor

benpicco commented Oct 1, 2019

The output looks good with putty.exe on same54-xpro.

putty-same54

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.
We shouldn't delay this indefinitely because of that - we can still patch it later.

@benpicco benpicco merged commit 3f0dfc1 into RIOT-OS:master Oct 1, 2019
@benpicco
Copy link
Contributor

benpicco commented Oct 1, 2019

As discussed on IRC, let's just go ahead with this.
Possible clock / early boot issues can still be sorted out in a follow-up PR, it's beyond the scope of a PR that provides the initial functionality.

@bergzand
Copy link
Member Author

bergzand commented Oct 1, 2019

Thanks everyone!

@bergzand bergzand deleted the pr/usb/cdcacm branch October 1, 2019 09:44
@keestux
Copy link
Contributor

keestux commented Oct 1, 2019

Thank to you, Koen. Great work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: USB Area: Universal Serial Bus CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants