Skip to content

Commit 5cefd0d

Browse files
c1728p90xc0170
authored andcommitted
Ignore disabled Kinetis USB endpoint interrupts
Ignore interrupts on disabled USB endpoints. This prevents handling interrupts when in the wrong state. Prior to this patch when running the serial test on a K64F the assert on line 908 of USBDevice.cpp would sometimes be triggered. This assert indicates that an endpoint 0 IN interrupt occurred before the device was ready. This occurs during the test_cdc_usb_reconnect test when the host sends a "Set Control Line State" USB request and the device acknowledges it just before USB is disconnected.
1 parent aa0cdea commit 5cefd0d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

usb/device/targets/TARGET_Freescale/USBPhy_Kinetis.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,11 @@ void USBPhyHw::process()
636636
uint32_t ev_odd = (USB0->STAT >> 2) & 0x01;
637637
int phy_ep = (num << 1) | dir;
638638

639+
bool tx_en = (USB0->ENDPOINT[PHY_TO_LOG(phy_ep)].ENDPT & USB_ENDPT_EPTXEN_MASK) ? true : false;
640+
bool rx_en = (USB0->ENDPOINT[PHY_TO_LOG(phy_ep)].ENDPT & USB_ENDPT_EPRXEN_MASK) ? true : false;
641+
639642
// setup packet
640-
if ((num == 0) && (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == SETUP_TOKEN)) {
643+
if (tx_en && (num == 0) && (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == SETUP_TOKEN)) {
641644
setup_suspend = true;
642645
Data1 |= 0x02 | 0x01; // set DATA1 for TX and RX
643646
bdt[EP_BDT_IDX(0, TX, EVEN)].info &= ~BD_OWN_MASK;
@@ -648,7 +651,7 @@ void USBPhyHw::process()
648651

649652
} else {
650653
// OUT packet
651-
if (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == OUT_TOKEN) {
654+
if (rx_en && (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == OUT_TOKEN)) {
652655
if (num == 0)
653656
events->ep0_out();
654657
else {
@@ -658,7 +661,7 @@ void USBPhyHw::process()
658661
}
659662

660663
// IN packet
661-
if (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == IN_TOKEN) {
664+
if (tx_en && (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == IN_TOKEN)) {
662665
if (num == 0) {
663666
events->ep0_in();
664667
if (set_addr == 1) {

0 commit comments

Comments
 (0)