CARME-M4 BSP  V1.5
stm32f4_sdio_sd.h
Go to the documentation of this file.
1 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F4_SDIO_SD_H__
31 #define __STM32F4_SDIO_SD_H__
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f4_sdio_sd_lld.h"
39 
48 typedef enum
49 {
58  SD_RX_OVERRUN = (6),
68  SD_ILLEGAL_CMD = (16),
70  SD_CC_ERROR = (18),
77  SD_ERASE_RESET = (25),
79  SD_INVALID_VOLTRANGE = (27),
80  SD_ADDR_OUT_OF_RANGE = (28),
81  SD_SWITCH_ERROR = (29),
82  SD_SDIO_DISABLED = (30),
83  SD_SDIO_FUNCTION_BUSY = (31),
84  SD_SDIO_FUNCTION_FAILED = (32),
85  SD_SDIO_UNKNOWN_FUNCTION = (33),
86 
91  SD_NOT_CONFIGURED,
92  SD_REQUEST_PENDING,
93  SD_REQUEST_NOT_APPLICABLE,
94  SD_INVALID_PARAMETER,
95  SD_UNSUPPORTED_FEATURE,
96  SD_UNSUPPORTED_HW,
97  SD_ERROR,
98  SD_OK = 0
99 } SD_Error;
100 
104 typedef enum
105 {
106  SD_TRANSFER_OK = 0,
107  SD_TRANSFER_BUSY = 1,
108  SD_TRANSFER_ERROR
110 
114 typedef enum
115 {
116  SD_CARD_READY = ((uint32_t)0x00000001),
117  SD_CARD_IDENTIFICATION = ((uint32_t)0x00000002),
118  SD_CARD_STANDBY = ((uint32_t)0x00000003),
119  SD_CARD_TRANSFER = ((uint32_t)0x00000004),
120  SD_CARD_SENDING = ((uint32_t)0x00000005),
121  SD_CARD_RECEIVING = ((uint32_t)0x00000006),
122  SD_CARD_PROGRAMMING = ((uint32_t)0x00000007),
123  SD_CARD_DISCONNECTED = ((uint32_t)0x00000008),
124  SD_CARD_ERROR = ((uint32_t)0x000000FF)
125 }SDCardState;
126 
127 
131 typedef struct
132 {
133  __IO uint8_t CSDStruct;
134  __IO uint8_t SysSpecVersion;
135  __IO uint8_t Reserved1;
136  __IO uint8_t TAAC;
137  __IO uint8_t NSAC;
138  __IO uint8_t MaxBusClkFrec;
139  __IO uint16_t CardComdClasses;
140  __IO uint8_t RdBlockLen;
141  __IO uint8_t PartBlockRead;
142  __IO uint8_t WrBlockMisalign;
143  __IO uint8_t RdBlockMisalign;
144  __IO uint8_t DSRImpl;
145  __IO uint8_t Reserved2;
146  __IO uint32_t DeviceSize;
147  __IO uint8_t MaxRdCurrentVDDMin;
148  __IO uint8_t MaxRdCurrentVDDMax;
149  __IO uint8_t MaxWrCurrentVDDMin;
150  __IO uint8_t MaxWrCurrentVDDMax;
151  __IO uint8_t DeviceSizeMul;
152  __IO uint8_t EraseGrSize;
153  __IO uint8_t EraseGrMul;
154  __IO uint8_t WrProtectGrSize;
155  __IO uint8_t WrProtectGrEnable;
156  __IO uint8_t ManDeflECC;
157  __IO uint8_t WrSpeedFact;
158  __IO uint8_t MaxWrBlockLen;
159  __IO uint8_t WriteBlockPaPartial;
160  __IO uint8_t Reserved3;
161  __IO uint8_t ContentProtectAppli;
162  __IO uint8_t FileFormatGrouop;
163  __IO uint8_t CopyFlag;
164  __IO uint8_t PermWrProtect;
165  __IO uint8_t TempWrProtect;
166  __IO uint8_t FileFormat;
167  __IO uint8_t ECC;
168  __IO uint8_t CSD_CRC;
169  __IO uint8_t Reserved4;
170 } SD_CSD;
171 
175 typedef struct
176 {
177  __IO uint8_t ManufacturerID;
178  __IO uint16_t OEM_AppliID;
179  __IO uint32_t ProdName1;
180  __IO uint8_t ProdName2;
181  __IO uint8_t ProdRev;
182  __IO uint32_t ProdSN;
183  __IO uint8_t Reserved1;
184  __IO uint16_t ManufactDate;
185  __IO uint8_t CID_CRC;
186  __IO uint8_t Reserved2;
187 } SD_CID;
188 
192 typedef struct
193 {
194  __IO uint8_t DAT_BUS_WIDTH;
195  __IO uint8_t SECURED_MODE;
196  __IO uint16_t SD_CARD_TYPE;
197  __IO uint32_t SIZE_OF_PROTECTED_AREA;
198  __IO uint8_t SPEED_CLASS;
199  __IO uint8_t PERFORMANCE_MOVE;
200  __IO uint8_t AU_SIZE;
201  __IO uint16_t ERASE_SIZE;
202  __IO uint8_t ERASE_TIMEOUT;
203  __IO uint8_t ERASE_OFFSET;
204 } SD_CardStatus;
205 
206 
210 typedef struct
211 {
212  SD_CSD SD_csd;
213  SD_CID SD_cid;
214  uint64_t CardCapacity;
215  uint32_t CardBlockSize;
216  uint16_t RCA;
217  uint8_t CardType;
218 } SD_CardInfo;
219 
223 #define SD_CMD_GO_IDLE_STATE ((uint8_t)0)
224 #define SD_CMD_SEND_OP_COND ((uint8_t)1)
225 #define SD_CMD_ALL_SEND_CID ((uint8_t)2)
226 #define SD_CMD_SET_REL_ADDR ((uint8_t)3)
227 #define SD_CMD_SET_DSR ((uint8_t)4)
228 #define SD_CMD_SDIO_SEN_OP_COND ((uint8_t)5)
229 #define SD_CMD_HS_SWITCH ((uint8_t)6)
230 #define SD_CMD_SEL_DESEL_CARD ((uint8_t)7)
231 #define SD_CMD_HS_SEND_EXT_CSD ((uint8_t)8)
232 #define SD_CMD_SEND_CSD ((uint8_t)9)
233 #define SD_CMD_SEND_CID ((uint8_t)10)
234 #define SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11)
235 #define SD_CMD_STOP_TRANSMISSION ((uint8_t)12)
236 #define SD_CMD_SEND_STATUS ((uint8_t)13)
237 #define SD_CMD_HS_BUSTEST_READ ((uint8_t)14)
238 #define SD_CMD_GO_INACTIVE_STATE ((uint8_t)15)
239 #define SD_CMD_SET_BLOCKLEN ((uint8_t)16)
240 #define SD_CMD_READ_SINGLE_BLOCK ((uint8_t)17)
241 #define SD_CMD_READ_MULT_BLOCK ((uint8_t)18)
242 #define SD_CMD_HS_BUSTEST_WRITE ((uint8_t)19)
243 #define SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20)
244 #define SD_CMD_SET_BLOCK_COUNT ((uint8_t)23)
245 #define SD_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24)
246 #define SD_CMD_WRITE_MULT_BLOCK ((uint8_t)25)
247 #define SD_CMD_PROG_CID ((uint8_t)26)
248 #define SD_CMD_PROG_CSD ((uint8_t)27)
249 #define SD_CMD_SET_WRITE_PROT ((uint8_t)28)
250 #define SD_CMD_CLR_WRITE_PROT ((uint8_t)29)
251 #define SD_CMD_SEND_WRITE_PROT ((uint8_t)30)
252 #define SD_CMD_SD_ERASE_GRP_START ((uint8_t)32)
254 #define SD_CMD_SD_ERASE_GRP_END ((uint8_t)33)
256 #define SD_CMD_ERASE_GRP_START ((uint8_t)35)
259 #define SD_CMD_ERASE_GRP_END ((uint8_t)36)
262 #define SD_CMD_ERASE ((uint8_t)38)
263 #define SD_CMD_FAST_IO ((uint8_t)39)
264 #define SD_CMD_GO_IRQ_STATE ((uint8_t)40)
265 #define SD_CMD_LOCK_UNLOCK ((uint8_t)42)
266 #define SD_CMD_APP_CMD ((uint8_t)55)
267 #define SD_CMD_GEN_CMD ((uint8_t)56)
268 #define SD_CMD_NO_CMD ((uint8_t)64)
269 
274 #define SD_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6)
275 #define SD_CMD_SD_APP_STAUS ((uint8_t)13)
276 #define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22)
277 #define SD_CMD_SD_APP_OP_COND ((uint8_t)41)
278 #define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42)
279 #define SD_CMD_SD_APP_SEND_SCR ((uint8_t)51)
280 #define SD_CMD_SDIO_RW_DIRECT ((uint8_t)52)
281 #define SD_CMD_SDIO_RW_EXTENDED ((uint8_t)53)
287 #define SD_CMD_SD_APP_GET_MKB ((uint8_t)43)
288 #define SD_CMD_SD_APP_GET_MID ((uint8_t)44)
289 #define SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45)
290 #define SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46)
291 #define SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47)
292 #define SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48)
293 #define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18)
294 #define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25)
295 #define SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38)
296 #define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49)
297 #define SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48)
299 /* Uncomment the following line to select the SDIO Data transfer mode */
300 #if !defined (SD_DMA_MODE) && !defined (SD_POLLING_MODE)
301 #define SD_DMA_MODE ((uint32_t)0x00000000)
302 /*#define SD_POLLING_MODE ((uint32_t)0x00000002)*/
303 #endif
304 
308 #define SD_PRESENT ((uint8_t)0x01)
309 #define SD_NOT_PRESENT ((uint8_t)0x00)
310 
314 #define SDIO_STD_CAPACITY_SD_CARD_V1_1 ((uint32_t)0x00000000)
315 #define SDIO_STD_CAPACITY_SD_CARD_V2_0 ((uint32_t)0x00000001)
316 #define SDIO_HIGH_CAPACITY_SD_CARD ((uint32_t)0x00000002)
317 #define SDIO_MULTIMEDIA_CARD ((uint32_t)0x00000003)
318 #define SDIO_SECURE_DIGITAL_IO_CARD ((uint32_t)0x00000004)
319 #define SDIO_HIGH_SPEED_MULTIMEDIA_CARD ((uint32_t)0x00000005)
320 #define SDIO_SECURE_DIGITAL_IO_COMBO_CARD ((uint32_t)0x00000006)
321 #define SDIO_HIGH_CAPACITY_MMC_CARD ((uint32_t)0x00000007)
322 
323 
324 extern SD_CardInfo SDCardInfo;
325 
326 
327 
328 void SD_DeInit(void);
329 SD_Error SD_Init(void);
332 uint8_t SD_Detect(void);
333 SD_Error SD_PowerON(void);
334 SD_Error SD_PowerOFF(void);
338 SD_Error SD_EnableWideBusOperation(uint32_t WideMode);
339 SD_Error SD_SelectDeselect(uint32_t addr);
340 SD_Error SD_ReadBlock(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize);
341 SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
342 SD_Error SD_ReadMultiBlocksFIXED(uint8_t *readbuff, uint32_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks);
343 SD_Error SD_WriteBlock(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize);
344 SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
345 SD_Error SD_WriteMultiBlocksFIXED(uint8_t *writebuff, uint32_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks);
348 SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr);
349 SD_Error SD_SendStatus(uint32_t *pcardstatus);
350 SD_Error SD_SendSDStatus(uint32_t *psdstatus);
352 void SD_ProcessDMAIRQ(void);
355 
364 #ifdef __cplusplus
365 }
366 #endif
367 
368 #endif /* __STM32F4_SDIO_SD_H__ */
369 
370 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
__IO uint8_t RdBlockMisalign
SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
Allows to read blocks from a specified address in a card. The Data transfer can be managed by DMA mod...
SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr)
Allows to erase memory area specified for the given card.
__IO uint8_t RdBlockLen
__IO uint8_t Reserved1
SD_Error SD_Init(void)
Initializes the SD Card and put it into StandBy State (Ready for data transfer).
__IO uint8_t WriteBlockPaPartial
SD Card Status.
__IO uint8_t PermWrProtect
__IO uint8_t MaxBusClkFrec
SD_Error SD_WriteBlock(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize)
Allows to write one block starting from a specified address in a card. The Data transfer can be manag...
__IO uint8_t ProdRev
__IO uint8_t WrProtectGrSize
__IO uint8_t MaxRdCurrentVDDMax
__IO uint8_t TempWrProtect
__IO uint32_t ProdSN
SD_Error SD_WaitWriteOperation(void)
This function waits until the SDIO DMA data transfer is finished. This function should be called afte...
__IO uint8_t Reserved1
__IO uint16_t OEM_AppliID
SD_Error SD_EnableWideBusOperation(uint32_t WideMode)
Enables wide bus opeartion for the requeseted card if supported by card.
SD_Error SD_WaitReadOperation(void)
This function waits until the SDIO DMA data transfer is finished. This function should be called afte...
__IO uint8_t ProdName2
__IO uint8_t FileFormatGrouop
SD_Error SD_PowerOFF(void)
Turns the SDIO output signals off.
uint64_t CardCapacity
__IO uint8_t DSRImpl
__IO uint8_t EraseGrSize
__IO uint8_t ManDeflECC
__IO uint8_t SysSpecVersion
SD_Error SD_PowerON(void)
Enquires cards about their operating voltage and configures clock controls.
SD Card information.
__IO uint8_t EraseGrMul
SD_Error SD_InitializeCards(void)
Intialises all cards or single card as the case may be Card(s) come into standby state.
__IO uint8_t Reserved3
__IO uint8_t MaxWrCurrentVDDMax
__IO uint8_t WrProtectGrEnable
__IO uint8_t MaxRdCurrentVDDMin
uint32_t CardBlockSize
SD_Error SD_ReadMultiBlocksFIXED(uint8_t *readbuff, uint32_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks)
SDCardState SD_GetState(void)
Returns the current card's state.
__IO uint8_t TAAC
SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
Allows to write blocks starting from a specified address in a card. The Data transfer can be managed ...
SD_Error SD_SendStatus(uint32_t *pcardstatus)
Returns the current card's status.
__IO uint32_t DeviceSize
__IO uint16_t CardComdClasses
__IO uint8_t ContentProtectAppli
Standard error defines.
__IO uint8_t WrSpeedFact
__IO uint8_t Reserved4
__IO uint8_t CSD_CRC
SDIO specific error defines.
Card Specific Data: CSD Register.
__IO uint8_t DeviceSizeMul
__IO uint8_t CSDStruct
__IO uint8_t Reserved2
SD_Error
__IO uint8_t Reserved2
__IO uint8_t CID_CRC
SDTransferState SD_GetStatus(void)
Gets the cuurent sd card data transfer status.
Card Identification Data: CID Register.
__IO uint8_t NSAC
SD_Error SD_ReadBlock(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize)
Allows to read one block from a specified address in a card. The Data transfer can be managed by DMA ...
__IO uint8_t ManufacturerID
__IO uint8_t MaxWrBlockLen
SD_Error SD_GetCardStatus(SD_CardStatus *cardstatus)
Enables wide bus opeartion for the requeseted card if supported by card.
__IO uint16_t ManufactDate
SD_Error SD_StopTransfer(void)
Aborts an ongoing data transfer.
__IO uint8_t MaxWrCurrentVDDMin
SDTransferState
SDIO Transfer state.
SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
Returns information about specific card.
SDCardState
SD Card States.
uint8_t SD_Detect(void)
Detect if SD card is correctly plugged in the memory slot.
SD_Error SD_SendSDStatus(uint32_t *psdstatus)
Returns the current SD card's status.
SDTransferState SD_GetTransferState(void)
Gets the cuurent data transfer state.
void SD_DeInit(void)
DeInitializes the SDIO interface.
__IO uint8_t CopyFlag
SD_Error SD_ProcessIRQSrc(void)
Allows to process all the interrupts that are high.
__IO uint8_t ECC
__IO uint8_t FileFormat
__IO uint32_t ProdName1
__IO uint8_t WrBlockMisalign
__IO uint8_t PartBlockRead
void SD_ProcessDMAIRQ(void)
This function waits until the SDIO DMA data transfer is finished.
SD_Error SD_SelectDeselect(uint32_t addr)
Selects od Deselects the corresponding card.