aboutsummaryrefslogtreecommitdiffstats
path: root/src/stm32/usbotg.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2020-05-02 08:40:10 -0400
committerKevin O'Connor <kevin@koconnor.net>2020-05-03 11:27:43 -0400
commite93c188766c4ca047a3b556568cd5d73d5320cba (patch)
tree453991b8bf988bd9e66d6eafce8843ec26909b45 /src/stm32/usbotg.c
parent0aa78ec76ed4efac9698eda06e11758c70c65876 (diff)
downloadkutter-e93c188766c4ca047a3b556568cd5d73d5320cba.tar.gz
kutter-e93c188766c4ca047a3b556568cd5d73d5320cba.tar.xz
kutter-e93c188766c4ca047a3b556568cd5d73d5320cba.zip
stm32: Wait for setup complete notification in usbotg.c
A setup packet is only valid after receiving the "setup complete" notification. Signed-off-by: Eric Callahan <arksine.code@gmail.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/stm32/usbotg.c')
-rw-r--r--src/stm32/usbotg.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/stm32/usbotg.c b/src/stm32/usbotg.c
index 99b9cc3a..1c2c5703 100644
--- a/src/stm32/usbotg.c
+++ b/src/stm32/usbotg.c
@@ -141,7 +141,7 @@ peek_rx_queue(uint32_t ep)
uint32_t pktsts = ((grx & USB_OTG_GRXSTSP_PKTSTS_Msk)
>> USB_OTG_GRXSTSP_PKTSTS_Pos);
if ((grx_ep == 0 || grx_ep == USB_CDC_EP_BULK_OUT)
- && (pktsts == 2 || pktsts == 6)) {
+ && (pktsts == 2 || pktsts == 4 || pktsts == 6)) {
// A packet is ready
if (grx_ep != ep)
return 0;
@@ -226,6 +226,7 @@ usb_read_ep0(void *data, uint_fast8_t max_len)
int_fast8_t
usb_read_ep0_setup(void *data, uint_fast8_t max_len)
{
+ static uint8_t setup_buf[8];
usb_irq_disable();
for (;;) {
uint32_t grx = peek_rx_queue(0);
@@ -238,10 +239,14 @@ usb_read_ep0_setup(void *data, uint_fast8_t max_len)
uint32_t pktsts = ((grx & USB_OTG_GRXSTSP_PKTSTS_Msk)
>> USB_OTG_GRXSTSP_PKTSTS_Pos);
if (pktsts == 6)
- // Found a setup packet
+ // Store setup packet
+ fifo_read_packet(setup_buf, sizeof(setup_buf));
+ else
+ // Discard other packets
+ fifo_read_packet(NULL, 0);
+ if (pktsts == 4)
+ // Setup complete
break;
- // Discard other packets
- fifo_read_packet(NULL, 0);
}
uint32_t ctl = EPIN(0)->DIEPCTL;
if (ctl & USB_OTG_DIEPCTL_EPENA) {
@@ -253,9 +258,11 @@ usb_read_ep0_setup(void *data, uint_fast8_t max_len)
while (OTG->GRSTCTL & USB_OTG_GRSTCTL_TXFFLSH)
;
}
- int_fast8_t ret = fifo_read_packet(data, max_len);
+ EPOUT(0)->DOEPINT = USB_OTG_DOEPINT_STUP;
usb_irq_enable();
- return ret;
+ // Return previously read setup packet
+ memcpy(data, setup_buf, max_len);
+ return max_len;
}
int_fast8_t