STM32091C_EVAL BSP User Manual
|
stm32091c_eval_sd.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32091c_eval_sd.h 00004 * @author MCD Application Team 00005 * @brief This file contains the common defines and functions prototypes for 00006 * the stm32091c_eval_sd.c driver. 00007 ****************************************************************************** 00008 * @attention 00009 * 00010 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00011 * 00012 * Redistribution and use in source and binary forms, with or without modification, 00013 * are permitted provided that the following conditions are met: 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00020 * may be used to endorse or promote products derived from this software 00021 * without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 ****************************************************************************** 00035 */ 00036 00037 /* Define to prevent recursive inclusion -------------------------------------*/ 00038 #ifndef __STM32091C_EVAL_SD_H 00039 #define __STM32091C_EVAL_SD_H 00040 00041 #ifdef __cplusplus 00042 extern "C" { 00043 #endif 00044 00045 /* Includes ------------------------------------------------------------------*/ 00046 #include "stm32091c_eval.h" 00047 00048 /** @addtogroup BSP 00049 * @{ 00050 */ 00051 00052 /** @addtogroup STM32091C_EVAL 00053 * @{ 00054 */ 00055 00056 /** @defgroup STM32091C_EVAL_SD STM32091C-EVAL SD 00057 * @{ 00058 */ 00059 00060 /* Private define ------------------------------------------------------------*/ 00061 00062 /** @defgroup STM32091C_EVAL_SD_Private_Defines Private Constants 00063 * @{ 00064 */ 00065 /** 00066 * @} 00067 */ 00068 /* Private variables ---------------------------------------------------------*/ 00069 00070 /** @defgroup STM32091C_EVAL_SD_Private_Variables Private Variables 00071 * @{ 00072 */ 00073 /** 00074 * @} 00075 */ 00076 00077 /** @defgroup STM32091C_EVAL_SD_Exported_Types Exported Types 00078 * @{ 00079 */ 00080 00081 /** 00082 * @brief SD status structure definition 00083 */ 00084 enum { 00085 BSP_SD_OK = 0x00, 00086 MSD_OK = 0x00, 00087 BSP_SD_ERROR = 0x01, 00088 MSD_ERROR = 0x01, 00089 BSP_SD_TIMEOUT 00090 }; 00091 00092 typedef struct 00093 { 00094 uint8_t Reserved1:2; /* Reserved */ 00095 uint16_t DeviceSize:12; /* Device Size */ 00096 uint8_t MaxRdCurrentVDDMin:3; /* Max. read current @ VDD min */ 00097 uint8_t MaxRdCurrentVDDMax:3; /* Max. read current @ VDD max */ 00098 uint8_t MaxWrCurrentVDDMin:3; /* Max. write current @ VDD min */ 00099 uint8_t MaxWrCurrentVDDMax:3; /* Max. write current @ VDD max */ 00100 uint8_t DeviceSizeMul:3; /* Device size multiplier */ 00101 } struct_v1; 00102 00103 00104 typedef struct 00105 { 00106 uint8_t Reserved1:6; /* Reserved */ 00107 uint32_t DeviceSize:22; /* Device Size */ 00108 uint8_t Reserved2:1; /* Reserved */ 00109 } struct_v2; 00110 00111 /** 00112 * @brief Card Specific Data: CSD Register 00113 */ 00114 typedef struct 00115 { 00116 /* Header part */ 00117 uint8_t CSDStruct:2; /* CSD structure */ 00118 uint8_t Reserved1:6; /* Reserved */ 00119 uint8_t TAAC:8; /* Data read access-time 1 */ 00120 uint8_t NSAC:8; /* Data read access-time 2 in CLK cycles */ 00121 uint8_t MaxBusClkFrec:8; /* Max. bus clock frequency */ 00122 uint16_t CardComdClasses:12; /* Card command classes */ 00123 uint8_t RdBlockLen:4; /* Max. read data block length */ 00124 uint8_t PartBlockRead:1; /* Partial blocks for read allowed */ 00125 uint8_t WrBlockMisalign:1; /* Write block misalignment */ 00126 uint8_t RdBlockMisalign:1; /* Read block misalignment */ 00127 uint8_t DSRImpl:1; /* DSR implemented */ 00128 00129 /* v1 or v2 struct */ 00130 union csd_version { 00131 struct_v1 v1; 00132 struct_v2 v2; 00133 } version; 00134 00135 uint8_t EraseSingleBlockEnable:1; /* Erase single block enable */ 00136 uint8_t EraseSectorSize:7; /* Erase group size multiplier */ 00137 uint8_t WrProtectGrSize:7; /* Write protect group size */ 00138 uint8_t WrProtectGrEnable:1; /* Write protect group enable */ 00139 uint8_t Reserved2:2; /* Reserved */ 00140 uint8_t WrSpeedFact:3; /* Write speed factor */ 00141 uint8_t MaxWrBlockLen:4; /* Max. write data block length */ 00142 uint8_t WriteBlockPartial:1; /* Partial blocks for write allowed */ 00143 uint8_t Reserved3:5; /* Reserved */ 00144 uint8_t FileFormatGrouop:1; /* File format group */ 00145 uint8_t CopyFlag:1; /* Copy flag (OTP) */ 00146 uint8_t PermWrProtect:1; /* Permanent write protection */ 00147 uint8_t TempWrProtect:1; /* Temporary write protection */ 00148 uint8_t FileFormat:2; /* File Format */ 00149 uint8_t Reserved4:2; /* Reserved */ 00150 uint8_t crc:7; /* Reserved */ 00151 uint8_t Reserved5:1; /* always 1*/ 00152 00153 } SD_CSD; 00154 00155 /** 00156 * @brief Card Identification Data: CID Register 00157 */ 00158 typedef struct 00159 { 00160 __IO uint8_t ManufacturerID; /* ManufacturerID */ 00161 __IO uint16_t OEM_AppliID; /* OEM/Application ID */ 00162 __IO uint32_t ProdName1; /* Product Name part1 */ 00163 __IO uint8_t ProdName2; /* Product Name part2*/ 00164 __IO uint8_t ProdRev; /* Product Revision */ 00165 __IO uint32_t ProdSN; /* Product Serial Number */ 00166 __IO uint8_t Reserved1; /* Reserved1 */ 00167 __IO uint16_t ManufactDate; /* Manufacturing Date */ 00168 __IO uint8_t CID_CRC; /* CID CRC */ 00169 __IO uint8_t Reserved2; /* always 1 */ 00170 } SD_CID; 00171 00172 /** 00173 * @brief SD Card information 00174 */ 00175 typedef struct 00176 { 00177 SD_CSD Csd; 00178 SD_CID Cid; 00179 uint32_t CardCapacity; /* Card Capacity */ 00180 uint32_t CardBlockSize; /* Card Block Size */ 00181 } SD_CardInfo; 00182 00183 /** 00184 * @} 00185 */ 00186 00187 /** @defgroup STM32091C_EVAL_SD_Exported_Constants Exported Constants 00188 * @{ 00189 */ 00190 00191 /** 00192 * @brief Block Size 00193 */ 00194 #define SD_BLOCK_SIZE 0x200 00195 00196 /** 00197 * @brief SD detection on its memory slot 00198 */ 00199 #define SD_PRESENT ((uint8_t)0x01) 00200 #define SD_NOT_PRESENT ((uint8_t)0x00) 00201 00202 /** 00203 * @} 00204 */ 00205 00206 /** @defgroup STM32091C_EVAL_SD_Exported_Macro Exported Macro 00207 * @{ 00208 */ 00209 00210 /** 00211 * @} 00212 */ 00213 00214 /** @defgroup STM32091C_EVAL_SD_Exported_Functions Exported Functions 00215 * @{ 00216 */ 00217 uint8_t BSP_SD_Init(void); 00218 uint8_t BSP_SD_IsDetected(void); 00219 uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks); 00220 uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks); 00221 uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr); 00222 uint8_t BSP_SD_GetStatus(void); 00223 uint8_t BSP_SD_GetCardInfo(SD_CardInfo *pCardInfo); 00224 00225 /* Link functions for SD Card peripheral */ 00226 void SD_IO_Init(void); 00227 void SD_IO_CSState(uint8_t state); 00228 void SD_IO_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLength); 00229 uint8_t SD_IO_WriteByte(uint8_t Data); 00230 00231 /** 00232 * @} 00233 */ 00234 00235 /** @defgroup STM32091C_EVAL_SD_Private_Functions Private Functions 00236 * @{ 00237 */ 00238 00239 /** 00240 * @} 00241 */ 00242 00243 /** 00244 * @} 00245 */ 00246 00247 /** 00248 * @} 00249 */ 00250 00251 /** 00252 * @} 00253 */ 00254 00255 #ifdef __cplusplus 00256 } 00257 #endif 00258 00259 #endif /* __STM32091C_EVAL_SD_H */ 00260 00261 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 5 2017 09:21:50 for STM32091C_EVAL BSP User Manual by 1.7.6.1