From 72da0c962364d1ec285e467275976bd2bf5a627d Mon Sep 17 00:00:00 2001 From: wh201906 Date: Tue, 24 Oct 2023 00:46:28 +0800 Subject: [PATCH 1/3] 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) {}; From 96dc4be112d2d10002730a133893cd05e54b2471 Mon Sep 17 00:00:00 2001 From: wh201906 Date: Tue, 24 Oct 2023 01:27:08 +0800 Subject: [PATCH 2/3] Add an entry in CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b5156d96..db267aff1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac ## [unreleased][unreleased] - Changed `lf em 4x05 dump` - now supports the `--ns` nosave parameter (@iceman1001) + - Fixed some wrong synchronization waits in usb_write() to increase the communication speed (@wh201906) - Added new command `data bmap` - breaks down a hexvalue to a binary template (@iceman1001) - Changed aid_desfire.json - added entreis from the Metrodroid project (@iceman1001) - Changed mad.json - added entries from the Metrodroid project (@iceman1001) From a0af1fa0853d3c7b17be20defb5a2fff2d0eca5e Mon Sep 17 00:00:00 2001 From: wh201906 Date: Tue, 24 Oct 2023 12:12:09 +0800 Subject: [PATCH 3/3] Use ping-pong mode from the start of usb_write() Before: 708608,708608,707584,707584,708608->708198.4 bytes/s After: 722944,733184,732160,731136,733184->730521.6 bytes/s Added some note for ping-pong mode and non ping-pong mode --- common_arm/usb_cdc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common_arm/usb_cdc.c b/common_arm/usb_cdc.c index 37ecd0497..4787ce112 100644 --- a/common_arm/usb_cdc.c +++ b/common_arm/usb_cdc.c @@ -777,7 +777,7 @@ int usb_write(const uint8_t *data, const size_t len) { } 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)) {}; while (length) { // Send next chunk @@ -810,9 +810,9 @@ int usb_write(const uint8_t *data, const size_t len) { if (len % AT91C_EP_IN_SIZE == 0) { - + // like AT91F_USB_SendZlp(), in non ping-pong mode 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_TXCOMP)) {}; UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP); while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {}; @@ -869,6 +869,8 @@ void AT91F_USB_SendData(AT91PS_UDP pudp, const char *pData, uint32_t length) { //*---------------------------------------------------------------------------- void AT91F_USB_SendZlp(AT91PS_UDP pudp) { UDP_SET_EP_FLAGS(AT91C_EP_CONTROL, AT91C_UDP_TXPKTRDY); + // for non ping-pong operation, wait until the FIFO is released + // the flag for FIFO released is AT91C_UDP_TXCOMP rather than AT91C_UDP_TXPKTRDY while (!(pudp->UDP_CSR[AT91C_EP_CONTROL] & AT91C_UDP_TXCOMP)) {}; UDP_CLEAR_EP_FLAGS(AT91C_EP_CONTROL, AT91C_UDP_TXCOMP); while (pudp->UDP_CSR[AT91C_EP_CONTROL] & AT91C_UDP_TXCOMP) {};