Skip to content

Commit d812e58

Browse files
committed
pbio/drv/usb/usb_nxt.c: Fix ZLPs on the control pipe
This is needed to correctly indicate end of descriptor when the descriptor size is an exact multiple of the endpoint packet size.
1 parent b43d551 commit d812e58

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lib/pbio/drv/usb/usb_nxt.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,14 @@ static void pbdrv_usb_nxt_write_data(int endpoint, const void *ptr_, uint32_t le
291291
pbdrv_usb_nxt_state.tx_data[tx] = (uint8_t *)(ptr + packet_size);
292292
pbdrv_usb_nxt_state.tx_len[tx] = length;
293293
} else {
294-
pbdrv_usb_nxt_state.tx_data[tx] = NULL;
294+
if (length == packet_size && endpoint == 0) {
295+
// If we are sending data to the control pipe, we must terminate the data
296+
// with a ZLP. In order to do so, we set the data pointer to non-NULL
297+
// but the length to 0. We do not want to send ZLPs on the Pybricks bulk pipe.
298+
pbdrv_usb_nxt_state.tx_data[tx] = (uint8_t *)(ptr);
299+
} else {
300+
pbdrv_usb_nxt_state.tx_data[tx] = NULL;
301+
}
295302
pbdrv_usb_nxt_state.tx_len[tx] = 0;
296303
}
297304

@@ -771,8 +778,7 @@ static void pbdrv_usb_nxt_isr(void) {
771778
}
772779

773780
/* and we will send the following data */
774-
if (pbdrv_usb_nxt_state.tx_len[endpoint] > 0
775-
&& pbdrv_usb_nxt_state.tx_data[endpoint] != NULL) {
781+
if (pbdrv_usb_nxt_state.tx_data[endpoint] != NULL) {
776782
pbdrv_usb_nxt_write_data(endpoint, pbdrv_usb_nxt_state.tx_data[endpoint],
777783
pbdrv_usb_nxt_state.tx_len[endpoint]);
778784
} else {

0 commit comments

Comments
 (0)