SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 21:37:21 2019 +0000
Revision:
0:8ede47d38d10
SPKT

Who changed what in which revision?

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