Issue with SD-Card Communication through SPI Interface on IMX8QM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issue with SD-Card Communication through SPI Interface on IMX8QM

1,512 Views
sujith_sajeev
Contributor II

Hi ,

I am currently working on the i.MX8QM MEK with Yocto kernel version 5.15.52. I am attempting to establish communication with an external SD card through the SPI interface. The SD card is connected via a micro-SD card (SPI) adapter to the SPI ports available on the Microbus headers (J29) on the baseboard.

To utilize the mmc-spi driver instead of spidev, I have modified the lpspi2 device node in the imx8qm-mek.dts file as follows:

&lpspi2 {
#address-cells = <1>;
#size-cells = <0>;
fsl,spi-num-chipselects = <1>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_lpspi2 &pinctrl_lpspi2_cs>;
cs-gpios = <&lsio_gpio3 10 GPIO_ACTIVE_LOW>;
status = "okay";

mmc-slot@0 {
compatible = "fsl,mpc8323rdb-mmc-slot", "mmc-spi-slot";
reg = <0>;
voltage-ranges = <3300 3300>;
spi-max-frequency = <30000000>;
};
};

The issue I am facing is that the obtained OCR (Operating Condition Register) value is 0x00, which appears to be invalid. Consequently, the initialization of the SD card fails, and it does not proceed to the block driver stage (i.e., no block device is formed).

Has anyone encountered a similar issue? I would greatly appreciate any insights or solutions to resolve this problem.

Thanks and Regards ,
Sujith Sajeev

 

0 Kudos
Reply
5 Replies

1,476 Views
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @sujith_sajeev 

 

Could you please share the pinctrl of your device tree?

Also, could you please confirm that the SD works with spidev?

 

Best regards,

--... ...--

Salas.

0 Kudos
Reply

1,446 Views
sujith_sajeev
Contributor II
Hi @Manuel_Salas 

Sorry for late response
 
1. Below is the pinctrl configuration from our device tree:
 
pinctrl_lpspi2: lpspi2grp {
 
fsl,pins = <
IMX8QM_SPI2_SCK_DMA_SPI2_SCK 0x06000040
IMX8QM_SPI2_SDO_DMA_SPI2_SDO 0x06000040
IMX8QM_SPI2_SDI_DMA_SPI2_SDI 0x06000040
>;
};
 
pinctrl_lpspi2_cs: lpspi2cs {
 
fsl,pins = <
IMX8QM_SPI2_CS0_LSIO_GPIO3_IO10 0x21
>;
 
};
 
2. I tested the SD card functionality using the spidev driver by changing the compatible property as shown below. During the write and read operations, 
the data is written successfully, but no data is returned during the read operation.
 
 
&lpspi2 {
#address-cells = <1>;
#size-cells = <0>;
fsl,spi-num-chipselects = <1>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_lpspi2 &pinctrl_lpspi2_cs>;
cs-gpios = <&lsio_gpio3 10 GPIO_ACTIVE_LOW>;
status = "okay";
 
mmc-slot@0 {
compatible = "rohm,dh2228fv";
  reg = <0>;
voltage-ranges = <3300 3300>;
  spi-max-frequency = <400000>;
};
};
 
 
Despite successful data writing, the read operation returns no data.
Is this what you expected to be confirmed? If not, could you please provide 
guidance on how to properly test the SD card using spidev?
 
Any insights on this issue would be greatly appreciated.
 
Thanks & Regards,
Sujith Sajeev
 
 
0 Kudos
Reply

1,374 Views
sujith_sajeev
Contributor II

Hi @Manuel_Salas 
Can you please provide your suggestions on this matter ?

Also , I tried to communicate with the SD using the sd-spi-communication library (using spidev driver). It was also unsuccessful since the initialization of SD card failed. It was seen that an undersized response was received for CMD0 during initialization (0x00 was received instead of 0x01). The github link of sd-spi-communication library is https://github.com/wpenson/sd-spi-communications-library.git

Please provide your suggestions on this matter. Your insight on this matter would be really helpful

Thanks and Regards 
Sujith Sajeev

0 Kudos
Reply

1,326 Views
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @sujith_sajeev 

I hope you are doing well.

I have not a i.MX8QM to test by my side, but I tested with other i.MX with the same environment as you and I could integrate the mmc-spi driver without any issue. 

Could you please share the logs related to the mmc spi driver on linux?

Also, about of sd-spi-communication library, I am not sure if it is totally compatible with an SD, because some commands differs a little from commands that you can find on reference manual.

Best regards,

Salas.

0 Kudos
Reply

1,317 Views
sujith_sajeev
Contributor II

Hi @Manuel_Salas ,

Thank you for your response.

I have successfully integrated the mmc_spi driver into my Yocto build (kernel version 5.15.52) without encountering any errors. I have also modified the lpspi2 node in the imx8qm-mek.dts file to use the mmc_spi driver instead of the spidev driver. This modification was made to facilitate communication with an SD card using a SPI interface SD card adapter module connected to the SPI ports (pins 3-8) on the J29 Mikrobus headers of the Baseboard. The edited lpspi2 node is as follows:

&lpspi2 {
    #address-cells = <1>;
    #size-cells = <0>;
    fsl,spi-num-chipselects = <1>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_lpspi2 &pinctrl_lpspi2_cs>;
    cs-gpios = <&lsio_gpio3 10 GPIO_ACTIVE_LOW>;
    status = "okay";

    mmc-slot@0 {
        compatible = "fsl,mpc8323rdb-mmc-slot", "mmc-spi-slot";
        reg = <0>;
        voltage-ranges = <3300 3300>;
        spi-max-frequency = <30000000>;
    };
};

The driver initialization appears to be successful, as evidenced by the following output:

root@imx8qmmek:/sys/bus/spi/devices/spi0.0# cat modalias 
spi:mpc8323rdb-mmc-slot
root@imx8qmmek:/sys/bus/spi/devices/spi0.0# cat uevent 
DRIVER=mmc_spi
OF_NAME=mmc-slot
OF_FULLNAME=/bus@5a000000/spi@5a020000/mmc-slot@0
OF_COMPATIBLE_0=fsl,mpc8323rdb-mmc-slot
OF_COMPATIBLE_1=mmc-spi-slot
OF_COMPATIBLE_N=2
MODALIAS=spi:mpc8323rdb-mmc-slot

However, the block device for the SD card is not created, which prevents me from communicating with the SD card. Given that the driver is operational but the block device is not being created, I am seeking your advice on potential resolutions for this issue.

For additional context, here is the output from mmc3:

root@imx8qmmek:/sys/kernel/debug/mmc3# cat ios
clock:        0 Hz
vdd:          0 (invalid)
bus mode:     2 (push-pull)
chip select:  1 (active high)
power mode:   0 (off)
bus width:    0 (1 bits)
timing spec:  0 (legacy)
signal voltage: 0 (3.30 V)
driver type:  0 (driver type B)

Your insights on this matter would be greatly appreciated.

Thank you and regards,
Sujith Sajeev

0 Kudos
Reply