2 ******************************************************************************
\r
3 * @file stm32l1xx_sdio.c
\r
4 * @author MCD Application Team
\r
6 * @date 05-March-2012
\r
7 * @brief This file provides firmware functions to manage the following
\r
8 * functionalities of the SDIO peripheral:
\r
10 * + Interrupts and flags management
\r
13 ==============================================================================
\r
14 ##### How to use this driver #####
\r
15 ==============================================================================
\r
17 (#) The SDIO clock (SDIOCLK = 48 MHz) is coming from a specific output of PLL
\r
18 (PLLVCO) througth a fixed divider by 2.
\r
19 Before to start working with SDIO peripheral make sure that the PLLVCO is
\r
20 well configured to 96MHz.
\r
21 The SDIO peripheral uses two clock signals:
\r
22 (++) SDIO adapter clock (SDIOCLK = 48 MHz).
\r
23 (++) APB2 bus clock (PCLK2).
\r
24 PCLK2 and SDIO_CK clock frequencies must respect the following
\r
25 condition: Frequenc(PCLK2) >= (3 / 8 x Frequency(SDIO_CK)).
\r
26 (#) Enable peripheral clock using
\r
27 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO, ENABLE).
\r
28 (#) According to the SDIO mode, enable the GPIO clocks using
\r
29 RCC_AHBPeriphClockCmd() function.
\r
30 The I/O can be one of the following configurations:
\r
31 (++) 1-bit data length: SDIO_CMD, SDIO_CK and D0.
\r
32 (++) 4-bit data length: SDIO_CMD, SDIO_CK and D[3:0].
\r
33 (++) 8-bit data length: SDIO_CMD, SDIO_CK and D[7:0].
\r
35 (#) Peripheral's alternate function:
\r
36 (++) Connect the pin to the desired peripherals' Alternate
\r
37 Function (AF) using GPIO_PinAFConfig() function.
\r
38 (++) Configure the desired pin in alternate function by:
\r
39 GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF.
\r
40 (++) Select the type, pull-up/pull-down and output speed via
\r
41 GPIO_PuPd, GPIO_OType and GPIO_Speed members.
\r
42 (++) Call GPIO_Init() function.
\r
44 (#) Program the Clock Edge, Clock Bypass, Clock Power Save, Bus Wide,
\r
45 hardware, flow control and the Clock Divider using the SDIO_Init()
\r
47 (#) Enable the Power ON State using the SDIO_SetPowerState(SDIO_PowerState_ON)
\r
49 (#) Enable the clock using the SDIO_ClockCmd() function.
\r
50 (#) Enable the NVIC and the corresponding interrupt using the function
\r
51 SDIO_ITConfig() if you need to use interrupt mode.
\r
52 (#) When using the DMA mode
\r
53 (++) Configure the DMA using DMA_Init() function.
\r
54 (++) Active the needed channel Request using SDIO_DMACmd() function.
\r
55 (#) Enable the DMA using the DMA_Cmd() function, when using DMA mode.
\r
56 (#) To control the CPSM (Command Path State Machine) and send commands to the
\r
57 card use the SDIO_SendCommand(), SDIO_GetCommandResponse() and
\r
58 SDIO_GetResponse() functions. First, user has to fill the command
\r
59 structure (pointer to SDIO_CmdInitTypeDef) according to the selected
\r
60 command to be sent. The parameters that should be filled are:
\r
61 (++) Command Argument.
\r
63 (++) Command Response type.
\r
65 (++) CPSM Status (Enable or Disable).
\r
66 To check if the command is well received, read the SDIO_CMDRESP register
\r
67 using the SDIO_GetCommandResponse(). The SDIO responses registers
\r
68 (SDIO_RESP1 to SDIO_RESP2), use the SDIO_GetResponse() function.
\r
69 (#) To control the DPSM (Data Path State Machine) and send/receive
\r
70 data to/from the card use the SDIO_DataConfig(), SDIO_GetDataCounter(),
\r
71 SDIO_ReadData(), SDIO_WriteData() and SDIO_GetFIFOCount() functions.
\r
73 *** Read Operations ***
\r
74 -----------------------
\r
76 (#) First, user has to fill the data structure (pointer to
\r
77 SDIO_DataInitTypeDef) according to the selected data type to be received.
\r
78 The parameters that should be filled are:
\r
81 (++) Data Block size.
\r
82 (++) Data Transfer direction: should be from card (To SDIO).
\r
83 (++) Data Transfer mode.
\r
84 (++) DPSM Status (Enable or Disable).
\r
85 (#) Configure the SDIO resources to receive the data from the card
\r
86 according to selected transfer mode (Refer to Step 8, 9 and 10).
\r
87 (#) Send the selected Read command (refer to step 11).
\r
88 (#) Use the SDIO flags/interrupts to check the transfer status.
\r
90 *** Write Operations ***
\r
91 ------------------------
\r
93 (#) First, user has to fill the data structure (pointer to
\r
94 SDIO_DataInitTypeDef) according to the selected data type to be received.
\r
95 The parameters that should be filled are:
\r
98 (++) Data Block size.
\r
99 (++) Data Transfer direction: should be to card (To CARD).
\r
100 (++) Data Transfer mode.
\r
101 (++) DPSM Status (Enable or Disable).
\r
102 (#) Configure the SDIO resources to send the data to the card
\r
103 according to selected transfer mode (Refer to Step 8, 9 and 10).
\r
104 (#) Send the selected Write command (refer to step 11).
\r
105 (#) Use the SDIO flags/interrupts to check the transfer status.
\r
109 ******************************************************************************
\r
112 * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
\r
114 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
\r
115 * You may not use this file except in compliance with the License.
\r
116 * You may obtain a copy of the License at:
\r
118 * http://www.st.com/software_license_agreement_liberty_v2
\r
120 * Unless required by applicable law or agreed to in writing, software
\r
121 * distributed under the License is distributed on an "AS IS" BASIS,
\r
122 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
123 * See the License for the specific language governing permissions and
\r
124 * limitations under the License.
\r
126 ******************************************************************************
\r
129 /* Includes ------------------------------------------------------------------*/
\r
130 #include "stm32l1xx_sdio.h"
\r
131 #include "stm32l1xx_rcc.h"
\r
133 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
137 /** @defgroup SDIO
\r
138 * @brief SDIO driver modules
\r
142 /* Private typedef -----------------------------------------------------------*/
\r
143 /* Private define ------------------------------------------------------------*/
\r
145 /* ------------ SDIO registers bit address in the alias region ----------- */
\r
146 #define SDIO_OFFSET (SDIO_BASE - PERIPH_BASE)
\r
148 /* --- CLKCR Register ---*/
\r
150 /* Alias word address of CLKEN bit */
\r
151 #define CLKCR_OFFSET (SDIO_OFFSET + 0x04)
\r
152 #define CLKEN_BitNumber 0x08
\r
153 #define CLKCR_CLKEN_BB (PERIPH_BB_BASE + (CLKCR_OFFSET * 32) + (CLKEN_BitNumber * 4))
\r
155 /* --- CMD Register ---*/
\r
157 /* Alias word address of SDIOSUSPEND bit */
\r
158 #define CMD_OFFSET (SDIO_OFFSET + 0x0C)
\r
159 #define SDIOSUSPEND_BitNumber 0x0B
\r
160 #define CMD_SDIOSUSPEND_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (SDIOSUSPEND_BitNumber * 4))
\r
162 /* Alias word address of ENCMDCOMPL bit */
\r
163 #define ENCMDCOMPL_BitNumber 0x0C
\r
164 #define CMD_ENCMDCOMPL_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (ENCMDCOMPL_BitNumber * 4))
\r
166 /* Alias word address of NIEN bit */
\r
167 #define NIEN_BitNumber 0x0D
\r
168 #define CMD_NIEN_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (NIEN_BitNumber * 4))
\r
170 /* Alias word address of ATACMD bit */
\r
171 #define ATACMD_BitNumber 0x0E
\r
172 #define CMD_ATACMD_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (ATACMD_BitNumber * 4))
\r
174 /* --- DCTRL Register ---*/
\r
176 /* Alias word address of DMAEN bit */
\r
177 #define DCTRL_OFFSET (SDIO_OFFSET + 0x2C)
\r
178 #define DMAEN_BitNumber 0x03
\r
179 #define DCTRL_DMAEN_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (DMAEN_BitNumber * 4))
\r
181 /* Alias word address of RWSTART bit */
\r
182 #define RWSTART_BitNumber 0x08
\r
183 #define DCTRL_RWSTART_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWSTART_BitNumber * 4))
\r
185 /* Alias word address of RWSTOP bit */
\r
186 #define RWSTOP_BitNumber 0x09
\r
187 #define DCTRL_RWSTOP_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWSTOP_BitNumber * 4))
\r
189 /* Alias word address of RWMOD bit */
\r
190 #define RWMOD_BitNumber 0x0A
\r
191 #define DCTRL_RWMOD_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWMOD_BitNumber * 4))
\r
193 /* Alias word address of SDIOEN bit */
\r
194 #define SDIOEN_BitNumber 0x0B
\r
195 #define DCTRL_SDIOEN_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (SDIOEN_BitNumber * 4))
\r
197 /* ---------------------- SDIO registers bit mask ------------------------ */
\r
199 /* --- CLKCR Register ---*/
\r
201 /* CLKCR register clear mask */
\r
202 #define CLKCR_CLEAR_MASK ((uint32_t)0xFFFF8100)
\r
204 /* --- PWRCTRL Register ---*/
\r
206 /* SDIO PWRCTRL Mask */
\r
207 #define PWR_PWRCTRL_MASK ((uint32_t)0xFFFFFFFC)
\r
209 /* --- DCTRL Register ---*/
\r
211 /* SDIO DCTRL Clear Mask */
\r
212 #define DCTRL_CLEAR_MASK ((uint32_t)0xFFFFFF08)
\r
214 /* --- CMD Register ---*/
\r
216 /* CMD Register clear mask */
\r
217 #define CMD_CLEAR_MASK ((uint32_t)0xFFFFF800)
\r
219 /* SDIO RESP Registers Address */
\r
220 #define SDIO_RESP_ADDR ((uint32_t)(SDIO_BASE + 0x14))
\r
222 /* Private macro -------------------------------------------------------------*/
\r
223 /* Private variables ---------------------------------------------------------*/
\r
224 /* Private function prototypes -----------------------------------------------*/
\r
225 /* Private functions ---------------------------------------------------------*/
\r
227 /** @defgroup SDIO_Private_Functions
\r
231 /** @defgroup SDIO_Group1 Initialization and Configuration functions
\r
232 * @brief Initialization and Configuration functions
\r
235 ==============================================================================
\r
236 ##### Initialization and Configuration functions #####
\r
237 ==============================================================================
\r
244 * @brief Deinitializes the SDIO peripheral registers to their default reset values.
\r
248 void SDIO_DeInit(void)
\r
250 RCC_APB2PeriphResetCmd(RCC_APB2Periph_SDIO, ENABLE);
\r
251 RCC_APB2PeriphResetCmd(RCC_APB2Periph_SDIO, DISABLE);
\r
255 * @brief Initializes the SDIO peripheral according to the specified
\r
256 * parameters in the SDIO_InitStruct.
\r
257 * @param SDIO_InitStruct : pointer to a SDIO_InitTypeDef structure
\r
258 * that contains the configuration information for the SDIO peripheral.
\r
261 void SDIO_Init(SDIO_InitTypeDef* SDIO_InitStruct)
\r
263 uint32_t tmpreg = 0;
\r
265 /* Check the parameters */
\r
266 assert_param(IS_SDIO_CLOCK_EDGE(SDIO_InitStruct->SDIO_ClockEdge));
\r
267 assert_param(IS_SDIO_CLOCK_BYPASS(SDIO_InitStruct->SDIO_ClockBypass));
\r
268 assert_param(IS_SDIO_CLOCK_POWER_SAVE(SDIO_InitStruct->SDIO_ClockPowerSave));
\r
269 assert_param(IS_SDIO_BUS_WIDE(SDIO_InitStruct->SDIO_BusWide));
\r
270 assert_param(IS_SDIO_HARDWARE_FLOW_CONTROL(SDIO_InitStruct->SDIO_HardwareFlowControl));
\r
272 /*---------------------------- SDIO CLKCR Configuration ------------------------*/
\r
273 /* Get the SDIO CLKCR value */
\r
274 tmpreg = SDIO->CLKCR;
\r
276 /* Clear CLKDIV, PWRSAV, BYPASS, WIDBUS, NEGEDGE, HWFC_EN bits */
\r
277 tmpreg &= CLKCR_CLEAR_MASK;
\r
279 /* Set CLKDIV bits according to SDIO_ClockDiv value */
\r
280 /* Set PWRSAV bit according to SDIO_ClockPowerSave value */
\r
281 /* Set BYPASS bit according to SDIO_ClockBypass value */
\r
282 /* Set WIDBUS bits according to SDIO_BusWide value */
\r
283 /* Set NEGEDGE bits according to SDIO_ClockEdge value */
\r
284 /* Set HWFC_EN bits according to SDIO_HardwareFlowControl value */
\r
285 tmpreg |= (SDIO_InitStruct->SDIO_ClockDiv | SDIO_InitStruct->SDIO_ClockPowerSave |
\r
286 SDIO_InitStruct->SDIO_ClockBypass | SDIO_InitStruct->SDIO_BusWide |
\r
287 SDIO_InitStruct->SDIO_ClockEdge | SDIO_InitStruct->SDIO_HardwareFlowControl);
\r
289 /* Write to SDIO CLKCR */
\r
290 SDIO->CLKCR = tmpreg;
\r
294 * @brief Fills each SDIO_InitStruct member with its default value.
\r
295 * @param SDIO_InitStruct: pointer to an SDIO_InitTypeDef structure which
\r
296 * will be initialized.
\r
299 void SDIO_StructInit(SDIO_InitTypeDef* SDIO_InitStruct)
\r
301 /* SDIO_InitStruct members default value */
\r
302 SDIO_InitStruct->SDIO_ClockDiv = 0x00;
\r
303 SDIO_InitStruct->SDIO_ClockEdge = SDIO_ClockEdge_Rising;
\r
304 SDIO_InitStruct->SDIO_ClockBypass = SDIO_ClockBypass_Disable;
\r
305 SDIO_InitStruct->SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
\r
306 SDIO_InitStruct->SDIO_BusWide = SDIO_BusWide_1b;
\r
307 SDIO_InitStruct->SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
\r
311 * @brief Enables or disables the SDIO Clock.
\r
312 * @param NewState: new state of the SDIO Clock. This parameter can be: ENABLE or DISABLE.
\r
315 void SDIO_ClockCmd(FunctionalState NewState)
\r
317 /* Check the parameters */
\r
318 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
320 *(__IO uint32_t *) CLKCR_CLKEN_BB = (uint32_t)NewState;
\r
324 * @brief Sets the power status of the controller.
\r
325 * @param SDIO_PowerState: new state of the Power state.
\r
326 * This parameter can be one of the following values:
\r
327 * @arg SDIO_PowerState_OFF: SDIO Power OFF.
\r
328 * @arg SDIO_PowerState_ON: SDIO Power ON.
\r
331 void SDIO_SetPowerState(uint32_t SDIO_PowerState)
\r
333 /* Check the parameters */
\r
334 assert_param(IS_SDIO_POWER_STATE(SDIO_PowerState));
\r
336 SDIO->POWER = SDIO_PowerState;
\r
340 * @brief Gets the power status of the controller.
\r
342 * @retval Power status of the controller. The returned value can
\r
343 * be one of the following:
\r
344 * - 0x00: Power OFF
\r
346 * - 0x03: Power ON
\r
348 uint32_t SDIO_GetPowerState(void)
\r
350 return (SDIO->POWER & (~PWR_PWRCTRL_MASK));
\r
357 /** @defgroup SDIO_Group2 DMA transfers management functions
\r
358 * @brief DMA transfers management functions
\r
361 ==============================================================================
\r
362 ##### DMA transfers management functions #####
\r
363 ==============================================================================
\r
364 [..] This section provide functions allowing to program SDIO DMA transfer.
\r
371 * @brief Enables or disables the SDIO DMA request.
\r
372 * @param NewState: new state of the selected SDIO DMA request.
\r
373 * This parameter can be: ENABLE or DISABLE.
\r
376 void SDIO_DMACmd(FunctionalState NewState)
\r
378 /* Check the parameters */
\r
379 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
381 *(__IO uint32_t *) DCTRL_DMAEN_BB = (uint32_t)NewState;
\r
388 /** @defgroup SDIO_Group3 Command path state machine (CPSM) management functions
\r
389 * @brief Command path state machine (CPSM) management functions
\r
392 ==============================================================================
\r
393 ##### Command path state machine (CPSM) management functions #####
\r
394 ==============================================================================
\r
395 [..] This section provide functions allowing to program and read the Command
\r
396 path state machine (CPSM).
\r
403 * @brief Initializes the SDIO Command according to the specified
\r
404 * parameters in the SDIO_CmdInitStruct and send the command.
\r
405 * @param SDIO_CmdInitStruct : pointer to a SDIO_CmdInitTypeDef
\r
406 * structure that contains the configuration information for the SDIO command.
\r
409 void SDIO_SendCommand(SDIO_CmdInitTypeDef *SDIO_CmdInitStruct)
\r
411 uint32_t tmpreg = 0;
\r
413 /* Check the parameters */
\r
414 assert_param(IS_SDIO_CMD_INDEX(SDIO_CmdInitStruct->SDIO_CmdIndex));
\r
415 assert_param(IS_SDIO_RESPONSE(SDIO_CmdInitStruct->SDIO_Response));
\r
416 assert_param(IS_SDIO_WAIT(SDIO_CmdInitStruct->SDIO_Wait));
\r
417 assert_param(IS_SDIO_CPSM(SDIO_CmdInitStruct->SDIO_CPSM));
\r
419 /*---------------------------- SDIO ARG Configuration ------------------------*/
\r
420 /* Set the SDIO Argument value */
\r
421 SDIO->ARG = SDIO_CmdInitStruct->SDIO_Argument;
\r
423 /*---------------------------- SDIO CMD Configuration ------------------------*/
\r
424 /* Get the SDIO CMD value */
\r
425 tmpreg = SDIO->CMD;
\r
426 /* Clear CMDINDEX, WAITRESP, WAITINT, WAITPEND, CPSMEN bits */
\r
427 tmpreg &= CMD_CLEAR_MASK;
\r
428 /* Set CMDINDEX bits according to SDIO_CmdIndex value */
\r
429 /* Set WAITRESP bits according to SDIO_Response value */
\r
430 /* Set WAITINT and WAITPEND bits according to SDIO_Wait value */
\r
431 /* Set CPSMEN bits according to SDIO_CPSM value */
\r
432 tmpreg |= (uint32_t)SDIO_CmdInitStruct->SDIO_CmdIndex | SDIO_CmdInitStruct->SDIO_Response
\r
433 | SDIO_CmdInitStruct->SDIO_Wait | SDIO_CmdInitStruct->SDIO_CPSM;
\r
435 /* Write to SDIO CMD */
\r
436 SDIO->CMD = tmpreg;
\r
440 * @brief Fills each SDIO_CmdInitStruct member with its default value.
\r
441 * @param SDIO_CmdInitStruct: pointer to an SDIO_CmdInitTypeDef
\r
442 * structure which will be initialized.
\r
445 void SDIO_CmdStructInit(SDIO_CmdInitTypeDef* SDIO_CmdInitStruct)
\r
447 /* SDIO_CmdInitStruct members default value */
\r
448 SDIO_CmdInitStruct->SDIO_Argument = 0x00;
\r
449 SDIO_CmdInitStruct->SDIO_CmdIndex = 0x00;
\r
450 SDIO_CmdInitStruct->SDIO_Response = SDIO_Response_No;
\r
451 SDIO_CmdInitStruct->SDIO_Wait = SDIO_Wait_No;
\r
452 SDIO_CmdInitStruct->SDIO_CPSM = SDIO_CPSM_Disable;
\r
456 * @brief Returns command index of last command for which response received.
\r
458 * @retval Returns the command index of the last command response received.
\r
460 uint8_t SDIO_GetCommandResponse(void)
\r
462 return (uint8_t)(SDIO->RESPCMD);
\r
466 * @brief Returns response received from the card for the last command.
\r
467 * @param SDIO_RESP: Specifies the SDIO response register.
\r
468 * This parameter can be one of the following values:
\r
469 * @arg SDIO_RESP1: Response Register 1.
\r
470 * @arg SDIO_RESP2: Response Register 2.
\r
471 * @arg SDIO_RESP3: Response Register 3.
\r
472 * @arg SDIO_RESP4: Response Register 4.
\r
473 * @retval The Corresponding response register value.
\r
475 uint32_t SDIO_GetResponse(uint32_t SDIO_RESP)
\r
477 __IO uint32_t tmp = 0;
\r
479 /* Check the parameters */
\r
480 assert_param(IS_SDIO_RESP(SDIO_RESP));
\r
482 tmp = SDIO_RESP_ADDR + SDIO_RESP;
\r
484 return (*(__IO uint32_t *) tmp);
\r
491 /** @defgroup SDIO_Group4 Data path state machine (DPSM) management functions
\r
492 * @brief Data path state machine (DPSM) management functions
\r
495 ==============================================================================
\r
496 ##### Data path state machine (DPSM) management functions #####
\r
497 ==============================================================================
\r
498 [..] This section provide functions allowing to program and read the Data path
\r
499 state machine (DPSM).
\r
506 * @brief Initializes the SDIO data path according to the specified
\r
507 * parameters in the SDIO_DataInitStruct.
\r
508 * @param SDIO_DataInitStruct : pointer to a SDIO_DataInitTypeDef structure that
\r
509 * contains the configuration information for the SDIO command.
\r
512 void SDIO_DataConfig(SDIO_DataInitTypeDef* SDIO_DataInitStruct)
\r
514 uint32_t tmpreg = 0;
\r
516 /* Check the parameters */
\r
517 assert_param(IS_SDIO_DATA_LENGTH(SDIO_DataInitStruct->SDIO_DataLength));
\r
518 assert_param(IS_SDIO_BLOCK_SIZE(SDIO_DataInitStruct->SDIO_DataBlockSize));
\r
519 assert_param(IS_SDIO_TRANSFER_DIR(SDIO_DataInitStruct->SDIO_TransferDir));
\r
520 assert_param(IS_SDIO_TRANSFER_MODE(SDIO_DataInitStruct->SDIO_TransferMode));
\r
521 assert_param(IS_SDIO_DPSM(SDIO_DataInitStruct->SDIO_DPSM));
\r
523 /*---------------------------- SDIO DTIMER Configuration ---------------------*/
\r
524 /* Set the SDIO Data TimeOut value */
\r
525 SDIO->DTIMER = SDIO_DataInitStruct->SDIO_DataTimeOut;
\r
527 /*---------------------------- SDIO DLEN Configuration -----------------------*/
\r
528 /* Set the SDIO DataLength value */
\r
529 SDIO->DLEN = SDIO_DataInitStruct->SDIO_DataLength;
\r
531 /*---------------------------- SDIO DCTRL Configuration ----------------------*/
\r
532 /* Get the SDIO DCTRL value */
\r
533 tmpreg = SDIO->DCTRL;
\r
534 /* Clear DEN, DTMODE, DTDIR and DBCKSIZE bits */
\r
535 tmpreg &= DCTRL_CLEAR_MASK;
\r
536 /* Set DEN bit according to SDIO_DPSM value */
\r
537 /* Set DTMODE bit according to SDIO_TransferMode value */
\r
538 /* Set DTDIR bit according to SDIO_TransferDir value */
\r
539 /* Set DBCKSIZE bits according to SDIO_DataBlockSize value */
\r
540 tmpreg |= (uint32_t)SDIO_DataInitStruct->SDIO_DataBlockSize | SDIO_DataInitStruct->SDIO_TransferDir
\r
541 | SDIO_DataInitStruct->SDIO_TransferMode | SDIO_DataInitStruct->SDIO_DPSM;
\r
543 /* Write to SDIO DCTRL */
\r
544 SDIO->DCTRL = tmpreg;
\r
548 * @brief Fills each SDIO_DataInitStruct member with its default value.
\r
549 * @param SDIO_DataInitStruct: pointer to an SDIO_DataInitTypeDef structure which
\r
550 * will be initialized.
\r
553 void SDIO_DataStructInit(SDIO_DataInitTypeDef* SDIO_DataInitStruct)
\r
555 /* SDIO_DataInitStruct members default value */
\r
556 SDIO_DataInitStruct->SDIO_DataTimeOut = 0xFFFFFFFF;
\r
557 SDIO_DataInitStruct->SDIO_DataLength = 0x00;
\r
558 SDIO_DataInitStruct->SDIO_DataBlockSize = SDIO_DataBlockSize_1b;
\r
559 SDIO_DataInitStruct->SDIO_TransferDir = SDIO_TransferDir_ToCard;
\r
560 SDIO_DataInitStruct->SDIO_TransferMode = SDIO_TransferMode_Block;
\r
561 SDIO_DataInitStruct->SDIO_DPSM = SDIO_DPSM_Disable;
\r
565 * @brief Returns number of remaining data bytes to be transferred.
\r
567 * @retval Number of remaining data bytes to be transferred
\r
569 uint32_t SDIO_GetDataCounter(void)
\r
571 return SDIO->DCOUNT;
\r
575 * @brief Read one data word from Rx FIFO.
\r
577 * @retval Data received
\r
579 uint32_t SDIO_ReadData(void)
\r
585 * @brief Write one data word to Tx FIFO.
\r
586 * @param Data: 32-bit data word to write.
\r
589 void SDIO_WriteData(uint32_t Data)
\r
595 * @brief Returns the number of words left to be written to or read from FIFO.
\r
597 * @retval Remaining number of words.
\r
599 uint32_t SDIO_GetFIFOCount(void)
\r
601 return SDIO->FIFOCNT;
\r
608 /** @defgroup SDIO_Group5 SDIO IO Cards mode management functions
\r
609 * @brief SDIO IO Cards mode management functions
\r
612 ==============================================================================
\r
613 ##### SDIO IO Cards mode management functions #####
\r
614 ==============================================================================
\r
615 [..] This section provide functions allowing to program and read the SDIO IO
\r
623 * @brief Starts the SD I/O Read Wait operation.
\r
624 * @param NewState: new state of the Start SDIO Read Wait operation.
\r
625 * This parameter can be: ENABLE or DISABLE.
\r
628 void SDIO_StartSDIOReadWait(FunctionalState NewState)
\r
630 /* Check the parameters */
\r
631 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
633 *(__IO uint32_t *) DCTRL_RWSTART_BB = (uint32_t) NewState;
\r
637 * @brief Stops the SD I/O Read Wait operation.
\r
638 * @param NewState: new state of the Stop SDIO Read Wait operation.
\r
639 * This parameter can be: ENABLE or DISABLE.
\r
642 void SDIO_StopSDIOReadWait(FunctionalState NewState)
\r
644 /* Check the parameters */
\r
645 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
647 *(__IO uint32_t *) DCTRL_RWSTOP_BB = (uint32_t) NewState;
\r
651 * @brief Sets one of the two options of inserting read wait interval.
\r
652 * @param SDIO_ReadWaitMode: SD I/O Read Wait operation mode.
\r
653 * This parametre can be:
\r
654 * @arg SDIO_ReadWaitMode_CLK: Read Wait control by stopping SDIOCLK.
\r
655 * @arg SDIO_ReadWaitMode_DATA2: Read Wait control using SDIO_DATA2.
\r
658 void SDIO_SetSDIOReadWaitMode(uint32_t SDIO_ReadWaitMode)
\r
660 /* Check the parameters */
\r
661 assert_param(IS_SDIO_READWAIT_MODE(SDIO_ReadWaitMode));
\r
663 *(__IO uint32_t *) DCTRL_RWMOD_BB = SDIO_ReadWaitMode;
\r
667 * @brief Enables or disables the SD I/O Mode Operation.
\r
668 * @param NewState: new state of SDIO specific operation.
\r
669 * This parameter can be: ENABLE or DISABLE.
\r
672 void SDIO_SetSDIOOperation(FunctionalState NewState)
\r
674 /* Check the parameters */
\r
675 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
677 *(__IO uint32_t *) DCTRL_SDIOEN_BB = (uint32_t)NewState;
\r
681 * @brief Enables or disables the SD I/O Mode suspend command sending.
\r
682 * @param NewState: new state of the SD I/O Mode suspend command.
\r
683 * This parameter can be: ENABLE or DISABLE.
\r
686 void SDIO_SendSDIOSuspendCmd(FunctionalState NewState)
\r
688 /* Check the parameters */
\r
689 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
691 *(__IO uint32_t *) CMD_SDIOSUSPEND_BB = (uint32_t)NewState;
\r
698 /** @defgroup SDIO_Group6 CE-ATA mode management functions
\r
699 * @brief CE-ATA mode management functions
\r
702 ==============================================================================
\r
703 ##### CE-ATA mode management functions #####
\r
704 ==============================================================================
\r
705 [..] This section provide functions allowing to program and read the CE-ATA
\r
713 * @brief Enables or disables the command completion signal.
\r
714 * @param NewState: new state of command completion signal.
\r
715 * This parameter can be: ENABLE or DISABLE.
\r
718 void SDIO_CommandCompletionCmd(FunctionalState NewState)
\r
720 /* Check the parameters */
\r
721 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
723 *(__IO uint32_t *) CMD_ENCMDCOMPL_BB = (uint32_t)NewState;
\r
727 * @brief Enables or disables the CE-ATA interrupt.
\r
728 * @param NewState: new state of CE-ATA interrupt. This parameter can be: ENABLE or DISABLE.
\r
731 void SDIO_CEATAITCmd(FunctionalState NewState)
\r
733 /* Check the parameters */
\r
734 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
736 *(__IO uint32_t *) CMD_NIEN_BB = (uint32_t)((~((uint32_t)NewState)) & ((uint32_t)0x1));
\r
740 * @brief Sends CE-ATA command (CMD61).
\r
741 * @param NewState: new state of CE-ATA command. This parameter can be: ENABLE or DISABLE.
\r
744 void SDIO_SendCEATACmd(FunctionalState NewState)
\r
746 /* Check the parameters */
\r
747 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
749 *(__IO uint32_t *) CMD_ATACMD_BB = (uint32_t)NewState;
\r
756 /** @defgroup SDIO_Group7 Interrupts and flags management functions
\r
757 * @brief Interrupts and flags management functions
\r
761 ==============================================================================
\r
762 ##### Interrupts and flags management functions #####
\r
763 ==============================================================================
\r
770 * @brief Enables or disables the SDIO interrupts.
\r
771 * @param SDIO_IT: specifies the SDIO interrupt sources to be enabled or disabled.
\r
772 * This parameter can be one or a combination of the following values:
\r
773 * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt.
\r
774 * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt.
\r
775 * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt.
\r
776 * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt.
\r
777 * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt.
\r
778 * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt.
\r
779 * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt.
\r
780 * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt.
\r
781 * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt.
\r
782 * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
\r
783 * bus mode interrupt.
\r
784 * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt.
\r
785 * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt.
\r
786 * @arg SDIO_IT_TXACT: Data transmit in progress interrupt.
\r
787 * @arg SDIO_IT_RXACT: Data receive in progress interrupt.
\r
788 * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt.
\r
789 * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt.
\r
790 * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt.
\r
791 * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt.
\r
792 * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt.
\r
793 * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt.
\r
794 * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt.
\r
795 * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt.
\r
796 * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt.
\r
797 * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61 interrupt.
\r
798 * @param NewState: new state of the specified SDIO interrupts.
\r
799 * This parameter can be: ENABLE or DISABLE.
\r
802 void SDIO_ITConfig(uint32_t SDIO_IT, FunctionalState NewState)
\r
804 /* Check the parameters */
\r
805 assert_param(IS_SDIO_IT(SDIO_IT));
\r
806 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
808 if (NewState != DISABLE)
\r
810 /* Enable the SDIO interrupts */
\r
811 SDIO->MASK |= SDIO_IT;
\r
815 /* Disable the SDIO interrupts */
\r
816 SDIO->MASK &= ~SDIO_IT;
\r
821 * @brief Checks whether the specified SDIO flag is set or not.
\r
822 * @param SDIO_FLAG: specifies the flag to check.
\r
823 * This parameter can be one of the following values:
\r
824 * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed).
\r
825 * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed).
\r
826 * @arg SDIO_FLAG_CTIMEOUT: Command response timeout.
\r
827 * @arg SDIO_FLAG_DTIMEOUT: Data timeout.
\r
828 * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error.
\r
829 * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error.
\r
830 * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed).
\r
831 * @arg SDIO_FLAG_CMDSENT: Command sent (no response required).
\r
832 * @arg SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero).
\r
833 * @arg SDIO_FLAG_STBITERR: Start bit not detected on all data signals in wide
\r
835 * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed).
\r
836 * @arg SDIO_FLAG_CMDACT: Command transfer in progress.
\r
837 * @arg SDIO_FLAG_TXACT: Data transmit in progress.
\r
838 * @arg SDIO_FLAG_RXACT: Data receive in progress.
\r
839 * @arg SDIO_FLAG_TXFIFOHE: Transmit FIFO Half Empty.
\r
840 * @arg SDIO_FLAG_RXFIFOHF: Receive FIFO Half Full.
\r
841 * @arg SDIO_FLAG_TXFIFOF: Transmit FIFO full.
\r
842 * @arg SDIO_FLAG_RXFIFOF: Receive FIFO full.
\r
843 * @arg SDIO_FLAG_TXFIFOE: Transmit FIFO empty.
\r
844 * @arg SDIO_FLAG_RXFIFOE: Receive FIFO empty.
\r
845 * @arg SDIO_FLAG_TXDAVL: Data available in transmit FIFO.
\r
846 * @arg SDIO_FLAG_RXDAVL: Data available in receive FIFO.
\r
847 * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received.
\r
848 * @arg SDIO_FLAG_CEATAEND: CE-ATA command completion signal received for CMD61.
\r
849 * @retval The new state of SDIO_FLAG (SET or RESET).
\r
851 FlagStatus SDIO_GetFlagStatus(uint32_t SDIO_FLAG)
\r
853 FlagStatus bitstatus = RESET;
\r
855 /* Check the parameters */
\r
856 assert_param(IS_SDIO_FLAG(SDIO_FLAG));
\r
858 if ((SDIO->STA & SDIO_FLAG) != (uint32_t)RESET)
\r
870 * @brief Clears the SDIO's pending flags.
\r
871 * @param SDIO_FLAG: specifies the flag to clear.
\r
872 * This parameter can be one or a combination of the following values:
\r
873 * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed).
\r
874 * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed).
\r
875 * @arg SDIO_FLAG_CTIMEOUT: Command response timeout.
\r
876 * @arg SDIO_FLAG_DTIMEOUT: Data timeout.
\r
877 * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error.
\r
878 * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error.
\r
879 * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed).
\r
880 * @arg SDIO_FLAG_CMDSENT: Command sent (no response required).
\r
881 * @arg SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero).
\r
882 * @arg SDIO_FLAG_STBITERR: Start bit not detected on all data signals in wide
\r
884 * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed).
\r
885 * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received.
\r
886 * @arg SDIO_FLAG_CEATAEND: CE-ATA command completion signal received for CMD61.
\r
889 void SDIO_ClearFlag(uint32_t SDIO_FLAG)
\r
891 /* Check the parameters */
\r
892 assert_param(IS_SDIO_CLEAR_FLAG(SDIO_FLAG));
\r
894 SDIO->ICR = SDIO_FLAG;
\r
898 * @brief Checks whether the specified SDIO interrupt has occurred or not.
\r
899 * @param SDIO_IT: specifies the SDIO interrupt source to check.
\r
900 * This parameter can be one of the following values:
\r
901 * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt.
\r
902 * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt.
\r
903 * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt.
\r
904 * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt.
\r
905 * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt.
\r
906 * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt.
\r
907 * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt.
\r
908 * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt.
\r
909 * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt.
\r
910 * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
\r
911 * bus mode interrupt.
\r
912 * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt.
\r
913 * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt.
\r
914 * @arg SDIO_IT_TXACT: Data transmit in progress interrupt.
\r
915 * @arg SDIO_IT_RXACT: Data receive in progress interrupt.
\r
916 * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt.
\r
917 * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt.
\r
918 * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt.
\r
919 * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt.
\r
920 * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt.
\r
921 * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt.
\r
922 * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt.
\r
923 * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt.
\r
924 * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt.
\r
925 * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61 interrupt.
\r
926 * @retval The new state of SDIO_IT (SET or RESET).
\r
928 ITStatus SDIO_GetITStatus(uint32_t SDIO_IT)
\r
930 ITStatus bitstatus = RESET;
\r
932 /* Check the parameters */
\r
933 assert_param(IS_SDIO_GET_IT(SDIO_IT));
\r
934 if ((SDIO->STA & SDIO_IT) != (uint32_t)RESET)
\r
946 * @brief Clears the SDIO's interrupt pending bits.
\r
947 * @param SDIO_IT: specifies the interrupt pending bit to clear.
\r
948 * This parameter can be one or a combination of the following values:
\r
949 * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt.
\r
950 * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt.
\r
951 * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt.
\r
952 * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt.
\r
953 * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt.
\r
954 * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt.
\r
955 * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt.
\r
956 * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt.
\r
957 * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt.
\r
958 * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
\r
959 * bus mode interrupt.
\r
960 * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt.
\r
961 * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61.
\r
964 void SDIO_ClearITPendingBit(uint32_t SDIO_IT)
\r
966 /* Check the parameters */
\r
967 assert_param(IS_SDIO_CLEAR_IT(SDIO_IT));
\r
969 SDIO->ICR = SDIO_IT;
\r
984 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r