annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_ll_sdmmc.c @ 60:96026ba1834f

more language updates
author heinrichsweikamp
date Fri, 10 Aug 2018 19:40:55 +0200
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_ll_sdmmc.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief SDMMC Low Layer HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * functionalities of the SDMMC peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + Initialization/de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * + I/O operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * + Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 * + Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 ##### SDMMC peripheral features #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 [..] The SD/SDIO MMC card host interface (SDIO) provides an interface between the APB2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 peripheral bus and MultiMedia cards (MMCs), SD memory cards, SDIO cards and CE-ATA
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 [..] The SDIO features include the following:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 (+) Full compliance with MultiMedia Card System Specification Version 4.2. Card support
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 for three different databus modes: 1-bit (default), 4-bit and 8-bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 (+) Full compatibility with previous versions of MultiMedia Cards (forward compatibility)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 (+) Full compliance with SD Memory Card Specifications Version 2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 (+) Full compliance with SD I/O Card Specification Version 2.0: card support for two
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 different data bus modes: 1-bit (default) and 4-bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (+) Full support of the CE-ATA features (full compliance with CE-ATA digital protocol
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 Rev1.1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 (+) Data transfer up to 48 MHz for the 8 bit mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 (+) Data and command output enable signals to control external bidirectional drivers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 This driver is a considered as a driver of service for external devices drivers
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 that interfaces with the SDIO peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 According to the device used (SD card/ MMC card / SDIO card ...), a set of APIs
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 is used in the device's driver to perform SDIO operations and functionalities.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 This driver is almost transparent for the final user, it is only used to implement other
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 functionalities of the external device.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 (+) The SDIO clock (SDIOCLK = 48 MHz) is coming from a specific output of PLL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 (PLL48CLK). Before start working with SDIO peripheral make sure that the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 PLL is well configured.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 The SDIO peripheral uses two clock signals:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 (++) SDIO adapter clock (SDIOCLK = 48 MHz)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 (++) APB2 bus clock (PCLK2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 -@@- PCLK2 and SDIO_CK clock frequencies must respect the following condition:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 Frequency(PCLK2) >= (3 / 8 x Frequency(SDIO_CK))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 (+) Enable/Disable peripheral clock using RCC peripheral macros related to SDIO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 (+) Enable the Power ON State using the SDIO_PowerState_ON(SDIOx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 function and disable it using the function SDIO_PowerState_OFF(SDIOx).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 (+) Enable/Disable the clock using the __SDIO_ENABLE()/__SDIO_DISABLE() macros.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 (+) Enable/Disable the peripheral interrupts using the macros __SDIO_ENABLE_IT(hsdio, IT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 and __SDIO_DISABLE_IT(hsdio, IT) if you need to use interrupt mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 (+) When using the DMA mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 (++) Configure the DMA in the MSP layer of the external device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 (++) Active the needed channel Request
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 (++) Enable the DMA using __SDIO_DMA_ENABLE() macro or Disable it using the macro
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 __SDIO_DMA_DISABLE().
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 (+) To control the CPSM (Command Path State Machine) and send
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 commands to the card use the SDIO_SendCommand(SDIOx),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 SDIO_GetCommandResponse() and SDIO_GetResponse() functions. First, user has
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 to fill the command structure (pointer to SDIO_CmdInitTypeDef) according
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 to the selected command to be sent.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 The parameters that should be filled are:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 (++) Command Argument
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 (++) Command Index
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 (++) Command Response type
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 (++) Command Wait
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 (++) CPSM Status (Enable or Disable).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 -@@- To check if the command is well received, read the SDIO_CMDRESP
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 register using the SDIO_GetCommandResponse().
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 The SDIO responses registers (SDIO_RESP1 to SDIO_RESP2), use the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 SDIO_GetResponse() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 (+) To control the DPSM (Data Path State Machine) and send/receive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 data to/from the card use the SDIO_DataConfig(), SDIO_GetDataCounter(),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 SDIO_ReadFIFO(), DIO_WriteFIFO() and SDIO_GetFIFOCount() functions.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 *** Read Operations ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 =======================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 (#) First, user has to fill the data structure (pointer to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 SDIO_DataInitTypeDef) according to the selected data type to be received.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 The parameters that should be filled are:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 (++) Data Timeout
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 (++) Data Length
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 (++) Data Block size
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 (++) Data Transfer direction: should be from card (To SDIO)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 (++) Data Transfer mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 (++) DPSM Status (Enable or Disable)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 (#) Configure the SDIO resources to receive the data from the card
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 according to selected transfer mode (Refer to Step 8, 9 and 10).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 (#) Send the selected Read command (refer to step 11).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 (#) Use the SDIO flags/interrupts to check the transfer status.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 *** Write Operations ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 ========================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 (#) First, user has to fill the data structure (pointer to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 SDIO_DataInitTypeDef) according to the selected data type to be received.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 The parameters that should be filled are:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 (++) Data Timeout
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 (++) Data Length
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 (++) Data Block size
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 (++) Data Transfer direction: should be to card (To CARD)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 (++) Data Transfer mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 (++) DPSM Status (Enable or Disable)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 (#) Configure the SDIO resources to send the data to the card according to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 selected transfer mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 (#) Send the selected Write command.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 (#) Use the SDIO flags/interrupts to check the transfer status.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 /** @defgroup SDMMC_LL SDMMC Low Layer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 * @brief Low layer module for SD and MMC driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 #if defined (HAL_SD_MODULE_ENABLED) || defined(HAL_MMC_MODULE_ENABLED)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 /** @defgroup SDMMC_LL_Exported_Functions SDMMC_LL Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 /** @defgroup HAL_SDMMC_LL_Group1 Initialization/de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 * @brief Initialization and Configuration functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 ##### Initialization/de-initialization functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 * @brief Initializes the SDIO according to the specified
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 * parameters in the SDIO_InitTypeDef and create the associated handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 * @param Init: SDIO initialization structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 HAL_StatusTypeDef SDIO_Init(SDIO_TypeDef *SDIOx, SDIO_InitTypeDef Init)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 assert_param(IS_SDIO_ALL_INSTANCE(SDIOx));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 assert_param(IS_SDIO_CLOCK_EDGE(Init.ClockEdge));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 assert_param(IS_SDIO_CLOCK_BYPASS(Init.ClockBypass));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 assert_param(IS_SDIO_CLOCK_POWER_SAVE(Init.ClockPowerSave));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 assert_param(IS_SDIO_BUS_WIDE(Init.BusWide));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 assert_param(IS_SDIO_HARDWARE_FLOW_CONTROL(Init.HardwareFlowControl));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 assert_param(IS_SDIO_CLKDIV(Init.ClockDiv));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 /* Set SDIO configuration parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 tmpreg |= (Init.ClockEdge |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 Init.ClockBypass |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 Init.ClockPowerSave |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 Init.BusWide |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 Init.HardwareFlowControl |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 Init.ClockDiv
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 /* Write to SDIO CLKCR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 MODIFY_REG(SDIOx->CLKCR, CLKCR_CLEAR_MASK, tmpreg);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 /** @defgroup HAL_SDMMC_LL_Group2 I/O operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 * @brief Data transfers functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 ##### I/O operation functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 This subsection provides a set of functions allowing to manage the SDIO data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 transfers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 * @brief Read data (word) from Rx FIFO in blocking mode (polling)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 uint32_t SDIO_ReadFIFO(SDIO_TypeDef *SDIOx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 /* Read data from Rx FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 return (SDIOx->FIFO);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 * @brief Write data (word) to Tx FIFO in blocking mode (polling)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 * @param pWriteData: pointer to data to write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 HAL_StatusTypeDef SDIO_WriteFIFO(SDIO_TypeDef *SDIOx, uint32_t *pWriteData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 /* Write data to FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 SDIOx->FIFO = *pWriteData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 /** @defgroup HAL_SDMMC_LL_Group3 Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 * @brief management functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 ##### Peripheral Control functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 This subsection provides a set of functions allowing to control the SDIO data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 transfers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 * @brief Set SDIO Power state to ON.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 HAL_StatusTypeDef SDIO_PowerState_ON(SDIO_TypeDef *SDIOx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 /* Set power state to ON */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 SDIOx->POWER = SDIO_POWER_PWRCTRL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 * @brief Set SDIO Power state to OFF.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 HAL_StatusTypeDef SDIO_PowerState_OFF(SDIO_TypeDef *SDIOx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 /* Set power state to OFF */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 SDIOx->POWER = (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 * @brief Get SDIO Power state.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 * @retval Power status of the controller. The returned value can be one of the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 * following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 * - 0x00: Power OFF
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 * - 0x02: Power UP
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 * - 0x03: Power ON
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 uint32_t SDIO_GetPowerState(SDIO_TypeDef *SDIOx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 return (SDIOx->POWER & SDIO_POWER_PWRCTRL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 * @brief Configure the SDIO command path according to the specified parameters in
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 * SDIO_CmdInitTypeDef structure and send the command
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 * @param SDIO_CmdInitStruct: pointer to a SDIO_CmdInitTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 * the configuration information for the SDIO command
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 HAL_StatusTypeDef SDIO_SendCommand(SDIO_TypeDef *SDIOx, SDIO_CmdInitTypeDef *SDIO_CmdInitStruct)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 assert_param(IS_SDIO_CMD_INDEX(SDIO_CmdInitStruct->CmdIndex));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 assert_param(IS_SDIO_RESPONSE(SDIO_CmdInitStruct->Response));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 assert_param(IS_SDIO_WAIT(SDIO_CmdInitStruct->WaitForInterrupt));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 assert_param(IS_SDIO_CPSM(SDIO_CmdInitStruct->CPSM));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 /* Set the SDIO Argument value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 SDIOx->ARG = SDIO_CmdInitStruct->Argument;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 /* Set SDIO command parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 tmpreg |= (uint32_t)(SDIO_CmdInitStruct->CmdIndex |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 SDIO_CmdInitStruct->Response |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 SDIO_CmdInitStruct->WaitForInterrupt |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 SDIO_CmdInitStruct->CPSM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 /* Write to SDIO CMD register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 MODIFY_REG(SDIOx->CMD, CMD_CLEAR_MASK, tmpreg);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 * @brief Return the command index of last command for which response received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 * @retval Command index of the last command response received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 uint8_t SDIO_GetCommandResponse(SDIO_TypeDef *SDIOx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 return (uint8_t)(SDIOx->RESPCMD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 * @brief Return the response received from the card for the last command
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 * @param SDIO_RESP: Specifies the SDIO response register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 * @arg SDIO_RESP1: Response Register 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 * @arg SDIO_RESP2: Response Register 2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 * @arg SDIO_RESP3: Response Register 3
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 * @arg SDIO_RESP4: Response Register 4
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 * @retval The Corresponding response register value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 uint32_t SDIO_GetResponse(uint32_t SDIO_RESP)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 __IO uint32_t tmp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 assert_param(IS_SDIO_RESP(SDIO_RESP));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 /* Get the response */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 tmp = SDIO_RESP_ADDR + SDIO_RESP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 return (*(__IO uint32_t *) tmp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 * @brief Configure the SDIO data path according to the specified
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 * parameters in the SDIO_DataInitTypeDef.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 * @param SDIO_DataInitStruct : pointer to a SDIO_DataInitTypeDef structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 * that contains the configuration information for the SDIO command.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 HAL_StatusTypeDef SDIO_DataConfig(SDIO_TypeDef *SDIOx, SDIO_DataInitTypeDef* SDIO_DataInitStruct)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 assert_param(IS_SDIO_DATA_LENGTH(SDIO_DataInitStruct->DataLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 assert_param(IS_SDIO_BLOCK_SIZE(SDIO_DataInitStruct->DataBlockSize));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 assert_param(IS_SDIO_TRANSFER_DIR(SDIO_DataInitStruct->TransferDir));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 assert_param(IS_SDIO_TRANSFER_MODE(SDIO_DataInitStruct->TransferMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 assert_param(IS_SDIO_DPSM(SDIO_DataInitStruct->DPSM));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 /* Set the SDIO Data Timeout value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 SDIOx->DTIMER = SDIO_DataInitStruct->DataTimeOut;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 /* Set the SDIO DataLength value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 SDIOx->DLEN = SDIO_DataInitStruct->DataLength;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 /* Set the SDIO data configuration parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 tmpreg |= (uint32_t)(SDIO_DataInitStruct->DataBlockSize |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 SDIO_DataInitStruct->TransferDir |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 SDIO_DataInitStruct->TransferMode |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 SDIO_DataInitStruct->DPSM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 /* Write to SDIO DCTRL */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 MODIFY_REG(SDIOx->DCTRL, DCTRL_CLEAR_MASK, tmpreg);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 * @brief Returns number of remaining data bytes to be transferred.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 * @retval Number of remaining data bytes to be transferred
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 uint32_t SDIO_GetDataCounter(SDIO_TypeDef *SDIOx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 return (SDIOx->DCOUNT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 * @brief Get the FIFO data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 * @param SDIOx: Pointer to SDIO register base
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 * @retval Data received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 uint32_t SDIO_GetFIFOCount(SDIO_TypeDef *SDIOx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 return (SDIOx->FIFO);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 * @brief Sets one of the two options of inserting read wait interval.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 * @param SDIO_ReadWaitMode: SD I/O Read Wait operation mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 * This parameter can be:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 * @arg SDIO_READ_WAIT_MODE_CLK: Read Wait control by stopping SDIOCLK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 * @arg SDIO_READ_WAIT_MODE_DATA2: Read Wait control using SDIO_DATA2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 HAL_StatusTypeDef SDIO_SetSDIOReadWaitMode(uint32_t SDIO_ReadWaitMode)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 assert_param(IS_SDIO_READWAIT_MODE(SDIO_ReadWaitMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 *(__IO uint32_t *)DCTRL_RWMOD_BB = SDIO_ReadWaitMode;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 #endif /* (HAL_SD_MODULE_ENABLED) || (HAL_MMC_MODULE_ENABLED) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/