mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

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