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

Port change should not re-initialize endpoints #23

Closed
mciantyre opened this issue Aug 24, 2023 · 7 comments · Fixed by #24
Closed

Port change should not re-initialize endpoints #23

mciantyre opened this issue Aug 24, 2023 · 7 comments · Fixed by #24
Labels
bug Something isn't working

Comments

@mciantyre
Copy link
Member

imxrt-usbd/src/driver.rs

Lines 405 to 408 in a2f2ce5

if usbsts & USBSTS::PCI::mask != 0 {
ral::write_reg!(ral::usb, self.usb, USBSTS, PCI: 1);
self.initialize_endpoints();
}

This branch in poll() tried to re-initialize (disable) endpoints under two conditions:

  1. when exiting reset.
  2. on deconfiguration.

However, we take this branch when exiting suspend. If we disable endpoints when exiting suspend, we break USB device functions.

This branch isn't properly handling the deconfiguration aspect of the problem; port change doesn't imply deconfiguration. Port change may imply device reset, but we already have dedicated code paths for that. So, we should be able to move this into a reset handling / driver initialization routine.

There's more troubleshooting and discussions in threads here.

@Finomnis
Copy link

Finomnis commented Sep 3, 2023

Any news on this? Otherwise I can try to understand the documentation of the USB peripheral, and try to come up with something.

@Finomnis
Copy link

Finomnis commented Sep 5, 2023

@mciantyre What's the point of configure? Why do we need that function, in general?

Trying to understand the code to come up with a sensible solution.

@mciantyre
Copy link
Member Author

Nothing on my end. If you're looking for a starting point, I'd start with something like this. This passed the expected test cases from the usb-device test suite.

What's the point of configure? Why do we need that function, in general?

My interpretation of the RM is that we should only enable (non-zero) endpoints once we're configured. configure() achieves that. As the UsbBus implementer, I don't know when the device is configured, so I ask the device user to tell me.

We might not need this with driver tweaks, but I never tested without it.

@Finomnis
Copy link

Finomnis commented Sep 11, 2023

It seems to work for me. Is there a reason why we shouldn't merge mciantyre@1d51056 as-is?

Also, it seems that the usb-device test suite does not contain a suspend test, if that's even possible.

@Finomnis
Copy link

Finomnis commented Sep 11, 2023

"I don't know when the device is configured" - Ok I think I get it now - I didn't realize that the driver has no way of knowing the the UsbDeviceState.

That said - where exactly did you read that requirement? I didn't find it in the IMXRT1060RM.pdf yet, although this is a complex chapter and I am sure I missed it.

Also, the current way of dealing with that will set us up for failure later - if the transition to UsbDeviceState::Configured is what causes configuration in the user code, this will later also happen when transitioning away from UsbDeviceState::Suspend.

@Finomnis
Copy link

Should I clone your change and open a PR for it, or will you do it directly? Your fix works on my project, so I'm happy to +1 it.

@mciantyre
Copy link
Member Author

it seems that the usb-device test suite does not contain a suspend test,

That's my issue: I can't easily reproduce and test this. If it works for you, we can move forward with #24.

where exactly did you read that requirement?

I interpreted the TXE and RXE field documentation for all non-zero ENDPTCTRL registers as the requirement.

We also need to tickle the TX / RX data toggle reset during configuration. Endpoint::enable() handles both enable and toggle reset in one go.

if the transition to UsbDeviceState::Configured is what causes configuration in the user code, this will later also happen when transitioning away from UsbDeviceState::Suspend.

Good point. I'll link to #4 so we can consider this when handling suspend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants