polpo / rp2040-psram

A header-only C library to allow access to SPI PSRAM via PIO on the RP2040 microcontroller.
MIT License
134 stars 13 forks source link

SPI > 33Mhz possible #5

Open 3s1d opened 1 year ago

3s1d commented 1 year ago

Hi,

I just wanted to let you know that I have the communication working using the spi hardware (+dma) of the rp2040. Actually you provided the trick:

    aspAcquire(aps);

    /* inititate read */
    uint8_t cmd[5] = { APS_FASTREAD };
    cmd[1] = addr >> 16;
    cmd[2] = addr >> 8;
    cmd[3] = addr & 0xFF;
    cmd[4] = 0;             //dummy
    spi_transfer(aps->spi, cmd, NULL, sizeof(cmd));

    /* receive data */
    //note: for fastread (>33Mhz) we need to switch to sampling on the falling egde
    if(aps->spi->baud_rate > 33000000)
        spi_set_format(aps->spi->hw_inst, 8, SPI_CPOL_0, SPI_CPHA_1, SPI_MSB_FIRST);
    spi_transfer(aps->spi, NULL, buf, size);
    if(aps->spi->baud_rate > 33000000)
        spi_set_format(aps->spi->hw_inst, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);

    aspRelease(aps);

Prior to the read operation I reconfigure the spi hardware to do sampling on the falling edge. I have it tested at 62.5Mhz (maximum for a pico running at default speed (125Mhz)).

Cheers, Juergen

polpo commented 1 year ago

Thank you for opening this issue, that is great to hear! I will try out this code. To get 62.5MHz, do you have to reconfigure the peripheral clock? When trying to use the SPI hardware I came across this post: https://forums.raspberrypi.com/viewtopic.php?t=333214. I typically overclock the Pico (in the 266-280MHz range) and wonder if the baud rate will also scale as I overclock.

3s1d commented 1 year ago

Hi Polpo,

no have not done anything like that. My pico should run at stock 125Mhz. I can confirm that the SPI clk runs at 62.5Mhz. I measured it with my scope.

Bests, Juergen