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