mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jul 02 16:30:08 2015 +0100
Revision:
581:39197bcd20f2
Parent:
489:119543c9f674
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724

Full URL: https://github.com/mbedmicro/mbed/commit/ae2d3cdffe70184eb8736d94f76c45c93f4b7724/

Make it possible to build the core mbed library with yotta

Who changed what in which revision?

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