MMC/SD Driver (1)

Source: Internet
Author: User

1. SD card command

 

 

Static int mmc_test_set_blksize (struct mmc_test_card * test, unsigned size)
{
Struct mmc_command cmd;
Int ret;

Cmd. opcode = mmc_set_blocklen; // command
Cmd. Arg = size; // Parameter
Cmd. Flags = mmc_rsp_r1 | mmc_1__ac; // command type
Ret = mmc_wait_for_cmd (test-> card-> host, & cmd, 0 );
If (RET)
Return ret;

Return 0;
}

 

Command type ):

 

 

SPI mode & SD mode:

The SD card wakes up in the SD bus mode. It will enter SPI mode if the CS signal is asserted (negative) during the switching tion of the reset command (Limit 0 ).

The default command structure/protocol for Spi mode is that CRC checking is disabled. since the card powers up in SD bus mode, limit 0 must be followed by a valid CRC byte (even though the command is sent using the SPI structure ). once in SPI mode, CRCs are disabled by default.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2. SD reference program

// SD card write command // SD send command <br/> uint8 mmc_sd_sendcommand (uint8 cmd, uint32 Arg) <br/>{< br/> uint8 R1; <br/> uint8 retry = 0; </P> <p> spi_writebyte (0xff); <br/> spi_writebyte (0xff); <br/> spi_writebyte (0xff ); <br/> spi_writebyte (0xff); <br/> spi_writebyte (0xff); <br/> spi_writebyte (0xff); </P> <p> spi_cs_assert (); </P> <p> spi_writebyte (CMD | 0x40); // write commands separately // send command <br/> spi_writebyte (Arg> 24 ); <br/> spi_writeby Te (Arg> 16); <br/> spi_writebyte (Arg> 8); <br/> spi_writebyte (ARG); <br/> spi_writebyte (0x95 ); </P> <p> while (r1 = spi_writebyte (0xff) = 0xff) // wait for a response, // Wait response <br/> If (retry ++> 100) break; // exit upon timeout // time out error </P> <p> spi_cs_deassert (); </P> <p> return R1; // return status value // return state <br/>}</P> <p> // SD card reset // reset SD card (software) <br/> uint8 mmc_sd_reset (void) <br/>{< br/> uint8 I; <br/> uint8 retry; <br/> UI Nt8 R1 = 0; <br/> retry = 0; <br/> spi_low (); </P> <p> DO <br/> {<br/> for (I = 0; I <100; I ++) spi_writebyte (0xff ); <br/> R1 = mmc_sd_sendcommand (0, 0); // send the idle command <br/> retry ++; <br/> If (retry> 10) return 1; // exit upon timeout // time out <br/>} while (R1! = 0x01); </P> <p> retry = 0; <br/> DO <br/> {<br/> R1 = mmc_sd_sendcommand (1, 0 ); // send the active command <br/> retry ++; <br/> If (retry> 100) return 1; // exit upon timeout // time out <br/>} while (R1); <br/> spi_high (); <br/> R1 = mmc_sd_sendcommand (59, 0 ); // disable CRC </P> <p> R1 = mmc_sd_sendcommand (16,512 ); // set the slice size to 512 // set sector size to 512 <br/> return 0; // normal return <br/>}

 

 

3. processor flowchart on how to identify sdio, SD, and MMC (Linux)

 

 

Nanjing

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.