SD driver using SPI interface for i.mx rt 1050

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

SD driver using SPI interface for i.mx rt 1050

1,730 Views
rreddy1
Contributor I

Hi,

I want to use SPI as an interface instead of USDHC for SD card in i.mx rt1050 evk. The existing sdk example uses sdmmc with usdhc interface. Can anyone guide on how to add spi as sdmmc interface in mcuexpresso.

Thank you

Labels (1)
0 Kudos
Reply
3 Replies

1,697 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello, 

Unfortunately, we don't have any official document or example project that demonstrates how to interface an SD card through LPSPI with the RT. However, you might use as a starting point the following community document that explains how to do this with a Kinetis MCU. 

https://community.nxp.com/t5/Kinetis-Microcontrollers/Porting-FatFs-file-system-to-KL26-SPI-SD-card-...

 

Regards, 

Victor

0 Kudos
Reply

1,692 Views
mjbcswitzerland
Specialist V

Hi

Beware that the KL26 has a different SPI to the one in the i.MX RT which means that the path would be to take the reference and ensure that it works correcty in the KL26. Then port the project to a different Kinetis part which has a compatible SPI. Then finally port to the i.MX RT.

Professionals requiring immediate proven solutions also have the possibility to use the uTasker project which supports SPI/LPSPI and SDHC on all Kinetis and i.MX RT parts without any further time investment.

Regards

Mark

 

0 Kudos
Reply

1,716 Views
mjbcswitzerland
Specialist V

Hi

The uTasker project supports utFAT on LPSPI of the i.MX RT 1050 (see simulation below where the SD card has been located on LPSPI1 - on 1060 but otherwise compatible).

Another possibility is to take a KL28 example since it has the same LPSPI interface as the i.MX RT uses. utFAT on KL28 is also available in the open source project version at https://github.com/uTasker/uTasker-Kinetis which works on i.MX RT without much porting effort. Below is the interface definition for the i.MX RT reference that would work with that version.

 

        // Configure to suit SD card SPI mode at between 100k and 400k - use LPSPI0
        //
        #define SPI_CS1_0               PIN_GPIO_SD_B0_01_GPIO3_IO13
        #define INITIALISE_SPI_SD_INTERFACE() _CONFIG_DRIVE_PORT_OUTPUT_VALUE(3, (SPI_CS1_0), (SPI_CS1_0), (PORT_SRE_FAST | PORT_DSE_MID)); \
                                        IOMUXC_LPSPI1_SCK_SELECT_INPUT = IOMUXC_LPSPI1_SCK_SELECT_INPUT_GPIO_SD_B0_00_ALT4; \
                                        IOMUXC_LPSPI1_SDI_SELECT_INPUT = IOMUXC_LPSPI1_SDI_SELECT_INPUT_GPIO_SD_B0_03_ALT4; \
                                        IOMUXC_LPSPI1_SDO_SELECT_INPUT = IOMUXC_LPSPI1_SDO_SELECT_INPUT_GPIO_SD_B0_02_ALT4; \
                                        _CONFIG_PERIPHERAL(GPIO_SD_B0_00, LPSPI1_SCK, (IOMUXC_SW_PAD_CTL_PAD_PKE | IOMUXC_SW_PAD_CTL_PAD_SPEED_MEDIUM | IOMUXC_SW_PAD_CTL_PAD_DSE_6)); \
                                        _CONFIG_PERIPHERAL(GPIO_SD_B0_02, LPSPI1_SDO, (IOMUXC_SW_PAD_CTL_PAD_PKE | IOMUXC_SW_PAD_CTL_PAD_SPEED_MEDIUM | IOMUXC_SW_PAD_CTL_PAD_DSE_6)); \
                                        _CONFIG_PERIPHERAL(GPIO_SD_B0_03, LPSPI1_SDI, (IOMUXC_SW_PAD_CTL_PAD_PKE | IOMUXC_SW_PAD_CTL_PAD_SPEED_MEDIUM | IOMUXC_SW_PAD_CTL_PAD_DSE_6)); \
                                        LPSPI1_CR = 0; \
                                        LPSPI_MASTER_CLOCK_SETTING(1, 32, 8, 8, 8); \
                                        LPSPI1_CFGR1 = (LPSPI_CFGR1_MASTER); \
                                        LPSPI1_CR = (LPSPI_CR_MEN); \
                                        LPSPI1_CR = (LPSPI_CR_RRF | LPSPI_CR_RTF | LPSPI_CR_MEN | LPSPI_CR_DBGEN); \
                                        LPSPI1_TCR = (LPSPI_TCR_CPHA | LPSPI_TCR_CPOL | LPSPI_TCR_PRESCALE_128 | LPSPI_TCR_MSBF | (8 - 1)); \
                                        LPSPI1_CR = (LPSPI_CR_MEN | LPSPI_CR_DBGEN)

        #define ENABLE_SPI_SD_OPERATION()
        #define SET_SD_CARD_MODE()

        // Set maximum speed
        //
        #define SET_SPI_SD_INTERFACE_FULL_SPEED()  LPSPI1_TCR = (LPSPI_TCR_CPHA | LPSPI_TCR_CPOL | LPSPI_TCR_PRESCALE_1 | (8 - 1))
        #if defined _WINDOWS
            #define WRITE_SPI_CMD(byte)    LPSPI1_TDR = (byte); LPSPI1_RDR = _fnSimSD_write((unsigned char)byte)
        #else
            #define WRITE_SPI_CMD(byte)    LPSPI1_TDR = (byte)
        #endif
        #define WAIT_TRANSMISSON_END() _WAIT_REGISTER_TRUE(LPSPI1_RSR, LPSPI_RSR_RXEMPTY)
        #define READ_SPI_DATA()        (unsigned char)LPSPI1_RDR

        #define SET_SD_DI_CS_HIGH()    _SETBITS(3, SPI_CS1_0)            // force DI and CS lines high ready for the initialisation sequence
        #define SET_SD_CS_LOW()        _CLEARBITS(3, SPI_CS1_0)          // assert the CS line of the SD card to be read
        #define SET_SD_CS_HIGH()       _SETBITS(3, SPI_CS1_0)            // negate the CS line of the SD card to be read
        #define POWER_UP_SD_CARD()                                       // apply power to the SD card if appropriate


        #define POWER_DOWN_SD_CARD()                                     // remove power from SD card interface
        #define GET_SDCARD_WP_STATE() 0                                  // no write protect switch available
        #define SDCARD_DETECTION()    0                                  // card detection input not present

 

 

mjbcswitzerland_0-1603838519706.png

 

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or product development requirements

 

0 Kudos
Reply