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