Sorry for constantly bothering you with issues ... but ...
In ft2232_spi_wr_and_rd() on a write the max_xfer is set to 4096:
|
uint32_t max_xfer = (readarr) ? _buffer_size : 4096; |
This is used to limit the xfer value to something below max_xfer. Subsequently mpsse_store() is called and finally mpsse_write(). The return values of mpsse_write() is compared with xfer len+3:
|
if ((uint32_t)ret != xfer+3) |
The problem is that mpsse_store() will internally already call mpsse_write() whenever the buffer is full e.g. here:
|
if ((ret = mpsse_write()) < 0) { |
Upon return mpsse_write() returns the number of bytes written. The problem is the previous comparison with xfer_len+3 will fail if mpsse_store() has already emptied the buffer and called mpsse_write itself. The final mpsse_write() will then only return the length of the last chunk.
This is triggered when writing to a full speed device with endpoints of 64 bytes. Data to flash seems to be written in chunks of 256 bytes which does fit into the 4096 bytes max_xfer limit but more importantly it also fits into the buffer of a high speed usb device with 512 bytes endpoint buffers. I am using a full speed device and thus this triggers.
This will also trigger if some upper layer tries to write > 512 bytes in a chunk. This just never seems to be the case.
May I suggest to just change
|
uint32_t max_xfer = (readarr) ? _buffer_size : 4096; |
to
uint32_t max_xfer = _buffer_size;
uint32_t max_xfer = _buffer_size-3; (see below)
Sorry for constantly bothering you with issues ... but ...
In ft2232_spi_wr_and_rd() on a write the max_xfer is set to 4096:
openFPGALoader/src/ftdispi.cpp
Line 171 in 5644850
This is used to limit the xfer value to something below max_xfer. Subsequently mpsse_store() is called and finally mpsse_write(). The return values of mpsse_write() is compared with xfer len+3:
openFPGALoader/src/ftdispi.cpp
Line 218 in 5644850
The problem is that mpsse_store() will internally already call mpsse_write() whenever the buffer is full e.g. here:
openFPGALoader/src/ftdipp_mpsse.cpp
Line 493 in 5644850
Upon return mpsse_write() returns the number of bytes written. The problem is the previous comparison with xfer_len+3 will fail if mpsse_store() has already emptied the buffer and called mpsse_write itself. The final mpsse_write() will then only return the length of the last chunk.
This is triggered when writing to a full speed device with endpoints of 64 bytes. Data to flash seems to be written in chunks of 256 bytes which does fit into the 4096 bytes max_xfer limit but more importantly it also fits into the buffer of a high speed usb device with 512 bytes endpoint buffers. I am using a full speed device and thus this triggers.
This will also trigger if some upper layer tries to write > 512 bytes in a chunk. This just never seems to be the case.
May I suggest to just change
openFPGALoader/src/ftdispi.cpp
Line 171 in 5644850
to
uint32_t max_xfer = _buffer_size;uint32_t max_xfer = _buffer_size-3;(see below)