Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/Rp2040SdioSetup/Rp2040SdioSetup.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ https://learn.adafruit.com/adafruit-microsd-spi-sdio
Wires should be short since signals can be as faster than 50 MHz.
*/
#define DISABLE_FS_H_WARNING // Disable warning for type File not defined.
#include "SdFat.h"
#include "SdFat_Adafruit_Fork.h"
//------------------------------------------------------------------------------
// Example GPIO definitions I use for debug. Edit for your setup.
// Run this example as is to print the symbol for your variant.
Expand All @@ -30,6 +30,10 @@ Wires should be short since signals can be as faster than 50 MHz.
#define RP_CLK_GPIO 18
#define RP_CMD_GPIO 19
#define RP_DAT0_GPIO 20 // DAT1: GPIO21, DAT2: GPIO22, DAT3: GPIO23.
#elif defined(ARDUINO_ADAFRUIT_METRO_RP2350) || defined(ARDUINO_ADAFRUIT_FRUITJAM_RP2350)
#define RP_CLK_GPIO 34
#define RP_CMD_GPIO 35
#define RP_DAT0_GPIO 36 // DAT1: GPIO37, DAT2: GPIO38, DAT3: GPIO39.
#elif defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_2)
#define RP_CLK_GPIO 16
#define RP_CMD_GPIO 17
Expand Down
27 changes: 25 additions & 2 deletions src/SdCard/Rp2040Sdio/PioSdioCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const uint PIO_CLK_DIV_INIT = 2;

const uint PIO_CLK_DIV_RUN = 1;

const uint PIN_SDIO_UNDEFINED = 31u;
const uint PIN_SDIO_UNDEFINED = 48u;

const uint DAT_FIFO_DEPTH = 8;
const uint CMD0_RETRIES = 10;
Expand Down Expand Up @@ -260,6 +260,26 @@ static void pioEnd() {
static bool pioInit() {
uint pin[] = {g_clkPin, g_cmdPin, g_dat0Pin,
g_dat0Pin + 1, g_dat0Pin + 2, g_dat0Pin + 3};

uint lowest_pin = pin[0];
uint highest_pin = pin[0];
uint gpio_base = 0;
for (uint i = 0; i < 6U; i++) {
if (pin[i] < lowest_pin) {
lowest_pin = pin[i];
}
if (pin[i] > highest_pin) {
highest_pin = pin[i];
}
}
if (highest_pin - lowest_pin > 31) {
sdError(PIO_ERROR_ADD_PROGRAM);
return false;
}
if (highest_pin > 31) {
gpio_base = 16;
}

if (g_wrRespOffset < 0) {
uint16_t patched_inst[rd_data_program.length]; // NOLINT
struct pio_program tmp_program;
Expand All @@ -280,6 +300,9 @@ static bool pioInit() {
sdError(PIO_ERROR_ADD_PROGRAM);
goto fail;
}
if (gpio_base > 0) {
pio_set_gpio_base(g_pio, gpio_base);
}
g_sm0 = pio_claim_unused_sm(g_pio, false);
if (g_sm0 < 0) {
sdError(PIO_ERROR_ADD_PROGRAM);
Expand Down Expand Up @@ -327,7 +350,7 @@ static bool pioInit() {
}

g_pio->input_sync_bypass |=
(1 << g_clkPin) | (1 << g_cmdPin) | (0XF << g_dat0Pin);
(1 << (g_clkPin-gpio_base)) | (1 << (g_cmdPin-gpio_base)) | (0XF << (g_dat0Pin-gpio_base));
pio_sm_set_consecutive_pindirs(g_pio, g_sm0, g_clkPin, 1, true);
pio_sm_set_consecutive_pindirs(g_pio, g_sm0, g_cmdPin, 1, true);
pio_sm_set_consecutive_pindirs(g_pio, g_sm0, g_dat0Pin, 4, false);
Expand Down