STM3210C_EVAL BSP User Manual: stm3210c_eval_sd.h Source File

STM3210C EVAL BSP Drivers

stm3210c_eval_sd.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm3210c_eval_sd.h
00004   * @author  MCD Application Team
00005   * @version V6.0.1
00006   * @date    18-December-2015
00007   * @brief   This file contains the common defines and functions prototypes for
00008   *          the stm3210c_eval_sd.c driver.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00013   *
00014   * Redistribution and use in source and binary forms, with or without modification,
00015   * are permitted provided that the following conditions are met:
00016   *   1. Redistributions of source code must retain the above copyright notice,
00017   *      this list of conditions and the following disclaimer.
00018   *   2. Redistributions in binary form must reproduce the above copyright notice,
00019   *      this list of conditions and the following disclaimer in the documentation
00020   *      and/or other materials provided with the distribution.
00021   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022   *      may be used to endorse or promote products derived from this software
00023   *      without specific prior written permission.
00024   *
00025   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035   *
00036   ******************************************************************************
00037   */ 
00038 
00039 /* Define to prevent recursive inclusion -------------------------------------*/
00040 #ifndef __STM3210C_EVAL_SD_H
00041 #define __STM3210C_EVAL_SD_H
00042 
00043 #ifdef __cplusplus
00044  extern "C" {
00045 #endif 
00046 
00047 /* Includes ------------------------------------------------------------------*/
00048 #include "stm3210c_eval.h" 
00049 
00050 /** @addtogroup BSP
00051   * @{
00052   */ 
00053 
00054 /** @addtogroup STM3210C_EVAL
00055   * @{
00056   */
00057     
00058 /** @addtogroup STM3210C_EVAL_SD
00059   * @{
00060   */    
00061 
00062 
00063 /** @defgroup STM3210C_EVAL_SD_Exported_Types Exported_Types
00064   * @{
00065   */
00066 
00067 /** 
00068   * @brief  SD status structure definition  
00069   */     
00070 #define MSD_OK         0x00
00071 #define MSD_ERROR      0x01
00072 
00073 typedef enum
00074 {
00075 /**
00076   * @brief  SD reponses and error flags
00077   */
00078   SD_RESPONSE_NO_ERROR      = (0x00),
00079   SD_IN_IDLE_STATE          = (0x01),
00080   SD_ERASE_RESET            = (0x02),
00081   SD_ILLEGAL_COMMAND        = (0x04),
00082   SD_COM_CRC_ERROR          = (0x08),
00083   SD_ERASE_SEQUENCE_ERROR   = (0x10),
00084   SD_ADDRESS_ERROR          = (0x20),
00085   SD_PARAMETER_ERROR        = (0x40),
00086   SD_RESPONSE_FAILURE       = (0xFF),
00087 
00088 /**
00089   * @brief  Data response error
00090   */
00091   SD_DATA_OK                = (0x05),
00092   SD_DATA_CRC_ERROR         = (0x0B),
00093   SD_DATA_WRITE_ERROR       = (0x0D),
00094   SD_DATA_OTHER_ERROR       = (0xFF)
00095 }SD_Info;
00096 
00097 /** 
00098   * @brief  Card Specific Data: CSD Register
00099   */ 
00100 typedef struct
00101 {
00102   __IO uint8_t  CSDStruct;            /* CSD structure */
00103   __IO uint8_t  SysSpecVersion;       /* System specification version */
00104   __IO uint8_t  Reserved1;            /* Reserved */
00105   __IO uint8_t  TAAC;                 /* Data read access-time 1 */
00106   __IO uint8_t  NSAC;                 /* Data read access-time 2 in CLK cycles */
00107   __IO uint8_t  MaxBusClkFrec;        /* Max. bus clock frequency */
00108   __IO uint16_t CardComdClasses;      /* Card command classes */
00109   __IO uint8_t  RdBlockLen;           /* Max. read data block length */
00110   __IO uint8_t  PartBlockRead;        /* Partial blocks for read allowed */
00111   __IO uint8_t  WrBlockMisalign;      /* Write block misalignment */
00112   __IO uint8_t  RdBlockMisalign;      /* Read block misalignment */
00113   __IO uint8_t  DSRImpl;              /* DSR implemented */
00114   __IO uint8_t  Reserved2;            /* Reserved */
00115   __IO uint32_t DeviceSize;           /* Device Size */
00116   __IO uint8_t  MaxRdCurrentVDDMin;   /* Max. read current @ VDD min */
00117   __IO uint8_t  MaxRdCurrentVDDMax;   /* Max. read current @ VDD max */
00118   __IO uint8_t  MaxWrCurrentVDDMin;   /* Max. write current @ VDD min */
00119   __IO uint8_t  MaxWrCurrentVDDMax;   /* Max. write current @ VDD max */
00120   __IO uint8_t  DeviceSizeMul;        /* Device size multiplier */
00121   __IO uint8_t  EraseGrSize;          /* Erase group size */
00122   __IO uint8_t  EraseGrMul;           /* Erase group size multiplier */
00123   __IO uint8_t  WrProtectGrSize;      /* Write protect group size */
00124   __IO uint8_t  WrProtectGrEnable;    /* Write protect group enable */
00125   __IO uint8_t  ManDeflECC;           /* Manufacturer default ECC */
00126   __IO uint8_t  WrSpeedFact;          /* Write speed factor */
00127   __IO uint8_t  MaxWrBlockLen;        /* Max. write data block length */
00128   __IO uint8_t  WriteBlockPaPartial;  /* Partial blocks for write allowed */
00129   __IO uint8_t  Reserved3;            /* Reserded */
00130   __IO uint8_t  ContentProtectAppli;  /* Content protection application */
00131   __IO uint8_t  FileFormatGrouop;     /* File format group */
00132   __IO uint8_t  CopyFlag;             /* Copy flag (OTP) */
00133   __IO uint8_t  PermWrProtect;        /* Permanent write protection */
00134   __IO uint8_t  TempWrProtect;        /* Temporary write protection */
00135   __IO uint8_t  FileFormat;           /* File Format */
00136   __IO uint8_t  ECC;                  /* ECC code */
00137   __IO uint8_t  CSD_CRC;              /* CSD CRC */
00138   __IO uint8_t  Reserved4;            /* always 1*/
00139 } SD_CSD;
00140 
00141 /** 
00142   * @brief  Card Identification Data: CID Register   
00143   */
00144 typedef struct
00145 {
00146   __IO uint8_t  ManufacturerID;       /* ManufacturerID */
00147   __IO uint16_t OEM_AppliID;          /* OEM/Application ID */
00148   __IO uint32_t ProdName1;            /* Product Name part1 */
00149   __IO uint8_t  ProdName2;            /* Product Name part2*/
00150   __IO uint8_t  ProdRev;              /* Product Revision */
00151   __IO uint32_t ProdSN;               /* Product Serial Number */
00152   __IO uint8_t  Reserved1;            /* Reserved1 */
00153   __IO uint16_t ManufactDate;         /* Manufacturing Date */
00154   __IO uint8_t  CID_CRC;              /* CID CRC */
00155   __IO uint8_t  Reserved2;            /* always 1 */
00156 } SD_CID;
00157 
00158 /** 
00159   * @brief SD Card information 
00160   */
00161 typedef struct
00162 {
00163   SD_CSD Csd;
00164   SD_CID Cid;
00165   uint32_t CardCapacity;  /* Card Capacity */
00166   uint32_t CardBlockSize; /* Card Block Size */
00167 } SD_CardInfo;
00168 
00169 /**
00170   * @}
00171   */
00172   
00173 /** @defgroup STM3210C_EVAL_SPI_SD_Exported_Constants Exported_Constants
00174   * @{
00175   */ 
00176   
00177 /**
00178   * @brief  Block Size
00179   */
00180 #define SD_BLOCK_SIZE    0x200
00181 
00182 /**
00183   * @brief  Start Data tokens:
00184   *         Tokens (necessary because at nop/idle (and CS active) only 0xff is 
00185   *         on the data/command line)  
00186   */ 
00187 #define SD_START_DATA_SINGLE_BLOCK_READ    0xFE  /* Data token start byte, Start Single Block Read */
00188 #define SD_START_DATA_MULTIPLE_BLOCK_READ  0xFE  /* Data token start byte, Start Multiple Block Read */
00189 #define SD_START_DATA_SINGLE_BLOCK_WRITE   0xFE  /* Data token start byte, Start Single Block Write */
00190 #define SD_START_DATA_MULTIPLE_BLOCK_WRITE 0xFD  /* Data token start byte, Start Multiple Block Write */
00191 #define SD_STOP_DATA_MULTIPLE_BLOCK_WRITE  0xFD  /* Data toke stop byte, Stop Multiple Block Write */
00192 
00193 /**
00194   * @brief  SD detection on its memory slot
00195   */
00196 #define SD_PRESENT               ((uint8_t)0x01)
00197 #define SD_NOT_PRESENT           ((uint8_t)0x00)
00198    
00199 /**
00200   * @brief  Commands: CMDxx = CMD-number | 0x40
00201   */
00202 #define SD_CMD_GO_IDLE_STATE          0   /* CMD0 = 0x40 */
00203 #define SD_CMD_SEND_OP_COND           1   /* CMD1 = 0x41 */
00204 #define SD_CMD_SEND_CSD               9   /* CMD9 = 0x49 */
00205 #define SD_CMD_SEND_CID               10  /* CMD10 = 0x4A */
00206 #define SD_CMD_STOP_TRANSMISSION      12  /* CMD12 = 0x4C */
00207 #define SD_CMD_SEND_STATUS            13  /* CMD13 = 0x4D */
00208 #define SD_CMD_SET_BLOCKLEN           16  /* CMD16 = 0x50 */
00209 #define SD_CMD_READ_SINGLE_BLOCK      17  /* CMD17 = 0x51 */
00210 #define SD_CMD_READ_MULT_BLOCK        18  /* CMD18 = 0x52 */
00211 #define SD_CMD_SET_BLOCK_COUNT        23  /* CMD23 = 0x57 */
00212 #define SD_CMD_WRITE_SINGLE_BLOCK     24  /* CMD24 = 0x58 */
00213 #define SD_CMD_WRITE_MULT_BLOCK       25  /* CMD25 = 0x59 */
00214 #define SD_CMD_PROG_CSD               27  /* CMD27 = 0x5B */
00215 #define SD_CMD_SET_WRITE_PROT         28  /* CMD28 = 0x5C */
00216 #define SD_CMD_CLR_WRITE_PROT         29  /* CMD29 = 0x5D */
00217 #define SD_CMD_SEND_WRITE_PROT        30  /* CMD30 = 0x5E */
00218 #define SD_CMD_SD_ERASE_GRP_START     32  /* CMD32 = 0x60 */
00219 #define SD_CMD_SD_ERASE_GRP_END       33  /* CMD33 = 0x61 */
00220 #define SD_CMD_UNTAG_SECTOR           34  /* CMD34 = 0x62 */
00221 #define SD_CMD_ERASE_GRP_START        35  /* CMD35 = 0x63 */
00222 #define SD_CMD_ERASE_GRP_END          36  /* CMD36 = 0x64 */
00223 #define SD_CMD_UNTAG_ERASE_GROUP      37  /* CMD37 = 0x65 */
00224 #define SD_CMD_ERASE                  38  /* CMD38 = 0x66 */
00225 
00226    
00227 /**
00228   * @}
00229   */
00230   
00231 /** @defgroup STM3210C_EVAL_SD_Exported_Macro Exported_Macro
00232   * @{
00233   */ 
00234 
00235 /**
00236   * @}
00237   */ 
00238 
00239 /** @addtogroup STM3210C_EVAL_SD_Exported_Functions
00240   * @{
00241   */   
00242 uint8_t BSP_SD_Init(void);
00243 uint8_t  BSP_SD_IsDetected(void);
00244 uint8_t BSP_SD_ReadBlocks(uint32_t* p32Data, uint64_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
00245 uint8_t BSP_SD_WriteBlocks(uint32_t* p32Data, uint64_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
00246 uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr);
00247 uint8_t BSP_SD_GetStatus(void);
00248 uint8_t BSP_SD_GetCardInfo(SD_CardInfo *pCardInfo);
00249    
00250 /* Link functions for SD Card peripheral*/
00251 void                    SD_IO_Init(void); 
00252 void                    SD_IO_WriteByte(uint8_t Data);
00253 uint8_t                 SD_IO_ReadByte(void);
00254 HAL_StatusTypeDef       SD_IO_WriteCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc, uint8_t Response);
00255 HAL_StatusTypeDef       SD_IO_WaitResponse(uint8_t Response);
00256 void                    SD_IO_WriteDummy(void);
00257 
00258 /**
00259   * @}
00260   */ 
00261 
00262 /**
00263   * @}
00264   */ 
00265 
00266 /**
00267   * @}
00268   */ 
00269 
00270 /**
00271   * @}
00272   */ 
00273 
00274 #ifdef __cplusplus
00275 }
00276 #endif
00277 
00278 #endif /* __STM3210C_EVAL_SD_H */
00279 
00280 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Thu Dec 10 2015 17:13:52 for STM3210C_EVAL BSP User Manual by   doxygen 1.7.6.1