Skip to content

Commit

Permalink
Fix some wrong synchronization waits in usb_write()
Browse files Browse the repository at this point in the history
To make the full use of the ping-pong endpoint
Transfer speed before this fix:
616448,618496,618496,615424,615424->616857.6 bytes/s
Transfer speed after this fix:
707584,709632,707584,709632,710656->709017.6 bytes/s (+14.9%)
Tested by running hw status
  • Loading branch information
wh201906 committed Oct 23, 2023
1 parent e20742d commit 72da0c9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common_arm/usb_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ int usb_write(const uint8_t *data, const size_t len) {
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {};

UDP_SET_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXPKTRDY);
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXPKTRDY) {};
while (!(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXPKTRDY)) {};
}

// Wait for the end of transfer
Expand All @@ -812,7 +812,7 @@ int usb_write(const uint8_t *data, const size_t len) {
if (len % AT91C_EP_IN_SIZE == 0) {

UDP_SET_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXPKTRDY);
while (!(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP)) {};
while (!(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXPKTRDY)) {};

UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP);
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {};
Expand Down

0 comments on commit 72da0c9

Please sign in to comment.