What is the raspberry pi pico maximum SPI frequency? I wwould like to know the theoretical maximum given no overclocking and the maximum that is stable,
As already answered, the maximum clock speed is 62.5MHz.
But there is something else to be aware of. By default, SPI is in the Motorola mode which toggles the chip select pin after each data word. Here is the diagram from section 220.127.116.11 of the datasheet (the commonly used SPI mode: SPO=0, SPH=0):
As you can see, after each word there is a gap of 1.5 clock cycles so that the SSPFSSOUT pin can toggle. That's unfortunate, as it reduces the effective SPI speed by about 16%.
I was trying to drive a ST7789 display, which doesn't need this signal so it's basically wasted. But because the ST7789 samples on the rising edge, SPI mode 3 (SPO=1, SPH=1) can also be used, which looks like this:
As you can see, in this mode the gap is only half a clock tick (the Q signal). That means there is only 6% overhead, which is a lot less. Still not ideal, but it does save a lot of overhead.
Some more notes to get good performance:
- Use DMA. I was using regular register writes, and for some reason it was slower than DMA even though it should have saturated the FIFO.
- You could try using 16-bit words instead of 8-bit words to reduce the overhead by half. You'll probably need to swap bytes though and it may complicate things.
- Apparently it's possible to avoid this gap altogether by using PIO (see the
pio/st7789_lcdexample). I haven't tested this myself.
(This post is here for anyone else trying to speed things up. I've spend hours to figure this all out and I hope it'll be helpful to someone).
Theoretical value, via Prash's comment, on page 526 of the RP2040 datasheet:
18.104.22.168. Clock ratios
… at the maximum SSPCLK (clk_peri) frequency on RP2040 of 133 MHz, the maximum peak bit rate in [controller] mode is 62.5 Mbps
Practical value? Unanswerable without knowing the electrical characteristics of your setup. Breadboards and jumper wires get noisy above a few MHz. The governing factor is mostly the speed of your SPI peripheral, too.