stm32_eval_sdio_sd.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32_eval_sdio_sd.h
00004   * @author  MCD Application Team
00005   * @version V4.3.0
00006   * @date    10/15/2010
00007   * @brief   This file contains all the functions prototypes for the SD Card 
00008   *          stm32_eval_sdio_sd driver firmware library.
00009   ******************************************************************************
00010   * @copy
00011   *
00012   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00013   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00014   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00015   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00016   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00017   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00018   *
00019   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00020   */ 
00021 
00022 /* Define to prevent recursive inclusion -------------------------------------*/
00023 #ifndef __STM32_EVAL_SDIO_SD_H
00024 #define __STM32_EVAL_SDIO_SD_H
00025 
00026 #ifdef __cplusplus
00027  extern "C" {
00028 #endif
00029 
00030 /* Includes ------------------------------------------------------------------*/
00031 #include "stm32_eval.h"
00032 
00033 /** @addtogroup Utilities
00034   * @{
00035   */
00036   
00037 /** @addtogroup STM32_EVAL
00038   * @{
00039   */ 
00040 
00041 /** @addtogroup Common
00042   * @{
00043   */
00044   
00045 /** @addtogroup STM32_EVAL_SDIO_SD
00046   * @{
00047   */  
00048 
00049 /** @defgroup STM32_EVAL_SDIO_SD_Exported_Types
00050   * @{
00051   */ 
00052 typedef enum
00053 {
00054 /** 
00055   * @brief  SDIO specific error defines  
00056   */   
00057   SD_CMD_CRC_FAIL                    = (1), /*!< Command response received (but CRC check failed) */
00058   SD_DATA_CRC_FAIL                   = (2), /*!< Data bock sent/received (CRC check Failed) */
00059   SD_CMD_RSP_TIMEOUT                 = (3), /*!< Command response timeout */
00060   SD_DATA_TIMEOUT                    = (4), /*!< Data time out */
00061   SD_TX_UNDERRUN                     = (5), /*!< Transmit FIFO under-run */
00062   SD_RX_OVERRUN                      = (6), /*!< Receive FIFO over-run */
00063   SD_START_BIT_ERR                   = (7), /*!< Start bit not detected on all data signals in widE bus mode */
00064   SD_CMD_OUT_OF_RANGE                = (8), /*!< CMD's argument was out of range.*/
00065   SD_ADDR_MISALIGNED                 = (9), /*!< Misaligned address */
00066   SD_BLOCK_LEN_ERR                   = (10), /*!< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length */
00067   SD_ERASE_SEQ_ERR                   = (11), /*!< An error in the sequence of erase command occurs.*/
00068   SD_BAD_ERASE_PARAM                 = (12), /*!< An Invalid selection for erase groups */
00069   SD_WRITE_PROT_VIOLATION            = (13), /*!< Attempt to program a write protect block */
00070   SD_LOCK_UNLOCK_FAILED              = (14), /*!< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
00071   SD_COM_CRC_FAILED                  = (15), /*!< CRC check of the previous command failed */
00072   SD_ILLEGAL_CMD                     = (16), /*!< Command is not legal for the card state */
00073   SD_CARD_ECC_FAILED                 = (17), /*!< Card internal ECC was applied but failed to correct the data */
00074   SD_CC_ERROR                        = (18), /*!< Internal card controller error */
00075   SD_GENERAL_UNKNOWN_ERROR           = (19), /*!< General or Unknown error */
00076   SD_STREAM_READ_UNDERRUN            = (20), /*!< The card could not sustain data transfer in stream read operation. */
00077   SD_STREAM_WRITE_OVERRUN            = (21), /*!< The card could not sustain data programming in stream mode */
00078   SD_CID_CSD_OVERWRITE               = (22), /*!< CID/CSD overwrite error */
00079   SD_WP_ERASE_SKIP                   = (23), /*!< only partial address space was erased */
00080   SD_CARD_ECC_DISABLED               = (24), /*!< Command has been executed without using internal ECC */
00081   SD_ERASE_RESET                     = (25), /*!< Erase sequence was cleared before executing because an out of erase sequence command was received */
00082   SD_AKE_SEQ_ERROR                   = (26), /*!< Error in sequence of authentication. */
00083   SD_INVALID_VOLTRANGE               = (27),
00084   SD_ADDR_OUT_OF_RANGE               = (28),
00085   SD_SWITCH_ERROR                    = (29),
00086   SD_SDIO_DISABLED                   = (30),
00087   SD_SDIO_FUNCTION_BUSY              = (31),
00088   SD_SDIO_FUNCTION_FAILED            = (32),
00089   SD_SDIO_UNKNOWN_FUNCTION           = (33),
00090 
00091 /** 
00092   * @brief  Standard error defines   
00093   */ 
00094   SD_INTERNAL_ERROR, 
00095   SD_NOT_CONFIGURED,
00096   SD_REQUEST_PENDING, 
00097   SD_REQUEST_NOT_APPLICABLE, 
00098   SD_INVALID_PARAMETER,  
00099   SD_UNSUPPORTED_FEATURE,  
00100   SD_UNSUPPORTED_HW,  
00101   SD_ERROR,  
00102   SD_OK  
00103 } SD_Error;
00104 
00105 /** 
00106   * @brief  SDIO Transfer state  
00107   */   
00108 typedef enum
00109 {
00110   SD_TRANSFER_OK  = 0,
00111   SD_TRANSFER_BUSY = 1,
00112   SD_TRANSFER_ERROR
00113 } SDTransferState;
00114 
00115 /** 
00116   * @brief  SD Card States 
00117   */   
00118 typedef enum
00119 {
00120   SD_CARD_READY                  = ((uint32_t)0x00000001),
00121   SD_CARD_IDENTIFICATION         = ((uint32_t)0x00000002),
00122   SD_CARD_STANDBY                = ((uint32_t)0x00000003),
00123   SD_CARD_TRANSFER               = ((uint32_t)0x00000004),
00124   SD_CARD_SENDING                = ((uint32_t)0x00000005),
00125   SD_CARD_RECEIVING              = ((uint32_t)0x00000006),
00126   SD_CARD_PROGRAMMING            = ((uint32_t)0x00000007),
00127   SD_CARD_DISCONNECTED           = ((uint32_t)0x00000008),
00128   SD_CARD_ERROR                  = ((uint32_t)0x000000FF)
00129 }SDCardState;
00130 
00131 
00132 /** 
00133   * @brief  Card Specific Data: CSD Register   
00134   */ 
00135 typedef struct
00136 {
00137   __IO uint8_t  CSDStruct;            /*!< CSD structure */
00138   __IO uint8_t  SysSpecVersion;       /*!< System specification version */
00139   __IO uint8_t  Reserved1;            /*!< Reserved */
00140   __IO uint8_t  TAAC;                 /*!< Data read access-time 1 */
00141   __IO uint8_t  NSAC;                 /*!< Data read access-time 2 in CLK cycles */
00142   __IO uint8_t  MaxBusClkFrec;        /*!< Max. bus clock frequency */
00143   __IO uint16_t CardComdClasses;      /*!< Card command classes */
00144   __IO uint8_t  RdBlockLen;           /*!< Max. read data block length */
00145   __IO uint8_t  PartBlockRead;        /*!< Partial blocks for read allowed */
00146   __IO uint8_t  WrBlockMisalign;      /*!< Write block misalignment */
00147   __IO uint8_t  RdBlockMisalign;      /*!< Read block misalignment */
00148   __IO uint8_t  DSRImpl;              /*!< DSR implemented */
00149   __IO uint8_t  Reserved2;            /*!< Reserved */
00150   __IO uint32_t DeviceSize;           /*!< Device Size */
00151   __IO uint8_t  MaxRdCurrentVDDMin;   /*!< Max. read current @ VDD min */
00152   __IO uint8_t  MaxRdCurrentVDDMax;   /*!< Max. read current @ VDD max */
00153   __IO uint8_t  MaxWrCurrentVDDMin;   /*!< Max. write current @ VDD min */
00154   __IO uint8_t  MaxWrCurrentVDDMax;   /*!< Max. write current @ VDD max */
00155   __IO uint8_t  DeviceSizeMul;        /*!< Device size multiplier */
00156   __IO uint8_t  EraseGrSize;          /*!< Erase group size */
00157   __IO uint8_t  EraseGrMul;           /*!< Erase group size multiplier */
00158   __IO uint8_t  WrProtectGrSize;      /*!< Write protect group size */
00159   __IO uint8_t  WrProtectGrEnable;    /*!< Write protect group enable */
00160   __IO uint8_t  ManDeflECC;           /*!< Manufacturer default ECC */
00161   __IO uint8_t  WrSpeedFact;          /*!< Write speed factor */
00162   __IO uint8_t  MaxWrBlockLen;        /*!< Max. write data block length */
00163   __IO uint8_t  WriteBlockPaPartial;  /*!< Partial blocks for write allowed */
00164   __IO uint8_t  Reserved3;            /*!< Reserded */
00165   __IO uint8_t  ContentProtectAppli;  /*!< Content protection application */
00166   __IO uint8_t  FileFormatGrouop;     /*!< File format group */
00167   __IO uint8_t  CopyFlag;             /*!< Copy flag (OTP) */
00168   __IO uint8_t  PermWrProtect;        /*!< Permanent write protection */
00169   __IO uint8_t  TempWrProtect;        /*!< Temporary write protection */
00170   __IO uint8_t  FileFormat;           /*!< File Format */
00171   __IO uint8_t  ECC;                  /*!< ECC code */
00172   __IO uint8_t  CSD_CRC;              /*!< CSD CRC */
00173   __IO uint8_t  Reserved4;            /*!< always 1*/
00174 } SD_CSD;
00175 
00176 /** 
00177   * @brief  Card Identification Data: CID Register   
00178   */
00179 typedef struct
00180 {
00181   __IO uint8_t  ManufacturerID;       /*!< ManufacturerID */
00182   __IO uint16_t OEM_AppliID;          /*!< OEM/Application ID */
00183   __IO uint32_t ProdName1;            /*!< Product Name part1 */
00184   __IO uint8_t  ProdName2;            /*!< Product Name part2*/
00185   __IO uint8_t  ProdRev;              /*!< Product Revision */
00186   __IO uint32_t ProdSN;               /*!< Product Serial Number */
00187   __IO uint8_t  Reserved1;            /*!< Reserved1 */
00188   __IO uint16_t ManufactDate;         /*!< Manufacturing Date */
00189   __IO uint8_t  CID_CRC;              /*!< CID CRC */
00190   __IO uint8_t  Reserved2;            /*!< always 1 */
00191 } SD_CID;
00192 
00193 /** 
00194   * @brief SD Card information 
00195   */
00196 typedef struct
00197 {
00198   SD_CSD SD_csd;
00199   SD_CID SD_cid;
00200   uint32_t CardCapacity;  /*!< Card Capacity */
00201   uint32_t CardBlockSize; /*!< Card Block Size */
00202   uint16_t RCA;
00203   uint8_t CardType;
00204 } SD_CardInfo;
00205 
00206 /**
00207   * @}
00208   */
00209   
00210 /** @defgroup STM32_EVAL_SDIO_SD_Exported_Constants
00211   * @{
00212   */ 
00213 
00214 /** 
00215   * @brief SDIO Commands  Index 
00216   */
00217 #define SD_CMD_GO_IDLE_STATE                       ((uint8_t)0)
00218 #define SD_CMD_SEND_OP_COND                        ((uint8_t)1)
00219 #define SD_CMD_ALL_SEND_CID                        ((uint8_t)2)
00220 #define SD_CMD_SET_REL_ADDR                        ((uint8_t)3) /*!< SDIO_SEND_REL_ADDR for SD Card */
00221 #define SD_CMD_SET_DSR                             ((uint8_t)4)
00222 #define SD_CMD_SDIO_SEN_OP_COND                    ((uint8_t)5)
00223 #define SD_CMD_HS_SWITCH                           ((uint8_t)6)
00224 #define SD_CMD_SEL_DESEL_CARD                      ((uint8_t)7)
00225 #define SD_CMD_HS_SEND_EXT_CSD                     ((uint8_t)8)
00226 #define SD_CMD_SEND_CSD                            ((uint8_t)9)
00227 #define SD_CMD_SEND_CID                            ((uint8_t)10)
00228 #define SD_CMD_READ_DAT_UNTIL_STOP                 ((uint8_t)11) /*!< SD Card doesn't support it */
00229 #define SD_CMD_STOP_TRANSMISSION                   ((uint8_t)12)
00230 #define SD_CMD_SEND_STATUS                         ((uint8_t)13)
00231 #define SD_CMD_HS_BUSTEST_READ                     ((uint8_t)14)
00232 #define SD_CMD_GO_INACTIVE_STATE                   ((uint8_t)15)
00233 #define SD_CMD_SET_BLOCKLEN                        ((uint8_t)16)
00234 #define SD_CMD_READ_SINGLE_BLOCK                   ((uint8_t)17)
00235 #define SD_CMD_READ_MULT_BLOCK                     ((uint8_t)18)
00236 #define SD_CMD_HS_BUSTEST_WRITE                    ((uint8_t)19)
00237 #define SD_CMD_WRITE_DAT_UNTIL_STOP                ((uint8_t)20) /*!< SD Card doesn't support it */
00238 #define SD_CMD_SET_BLOCK_COUNT                     ((uint8_t)23) /*!< SD Card doesn't support it */
00239 #define SD_CMD_WRITE_SINGLE_BLOCK                  ((uint8_t)24)
00240 #define SD_CMD_WRITE_MULT_BLOCK                    ((uint8_t)25)
00241 #define SD_CMD_PROG_CID                            ((uint8_t)26) /*!< reserved for manufacturers */
00242 #define SD_CMD_PROG_CSD                            ((uint8_t)27)
00243 #define SD_CMD_SET_WRITE_PROT                      ((uint8_t)28)
00244 #define SD_CMD_CLR_WRITE_PROT                      ((uint8_t)29)
00245 #define SD_CMD_SEND_WRITE_PROT                     ((uint8_t)30)
00246 #define SD_CMD_SD_ERASE_GRP_START                  ((uint8_t)32) /*!< To set the address of the first write
00247                                                                   block to be erased. (For SD card only) */
00248 #define SD_CMD_SD_ERASE_GRP_END                    ((uint8_t)33) /*!< To set the address of the last write block of the
00249                                                                   continuous range to be erased. (For SD card only) */
00250 #define SD_CMD_ERASE_GRP_START                     ((uint8_t)35) /*!< To set the address of the first write block to be erased.
00251                                                                   (For MMC card only spec 3.31) */
00252 
00253 #define SD_CMD_ERASE_GRP_END                       ((uint8_t)36) /*!< To set the address of the last write block of the
00254                                                                   continuous range to be erased. (For MMC card only spec 3.31) */
00255 
00256 #define SD_CMD_ERASE                               ((uint8_t)38)
00257 #define SD_CMD_FAST_IO                             ((uint8_t)39) /*!< SD Card doesn't support it */
00258 #define SD_CMD_GO_IRQ_STATE                        ((uint8_t)40) /*!< SD Card doesn't support it */
00259 #define SD_CMD_LOCK_UNLOCK                         ((uint8_t)42)
00260 #define SD_CMD_APP_CMD                             ((uint8_t)55)
00261 #define SD_CMD_GEN_CMD                             ((uint8_t)56)
00262 #define SD_CMD_NO_CMD                              ((uint8_t)64)
00263 
00264 /** 
00265   * @brief Following commands are SD Card Specific commands.
00266   *        SDIO_APP_CMD should be sent before sending these commands. 
00267   */
00268 #define SD_CMD_APP_SD_SET_BUSWIDTH                 ((uint8_t)6)  /*!< For SD Card only */
00269 #define SD_CMD_SD_APP_STAUS                        ((uint8_t)13) /*!< For SD Card only */
00270 #define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS        ((uint8_t)22) /*!< For SD Card only */
00271 #define SD_CMD_SD_APP_OP_COND                      ((uint8_t)41) /*!< For SD Card only */
00272 #define SD_CMD_SD_APP_SET_CLR_CARD_DETECT          ((uint8_t)42) /*!< For SD Card only */
00273 #define SD_CMD_SD_APP_SEND_SCR                     ((uint8_t)51) /*!< For SD Card only */
00274 #define SD_CMD_SDIO_RW_DIRECT                      ((uint8_t)52) /*!< For SD I/O Card only */
00275 #define SD_CMD_SDIO_RW_EXTENDED                    ((uint8_t)53) /*!< For SD I/O Card only */
00276 
00277 /** 
00278   * @brief Following commands are SD Card Specific security commands.
00279   *        SDIO_APP_CMD should be sent before sending these commands. 
00280   */
00281 #define SD_CMD_SD_APP_GET_MKB                      ((uint8_t)43) /*!< For SD Card only */
00282 #define SD_CMD_SD_APP_GET_MID                      ((uint8_t)44) /*!< For SD Card only */
00283 #define SD_CMD_SD_APP_SET_CER_RN1                  ((uint8_t)45) /*!< For SD Card only */
00284 #define SD_CMD_SD_APP_GET_CER_RN2                  ((uint8_t)46) /*!< For SD Card only */
00285 #define SD_CMD_SD_APP_SET_CER_RES2                 ((uint8_t)47) /*!< For SD Card only */
00286 #define SD_CMD_SD_APP_GET_CER_RES1                 ((uint8_t)48) /*!< For SD Card only */
00287 #define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK   ((uint8_t)18) /*!< For SD Card only */
00288 #define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK  ((uint8_t)25) /*!< For SD Card only */
00289 #define SD_CMD_SD_APP_SECURE_ERASE                 ((uint8_t)38) /*!< For SD Card only */
00290 #define SD_CMD_SD_APP_CHANGE_SECURE_AREA           ((uint8_t)49) /*!< For SD Card only */
00291 #define SD_CMD_SD_APP_SECURE_WRITE_MKB             ((uint8_t)48) /*!< For SD Card only */
00292   
00293 #define SD_DMA_MODE                                ((uint32_t)0x00000000)
00294 #define SD_INTERRUPT_MODE                          ((uint32_t)0x00000001)
00295 #define SD_POLLING_MODE                            ((uint32_t)0x00000002)
00296 
00297 /**
00298   * @brief  SD detection on its memory slot
00299   */
00300 #define SD_PRESENT                                 ((uint8_t)0x01)
00301 #define SD_NOT_PRESENT                             ((uint8_t)0x00)
00302 
00303 /** 
00304   * @brief Supported SD Memory Cards 
00305   */
00306 #define SDIO_STD_CAPACITY_SD_CARD_V1_1             ((uint32_t)0x00000000)
00307 #define SDIO_STD_CAPACITY_SD_CARD_V2_0             ((uint32_t)0x00000001)
00308 #define SDIO_HIGH_CAPACITY_SD_CARD                 ((uint32_t)0x00000002)
00309 #define SDIO_MULTIMEDIA_CARD                       ((uint32_t)0x00000003)
00310 #define SDIO_SECURE_DIGITAL_IO_CARD                ((uint32_t)0x00000004)
00311 #define SDIO_HIGH_SPEED_MULTIMEDIA_CARD            ((uint32_t)0x00000005)
00312 #define SDIO_SECURE_DIGITAL_IO_COMBO_CARD          ((uint32_t)0x00000006)
00313 #define SDIO_HIGH_CAPACITY_MMC_CARD                ((uint32_t)0x00000007)
00314 
00315 /**
00316   * @}
00317   */ 
00318   
00319 /** @defgroup STM32_EVAL_SDIO_SD_Exported_Macros
00320   * @{
00321   */ 
00322 /**
00323   * @}
00324   */ 
00325 
00326 /** @defgroup STM32_EVAL_SDIO_SD_Exported_Functions
00327   * @{
00328   */ 
00329 void SD_DeInit(void);
00330 SD_Error SD_Init(void);
00331 SDTransferState SD_GetStatus(void);
00332 SDCardState SD_GetState(void);
00333 uint8_t SD_Detect(void);
00334 SD_Error SD_PowerON(void);
00335 SD_Error SD_PowerOFF(void);
00336 SD_Error SD_InitializeCards(void);
00337 SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo);
00338 SD_Error SD_EnableWideBusOperation(uint32_t WideMode);
00339 SD_Error SD_SetDeviceMode(uint32_t Mode);
00340 SD_Error SD_SelectDeselect(uint32_t addr);
00341 SD_Error SD_ReadBlock(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize);
00342 SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
00343 SD_Error SD_WriteBlock(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize);
00344 SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
00345 SDTransferState SD_GetTransferState(void);
00346 SD_Error SD_StopTransfer(void);
00347 SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr);
00348 SD_Error SD_SendStatus(uint32_t *pcardstatus);
00349 SD_Error SD_SendSDStatus(uint32_t *psdstatus);
00350 SD_Error SD_ProcessIRQSrc(void);
00351 
00352 #ifdef __cplusplus
00353 }
00354 #endif
00355 
00356 #endif /* __STM32_EVAL_SDIO_SD_H */
00357 /**
00358   * @}
00359   */
00360 
00361 /**
00362   * @}
00363   */
00364 
00365 /**
00366   * @}
00367   */
00368 
00369 /**
00370   * @}
00371   */ 
00372 
00373 /**
00374   * @}
00375   */ 
00376 
00377 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32