USE_SPI_DMA with W5100S-EVB-Pico receive data error

I am using W5100S-EVB-Pico to implement an edge device that uses the FTP code from WizNet Github. The library is configured for W5100S at 50MHz SPI speed. Transferring a 25kB buffer from my PC to a memory buffer in the Pico takes 33ms which is too slow for my application. So, I define USE_SPI_DMA in w5x00_spi.h to enable DMA transfers. The transfer time is reduced to 9ms which is great, but the very first bit of the transfer is corrupted every time.

The number of bytes transferred is identical between DMA and non-DMA mode and there are no network or FTP-library errors. The exact issue seems to be that the very first bit of the transfer is duplicated in bits 0 and 1 and the last bit of the transfer is lost (to be clear I do mean a single bit not a byte).

Example:
25kB transfer starts with 0x8F and ends with 0x00 0x33. With non-DMA the data received in my Pico is (first byte on wire) 0x8F…0x00 0x33 (last byte on wire). With DMA enabled the data received in my Pico is 0xC7 … 0xX0 0x19. The entire transfer is right-shifted 1 bit and the very first bit is always duplicated, it occurs 100% of the time. If the first bit transferred is a 1 then the first two bits received will be 1, and if the first bit transferred is a 0 then the first two bits received will be zero. I have verified the data is correct on the wire using Wireshark.

Something about the DMA mode causes the first bit to be sampled twice and throws off the entire data buffer. It is not possible to correct this in software because a left shift operation on 25kB is very high CPU usage and the final bit value is lost with no way to recover it.

1 Like