-
Notifications
You must be signed in to change notification settings - Fork 204
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
Rework USB OUT endpoint interrupts #459
Conversation
166798f
to
f242e68
Compare
hal/src/thumbv6m/usb/bus.rs
Outdated
@@ -995,6 +997,7 @@ impl Inner { | |||
} | |||
Err(err) => { | |||
dbgprint!("UsbBus::read from ep {:?} -> {:?}\n", ep, err); | |||
drop(bank); // bank holds a reference to self.desc, which print_epstatus() needs |
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.
Just noticed this might've broken isochronous transfers; I've got some other local changes that might also be where the problem comes from, but need to do some more digging.
This was the problem - previously this PR just deleted the drop(bank);
above.
f242e68
to
53ef89f
Compare
I've made a few changes from the original version of this PR, the main one is that the transfer complete and transfer failed flags are cleared in |
53ef89f
to
4a0fff5
Compare
799dc17
to
ca977fd
Compare
Has a little debug code left from atsamd-rs/atsamd#459
49ba6e7
to
8227495
Compare
8227495
to
0eb198a
Compare
Previously, when the USB interrupt was unmasked and a host issued an OUT transfer to an endpoint that was not `read()` before the next OUT transfer attempt to that endpoint, the USB ISR would continually fire until `read()` was called on that endpoint. If a higher priority ISR didn't somehow clear the condition that prevented the `read()`, the CPU would lock up. This change moves the clearing of the endpoint's transfer complete and transfer failed interrupt flags in to `poll(), so that a USB Class can safely skip a `read()` without having to chose between discarding data, or locking up in the USB ISR.
0eb198a
to
bbd02ec
Compare
* Rework USB OUT endpoint interrupts Previously, when the USB interrupt was unmasked and a host issued an OUT transfer to an endpoint that was not `read()` before the next OUT transfer attempt to that endpoint, the USB ISR would continually fire until `read()` was called on that endpoint. If a higher priority ISR didn't somehow clear the condition that prevented the `read()`, the CPU would lock up. This change moves the clearing of the endpoint's transfer complete and transfer failed interrupt flags in to `poll(), so that a USB Class can safely skip a `read()` without having to chose between discarding data, or locking up in the USB ISR. * Optimisation in USB poll()
(this PR has been heavily edited from the original - sorry)
Previously, when the USB interrupt was unmasked and a host issued an OUT transfer to an endpoint, the USB interrupt would continually fire until
read()
was called on that endpoint. This could lead to a hang if the USB class controlling the endpoint was dependent on some lower-priority task before it could successfully read. For example: if the class received data over USB to feed out to an interrupt-driven serial port, the class might have a full buffer so not call the endpointread()
, but the buffer would not drain because the serial port interrupt was lower priority than the USB one. This behaviour came about because the USBpoll()
method didn't clear the endpoint interrupts for OUT transfers, but relied on theread()
methods on endpoints to clear them.The endpoints have a non-interrupting flag that indicates when the endpoint is ready to be read, and this change switches to using that to indicate data is available.
One subtle consequence of this change is that if a USB class doesn't
read()
a successful OUT transfer, the OUT data will sit idle indefinitely, until either it or the host transfers data. A simple workaround is to enable the SOF interrupts using #456 so thatpoll()
gets called within the next millisecond.