From 72da0c962364d1ec285e467275976bd2bf5a627d Mon Sep 17 00:00:00 2001 From: wh201906 Date: Tue, 24 Oct 2023 00:46:28 +0800 Subject: [PATCH] Fix some wrong synchronization waits in usb_write() 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 --- common_arm/usb_cdc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common_arm/usb_cdc.c b/common_arm/usb_cdc.c index cb2d0c64a..37ecd0497 100644 --- a/common_arm/usb_cdc.c +++ b/common_arm/usb_cdc.c @@ -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 @@ -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) {};