mbed library with additional peripherals for ST F401 board

Fork of mbed-src by mbed official

This mbed LIB has additional peripherals for ST F401 board

  • UART2 : PA_3 rx, PA_2 tx
  • UART3 : PC_7 rx, PC_6 tx
  • I2C2 : PB_3 SDA, PB_10 SCL
  • I2C3 : PB_4 SDA, PA_8 SCL
Committer:
mbed_official
Date:
Wed Feb 26 09:45:12 2014 +0000
Revision:
106:ced8cbb51063
Parent:
87:085cde657901
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd

Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/

[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license

Who changed what in which revision?

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