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