Zephyr SD card returns "Card never left busy state"

Using the zephyr RTOS I currently want to acces filesystem on a SD card. I wired it correctly and used this example to getting started: https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/subsys/fs/fs_sample

The log returns follwowing error:

[00:00:03.463,989] <inf> sd: Detected SD card
[00:00:05.601,104] <err> sd: Card never left busy state
[00:00:05.601,135] <err> sd: Card init failed
[00:00:05.601,165] <err> main: Storage init ERROR!

Hence, I wired my Logic to get some more details

.

There is definitely some communication, but not as described here: http://elm-chan.org/docs/mmc/mmc_e.html.

Here are the first commands:

name type start_time duration mosi miso

SPI result 1.0015495 3.05e-05 0x40 0xFF

SPI result 1.00158175 3.05e-05 0x00 0xFF

SPI result 1.001614 3.05e-05 0x00 0xFF

SPI result 1.00164625 3.075e-05 0x00 0xFF

SPI result 1.00167875 3.05e-05 0x00 0xFF

SPI result 1.001711 3.05e-05 0x95 0xFF

SPI result 1.0017435 3.05e-05 0xFF 0xFF

SPI result 1.00177575 3.05e-05 0xFF 0x01

SPI result 1.001808 3.05e-05 0xFF 0xFF

SPI result 1.00184025 3.075e-05 0xFF 0xFF

SPI result 1.00187275 3.05e-05 0xFF 0xFF

SPI result 1.001905 3.05e-05 0xFF 0xFF

SPI result 1.00193725 3.05e-05 0xFF 0xFF

SPI result 1.0019695 3.05e-05 0xFF 0xFF

SPI result 1.00200175 3.075e-05 0xFF 0xFF

SPI result 1.00203425 3.05e-05 0xFF 0xFF

SPI result 1.0020665 3.05e-05 0xFF 0xFF

SPI result 1.00209875 3.05e-05 0xFF 0xFF

SPI result 1.00213125 3.05e-05 0xFF 0xFF

SPI result 1.0021635 3.05e-05 0xFF 0xFF

I doubt that the correct frequency is not set properly. But cannot figure out, where it should be.

I formatted the SD card to FAT many time. Always getting the same result.

Parents
  • Hi

    Are you using SPI or QSPI for communication here? The frequency should be set in SPI or QSPI section of your .dts (device tree) file in something like the following:

    &qspi {
    	status = "okay";
    	pinctrl-0 = <&qspi_default>;
    	pinctrl-1 = <&qspi_sleep>;
    	pinctrl-names = "default", "sleep";
    	mx25r64: mx25r6435f@0 {
    		compatible = "nordic,qspi-nor";
    		reg = <0>;
    		/* MX25R64 supports only pp and pp4io */
    		writeoc = "pp4io";
    		/* MX25R64 supports all readoc options */
    		readoc = "read4io";
    		sck-frequency = <8000000>;
    		};
    	};

    What SDK version are you using for development of your application, and what GPIOs on the nRF52840 are you using for connecting to the SD card?

    Best regards,

    Simon

Reply
  • Hi

    Are you using SPI or QSPI for communication here? The frequency should be set in SPI or QSPI section of your .dts (device tree) file in something like the following:

    &qspi {
    	status = "okay";
    	pinctrl-0 = <&qspi_default>;
    	pinctrl-1 = <&qspi_sleep>;
    	pinctrl-names = "default", "sleep";
    	mx25r64: mx25r6435f@0 {
    		compatible = "nordic,qspi-nor";
    		reg = <0>;
    		/* MX25R64 supports only pp and pp4io */
    		writeoc = "pp4io";
    		/* MX25R64 supports all readoc options */
    		readoc = "read4io";
    		sck-frequency = <8000000>;
    		};
    	};

    What SDK version are you using for development of your application, and what GPIOs on the nRF52840 are you using for connecting to the SD card?

    Best regards,

    Simon

