Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Utilities/STM32_EVAL/Common/stm32_eval_spi_sd.h @ 0:c59513fd84fb
Initial commit of STM32 test code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 03 Oct 2011 21:19:15 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c59513fd84fb |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm32_eval_spi_sd.h | |
4 * @author MCD Application Team | |
5 * @version V4.5.0 | |
6 * @date 07-March-2011 | |
7 * @brief This file contains all the functions prototypes for the stm32_eval_spi_sd | |
8 * firmware driver. | |
9 ****************************************************************************** | |
10 * @attention | |
11 * | |
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS | |
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE | |
14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY | |
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING | |
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE | |
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. | |
18 * | |
19 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> | |
20 ****************************************************************************** | |
21 */ | |
22 | |
23 /* Define to prevent recursive inclusion -------------------------------------*/ | |
24 #ifndef __STM32_EVAL_SPI_SD_H | |
25 #define __STM32_EVAL_SPI_SD_H | |
26 | |
27 #ifdef __cplusplus | |
28 extern "C" { | |
29 #endif | |
30 | |
31 /* Includes ------------------------------------------------------------------*/ | |
32 #include "stm32_eval.h" | |
33 | |
34 /** @addtogroup Utilities | |
35 * @{ | |
36 */ | |
37 | |
38 /** @addtogroup STM32_EVAL | |
39 * @{ | |
40 */ | |
41 | |
42 /** @addtogroup Common | |
43 * @{ | |
44 */ | |
45 | |
46 /** @addtogroup STM32_EVAL_SPI_SD | |
47 * @{ | |
48 */ | |
49 | |
50 /** @defgroup STM32_EVAL_SPI_SD_Exported_Types | |
51 * @{ | |
52 */ | |
53 | |
54 typedef enum | |
55 { | |
56 /** | |
57 * @brief SD reponses and error flags | |
58 */ | |
59 SD_RESPONSE_NO_ERROR = (0x00), | |
60 SD_IN_IDLE_STATE = (0x01), | |
61 SD_ERASE_RESET = (0x02), | |
62 SD_ILLEGAL_COMMAND = (0x04), | |
63 SD_COM_CRC_ERROR = (0x08), | |
64 SD_ERASE_SEQUENCE_ERROR = (0x10), | |
65 SD_ADDRESS_ERROR = (0x20), | |
66 SD_PARAMETER_ERROR = (0x40), | |
67 SD_RESPONSE_FAILURE = (0xFF), | |
68 | |
69 /** | |
70 * @brief Data response error | |
71 */ | |
72 SD_DATA_OK = (0x05), | |
73 SD_DATA_CRC_ERROR = (0x0B), | |
74 SD_DATA_WRITE_ERROR = (0x0D), | |
75 SD_DATA_OTHER_ERROR = (0xFF) | |
76 } SD_Error; | |
77 | |
78 /** | |
79 * @brief Card Specific Data: CSD Register | |
80 */ | |
81 typedef struct | |
82 { | |
83 __IO uint8_t CSDStruct; /*!< CSD structure */ | |
84 __IO uint8_t SysSpecVersion; /*!< System specification version */ | |
85 __IO uint8_t Reserved1; /*!< Reserved */ | |
86 __IO uint8_t TAAC; /*!< Data read access-time 1 */ | |
87 __IO uint8_t NSAC; /*!< Data read access-time 2 in CLK cycles */ | |
88 __IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */ | |
89 __IO uint16_t CardComdClasses; /*!< Card command classes */ | |
90 __IO uint8_t RdBlockLen; /*!< Max. read data block length */ | |
91 __IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */ | |
92 __IO uint8_t WrBlockMisalign; /*!< Write block misalignment */ | |
93 __IO uint8_t RdBlockMisalign; /*!< Read block misalignment */ | |
94 __IO uint8_t DSRImpl; /*!< DSR implemented */ | |
95 __IO uint8_t Reserved2; /*!< Reserved */ | |
96 __IO uint32_t DeviceSize; /*!< Device Size */ | |
97 __IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */ | |
98 __IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */ | |
99 __IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */ | |
100 __IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */ | |
101 __IO uint8_t DeviceSizeMul; /*!< Device size multiplier */ | |
102 __IO uint8_t EraseGrSize; /*!< Erase group size */ | |
103 __IO uint8_t EraseGrMul; /*!< Erase group size multiplier */ | |
104 __IO uint8_t WrProtectGrSize; /*!< Write protect group size */ | |
105 __IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */ | |
106 __IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */ | |
107 __IO uint8_t WrSpeedFact; /*!< Write speed factor */ | |
108 __IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */ | |
109 __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */ | |
110 __IO uint8_t Reserved3; /*!< Reserded */ | |
111 __IO uint8_t ContentProtectAppli; /*!< Content protection application */ | |
112 __IO uint8_t FileFormatGrouop; /*!< File format group */ | |
113 __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */ | |
114 __IO uint8_t PermWrProtect; /*!< Permanent write protection */ | |
115 __IO uint8_t TempWrProtect; /*!< Temporary write protection */ | |
116 __IO uint8_t FileFormat; /*!< File Format */ | |
117 __IO uint8_t ECC; /*!< ECC code */ | |
118 __IO uint8_t CSD_CRC; /*!< CSD CRC */ | |
119 __IO uint8_t Reserved4; /*!< always 1*/ | |
120 } SD_CSD; | |
121 | |
122 /** | |
123 * @brief Card Identification Data: CID Register | |
124 */ | |
125 typedef struct | |
126 { | |
127 __IO uint8_t ManufacturerID; /*!< ManufacturerID */ | |
128 __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */ | |
129 __IO uint32_t ProdName1; /*!< Product Name part1 */ | |
130 __IO uint8_t ProdName2; /*!< Product Name part2*/ | |
131 __IO uint8_t ProdRev; /*!< Product Revision */ | |
132 __IO uint32_t ProdSN; /*!< Product Serial Number */ | |
133 __IO uint8_t Reserved1; /*!< Reserved1 */ | |
134 __IO uint16_t ManufactDate; /*!< Manufacturing Date */ | |
135 __IO uint8_t CID_CRC; /*!< CID CRC */ | |
136 __IO uint8_t Reserved2; /*!< always 1 */ | |
137 } SD_CID; | |
138 | |
139 /** | |
140 * @brief SD Card information | |
141 */ | |
142 typedef struct | |
143 { | |
144 SD_CSD SD_csd; | |
145 SD_CID SD_cid; | |
146 uint32_t CardCapacity; /*!< Card Capacity */ | |
147 uint32_t CardBlockSize; /*!< Card Block Size */ | |
148 } SD_CardInfo; | |
149 | |
150 /** | |
151 * @} | |
152 */ | |
153 | |
154 /** @defgroup STM32_EVAL_SPI_SD_Exported_Constants | |
155 * @{ | |
156 */ | |
157 | |
158 /** | |
159 * @brief Block Size | |
160 */ | |
161 #define SD_BLOCK_SIZE 0x200 | |
162 | |
163 /** | |
164 * @brief Dummy byte | |
165 */ | |
166 #define SD_DUMMY_BYTE 0xFF | |
167 | |
168 /** | |
169 * @brief Start Data tokens: | |
170 * Tokens (necessary because at nop/idle (and CS active) only 0xff is | |
171 * on the data/command line) | |
172 */ | |
173 #define SD_START_DATA_SINGLE_BLOCK_READ 0xFE /*!< Data token start byte, Start Single Block Read */ | |
174 #define SD_START_DATA_MULTIPLE_BLOCK_READ 0xFE /*!< Data token start byte, Start Multiple Block Read */ | |
175 #define SD_START_DATA_SINGLE_BLOCK_WRITE 0xFE /*!< Data token start byte, Start Single Block Write */ | |
176 #define SD_START_DATA_MULTIPLE_BLOCK_WRITE 0xFD /*!< Data token start byte, Start Multiple Block Write */ | |
177 #define SD_STOP_DATA_MULTIPLE_BLOCK_WRITE 0xFD /*!< Data toke stop byte, Stop Multiple Block Write */ | |
178 | |
179 /** | |
180 * @brief SD detection on its memory slot | |
181 */ | |
182 #define SD_PRESENT ((uint8_t)0x01) | |
183 #define SD_NOT_PRESENT ((uint8_t)0x00) | |
184 | |
185 | |
186 /** | |
187 * @brief Commands: CMDxx = CMD-number | 0x40 | |
188 */ | |
189 #define SD_CMD_GO_IDLE_STATE 0 /*!< CMD0 = 0x40 */ | |
190 #define SD_CMD_SEND_OP_COND 1 /*!< CMD1 = 0x41 */ | |
191 #define SD_CMD_SEND_CSD 9 /*!< CMD9 = 0x49 */ | |
192 #define SD_CMD_SEND_CID 10 /*!< CMD10 = 0x4A */ | |
193 #define SD_CMD_STOP_TRANSMISSION 12 /*!< CMD12 = 0x4C */ | |
194 #define SD_CMD_SEND_STATUS 13 /*!< CMD13 = 0x4D */ | |
195 #define SD_CMD_SET_BLOCKLEN 16 /*!< CMD16 = 0x50 */ | |
196 #define SD_CMD_READ_SINGLE_BLOCK 17 /*!< CMD17 = 0x51 */ | |
197 #define SD_CMD_READ_MULT_BLOCK 18 /*!< CMD18 = 0x52 */ | |
198 #define SD_CMD_SET_BLOCK_COUNT 23 /*!< CMD23 = 0x57 */ | |
199 #define SD_CMD_WRITE_SINGLE_BLOCK 24 /*!< CMD24 = 0x58 */ | |
200 #define SD_CMD_WRITE_MULT_BLOCK 25 /*!< CMD25 = 0x59 */ | |
201 #define SD_CMD_PROG_CSD 27 /*!< CMD27 = 0x5B */ | |
202 #define SD_CMD_SET_WRITE_PROT 28 /*!< CMD28 = 0x5C */ | |
203 #define SD_CMD_CLR_WRITE_PROT 29 /*!< CMD29 = 0x5D */ | |
204 #define SD_CMD_SEND_WRITE_PROT 30 /*!< CMD30 = 0x5E */ | |
205 #define SD_CMD_SD_ERASE_GRP_START 32 /*!< CMD32 = 0x60 */ | |
206 #define SD_CMD_SD_ERASE_GRP_END 33 /*!< CMD33 = 0x61 */ | |
207 #define SD_CMD_UNTAG_SECTOR 34 /*!< CMD34 = 0x62 */ | |
208 #define SD_CMD_ERASE_GRP_START 35 /*!< CMD35 = 0x63 */ | |
209 #define SD_CMD_ERASE_GRP_END 36 /*!< CMD36 = 0x64 */ | |
210 #define SD_CMD_UNTAG_ERASE_GROUP 37 /*!< CMD37 = 0x65 */ | |
211 #define SD_CMD_ERASE 38 /*!< CMD38 = 0x66 */ | |
212 | |
213 /** | |
214 * @} | |
215 */ | |
216 | |
217 /** @defgroup STM32_EVAL_SPI_SD_Exported_Macros | |
218 * @{ | |
219 */ | |
220 /** | |
221 * @brief Select SD Card: ChipSelect pin low | |
222 */ | |
223 #define SD_CS_LOW() GPIO_ResetBits(SD_CS_GPIO_PORT, SD_CS_PIN) | |
224 /** | |
225 * @brief Deselect SD Card: ChipSelect pin high | |
226 */ | |
227 #define SD_CS_HIGH() GPIO_SetBits(SD_CS_GPIO_PORT, SD_CS_PIN) | |
228 /** | |
229 * @} | |
230 */ | |
231 | |
232 /** @defgroup STM32_EVAL_SPI_SD_Exported_Functions | |
233 * @{ | |
234 */ | |
235 void SD_DeInit(void); | |
236 SD_Error SD_Init(void); | |
237 uint8_t SD_Detect(void); | |
238 SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo); | |
239 SD_Error SD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize); | |
240 SD_Error SD_ReadMultiBlocks(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks); | |
241 SD_Error SD_WriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize); | |
242 SD_Error SD_WriteMultiBlocks(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks); | |
243 SD_Error SD_GetCSDRegister(SD_CSD* SD_csd); | |
244 SD_Error SD_GetCIDRegister(SD_CID* SD_cid); | |
245 | |
246 void SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc); | |
247 SD_Error SD_GetResponse(uint8_t Response); | |
248 uint8_t SD_GetDataResponse(void); | |
249 SD_Error SD_GoIdleState(void); | |
250 uint16_t SD_GetStatus(void); | |
251 | |
252 uint8_t SD_WriteByte(uint8_t byte); | |
253 uint8_t SD_ReadByte(void); | |
254 | |
255 #ifdef __cplusplus | |
256 } | |
257 #endif | |
258 | |
259 #endif /* __STM32_EVAL_SPI_SD_H */ | |
260 /** | |
261 * @} | |
262 */ | |
263 | |
264 /** | |
265 * @} | |
266 */ | |
267 | |
268 /** | |
269 * @} | |
270 */ | |
271 | |
272 /** | |
273 * @} | |
274 */ | |
275 | |
276 /** | |
277 * @} | |
278 */ | |
279 | |
280 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |