mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Nov 07 15:45:07 2014 +0000
Revision:
394:83f921546702
Parent:
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx_ll_sdmmc.c@354:e67efb2aab0e
Synchronized with git revision aab52cb7ec5a665869e507dd988bbfd55b7e087e

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

Tests: Fix cpputest testrunner

Who changed what in which revision?

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