Skip to content

Commit

Permalink
mimxrt/sdcard: Fix power-up issue.
Browse files Browse the repository at this point in the history
Fixed card detection issue at startup caused by debouncing
of card detection signals by adding 2ms delay.
  • Loading branch information
alphaFred committed Aug 5, 2021
1 parent 2616459 commit e1533c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions ports/mimxrt/machine_sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "py/runtime.h"
#include "py/mperrno.h"
#include "extmod/vfs.h"
#include "ticks.h"
#include "fsl_cache.h"

#include "sdcard.h"
Expand Down Expand Up @@ -72,6 +73,9 @@ STATIC bool machine_sdcard_init_helper(mimxrt_sdcard_obj_t *self, const mp_arg_v
sdcard_init_pins(self);

self->initialized = false;

ticks_delay_us64(2ULL * 1000ULL); // Wait 2ms to allow USDHC signals to settle/debounce

return sdcard_detect(self);
}

Expand Down
17 changes: 9 additions & 8 deletions ports/mimxrt/modules/_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
import mimxrt
from machine import Pin

bdev = mimxrt.Flash()
try:
Expand All @@ -16,18 +17,18 @@
os.chdir("/flash")
sys.path.append("/flash")

# do not mount the SD card if SKIPSD exists and SDCard module is available.
# do not mount the SD card if SKIPSD exists.
try:
from machine import SDCard

os.stat("SKIPSD")
except:
sdcard = SDCard(1)
if sdcard:
try:
try:
from machine import SDCard

sdcard = SDCard(1)
if sdcard:
fat = os.VfsFat(sdcard)
os.mount(fat, "/sdcard")
os.chdir("/sdcard")
sys.path.append("/sdcard")
except:
print("Mounting SD card failed")
except:
pass # Fail silently

0 comments on commit e1533c7

Please sign in to comment.