democloid / pico-sdio-example

Raspberry Pi Pico SDIO implementation example
GNU General Public License v3.0
14 stars 2 forks source link

Trying to get this running #1

Open carlk3 opened 1 year ago

carlk3 commented 1 year ago

Hi, I'm trying to get this running. I cloned it and made a few changes, primarily to accommodate my hardware's pin assignments:

pico-sdio-example$ git diff  -U0
diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp
index b15dbc0..ad6d67c 100644
--- a/src/bench/bench.cpp
+++ b/src/bench/bench.cpp
@@ -92 +92 @@ using namespace std;
-#define error(s) printf("ERROR: %s\n", s)
+#define error(s) {printf("ERROR: %s\n", s); panic(s);}
diff --git a/src/sdio/sdio.h b/src/sdio/sdio.h
index eef8525..64b1cbb 100644
--- a/src/sdio/sdio.h
+++ b/src/sdio/sdio.h
@@ -11,0 +12 @@
+#ifdef original
@@ -17,0 +19,8 @@
+#else
+#  define SDIO_CLK 17
+#  define SDIO_CMD 18
+#  define SDIO_D0  19
+#  define SDIO_D1  20
+#  define SDIO_D2  21
+#  define SDIO_D3  22
+#endif
diff --git a/src/sdio/sdio.pio b/src/sdio/sdio.pio
index 130af88..e01d7c7 100644
--- a/src/sdio/sdio.pio
+++ b/src/sdio/sdio.pio
@@ -27 +27 @@
-.define SDIO_CLK_GPIO 10
+.define SDIO_CLK_GPIO 17

The only main() I found was in bench.cpp. Trying to run that, it looks like the sd.begin(SD_CONFIG) goes OK:

SD card (SD mode): Fields -- Start bit Transmission: host Command: GO_IDLE_STATE (0) Argument: 0x00000000 CRC: 0x4a End bit Start bit Transmission: host Command: SEND_IF_COND (8) Argument: 0x000001aa CRC: 0x43 End bit Start bit Transmission: card Command: SEND_IF_COND (8) Argument: 0x000001aa CRC: 0x9 End bit Start bit Transmission: host Command: APP_CMD (55) Argument: 0x00000000 CRC: 0x32 End bit Start bit Transmission: card Command: Non-existant (55) Argument: 0x00000120 CRC: 0x41 End bit Start bit Transmission: host Command: SD_SEND_OP_COND (41) Argument: 0xd0040000 CRC: 0x25 End bit Start bit Transmission: card Reserved Argument Reserved End bit Start bit Transmission: host Command: APP_CMD (55) Argument: 0x00000000 CRC: 0x32 End bit Start bit Transmission: card Command: Non-existant (55) Argument: 0x00000120 CRC: 0x41 End bit Start bit Transmission: host Command: SD_SEND_OP_COND (41) Argument: 0xd0040000 CRC: 0x25 End bit Start bit Transmission: card Reserved Argument Reserved End bit Start bit Transmission: host Command: APP_CMD (55) Argument: 0x00000000 CRC: 0x32 End bit Start bit Transmission: card Command: Non-existant (55) Argument: 0x00000120 CRC: 0x41 End bit Start bit Transmission: host Command: SD_SEND_OP_COND (41) Argument: 0xd0040000 CRC: 0x25 End bit Start bit Transmission: card Reserved Argument Reserved End bit Start bit Transmission: host Command: APP_CMD (55) Argument: 0x00000000 CRC: 0x32 End bit Start bit Transmission: card Command: Non-existant (55) Argument: 0x00000120 CRC: 0x41 End bit Start bit Transmission: host Command: SD_SEND_OP_COND (41) Argument: 0xd0040000 CRC: 0x25 End bit Start bit Transmission: card Reserved Argument Reserved End bit Start bit Transmission: host Command: APP_CMD (55) Argument: 0x00000000 CRC: 0x32 End bit Start bit Transmission: card Command: Non-existant (55) Argument: 0x00000120 CRC: 0x41 End bit Start bit Transmission: host Command: SD_SEND_OP_COND (41) Argument: 0xd0040000 CRC: 0x25 End bit Start bit Transmission: card Reserved Argument Reserved End bit Start bit Transmission: host Command: APP_CMD (55) Argument: 0x00000000 CRC: 0x32 End bit Start bit Transmission: card Command: Non-existant (55) Argument: 0x00000120 CRC: 0x41 End bit Start bit Transmission: host Command: SD_SEND_OP_COND (41) Argument: 0xd0040000 CRC: 0x25 End bit Start bit Transmission: card Reserved Argument Reserved End bit Start bit Transmission: host Command: ALL_SEND_CID (2) Argument: 0x00000000 CRC: 0x26 End bit Start bit Transmission: card Reserved Argument End bit Start bit Transmission: host Command: SEND_RELATIVE_ADDR (3) Argument: 0x00000000 CRC: 0x10 End bit Start bit Transmission: card Command: SEND_RELATIVE_ADDR (3) Argument: 0x59b40520 CRC: 0x33 End bit Start bit Transmission: host Command: SEND_CSD (9) Argument: 0x59b40520 CRC: 0x3e End bit Start bit Transmission: card Reserved Argument End bit Start bit Transmission: host Command: SELECT/DESELECT_CARD (7) Argument: 0x59b40520 CRC: 0x28 End bit Start bit Transmission: card Command: SELECT/DESELECT_CARD (7) Argument: 0x00000700 CRC: 0x3a End bit Start bit Transmission: host Command: APP_CMD (55) Argument: 0x59b40520 CRC: 0x5b End bit Start bit Transmission: card Command: Non-existant (55) Argument: 0x00000920 CRC: 0x19 End bit Start bit Transmission: host Command: SET_BUS_WIDTH (6) Argument: 0x00000002 CRC: 0x65 End bit Start bit Transmission: card Command: SWITCH_FUNC (6) Argument: 0x00000920 CRC: 0x5c End bit

