Getting the SDCard of iMXRT1050-EVK working on NuttX

I decided to test the SDCard support on iMXRT1050-EVK board, but go these errors:

CC: chip/imxrt_lowputc.c
chip/imxrt_lowputc.c: In function 'imxrt_lpuart_configure':
chip/imxrt_lowputc.c:559:2: warning: #warning missing logic [-Wcpp]
559 | #warning missing logic
| ^
CC: chip/imxrt_idle.c
CC: chip/imxrt_timerisr.c
chip/imxrt_timerisr.c:63:2: warning: #warning REVISIT these clock settings [-Wcpp]
63 | #warning REVISIT these clock settings
| ^
CC: chip/imxrt_usdhc.c
chip/imxrt_usdhc.c:100:4: error: #error "CONFIG_SDIO_BLOCKSETUP is mandatory for this driver"
100 | # error "CONFIG_SDIO_BLOCKSETUP is mandatory for this driver"
| ^
In file included from chip/imxrt_usdhc.c:60:
chip/imxrt_usdhc.c: In function 'imxrt_usdhc_initialize':
chip/imxrt_usdhc.c:3144:25: error: 'GPIO_USDHC1_DATA0' undeclared (first use in this function); did you mean 'GPIO_USDHC1_DATA0_1'?
3144 | imxrt_config_gpio(PIN_USDHC1_D0);
| ^
chip/imxrt_usdhc.c:3144:25: note: each undeclared identifier is reported only once for each function it appears in
chip/imxrt_usdhc.c:3145:25: error: 'GPIO_USDHC1_CLK' undeclared (first use in this function); did you mean 'GPIO_USDHC1_CLK_1'?
3145 | imxrt_config_gpio(PIN_USDHC1_DCLK);
| ^
chip/imxrt_usdhc.c:3146:25: error: 'GPIO_USDHC1_CMD' undeclared (first use in this function); did you mean 'GPIO_USDHC1_CMD_1'?
3146 | imxrt_config_gpio(PIN_USDHC1_CMD);
| ^
make[1]: *** [Makefile:151: imxrt_usdhc.o] Error 1

The first error as easy to fix: just run “make menuconfig” press the key “/” and search for “CONFIG_SDIO_BLOCKSETUP” you will find the:

Prompt: SDIO block setup

Just press 1 do go directly to it and then enable it:

[*] SDIO block setup

After trying to compile again you will see that the pins definition still missing: PIN_USDHC1_D0, PIN_USDHC1_DCLK, PIN_USDHC1_CMD. Just like we did for SPI in the previous post, you need to start looking the schematics.

First let see the SDCard slot:

So, let search for these pins: SD1_CLK, SD1_CMD, SD1_D0, SD1_D1, SD1_SD2, SD1_D3 and SD_CD_SW:

So, we have:

SD1_CMD = GPIO_SD_B0_00
SD1_CLK = GPIO_SD_B0_01
SD1_D0 = GPIO_SD_B0_02
SD1_D1 = GPIO_SD_B0_03
SD1_D2 = GPIO_SD_B0_04
SD1_D3 = GPIO_SD_B0_05
SD_CD_SW = GPIO_B1_12

And like we did for the SPI, let’s to look at arch/arm/src/imxrt/hardware/rt105x/imxrt105x_pinmux.h for these GPIO_SD_* pins definition:

#define GPIO_USDHC1_CMD_1 (GPIO_PERIPH | GPIO_ALT0 | GPIO_PADMUX(IMXRT_PADMUX_GPIO_SD_B0_00_INDEX))
#define GPIO_USDHC1_CLK_1 (GPIO_PERIPH | GPIO_ALT0 | GPIO_PADMUX(IMXRT_PADMUX_GPIO_SD_B0_01_INDEX))
#define GPIO_USDHC1_DATA0_1 (GPIO_PERIPH | GPIO_ALT0 | GPIO_PADMUX(IMXRT_PADMUX_GPIO_SD_B0_02_INDEX))
#define GPIO_USDHC1_DATA1_1 (GPIO_PERIPH | GPIO_ALT0 | GPIO_PADMUX(IMXRT_PADMUX_GPIO_SD_B0_03_INDEX))
#define GPIO_USDHC1_DATA2_1 (GPIO_PERIPH | GPIO_ALT0 | GPIO_PADMUX(IMXRT_PADMUX_GPIO_SD_B0_04_INDEX))
#define GPIO_USDHC1_DATA3_1 (GPIO_PERIPH | GPIO_ALT0 | GPIO_PADMUX(IMXRT_PADMUX_GPIO_SD_B0_05_INDEX))
#define GPIO_GPIO2_IO28_1 (GPIO_PERIPH | GPIO_ALT5 | GPIO_PADMUX(IMXRT_PADMUX_GPIO_B1_12_INDEX))

