Skip to content

Some SD card init fixes.#10

Open
profi200 wants to merge 13 commits into
LNH-team:developfrom
profi200:develop
Open

Some SD card init fixes.#10
profi200 wants to merge 13 commits into
LNH-team:developfrom
profi200:develop

Conversation

@profi200
Copy link
Copy Markdown

@profi200 profi200 commented Feb 10, 2026

  • Makes sure the SD card is initialized at no more than 400 kHz +-20 kHz tolerance.
  • Give the SD card the correct voltage range.
  • Disable DAT3 pull-up before going into 4-bit mode.
  • Prevents some clock glitches when the command and clock state machine starts.
  • Makes sure CMD and DAT lines are high before starting the clock.
  • Prevents skipped SD commands (makes SD init succeed first try).
  • Makes SD init more spec compliant.

Additionally this:

  • Sets all unused GPIOs to inputs with pull-down. Inputs later disabled to save power.
  • Sets GPIO slew rate to slow. This is more than sufficient for speeds up to 25 MHz.

What's not fixed is clock glitches on command response timeouts. This is due to restarting the state machine while it's clocking the SD.

@profi200
Copy link
Copy Markdown
Author

profi200 commented Feb 10, 2026

Caveat:
The DSpico might be detected too late on DSi systems. There is a noticeably delay between card insert and the icon appearing.

@profi200 profi200 marked this pull request as draft February 11, 2026 20:54
@profi200 profi200 marked this pull request as ready for review February 18, 2026 17:56
Reduces SD mount retries to 3 times.
Comment thread src/sd/SdCard.cpp Outdated
Comment thread src/sd/SdCard.cpp Outdated
Comment thread src/sd/SdCard.cpp Outdated
Comment thread src/common.h Outdated
Comment thread src/common.h Outdated
Added OCR and ACMD42 defines.
@profi200
Copy link
Copy Markdown
Author

profi200 commented May 8, 2026

Should i also include this change?

diff --git a/src/main.cpp b/src/main.cpp
index ae41135..6947b79 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -208,9 +208,9 @@ static inline void earlyGpioInit(void)
     gpio_disable_pulls(SDIO_D3);
 #endif
 
-    gpio_pull_down(PIN_RST);
-    gpio_pull_up(PIN_CEB);
-    gpio_pull_up(PIN_WREB);
+    gpio_disable_pulls(PIN_RST);
+    gpio_disable_pulls(PIN_CEB);
+    gpio_disable_pulls(PIN_WREB);
     gpio_disable_pulls(PIN_D0);
     gpio_disable_pulls(PIN_D1);
     gpio_disable_pulls(PIN_D2);
@@ -219,7 +219,7 @@ static inline void earlyGpioInit(void)
     gpio_disable_pulls(PIN_D5);
     gpio_disable_pulls(PIN_D6);
     gpio_disable_pulls(PIN_D7);
-    gpio_pull_up(PIN_CS2);
+    gpio_disable_pulls(PIN_CS2);
 
     // Set SDIO and NTRCARD DAT pin slew rate.
     // Default slew rate after reset is slow. Good enough for 25 MHz.

Actually i just did because why not if i'm in there already? That change was tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants