mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu Aug 20 10:45:13 2015 +0100
Revision:
613:bc40b8d2aec4
Parent:
532:fe11edbda85c
Synchronized with git revision 92ca8c7b60a283b6bb60eb65b183dac1599f0ade

Full URL: https://github.com/mbedmicro/mbed/commit/92ca8c7b60a283b6bb60eb65b183dac1599f0ade/

Nordic: update application start address in GCC linker script

Who changed what in which revision?

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