MDD_SDSPI_MediaInitialize Function

MDD File System Interface Library

MDDFS Interface Library Help
MDD_SDSPI_MediaInitialize Function
C
MEDIA_INFORMATION * MDD_SDSPI_MediaInitialize();
Description

This function will send initialization commands to and SD card.

Preconditions

The MDD_MediaInitialize function pointer must be pointing to this function.

Return Values
Return Values 
Description 
errorCode member may contain the following values 
  • MEDIA_NO_ERROR - The media initialized successfully
  • MEDIA_CANNOT_INITIALIZE - Cannot initialize the media.
 
Side Effects

None.

Remarks

Psuedo code flow for the media initialization process is as follows: 

 

-----------------------------------------------------------------------------------------

SD Card SPI Initialization Sequence (for physical layer v1.x or v2.0 device) is as follows:

-----------------------------------------------------------------------------------------

  1. Power up tasks a. Initialize microcontroller SPI module to no more than 400kbps rate so as to support MMC devices. b. Add delay for SD card power up, prior to sending it any commands. It wants the longer of: 1ms, the Vdd ramp time (time from 2.7V to Vdd stable), and 74+ clock pulses.
  2. Send CMD0 (GO_IDLE_STATE) with CS = 0. This puts the media in SPI mode and software resets the SD/MMC card.
  3. Send CMD8 (SEND_IF_COND). This requests what voltage the card wants to run at.  

Some cards will not support this command. a. If illegal command response is received, this implies either a v1.x physical spec device, or not an SD card (ex: MMC). b. If normal response is received, then it must be a v2.0 or later SD memory card.  

If v1.x device:

---------------

  1. Send CMD1 repeatedly, until initialization complete (indicated by R1 response byte/idle bit == 0)
  2. Basic initialization is complete. May now switch to higher SPI frequencies.
  3. Send CMD9 to read the CSD structure. This will tell us the total flash size and other info which will be useful later.
  4. Parse CSD structure bits (based on v1.x structure format) and extract useful information about the media.
  5. The card is now ready to perform application data transfers.
 

If v2.0+ device:

---------------

  1. Verify the voltage range is feasible. If not, unusable card, should notify user that the card is incompatible with this host.
  2. Send CMD58 (Read OCR).
  3. Send CMD55, then ACMD41 (SD_SEND_OP_COND, with HCS = 1). a. Loop CMD55/ACMD41 until R1 response byte == 0x00 (indicating the card is no longer busy/no longer in idle state).
  4. Send CMD58 (Get CCS). a. If CCS = 1 --> SDHC card. b. If CCS = 0 --> Standard capacity SD card (which is v2.0+).
  5. Basic initialization is complete. May now switch to higher SPI frequencies.
  6. Send CMD9 to read the CSD structure. This will tell us the total flash size and other info which will be useful later.
  7. Parse CSD structure bits (based on v2.0 structure format) and extract useful information about the media.
  8. The card is now ready to perform application data transfers.

Microchip MDD File System Interface 1.4.2 - [Oct 15, 2012]
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.