STM3210C_EVAL BSP User Manual
|
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 V7.0.0 00006 * @date 14-April-2017 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>© COPYRIGHT(c) 2016 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 STM3210C EVAL SD Exported Types 00064 * @{ 00065 */ 00066 00067 /** 00068 * @brief SD status structure definition 00069 */ 00070 enum { 00071 BSP_SD_OK = 0x00, 00072 MSD_OK = 0x00, 00073 BSP_SD_ERROR = 0x01, 00074 BSP_SD_TIMEOUT 00075 }; 00076 00077 typedef struct 00078 { 00079 uint8_t Reserved1:2; /* Reserved */ 00080 uint16_t DeviceSize:12; /* Device Size */ 00081 uint8_t MaxRdCurrentVDDMin:3; /* Max. read current @ VDD min */ 00082 uint8_t MaxRdCurrentVDDMax:3; /* Max. read current @ VDD max */ 00083 uint8_t MaxWrCurrentVDDMin:3; /* Max. write current @ VDD min */ 00084 uint8_t MaxWrCurrentVDDMax:3; /* Max. write current @ VDD max */ 00085 uint8_t DeviceSizeMul:3; /* Device size multiplier */ 00086 } struct_v1; 00087 00088 00089 typedef struct 00090 { 00091 uint8_t Reserved1:6; /* Reserved */ 00092 uint32_t DeviceSize:22; /* Device Size */ 00093 uint8_t Reserved2:1; /* Reserved */ 00094 } struct_v2; 00095 00096 /** 00097 * @brief Card Specific Data: CSD Register 00098 */ 00099 typedef struct 00100 { 00101 /* Header part */ 00102 uint8_t CSDStruct:2; /* CSD structure */ 00103 uint8_t Reserved1:6; /* Reserved */ 00104 uint8_t TAAC:8; /* Data read access-time 1 */ 00105 uint8_t NSAC:8; /* Data read access-time 2 in CLK cycles */ 00106 uint8_t MaxBusClkFrec:8; /* Max. bus clock frequency */ 00107 uint16_t CardComdClasses:12; /* Card command classes */ 00108 uint8_t RdBlockLen:4; /* Max. read data block length */ 00109 uint8_t PartBlockRead:1; /* Partial blocks for read allowed */ 00110 uint8_t WrBlockMisalign:1; /* Write block misalignment */ 00111 uint8_t RdBlockMisalign:1; /* Read block misalignment */ 00112 uint8_t DSRImpl:1; /* DSR implemented */ 00113 00114 /* v1 or v2 struct */ 00115 union csd_version { 00116 struct_v1 v1; 00117 struct_v2 v2; 00118 } version; 00119 00120 uint8_t EraseSingleBlockEnable:1; /* Erase single block enable */ 00121 uint8_t EraseSectorSize:7; /* Erase group size multiplier */ 00122 uint8_t WrProtectGrSize:7; /* Write protect group size */ 00123 uint8_t WrProtectGrEnable:1; /* Write protect group enable */ 00124 uint8_t Reserved2:2; /* Reserved */ 00125 uint8_t WrSpeedFact:3; /* Write speed factor */ 00126 uint8_t MaxWrBlockLen:4; /* Max. write data block length */ 00127 uint8_t WriteBlockPartial:1; /* Partial blocks for write allowed */ 00128 uint8_t Reserved3:5; /* Reserved */ 00129 uint8_t FileFormatGrouop:1; /* File format group */ 00130 uint8_t CopyFlag:1; /* Copy flag (OTP) */ 00131 uint8_t PermWrProtect:1; /* Permanent write protection */ 00132 uint8_t TempWrProtect:1; /* Temporary write protection */ 00133 uint8_t FileFormat:2; /* File Format */ 00134 uint8_t Reserved4:2; /* Reserved */ 00135 uint8_t crc:7; /* Reserved */ 00136 uint8_t Reserved5:1; /* always 1*/ 00137 00138 } SD_CSD; 00139 00140 /** 00141 * @brief Card Identification Data: CID Register 00142 */ 00143 typedef struct 00144 { 00145 __IO uint8_t ManufacturerID; /* ManufacturerID */ 00146 __IO uint16_t OEM_AppliID; /* OEM/Application ID */ 00147 __IO uint32_t ProdName1; /* Product Name part1 */ 00148 __IO uint8_t ProdName2; /* Product Name part2*/ 00149 __IO uint8_t ProdRev; /* Product Revision */ 00150 __IO uint32_t ProdSN; /* Product Serial Number */ 00151 __IO uint8_t Reserved1; /* Reserved1 */ 00152 __IO uint16_t ManufactDate; /* Manufacturing Date */ 00153 __IO uint8_t CID_CRC; /* CID CRC */ 00154 __IO uint8_t Reserved2; /* always 1 */ 00155 } SD_CID; 00156 00157 /** 00158 * @brief SD Card information 00159 */ 00160 typedef struct 00161 { 00162 SD_CSD Csd; 00163 SD_CID Cid; 00164 uint32_t CardCapacity; /*!< Card Capacity */ 00165 uint32_t CardBlockSize; /*!< Card Block Size */ 00166 uint32_t LogBlockNbr; /*!< Specifies the Card logical Capacity in blocks */ 00167 uint32_t LogBlockSize; /*!< Specifies logical block size in bytes */ 00168 } SD_CardInfo; 00169 00170 /** 00171 * @} 00172 */ 00173 00174 /** @defgroup STM3210C_EVAL_SPI_SD_Exported_Constants STM3210C EVAL SPI SD Exported Constants 00175 * @{ 00176 */ 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 #define SD_DATATIMEOUT 100000000U 00185 00186 /** 00187 * @brief SD Card information structure 00188 */ 00189 #define BSP_SD_CardInfo SD_CardInfo 00190 00191 /** 00192 * @brief SD transfer state definition 00193 */ 00194 #define SD_TRANSFER_OK ((uint8_t)0x00) 00195 #define SD_TRANSFER_BUSY ((uint8_t)0x01) 00196 00197 /** 00198 * @} 00199 */ 00200 00201 /** @addtogroup STM3210C_EVAL_SD_Exported_Functions 00202 * @{ 00203 */ 00204 uint8_t BSP_SD_Init(void); 00205 uint8_t BSP_SD_IsDetected(void); 00206 uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout); 00207 uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout); 00208 uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr); 00209 uint8_t BSP_SD_GetCardState(void); 00210 uint8_t BSP_SD_GetCardInfo(SD_CardInfo *pCardInfo); 00211 00212 /* Link functions for SD Card peripheral*/ 00213 void SD_IO_Init(void); 00214 void SD_IO_CSState(uint8_t state); 00215 void SD_IO_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLength); 00216 void SD_IO_WriteData(const uint8_t *Data, uint16_t DataLength); 00217 void SD_IO_ReadData(const uint8_t *Data, uint16_t DataLength); 00218 uint8_t SD_IO_WriteByte(uint8_t Data); 00219 00220 /* Link function for HAL delay */ 00221 void HAL_Delay(__IO uint32_t Delay); 00222 00223 /** 00224 * @} 00225 */ 00226 00227 /** 00228 * @} 00229 */ 00230 00231 /** 00232 * @} 00233 */ 00234 00235 /** 00236 * @} 00237 */ 00238 00239 #ifdef __cplusplus 00240 } 00241 #endif 00242 00243 #endif /* __STM3210C_EVAL_SD_H */ 00244 00245 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Fri Apr 14 2017 13:00:47 for STM3210C_EVAL BSP User Manual by 1.7.6.1