stm32f103xb : Process USB TX before USB RX
If TX and RX USB events are pending at the same time, process the TX
event first. This prevents MSD problems from packets being processed
in the wrong order.
@@ -648,35 +648,35 @@ void USBD_Handler(void)
num = istr & ISTR_EP_ID;
val = EPxREG(num);
- if (val & EP_CTR_RX) {
- EPxREG(num) = EP_VAL_UNCHANGED(val) & ~EP_CTR_RX;
+ if (val & EP_CTR_TX) {
+ EPxREG(num) = EP_VAL_UNCHANGED(val) & ~EP_CTR_TX;
#ifdef __RTX
if (USBD_RTX_EPTask[num]) {
- isr_evt_set((val & EP_SETUP) ? USBD_EVT_SETUP : USBD_EVT_OUT, USBD_RTX_EPTask[num]);
+ isr_evt_set(USBD_EVT_IN, USBD_RTX_EPTask[num]);
}
#else
if (USBD_P_EP[num]) {
- USBD_P_EP[num]((val & EP_SETUP) ? USBD_EVT_SETUP : USBD_EVT_OUT);
+ USBD_P_EP[num](USBD_EVT_IN);
}
#endif
}
- if (val & EP_CTR_TX) {
- EPxREG(num) = EP_VAL_UNCHANGED(val) & ~EP_CTR_TX;
+ if (val & EP_CTR_RX) {
+ EPxREG(num) = EP_VAL_UNCHANGED(val) & ~EP_CTR_RX;
#ifdef __RTX
if (USBD_RTX_EPTask[num]) {
- isr_evt_set(USBD_EVT_IN, USBD_RTX_EPTask[num]);
+ isr_evt_set((val & EP_SETUP) ? USBD_EVT_SETUP : USBD_EVT_OUT, USBD_RTX_EPTask[num]);
}
#else
if (USBD_P_EP[num]) {
- USBD_P_EP[num](USBD_EVT_IN);
+ USBD_P_EP[num]((val & EP_SETUP) ? USBD_EVT_SETUP : USBD_EVT_OUT);
}
#endif
