STM8S/A Standard Peripherals Firmware Library: stm8s_eval_spi_sd.h Source File

STM8S/A

stm8s_eval_spi_sd.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm8_eval_spi_sd.h
00004   * @author  MCD Application Team
00005   * @version V1.0.1
00006   * @date    30-September-2014
00007   * @brief   This file contains all the functions prototypes for the stm8s_eval_spi_sd
00008   *          firmware driver.
00009   ******************************************************************************
00010   *
00011   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00012   * You may not use this file except in compliance with the License.
00013   * You may obtain a copy of the License at:
00014   *
00015   *        http://www.st.com/software_license_agreement_liberty_v2
00016   *
00017   * Unless required by applicable law or agreed to in writing, software 
00018   * distributed under the License is distributed on an "AS IS" BASIS, 
00019   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   * See the License for the specific language governing permissions and
00021   * limitations under the License.
00022   *
00023   ******************************************************************************
00024   */
00025 
00026 /* Define to prevent recursive inclusion -------------------------------------*/
00027 #ifndef __STM8S_EVAL_SPI_SD_H
00028 #define __STM8S_EVAL_SPI_SD_H
00029 
00030 /* Includes ------------------------------------------------------------------*/
00031 #include "stm8s_eval.h"
00032 
00033 /** @addtogroup Utilities
00034   * @{
00035   */
00036   
00037 /** @addtogroup STM8S_EVAL
00038   * @{
00039   */ 
00040 
00041 /** @addtogroup Common
00042   * @{
00043   */
00044   
00045 /** @addtogroup STM8S_EVAL_SPI_SD
00046   * @{
00047   */  
00048 
00049 /** @defgroup STM8S_EVAL_SPI_SD_Exported_Types
00050   * @{
00051   */ 
00052 
00053 /** 
00054   * @brief  Card Specific Data: CSD Register   
00055   */ 
00056 typedef struct
00057 {
00058   __IO uint8_t  CSDStruct;            /*!< CSD structure */
00059   __IO uint8_t  SysSpecVersion;       /*!< System specification version */
00060   __IO uint8_t  Reserved1;            /*!< Reserved */
00061   __IO uint8_t  TAAC;                 /*!< Data read access-time 1 */
00062   __IO uint8_t  NSAC;                 /*!< Data read access-time 2 in CLK cycles */
00063   __IO uint8_t  MaxBusClkFrec;        /*!< Max. bus clock frequency */
00064   __IO uint16_t CardComdClasses;      /*!< Card command classes */
00065   __IO uint8_t  RdBlockLen;           /*!< Max. read data block length */
00066   __IO uint8_t  PartBlockRead;        /*!< Partial blocks for read allowed */
00067   __IO uint8_t  WrBlockMisalign;      /*!< Write block misalignment */
00068   __IO uint8_t  RdBlockMisalign;      /*!< Read block misalignment */
00069   __IO uint8_t  DSRImpl;              /*!< DSR implemented */
00070   __IO uint8_t  Reserved2;            /*!< Reserved */
00071   __IO uint32_t DeviceSize;           /*!< Device Size */
00072   __IO uint8_t  MaxRdCurrentVDDMin;   /*!< Max. read current @ VDD min */
00073   __IO uint8_t  MaxRdCurrentVDDMax;   /*!< Max. read current @ VDD max */
00074   __IO uint8_t  MaxWrCurrentVDDMin;   /*!< Max. write current @ VDD min */
00075   __IO uint8_t  MaxWrCurrentVDDMax;   /*!< Max. write current @ VDD max */
00076   __IO uint8_t  DeviceSizeMul;        /*!< Device size multiplier */
00077   __IO uint8_t  EraseGrSize;          /*!< Erase group size */
00078   __IO uint8_t  EraseGrMul;           /*!< Erase group size multiplier */
00079   __IO uint8_t  WrProtectGrSize;      /*!< Write protect group size */
00080   __IO uint8_t  WrProtectGrEnable;    /*!< Write protect group enable */
00081   __IO uint8_t  ManDeflECC;           /*!< Manufacturer default ECC */
00082   __IO uint8_t  WrSpeedFact;          /*!< Write speed factor */
00083   __IO uint8_t  MaxWrBlockLen;        /*!< Max. write data block length */
00084   __IO uint8_t  WriteBlockPaPartial;  /*!< Partial blocks for write allowed */
00085   __IO uint8_t  Reserved3;            /*!< Reserved */
00086   __IO uint8_t  ContentProtectAppli;  /*!< Content protection application */
00087   __IO uint8_t  FileFormatGrouop;     /*!< File format group */
00088   __IO uint8_t  CopyFlag;             /*!< Copy flag (OTP) */
00089   __IO uint8_t  PermWrProtect;        /*!< Permanent write protection */
00090   __IO uint8_t  TempWrProtect;        /*!< Temporary write protection */
00091   __IO uint8_t  FileFormat;           /*!< File Format */
00092   __IO uint8_t  ECC;                  /*!< ECC code */
00093   __IO uint8_t  CSD_CRC;              /*!< CSD CRC */
00094   __IO uint8_t  Reserved4;            /*!< always 1*/
00095 } SD_CSD;
00096 
00097 /** 
00098   * @brief  Card Identification Data: CID Register   
00099   */
00100 typedef struct
00101 {
00102   __IO uint8_t  ManufacturerID;       /*!< ManufacturerID */
00103   __IO uint16_t OEM_AppliID;          /*!< OEM/Application ID */
00104   __IO uint32_t ProdName1;            /*!< Product Name part1 */
00105   __IO uint8_t  ProdName2;            /*!< Product Name part2*/
00106   __IO uint8_t  ProdRev;              /*!< Product Revision */
00107   __IO uint32_t ProdSN;               /*!< Product Serial Number */
00108   __IO uint8_t  Reserved1;            /*!< Reserved1 */
00109   __IO uint16_t ManufactDate;         /*!< Manufacturing Date */
00110   __IO uint8_t  CID_CRC;              /*!< CID CRC */
00111   __IO uint8_t  Reserved2;            /*!< always 1 */
00112 } SD_CID;
00113 
00114 /** 
00115   * @brief SD Card information 
00116   */
00117 typedef struct
00118 {
00119   SD_CSD SD_csd;
00120   SD_CID SD_cid;
00121   uint32_t CardCapacity;  /*!< Card Capacity */
00122   uint32_t CardBlockSize; /*!< Card Block Size */
00123 } SD_CardInfo;
00124 
00125 /**
00126   * @}
00127   */
00128   
00129 /** @defgroup STM8S_EVAL_SPI_SD_Exported_Constants
00130   * @{
00131   */ 
00132 
00133 /**
00134   * @brief  SD responses and error flags
00135   */
00136 #define  SD_RESPONSE_NO_ERROR         0x00
00137 #define  SD_IN_IDLE_STATE             0x01
00138 #define  SD_ERASE_RESET               0x02
00139 #define  SD_ILLEGAL_COMMAND           0x04
00140 #define  SD_COM_CRC_ERROR             0x08
00141 #define  SD_ERASE_SEQUENCE_ERROR      0x10
00142 #define  SD_ADDRESS_ERROR             0x20
00143 #define  SD_PARAMETER_ERROR           0x40
00144 #define  SD_RESPONSE_FAILURE          0xFF
00145 
00146 /**
00147   * @brief  Data response error
00148   */
00149 #define  SD_DATA_OK                   0x05
00150 #define  SD_DATA_CRC_ERROR            0x0B
00151 #define  SD_DATA_WRITE_ERROR          0x0D
00152 #define  SD_DATA_OTHER_ERROR          0xFF
00153     
00154 /**
00155   * @brief  Block Size
00156   */
00157 #define SD_BLOCK_SIZE    0x200
00158 
00159 /**
00160   * @brief  Dummy byte
00161   */
00162 #define SD_DUMMY_BYTE   0xFF
00163 
00164 /**
00165   * @brief  Start Data tokens:
00166   *         Tokens (necessary because at nop/idle (and CS active) only 0xff is 
00167   *         on the data/command line)  
00168   */
00169 #define SD_START_DATA_SINGLE_BLOCK_READ    0xFE  /*!< Data token start byte, Start Single Block Read */
00170 #define SD_START_DATA_MULTIPLE_BLOCK_READ  0xFE  /*!< Data token start byte, Start Multiple Block Read */
00171 #define SD_START_DATA_SINGLE_BLOCK_WRITE   0xFE  /*!< Data token start byte, Start Single Block Write */
00172 #define SD_START_DATA_MULTIPLE_BLOCK_WRITE 0xFD  /*!< Data token start byte, Start Multiple Block Write */
00173 #define SD_STOP_DATA_MULTIPLE_BLOCK_WRITE  0xFD  /*!< Data toke stop byte, Stop Multiple Block Write */
00174 
00175 /**
00176   * @brief  SD detection on its memory slot
00177   */
00178 #define SD_PRESENT        ((uint8_t)0x01)
00179 #define SD_NOT_PRESENT    ((uint8_t)0x00)
00180 
00181 
00182 /**
00183   * @brief  Commands: CMDxx = CMD-number | 0x40
00184   */
00185 #define SD_CMD_GO_IDLE_STATE          0   /*!< CMD0 = 0x40 */
00186 #define SD_CMD_SEND_OP_COND           1   /*!< CMD1 = 0x41 */
00187 #define SD_CMD_SEND_CSD               9   /*!< CMD9 = 0x49 */
00188 #define SD_CMD_SEND_CID               10  /*!< CMD10 = 0x4A */
00189 #define SD_CMD_STOP_TRANSMISSION      12  /*!< CMD12 = 0x4C */
00190 #define SD_CMD_SEND_STATUS            13  /*!< CMD13 = 0x4D */
00191 #define SD_CMD_SET_BLOCKLEN           16  /*!< CMD16 = 0x50 */
00192 #define SD_CMD_READ_SINGLE_BLOCK      17  /*!< CMD17 = 0x51 */
00193 #define SD_CMD_READ_MULT_BLOCK        18  /*!< CMD18 = 0x52 */
00194 #define SD_CMD_SET_BLOCK_COUNT        23  /*!< CMD23 = 0x57 */
00195 #define SD_CMD_WRITE_SINGLE_BLOCK     24  /*!< CMD24 = 0x58 */
00196 #define SD_CMD_WRITE_MULT_BLOCK       25  /*!< CMD25 = 0x59 */
00197 #define SD_CMD_PROG_CSD               27  /*!< CMD27 = 0x5B */
00198 #define SD_CMD_SET_WRITE_PROT         28  /*!< CMD28 = 0x5C */
00199 #define SD_CMD_CLR_WRITE_PROT         29  /*!< CMD29 = 0x5D */
00200 #define SD_CMD_SEND_WRITE_PROT        30  /*!< CMD30 = 0x5E */
00201 #define SD_CMD_SD_ERASE_GRP_START     32  /*!< CMD32 = 0x60 */
00202 #define SD_CMD_SD_ERASE_GRP_END       33  /*!< CMD33 = 0x61 */
00203 #define SD_CMD_UNTAG_SECTOR           34  /*!< CMD34 = 0x62 */
00204 #define SD_CMD_ERASE_GRP_START        35  /*!< CMD35 = 0x63 */
00205 #define SD_CMD_ERASE_GRP_END          36  /*!< CMD36 = 0x64 */
00206 #define SD_CMD_UNTAG_ERASE_GROUP      37  /*!< CMD37 = 0x65 */
00207 #define SD_CMD_ERASE                  38  /*!< CMD38 = 0x66 */
00208 
00209 /**
00210   * @}
00211   */ 
00212   
00213 /** @defgroup STM8S_EVAL_SPI_SD_Exported_Macros
00214   * @{
00215   */
00216 /** 
00217   * @brief  Select SD Card: ChipSelect pin low   
00218   */  
00219 #define SD_CS_LOW()     GPIO_WriteLow(SD_CS_GPIO_PORT, SD_CS_PIN)
00220 /** 
00221   * @brief  Deselect SD Card: ChipSelect pin high   
00222   */ 
00223 #define SD_CS_HIGH()    GPIO_WriteHigh(SD_CS_GPIO_PORT, SD_CS_PIN)
00224 /**
00225   * @}
00226   */ 
00227 
00228 /** @defgroup STM8S_EVAL_SPI_SD_Exported_Functions
00229   * @{
00230   */ 
00231 /*----- High layer function -----*/
00232 void SD_DeInit(void);  
00233 uint8_t SD_Init(void);
00234 uint8_t SD_Detect(void);
00235 uint8_t SD_GetCardInfo(SD_CardInfo *cardinfo);
00236 uint8_t SD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize);
00237 uint8_t SD_ReadBuffer(uint8_t *pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead);
00238 uint8_t SD_WriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize);
00239 uint8_t SD_WriteBuffer(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t NumByteToWrite);
00240 uint8_t SD_GetCSDRegister(SD_CSD* SD_csd);
00241 uint8_t SD_GetCIDRegister(SD_CID* SD_cid);
00242 /*----- Medium layer function -----*/
00243 void SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc);
00244 uint8_t SD_GetResponse(uint8_t Response);
00245 uint8_t SD_GetDataResponse(void);
00246 uint8_t SD_GoIdleState(void);
00247 uint16_t SD_GetStatus(void);
00248 /*----- Low layer function -----*/
00249 uint8_t SD_WriteByte(uint8_t byte);
00250 uint8_t SD_ReadByte(void);
00251 
00252 
00253 #endif /* __STM8S_EVAL_SPI_SD_H */
00254 /**
00255   * @}
00256   */
00257 
00258 /**
00259   * @}
00260   */
00261 
00262 /**
00263   * @}
00264   */
00265 
00266 /**
00267   * @}
00268   */ 
00269 
00270 /**
00271   * @}
00272   */    
00273 
00274 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com