2

I am trying to use the Raspberry Pi 4 model B to program the Lattice ICE40 FPGA chip via SPI. It requires continuous clock signal throughout the whole transmission of the bitfile, which is easily bigger than 1Mb.

I am using the spidev library and thanks to the following posts:

SPI transfer fails with buffer size greater than 4096

How to transfer large amount of data (100Kbytes) over SPI?

I was able to configure the buffer size to a bigger number. However even after this, the transmission is still split after 65536 bytes no matter the buffer size setting in /boot/cmdline.txt

Where does this limitation come from? Can it be bypassed?

1 Answer 1

2

It turns out that this limitation is set directly in spidev and it has its reason:

https://github.com/doceme/py-spidev/issues/62#issuecomment-422475465

Indeed, it looks like that the maximum supported transfer length is limited by the device driver, which can be seen right there:

https://github.com/raspberrypi/linux/blob/bfef951a177d4d3f10e8b5072316a517d68a2a27/drivers/spi/spi-bcm2835.c#L371C1-L371C1

I am not sure whether fixing this would be as easy as changing the value and recompiling the driver as I am going to instead bitbang the bitmap myself.

EDIT:

So I've spent some more time on this and found, that the 65535 bytes limit is unfortunately definitive right now. The reason for this is that the register DLEN which holds the data length inside the CPU is 16-bit. This has been the case for the first BCM2835 CPU used in RPi 1 and still remains the case for the BCM2711 in RPi 4.

This can be found in the CPU datasheet here (page 139):

https://datasheets.raspberrypi.com/bcm2711/bcm2711-peripherals.pdf

You can still remove the constrain in the spidev code (spidev_module.c line 47) and this will work, however the driver will not use DMA for this and thus the transfer speed can be significantly limited.

1
  • 1
    Suggest you mark your answer as "Selected" as this may help others struggling with the same issue.
    – Seamus
    Sep 3, 2023 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.