BusPirate / Bus_Pirate

Community driven firmware and hardware for Bus Pirate version 3 and 4
625 stars 131 forks source link

flush FTDI buffer to avoid 16ms latency timeout #169

Open denis2342 opened 1 year ago

denis2342 commented 1 year ago

with this patch I could cut down the time to read a 4MB spi flash from 1min to 30sec.

Topper69 commented 1 year ago

Hi,

With your commit i can't compile : "FTDI_CTS" unable to resolve identifier "FTDI_CTS" on spi.c file.

denis2342 commented 1 year ago

it is defined in hardwarev3.h line 104 and 105:

define FTDI_CTS_DIR TRISAbits.TRISA3

define FTDI_CTS PORTAbits.RA3

Topper69 commented 1 year ago

Hi,

Indeed, the issue is with BUSPIRATEV4 board. Could you add

ifdef BUSPIRATEV4

...

else

...

endif

to exclude your patch for BUSPIRATEV4 board.

denis2342 commented 1 year ago

small explanation how this patch is 30 seconds faster on a 4MB flash.

the flashrom software reads the flash in chunks of 2kb blocks. the FTDI chip sends the data in even smaller chunks over the USB interface. But the last chunk of the 2KB does not fill the buffer so the FTDI chip waits up to 16ms before it sends a not completely full buffer. Toggling the CTS line flushes the buffer immediately. 4MB flash divided by 2KB are 2048 transfers where we can save 16ms which is (in theory) 32.768 seconds.

for further reading: https://ftdichip.com/wp-content/uploads/2020/08/AN232B-04_DataLatencyFlow.pdf