Children
  • I use SPI, is the frquency wrong in this case?

    &spi1 {
        status = "okay";
        cs-gpios = <&gpio0 3  GPIO_ACTIVE_LOW>;
    
        sdhc0: sdhc@0 {
                compatible = "zephyr,sdhc-spi-slot";
                reg = <0>;
                status = "okay";
                mmc {
                    compatible = "zephyr,sdmmc-disk";
                    status = "okay";
                };
                spi-max-frequency = <24000000>;
        };
    };

    SDK v2.3.0

    MISO: P1.08

    SCK: P0.31

    MOSI: P0.30

  • I attached the opensource sigrok to get more information. These are the SD card commands exchange between the host and the card:

    3105403-3105500 SD card (SPI mode): Commands/replies: CMD0 (GO_IDLE_STATE): Reset the SD card
    3105517-3105533 SD card (SPI mode): Commands/replies: R1: 0x01
    3105773-3105870 SD card (SPI mode): Commands/replies: CMD8: 48 00 00 01 aa 87
    3105886-3105902 SD card (SPI mode): Commands/replies: R1: 0x01
    3106143-3106240 SD card (SPI mode): Commands/replies: CMD59 (CRC_ON_OFF): Turn the SD card CRC option on
    3106256-3106273 SD card (SPI mode): Commands/replies: R1: 0x01
    3106513-3106610 SD card (SPI mode): Commands/replies: CMD5: 45 00 00 00 00 5b
    3106626-3106642 SD card (SPI mode): Commands/replies: R1: 0x05
    3106895-3106994 SD card (SPI mode): Commands/replies: CMD0 (GO_IDLE_STATE): Reset the SD card
    3107009-3107025 SD card (SPI mode): Commands/replies: R1: 0x01
    3107265-3107362 SD card (SPI mode): Commands/replies: CMD8: 48 00 00 01 aa 87
    3107378-3107395 SD card (SPI mode): Commands/replies: R1: 0x01
    3107636-3107733 SD card (SPI mode): Commands/replies: CMD59 (CRC_ON_OFF): Turn the SD card CRC option on
    3107749-3107765 SD card (SPI mode): Commands/replies: R1: 0x01
    3108004-3108101 SD card (SPI mode): Commands/replies: CMD58: 7a 00 00 00 00 fd
    3108117-3108133 SD card (SPI mode): Commands/replies: R1: 0x01
    3108374-3108471 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3108488-3108504 SD card (SPI mode): Commands/replies: R1: 0x01
    3108743-3108840 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3108856-3108872 SD card (SPI mode): Commands/replies: R1: 0x01
    3114147-3114244 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3114260-3114276 SD card (SPI mode): Commands/replies: R1: 0x01
    3114515-3114612 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3114628-3114644 SD card (SPI mode): Commands/replies: R1: 0x01
    3119929-3120026 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3120042-3120058 SD card (SPI mode): Commands/replies: R1: 0x01
    3120297-3120394 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3120410-3120426 SD card (SPI mode): Commands/replies: R1: 0x01
    3125712-3125809 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3125825-3125841 SD card (SPI mode): Commands/replies: R1: 0x01
    3126080-3126177 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3126193-3126209 SD card (SPI mode): Commands/replies: R1: 0x01
    3131495-3131592 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3131608-3131624 SD card (SPI mode): Commands/replies: R1: 0x01
    3131863-3131960 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3131976-3131992 SD card (SPI mode): Commands/replies: R1: 0x01
    3137278-3137375 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3137391-3137407 SD card (SPI mode): Commands/replies: R1: 0x01
    3137645-3137742 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3137759-3137775 SD card (SPI mode): Commands/replies: R1: 0x01
    3143060-3143157 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3143174-3143190 SD card (SPI mode): Commands/replies: R1: 0x01
    3143428-3143525 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3143542-3143558 SD card (SPI mode): Commands/replies: R1: 0x01
    3148843-3148940 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3148956-3148973 SD card (SPI mode): Commands/replies: R1: 0x01
    3149211-3149308 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3149325-3149341 SD card (SPI mode): Commands/replies: R1: 0x01
    3154626-3154723 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3154739-3154755 SD card (SPI mode): Commands/replies: R1: 0x01
    3154994-3155091 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3155107-3155123 SD card (SPI mode): Commands/replies: R1: 0x01
    3160409-3160506 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3160522-3160538 SD card (SPI mode): Commands/replies: R1: 0x01
    3160777-3160874 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3160890-3160906 SD card (SPI mode): Commands/replies: R1: 0x01
    3166192-3166289 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3166305-3166321 SD card (SPI mode): Commands/replies: R1: 0x01
    3166560-3166657 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3166673-3166689 SD card (SPI mode): Commands/replies: R1: 0x01
    3171975-3172072 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3172088-3172104 SD card (SPI mode): Commands/replies: R1: 0x01
    3172343-3172440 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3172456-3172472 SD card (SPI mode): Commands/replies: R1: 0x01
    3177757-3177854 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3177871-3177887 SD card (SPI mode): Commands/replies: R1: 0x01
    3178126-3178223 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3178239-3178255 SD card (SPI mode): Commands/replies: R1: 0x01
    3183540-3183637 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3183653-3183670 SD card (SPI mode): Commands/replies: R1: 0x01
    3183908-3184005 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3184022-3184038 SD card (SPI mode): Commands/replies: R1: 0x01
    3189323-3189420 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3189436-3189452 SD card (SPI mode): Commands/replies: R1: 0x01
    3189691-3189788 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3189804-3189821 SD card (SPI mode): Commands/replies: R1: 0x01
    3195106-3195203 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3195219-3195235 SD card (SPI mode): Commands/replies: R1: 0x01
    3195474-3195571 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3195587-3195603 SD card (SPI mode): Commands/replies: R1: 0x01
    3200889-3200986 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3201002-3201018 SD card (SPI mode): Commands/replies: R1: 0x01
    3201257-3201354 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3201370-3201386 SD card (SPI mode): Commands/replies: R1: 0x01
    3206671-3206768 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3206785-3206801 SD card (SPI mode): Commands/replies: R1: 0x01
    3207040-3207137 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3207153-3207169 SD card (SPI mode): Commands/replies: R1: 0x01
    3212454-3212551 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3212568-3212584 SD card (SPI mode): Commands/replies: R1: 0x01
    3212823-3212920 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3212936-3212952 SD card (SPI mode): Commands/replies: R1: 0x01
    3218237-3218334 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3218350-3218366 SD card (SPI mode): Commands/replies: R1: 0x01
    3218605-3218702 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3218718-3218734 SD card (SPI mode): Commands/replies: R1: 0x01
    3224020-3224117 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3224133-3224149 SD card (SPI mode): Commands/replies: R1: 0x01
    3224388-3224485 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3224502-3224518 SD card (SPI mode): Commands/replies: R1: 0x01
    3229803-3229900 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3229916-3229932 SD card (SPI mode): Commands/replies: R1: 0x01
    3230171-3230268 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3230284-3230300 SD card (SPI mode): Commands/replies: R1: 0x01
    3235585-3235682 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3235699-3235715 SD card (SPI mode): Commands/replies: R1: 0x01
    3235954-3236051 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3236067-3236083 SD card (SPI mode): Commands/replies: R1: 0x01
    3241368-3241465 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3241482-3241498 SD card (SPI mode): Commands/replies: R1: 0x01
    3241737-3241834 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3241850-3241866 SD card (SPI mode): Commands/replies: R1: 0x01
    3247151-3247248 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3247264-3247280 SD card (SPI mode): Commands/replies: R1: 0x01
    3247519-3247616 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3247632-3247648 SD card (SPI mode): Commands/replies: R1: 0x01
    3252934-3253031 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3253047-3253063 SD card (SPI mode): Commands/replies: R1: 0x01
    3253302-3253399 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3253415-3253431 SD card (SPI mode): Commands/replies: R1: 0x01
    3258717-3258814 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3258830-3258846 SD card (SPI mode): Commands/replies: R1: 0x01
    3259085-3259182 SD card (SPI mode): Commands/replies: ACMD41 (SD_SEND_OP_COND): Send HCS info and activate the card init process
    3259198-3259214 SD card (SPI mode): Commands/replies: R1: 0x01
    3264500-3264597 SD card (SPI mode): Commands/replies: CMD55 (APP_CMD): Next command is an application-specific command
    3530441-3530457 SD card (SPI mode): Commands/replies: R1: 0x00
    

    It seems to get stuck between command 55 and 41 and does not follow the initialization steps: http://chlazza.nfshost.com/imgs/SDcardInitFlowchart_3.01.png

    The code stuck in function disk_access_ioctl

  • Can you please try to see if you see the same issue with lower qspi frequency? It seems that at that high speed there is some deadlock inside the driver trying to take a mutex.

  • How do I connect qspi to an sd card? I do not find a tutorial from zephyr.

  • Do you have an example project using qspi for SD card?

Related