stm32_eval_spi_sd.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32_eval_spi_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 stm32_eval_spi_sd
00008   *          firmware driver.
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_SPI_SD_H
00024 #define __STM32_EVAL_SPI_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_SPI_SD
00046   * @{
00047   */  
00048 
00049 /** @defgroup STM32_EVAL_SPI_SD_Exported_Types
00050   * @{
00051   */ 
00052 
00053 typedef enum
00054 {
00055 /**
00056   * @brief  SD reponses and error flags
00057   */
00058   SD_RESPONSE_NO_ERROR      = (0x00),
00059   SD_IN_IDLE_STATE          = (0x01),
00060   SD_ERASE_RESET            = (0x02),
00061   SD_ILLEGAL_COMMAND        = (0x04),
00062   SD_COM_CRC_ERROR          = (0x08),
00063   SD_ERASE_SEQUENCE_ERROR   = (0x10),
00064   SD_ADDRESS_ERROR          = (0x20),
00065   SD_PARAMETER_ERROR        = (0x40),
00066   SD_RESPONSE_FAILURE       = (0xFF),
00067 
00068 /**
00069   * @brief  Data response error
00070   */
00071   SD_DATA_OK                = (0x05),
00072   SD_DATA_CRC_ERROR         = (0x0B),
00073   SD_DATA_WRITE_ERROR       = (0x0D),
00074   SD_DATA_OTHER_ERROR       = (0xFF)
00075 } SD_Error;
00076 
00077 /** 
00078   * @brief  Card Specific Data: CSD Register   
00079   */ 
00080 typedef struct
00081 {
00082   __IO uint8_t  CSDStruct;            /*!< CSD structure */
00083   __IO uint8_t  SysSpecVersion;       /*!< System specification version */
00084   __IO uint8_t  Reserved1;            /*!< Reserved */
00085   __IO uint8_t  TAAC;                 /*!< Data read access-time 1 */
00086   __IO uint8_t  NSAC;                 /*!< Data read access-time 2 in CLK cycles */
00087   __IO uint8_t  MaxBusClkFrec;        /*!< Max. bus clock frequency */
00088   __IO uint16_t CardComdClasses;      /*!< Card command classes */
00089   __IO uint8_t  RdBlockLen;           /*!< Max. read data block length */
00090   __IO uint8_t  PartBlockRead;        /*!< Partial blocks for read allowed */
00091   __IO uint8_t  WrBlockMisalign;      /*!< Write block misalignment */
00092   __IO uint8_t  RdBlockMisalign;      /*!< Read block misalignment */
00093   __IO uint8_t  DSRImpl;              /*!< DSR implemented */
00094   __IO uint8_t  Reserved2;            /*!< Reserved */
00095   __IO uint32_t DeviceSize;           /*!< Device Size */
00096   __IO uint8_t  MaxRdCurrentVDDMin;   /*!< Max. read current @ VDD min */
00097   __IO uint8_t  MaxRdCurrentVDDMax;   /*!< Max. read current @ VDD max */
00098   __IO uint8_t  MaxWrCurrentVDDMin;   /*!< Max. write current @ VDD min */
00099   __IO uint8_t  MaxWrCurrentVDDMax;   /*!< Max. write current @ VDD max */
00100   __IO uint8_t  DeviceSizeMul;        /*!< Device size multiplier */
00101   __IO uint8_t  EraseGrSize;          /*!< Erase group size */
00102   __IO uint8_t  EraseGrMul;           /*!< Erase group size multiplier */
00103   __IO uint8_t  WrProtectGrSize;      /*!< Write protect group size */
00104   __IO uint8_t  WrProtectGrEnable;    /*!< Write protect group enable */
00105   __IO uint8_t  ManDeflECC;           /*!< Manufacturer default ECC */
00106   __IO uint8_t  WrSpeedFact;          /*!< Write speed factor */
00107   __IO uint8_t  MaxWrBlockLen;        /*!< Max. write data block length */
00108   __IO uint8_t  WriteBlockPaPartial;  /*!< Partial blocks for write allowed */
00109   __IO uint8_t  Reserved3;            /*!< Reserded */
00110   __IO uint8_t  ContentProtectAppli;  /*!< Content protection application */
00111   __IO uint8_t  FileFormatGrouop;     /*!< File format group */
00112   __IO uint8_t  CopyFlag;             /*!< Copy flag (OTP) */
00113   __IO uint8_t  PermWrProtect;        /*!< Permanent write protection */
00114   __IO uint8_t  TempWrProtect;        /*!< Temporary write protection */
00115   __IO uint8_t  FileFormat;           /*!< File Format */
00116   __IO uint8_t  ECC;                  /*!< ECC code */
00117   __IO uint8_t  CSD_CRC;              /*!< CSD CRC */
00118   __IO uint8_t  Reserved4;            /*!< always 1*/
00119 } SD_CSD;
00120 
00121 /** 
00122   * @brief  Card Identification Data: CID Register   
00123   */
00124 typedef struct
00125 {
00126   __IO uint8_t  ManufacturerID;       /*!< ManufacturerID */
00127   __IO uint16_t OEM_AppliID;          /*!< OEM/Application ID */
00128   __IO uint32_t ProdName1;            /*!< Product Name part1 */
00129   __IO uint8_t  ProdName2;            /*!< Product Name part2*/
00130   __IO uint8_t  ProdRev;              /*!< Product Revision */
00131   __IO uint32_t ProdSN;               /*!< Product Serial Number */
00132   __IO uint8_t  Reserved1;            /*!< Reserved1 */
00133   __IO uint16_t ManufactDate;         /*!< Manufacturing Date */
00134   __IO uint8_t  CID_CRC;              /*!< CID CRC */
00135   __IO uint8_t  Reserved2;            /*!< always 1 */
00136 } SD_CID;
00137 
00138 /** 
00139   * @brief SD Card information 
00140   */
00141 typedef struct
00142 {
00143   SD_CSD SD_csd;
00144   SD_CID SD_cid;
00145   uint32_t CardCapacity;  /*!< Card Capacity */
00146   uint32_t CardBlockSize; /*!< Card Block Size */
00147 } SD_CardInfo;
00148 
00149 /**
00150   * @}
00151   */
00152   
00153 /** @defgroup STM32_EVAL_SPI_SD_Exported_Constants
00154   * @{
00155   */ 
00156     
00157 /**
00158   * @brief  Block Size
00159   */
00160 #define SD_BLOCK_SIZE    0x200
00161 
00162 /**
00163   * @brief  Dummy byte
00164   */
00165 #define SD_DUMMY_BYTE   0xFF
00166 
00167 /**
00168   * @brief  Start Data tokens:
00169   *         Tokens (necessary because at nop/idle (and CS active) only 0xff is 
00170   *         on the data/command line)  
00171   */
00172 #define SD_START_DATA_SINGLE_BLOCK_READ    0xFE  /*!< Data token start byte, Start Single Block Read */
00173 #define SD_START_DATA_MULTIPLE_BLOCK_READ  0xFE  /*!< Data token start byte, Start Multiple Block Read */
00174 #define SD_START_DATA_SINGLE_BLOCK_WRITE   0xFE  /*!< Data token start byte, Start Single Block Write */
00175 #define SD_START_DATA_MULTIPLE_BLOCK_WRITE 0xFD  /*!< Data token start byte, Start Multiple Block Write */
00176 #define SD_STOP_DATA_MULTIPLE_BLOCK_WRITE  0xFD  /*!< Data toke stop byte, Stop Multiple Block Write */
00177 
00178 /**
00179   * @brief  SD detection on its memory slot
00180   */
00181 #define SD_PRESENT        ((uint8_t)0x01)
00182 #define SD_NOT_PRESENT    ((uint8_t)0x00)
00183 
00184 
00185 /**
00186   * @brief  Commands: CMDxx = CMD-number | 0x40
00187   */
00188 #define SD_CMD_GO_IDLE_STATE          0   /*!< CMD0 = 0x40 */
00189 #define SD_CMD_SEND_OP_COND           1   /*!< CMD1 = 0x41 */
00190 #define SD_CMD_SEND_CSD               9   /*!< CMD9 = 0x49 */
00191 #define SD_CMD_SEND_CID               10  /*!< CMD10 = 0x4A */
00192 #define SD_CMD_STOP_TRANSMISSION      12  /*!< CMD12 = 0x4C */
00193 #define SD_CMD_SEND_STATUS            13  /*!< CMD13 = 0x4D */
00194 #define SD_CMD_SET_BLOCKLEN           16  /*!< CMD16 = 0x50 */
00195 #define SD_CMD_READ_SINGLE_BLOCK      17  /*!< CMD17 = 0x51 */
00196 #define SD_CMD_READ_MULT_BLOCK        18  /*!< CMD18 = 0x52 */
00197 #define SD_CMD_SET_BLOCK_COUNT        23  /*!< CMD23 = 0x57 */
00198 #define SD_CMD_WRITE_SINGLE_BLOCK     24  /*!< CMD24 = 0x58 */
00199 #define SD_CMD_WRITE_MULT_BLOCK       25  /*!< CMD25 = 0x59 */
00200 #define SD_CMD_PROG_CSD               27  /*!< CMD27 = 0x5B */
00201 #define SD_CMD_SET_WRITE_PROT         28  /*!< CMD28 = 0x5C */
00202 #define SD_CMD_CLR_WRITE_PROT         29  /*!< CMD29 = 0x5D */
00203 #define SD_CMD_SEND_WRITE_PROT        30  /*!< CMD30 = 0x5E */
00204 #define SD_CMD_SD_ERASE_GRP_START     32  /*!< CMD32 = 0x60 */
00205 #define SD_CMD_SD_ERASE_GRP_END       33  /*!< CMD33 = 0x61 */
00206 #define SD_CMD_UNTAG_SECTOR           34  /*!< CMD34 = 0x62 */
00207 #define SD_CMD_ERASE_GRP_START        35  /*!< CMD35 = 0x63 */
00208 #define SD_CMD_ERASE_GRP_END          36  /*!< CMD36 = 0x64 */
00209 #define SD_CMD_UNTAG_ERASE_GROUP      37  /*!< CMD37 = 0x65 */
00210 #define SD_CMD_ERASE                  38  /*!< CMD38 = 0x66 */
00211 
00212 /**
00213   * @}
00214   */ 
00215   
00216 /** @defgroup STM32_EVAL_SPI_SD_Exported_Macros
00217   * @{
00218   */
00219 /** 
00220   * @brief  Select SD Card: ChipSelect pin low   
00221   */  
00222 #define SD_CS_LOW()     GPIO_ResetBits(SD_CS_GPIO_PORT, SD_CS_PIN)
00223 /** 
00224   * @brief  Deselect SD Card: ChipSelect pin high   
00225   */ 
00226 #define SD_CS_HIGH()    GPIO_SetBits(SD_CS_GPIO_PORT, SD_CS_PIN)
00227 /**
00228   * @}
00229   */ 
00230 
00231 /** @defgroup STM32_EVAL_SPI_SD_Exported_Functions
00232   * @{
00233   */ 
00234 void SD_DeInit(void);  
00235 SD_Error SD_Init(void);
00236 uint8_t SD_Detect(void);
00237 SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo);
00238 SD_Error SD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize);
00239 SD_Error SD_ReadMultiBlocks(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
00240 SD_Error SD_WriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize);
00241 SD_Error SD_WriteMultiBlocks(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
00242 SD_Error SD_GetCSDRegister(SD_CSD* SD_csd);
00243 SD_Error SD_GetCIDRegister(SD_CID* SD_cid);
00244 
00245 void SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc);
00246 SD_Error SD_GetResponse(uint8_t Response);
00247 uint8_t SD_GetDataResponse(void);
00248 SD_Error SD_GoIdleState(void);
00249 uint16_t SD_GetStatus(void);
00250 
00251 uint8_t SD_WriteByte(uint8_t byte);
00252 uint8_t SD_ReadByte(void);
00253 
00254 #ifdef __cplusplus
00255 }
00256 #endif
00257 
00258 #endif /* __STM32_EVAL_SPI_SD_H */
00259 /**
00260   * @}
00261   */
00262 
00263 /**
00264   * @}
00265   */
00266 
00267 /**
00268   * @}
00269   */
00270 
00271 /**
00272   * @}
00273   */ 
00274 
00275 /**
00276   * @}
00277   */    
00278 
00279 /******************* (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