It prints:

FreeStack: 241592
SDIOSDIOType is FAT0
Card size: 15.8335 GB (GB = 1E9 bytes)

Manufacturer ID: 0X74
OEM ID: JE
Product: SDU1
Revision: 0.2
Serial number: 0X336E46
Manufacturing date: 1/2019

However, the file.open("bench.dat"...) does nothing at all, maybe because FsVolume::m_cwv is 0, so return FsVolume::m_cwv && open(FsVolume::m_cwv, path, oflag); returns false:

m_cwv: 0x0
m_fVol: 0x68834904
m_xVol: 0x741a2201
m_blockDev: 0x781b681b
m_volMem: [288]

What am I doing wrong?

juico commented 1 year ago

Hey, i got it working myself with slightly different pins although i think this is not the issue. Have you tried with a different SD card and with reformatting the SD card? i had succes with some sandisk ultra cards(32gb and 64gb) and samsung evo 128gb. Some other cards did not work for me but it was mostly CRC errors.

Perhaps you could try enabling debugging on SDFat in DebugMacros.h but as it relies on the arduino framework you might need to rewrite some things so it outputs to the UART or something. This might give you some insight on where it struggles in SDFat.

carlk3 commented 1 year ago

I never could figure out why it wouldn't run. It always triggers an error here:

  if (!file.open("bench.dat", O_RDWR | O_CREAT | O_TRUNC)) {
    error("open failed");
  }

I also downloaded your SDIO.zip and took a look at it. I haven't yet delved into PlatformIO (it's on my to do list), so I haven't been able to get it running.

I eventually gave up and went back to my own project, and I finally succeeded along that path. Here is what I came up with: https://github.com/carlk3/no-OS-FatFS-SD-SPI-RPi-Pico/tree/sdio I used the same general idea of using the ZuluSCSI SDIO driver, but I integrated it with FatFs instead of SdFat.

Thanks for your ideas and help!

democloid commented 1 year ago

Other than the obvious like trying another SD card and such, have you tried lowering the clock speed?

carlk3 commented 1 year ago

Other than the obvious like trying another SD card and such, have you tried lowering the clock speed?

I just tried it. I changed the second rp2040_sdio_init from rp2040_sdio_init(1) to rp2040_sdio_init(25). No difference.

It seems to be an issue with the program. FsVolume::m_cwv is NULL at the point where file.open("bench.dat"...) is called from main.