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

capsules: usb/cdc: Fixup the CDC control message logic #2082

Merged
merged 5 commits into from Sep 10, 2020

Conversation

alistair23
Copy link
Contributor

Pull Request Overview

Update the comment to use SET_CONTROL_LINE_STATE to match the phrase in
the spec. As well as that accept the request no matter what the value
is, but let's document what the options are.

Testing Strategy

Test USB CDC on OpenTitan.

TODO or Help Wanted

N/A

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

brghena
brghena previously approved these changes Aug 22, 2020
hudson-ayers
hudson-ayers previously approved these changes Aug 24, 2020
@hudson-ayers
Copy link
Contributor

cc @gendx , just to confirm that always accepting the request won't be a problem for OpenSK.

@bradjc
Copy link
Contributor

bradjc commented Aug 24, 2020

Why the change in the logic? I don't think my approach was particularly robust, but I do remember getting multiple of the various control messages.

@alistair23
Copy link
Contributor Author

My Linux (5.7) kernel sends a value of 3, so with the current logic the CDC device doesn't work.

@bradjc
Copy link
Contributor

bradjc commented Aug 26, 2020

On my mac with tockloader, I get two CONTROL_LINE_STATE messages, 0x02 and then 0x00. With miniterm I get one, just 0x03. So with this change tockloader doesn't work for me. Maybe we should use this change, but remove the disconnect case in the if statement?

@gendx
Copy link
Contributor

gendx commented Aug 27, 2020

cc @gendx , just to confirm that always accepting the request won't be a problem for OpenSK.

I didn't test the CDC capsule, but it shouldn't be a problem when that capsule is disabled. I didn't check the latest developments, but I don't think the current Tock implementation allows to have multiple USB capsules running at the same time anyway.

@alistair23 alistair23 dismissed stale reviews from hudson-ayers and brghena via 429eabd August 27, 2020 15:46
@alistair23
Copy link
Contributor Author

I have removed the disconnect logic.

capsules/src/usb/cdc.rs Outdated Show resolved Hide resolved
@bradjc
Copy link
Contributor

bradjc commented Sep 3, 2020

My proposed change doesn't work either :(.

I was hoping to avoid changing tockloader, but it seems like I will have to. There doesn't seem to be any way for the host to signal over CDC-ACM "ok, you may now send serial data to me". The serial library in python has this pesky line in it: https://github.com/pyserial/pyserial/blob/master/serial/serialposix.py#L352 which seems to be the issue for tockloader. Basically, anything received before all configuration is finished is just dropped. And since each serial tool has its own setup process, the device can't really know when it is safe to send.

So, my updated approach is:

  • On the device, wait for the host to configure the baud rate to 115200 before trying to send anything. This will be useful for using baud rate configuration to enter bootloader mode in the future.
  • On the host, edit tockloader to remove the call to reset_input_buffer() inside the serial library.

@bradjc
Copy link
Contributor

bradjc commented Sep 3, 2020

I couldn't push to this PR so I put my changes here: https://github.com/tock/tock/compare/pr/2082

@bradjc
Copy link
Contributor

bradjc commented Sep 3, 2020

And note, since miniterm uses pyserial, running miniterm.py /dev/xxx 115200 will miss the first message from the board to the host.

alistair23 and others added 4 commits September 9, 2020 08:49
Update the comment to use SET_CONTROL_LINE_STATE to match the pharse in
the spec. As well as that accept the request no matter what the value
is, but let's document what the options are.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Instead of connecting and disconnecting with SET_CONTROL_LINE_STATE
let's only ever start a connection.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
@alistair23
Copy link
Contributor Author

I have added your patches @bradjc and converted the values to enums.

}

#[derive(PartialEq)]
enum CDCCntrlMessage {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit pick: "ctrl" is a much more common abbreviation for "control". Otherwise, is saving two letters worth it over fully spelling "control"?

@@ -211,6 +243,7 @@ impl<'a, U: hil::usb::UsbController<'a>> CdcAcm<'a, U> {
Buffer64::default(),
],
state: Cell::new(State::Disabled),
ctrl_state: Cell::new(CtrlState::Idle),
Copy link
Contributor

Choose a reason for hiding this comment

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

And here "ctrl" is used.

@bradjc
Copy link
Contributor

bradjc commented Sep 10, 2020

bors r+

@bors bors bot merged commit ea4acbe into tock:master Sep 10, 2020
@alistair23 alistair23 deleted the alistair/cdc-fixup branch September 10, 2020 15:23
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.

None yet

6 participants