So, we need to include the missing SD1 pins pointing to these defines names at boards/arm/imxrt/imxrt1050-evk/include/board.h this way:

/* MMC/SD SD1 */

#define PIN_USDHC1_DCLK GPIO_USDHC1_CLK_1
#define PIN_USDHC1_CMD GPIO_USDHC1_CMD_1
#define PIN_USDHC1_D0 GPIO_USDHC1_DATA0_1

Ok, after defining these pins the compilation finished correctly. But the fact of the USDHC driver is only failing because DATA0 rings a bell! Probably it is using SD Card with 1-bit interface, we need to enable 4-bits interface:

$ make menuconfig

System Type ->
USDHC Configuration ->
Bus width for USDHC1 (Four bit)

Perfect, now the compilation is failing, this is exactly what I was waiting for:

CC: chip/imxrt_usdhc.c
In file included from chip/imxrt_usdhc.c:60:
chip/imxrt_usdhc.c: In function 'imxrt_usdhc_initialize':
chip/imxrt_usdhc.c:3138:25: error: 'GPIO_USDHC1_DATA1' undeclared (first use in this function); did you mean 'GPIO_USDHC1_DATA2_1'?
3138 | imxrt_config_gpio(PIN_USDHC1_D1);
| ^
chip/imxrt_usdhc.c:3138:25: note: each undeclared identifier is reported only once for each function it appears in
chip/imxrt_usdhc.c:3139:25: error: 'GPIO_USDHC1_DATA2' undeclared (first use in this function); did you mean 'GPIO_USDHC1_DATA2_1'?
3139 | imxrt_config_gpio(PIN_USDHC1_D2);
| ^
chip/imxrt_usdhc.c:3140:25: error: 'GPIO_USDHC1_DATA3' undeclared (first use in this function); did you mean 'GPIO_USDHC1_DATA3_1'?
3140 | imxrt_config_gpio(PIN_USDHC1_D3);
| ^
make[1]: *** [Makefile:151: imxrt_usdhc.o] Error 1
make[1]: Leaving directory '/comum/workspace/Consultancy/iDTech/NuttX/nuttx/arch/arm/src'
make: *** [tools/LibTargets.mk:155: arch/arm/src/libarch.a] Error 2

You already know what to do, right? Just insert all the pins to board.h :

/* MMC/SD */

#define PIN_USDHC1_DCLK GPIO_USDHC1_CLK_1
#define PIN_USDHC1_CMD GPIO_USDHC1_CMD_1
#define PIN_USDHC1_D0 GPIO_USDHC1_DATA0_1
#define PIN_USDHC1_D1 GPIO_USDHC1_DATA1_1
#define PIN_USDHC1_D2 GPIO_USDHC1_DATA2_1
#define PIN_USDHC1_D3 GPIO_USDHC1_DATA3_1

Excellent! Now it is compiling with 4-bit SDCard interface.

But wait! What about the SDCard insertion pin (SD_CD_SW)? If you look at arch/arm/src/imxrt/imxrt_usdhc.c you will see that it is waiting for a pin named PIN_USDHC1_CD_GPIO, so let to declare it pointing to our pin:

#define PIN_USDHC1_CD_GPIO (IOMUX_VSD_DEFAULT | \
        GPIO_PORT2 | GPIO_PIN28)

With everything in place, compile, flash, put a SDCard in the board’s slot and Voilà:

NuttShell (NSH) NuttX-9.1.0

nsh> uname -a
NuttX 9.1.0 74c16e8d6d-dirty Aug 9 2020 12:58:00 arm imxrt1050-evk

nsh> ls /dev
/dev:
 console
 mmcsd0
 null
 numdisp0
 ttyS0

nsh> mount -t vfat /dev/mmcsd0 /mnt

nsh> ls /mnt
/mnt:
LOST.DIR/
Android/
.android_secure/
nsh>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s