Skip to content

Fix abrupt USB disconnection leaving stale data in DAP queue buffers. #1090

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/board/microbitv2/kl27z/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void PORTCD_IRQHandler(void)
USBD_Reset();
usbd_reset_core();
usb_pc_connected = false;
usb_state = USB_DISCONNECTED;
usb_state = USB_DISCONNECTING;
}
else {
// Cable inserted
Expand Down
4 changes: 2 additions & 2 deletions source/board/microbitv2/nrf52820/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void GPIOTE_IRQHandler(void)
USBD_Reset();
usbd_reset_core();
usb_pc_connected = false;
usb_state = USB_DISCONNECTED;
usb_state = USB_DISCONNECTING;
} else {
// Cable inserted
wake_from_usb = 1;
Expand All @@ -272,7 +272,7 @@ void POWER_CLOCK_IRQHandler(void)
USBD_Reset();
usbd_reset_core();
usb_pc_connected = false;
usb_state = USB_DISCONNECTED;
usb_state = USB_DISCONNECTING;
}
}
#endif // POWER_IRQ_USBDETECTED
14 changes: 11 additions & 3 deletions source/daplink/interface/main_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,13 @@ void main_task(void * arg)
switch (usb_state) {
case USB_DISCONNECTING:
usb_state = USB_DISCONNECTED;
// Disable board power before USB is disconnected.
// Disable target power as USB was disconnected.
gpio_set_board_power(false);
usbd_connect(0);
// Clear the DAP queue buffers
#if (USBD_HID_ENABLE)
usbd_bulk_init();
usbd_hid_init();
#endif
break;

case USB_CONNECTING:
Expand Down Expand Up @@ -435,12 +439,16 @@ void main_task(void * arg)
break;

case USB_CONNECTED:
if (!usbd_configured()) {
usb_state = USB_DISCONNECTING;
}
break;

case USB_DISCONNECTED:
if (usbd_configured()) {
usb_state = USB_CONNECTED;
}
else {
usb_state = USB_DISCONNECTED;
usb_state_count = USB_CONNECT_DELAY;
usb_no_config_count = USB_CONFIGURE_TIMEOUT;
}
Expand Down