Skip to content

Commit

Permalink
hosted/bmp_libusb: Added logic for determining the max packet size a …
Browse files Browse the repository at this point in the history
…CMSIS-DAP probe supports
  • Loading branch information
dragonmux committed Jan 14, 2024
1 parent 95724f2 commit 6854e19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/platforms/hosted/bmp_hosted.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef struct bmda_probe {
uint8_t interface_num;
uint8_t in_ep;
uint8_t out_ep;
uint16_t max_packet_length;
#endif
} bmda_probe_s;

Expand Down
7 changes: 7 additions & 0 deletions src/platforms/hosted/bmp_libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ static void check_cmsis_interface_type(libusb_device *const device, bmda_probe_s
if (strstr(interface_string, "CMSIS") == NULL)
continue;

/* Scan through the endpoints finding the one with the narrowest max transfer length */
info->max_packet_length = UINT16_MAX;
for (uint8_t index = 0; index < descriptor->bNumEndpoints; ++index)
info->max_packet_length = MIN(descriptor->endpoint[index].wMaxPacketSize, info->max_packet_length);

/* Check if it's a CMSIS-DAP v2 interface */
if (descriptor->bInterfaceClass == 0xffU && descriptor->bNumEndpoints == 2U) {
info->interface_num = descriptor->bInterfaceNumber;
Expand All @@ -417,6 +422,8 @@ static void check_cmsis_interface_type(libusb_device *const device, bmda_probe_s
else
info->out_ep = ep;
}
/* If we've found a CMSIS-DAP v2 interface, look no further - we want to prefer these to v1. */
break;
}
}
}
Expand Down

0 comments on commit 6854e19

Please sign in to comment.