Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flush FTDI buffer to avoid 16ms latency timeout #169

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

denis2342
Copy link

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

@Topper69
Copy link

Topper69 commented Apr 5, 2023

Hi,

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

@denis2342
Copy link
Author

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

#define FTDI_CTS_DIR TRISAbits.TRISA3
#define FTDI_CTS PORTAbits.RA3

@Topper69
Copy link

Topper69 commented Apr 6, 2023

Hi,

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

#ifdef BUSPIRATEV4
...
#else
...
#endif

to exclude your patch for BUSPIRATEV4 board.

@denis2342
Copy link
Author

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

mikebdp2 added a commit to mikebdp2/Bus_Pirate that referenced this pull request Feb 11, 2024
Based on the original work of @denis2342 at
BusPirate#169
- I have reviewed this commit and believe it is OK.
Also improved the ifdef, works fine both for v3 and v4.

Co-authored-by: denis2342 <[email protected]>
Signed-off-by: Mike Banon <[email protected]>
with this patch I could cut down the time to read a
4MB spi flash from 1min to 30sec.
@denis2342 denis2342 force-pushed the master branch 2 times, most recently from 9b3566c to 4c2c104 Compare March 15, 2024 16:12
1. USB led logic is corrected (was reversed)
2. pirate-loader hello now works without resetting the buspirate
3. you get into the bootloader while pressing the mode button at start
4. changed version to 4.12
pirate-loader does not show errors anymore after successful actions
like hello or flashing new firmware. also better error reporting.
increased version to 1.0.4

should be used with bootloader 4.12 but works with 4.10 also
flashrom starts with binary mode and then wants to
return to interactive mode to get the version and stuff. the method
to reset only works for BPv3. the BPv4 uses USB which does not like
the reset. Use another method to get back to the interactive mode.
@denis2342 denis2342 force-pushed the master branch 2 times, most recently from 67a56ce to 9dac9c6 Compare March 31, 2024 19:19
A change about 8 years ago made the SPI speed table incompatible
with the flashrom tool. flashrom thinks it set 8MHz SPI speed when in
reality it was only 2.6MHz. Changing the table back to the state
it was to make it (again) compatible with the flashrom tool.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants