Patched for Audio example - Add status check when DFSDM's filter and channel de-init.

Dependents:   DISCO_F413ZH-AUDIO-demo

The base repository is https://os.mbed.com/teams/ST/code/BSP_DISCO_F413ZH/. I've just added workaround patch for Audio-in demo on DISCO_F413ZH board(Microphone U16, U17)

Committer:
Daniel_Lee
Date:
Fri Jan 31 07:17:05 2020 +0000
Revision:
4:c051317d4051
Parent:
3:42b354f5069c
Patched for Audio example;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
arostm 0:4af3ca173992 1 /**
arostm 0:4af3ca173992 2 ******************************************************************************
arostm 0:4af3ca173992 3 * @file stm32f413h_discovery_sd.c
arostm 0:4af3ca173992 4 * @author MCD Application Team
arostm 0:4af3ca173992 5 * @brief This file includes the uSD card driver mounted on STM32F413H-DISCOVERY
arostm 0:4af3ca173992 6 * board.
arostm 0:4af3ca173992 7 ******************************************************************************
arostm 0:4af3ca173992 8 * @attention
arostm 0:4af3ca173992 9 *
arostm 0:4af3ca173992 10 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
arostm 0:4af3ca173992 11 *
arostm 0:4af3ca173992 12 * Redistribution and use in source and binary forms, with or without modification,
arostm 0:4af3ca173992 13 * are permitted provided that the following conditions are met:
arostm 0:4af3ca173992 14 * 1. Redistributions of source code must retain the above copyright notice,
arostm 0:4af3ca173992 15 * this list of conditions and the following disclaimer.
arostm 0:4af3ca173992 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
arostm 0:4af3ca173992 17 * this list of conditions and the following disclaimer in the documentation
arostm 0:4af3ca173992 18 * and/or other materials provided with the distribution.
arostm 0:4af3ca173992 19 * 3. Neither the name of STMicroelectronics nor the names of its contributors
arostm 0:4af3ca173992 20 * may be used to endorse or promote products derived from this software
arostm 0:4af3ca173992 21 * without specific prior written permission.
arostm 0:4af3ca173992 22 *
arostm 0:4af3ca173992 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
arostm 0:4af3ca173992 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
arostm 0:4af3ca173992 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
arostm 0:4af3ca173992 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
arostm 0:4af3ca173992 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
arostm 0:4af3ca173992 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
arostm 0:4af3ca173992 29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
arostm 0:4af3ca173992 30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
arostm 0:4af3ca173992 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
arostm 0:4af3ca173992 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
arostm 0:4af3ca173992 33 *
arostm 0:4af3ca173992 34 ******************************************************************************
arostm 0:4af3ca173992 35 */
arostm 0:4af3ca173992 36
arostm 0:4af3ca173992 37 /* File Info : -----------------------------------------------------------------
arostm 0:4af3ca173992 38 User NOTES
arostm 0:4af3ca173992 39 1. How To use this driver:
arostm 0:4af3ca173992 40 --------------------------
arostm 0:4af3ca173992 41 - This driver is used to drive the micro SD external card mounted on STM32F413H-DISCOVERY
arostm 0:4af3ca173992 42 board.
arostm 0:4af3ca173992 43 - This driver does not need a specific component driver for the micro SD device
arostm 0:4af3ca173992 44 to be included with.
arostm 0:4af3ca173992 45
arostm 0:4af3ca173992 46 2. Driver description:
arostm 0:4af3ca173992 47 ---------------------
arostm 0:4af3ca173992 48 + Initialization steps:
arostm 0:4af3ca173992 49 o Initialize the micro SD card using the BSP_SD_Init() function. This
arostm 0:4af3ca173992 50 function includes the MSP layer hardware resources initialization and the
arostm 0:4af3ca173992 51 SDIO interface configuration to interface with the external micro SD. It
arostm 0:4af3ca173992 52 also includes the micro SD initialization sequence.
arostm 0:4af3ca173992 53 o To check the SD card presence you can use the function BSP_SD_IsDetected() which
arostm 0:4af3ca173992 54 returns the detection status
arostm 0:4af3ca173992 55 o If SD presence detection interrupt mode is desired, you must configure the
arostm 0:4af3ca173992 56 SD detection interrupt mode by calling the function BSP_SD_ITConfig(). The interrupt
arostm 0:4af3ca173992 57 is generated as an external interrupt whenever the micro SD card is
arostm 0:4af3ca173992 58 plugged/unplugged in/from the board.
arostm 0:4af3ca173992 59 o The function BSP_SD_GetCardInfo() is used to get the micro SD card information
arostm 0:4af3ca173992 60 which is stored in the structure "HAL_SD_CardInfoTypeDef".
arostm 0:4af3ca173992 61
arostm 0:4af3ca173992 62 + Micro SD card operations
arostm 0:4af3ca173992 63 o The micro SD card can be accessed with read/write block(s) operations once
arostm 0:4af3ca173992 64 it is ready for access. The access can be performed whether using the polling
arostm 0:4af3ca173992 65 mode by calling the functions BSP_SD_ReadBlocks()/BSP_SD_WriteBlocks(), or by DMA
arostm 0:4af3ca173992 66 transfer using the functions BSP_SD_ReadBlocks_DMA()/BSP_SD_WriteBlocks_DMA()
arostm 0:4af3ca173992 67 o The DMA transfer complete is used with interrupt mode. Once the SD transfer
arostm 0:4af3ca173992 68 is complete, the SD interrupt is handled using the function BSP_SD_IRQHandler(),
arostm 0:4af3ca173992 69 the DMA Tx/Rx transfer complete are handled using the functions
arostm 0:4af3ca173992 70 BSP_SD_DMA_Tx_IRQHandler()/BSP_SD_DMA_Rx_IRQHandler(). The corresponding user callbacks
arostm 0:4af3ca173992 71 are implemented by the user at application level.
arostm 0:4af3ca173992 72 o The SD erase block(s) is performed using the function BSP_SD_Erase() with specifying
arostm 0:4af3ca173992 73 the number of blocks to erase.
arostm 0:4af3ca173992 74 o The SD runtime status is returned when calling the function BSP_SD_GetCardState().
arostm 0:4af3ca173992 75
arostm 0:4af3ca173992 76 ------------------------------------------------------------------------------*/
arostm 0:4af3ca173992 77
arostm 0:4af3ca173992 78 /* Includes ------------------------------------------------------------------*/
arostm 0:4af3ca173992 79 #include "stm32f413h_discovery_sd.h"
arostm 0:4af3ca173992 80
arostm 0:4af3ca173992 81 /** @addtogroup BSP
arostm 0:4af3ca173992 82 * @{
arostm 0:4af3ca173992 83 */
arostm 0:4af3ca173992 84
arostm 0:4af3ca173992 85 /** @addtogroup STM32F413H_DISCOVERY
arostm 0:4af3ca173992 86 * @{
arostm 0:4af3ca173992 87 */
arostm 0:4af3ca173992 88
arostm 0:4af3ca173992 89 /** @defgroup STM32F413H_DISCOVERY_SD STM32F413H_DISCOVERY SD
arostm 0:4af3ca173992 90 * @{
arostm 0:4af3ca173992 91 */
arostm 0:4af3ca173992 92
arostm 0:4af3ca173992 93 /** @defgroup STM32F413H_DISCOVERY_SD_Private_Variables STM32F413H DISCOVERY SD Private Variables
arostm 0:4af3ca173992 94 * @{
arostm 0:4af3ca173992 95 */
arostm 0:4af3ca173992 96 SD_HandleTypeDef uSdHandle;
arostm 0:4af3ca173992 97
arostm 0:4af3ca173992 98 /**
arostm 0:4af3ca173992 99 * @}
arostm 0:4af3ca173992 100 */
arostm 0:4af3ca173992 101
arostm 0:4af3ca173992 102 /** @defgroup STM32F413H_DISCOVERY_SD_Private_Functions STM32F413H DISCOVERY SD Private Functions
arostm 0:4af3ca173992 103 * @{
arostm 0:4af3ca173992 104 */
arostm 0:4af3ca173992 105
arostm 0:4af3ca173992 106 /**
arostm 0:4af3ca173992 107 * @brief Initializes the SD card device.
arostm 0:4af3ca173992 108 * @retval SD status
arostm 0:4af3ca173992 109 */
arostm 0:4af3ca173992 110 uint8_t BSP_SD_Init(void)
arostm 0:4af3ca173992 111 {
arostm 0:4af3ca173992 112 uint8_t sd_state = MSD_OK;
arostm 0:4af3ca173992 113
arostm 0:4af3ca173992 114 /* uSD device interface configuration */
arostm 0:4af3ca173992 115 uSdHandle.Instance = SDIO;
arostm 0:4af3ca173992 116
arostm 0:4af3ca173992 117 uSdHandle.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
arostm 0:4af3ca173992 118 uSdHandle.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
arostm 0:4af3ca173992 119 uSdHandle.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
arostm 0:4af3ca173992 120 uSdHandle.Init.BusWide = SDIO_BUS_WIDE_1B;
arostm 0:4af3ca173992 121 uSdHandle.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_ENABLE;
arostm 0:4af3ca173992 122 uSdHandle.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV;
arostm 0:4af3ca173992 123
arostm 0:4af3ca173992 124 /* Msp SD Detect pin initialization */
arostm 0:4af3ca173992 125 BSP_SD_Detect_MspInit(&uSdHandle, NULL);
arostm 0:4af3ca173992 126
arostm 0:4af3ca173992 127 /* Check if SD card is present */
arostm 0:4af3ca173992 128 if(BSP_SD_IsDetected() != SD_PRESENT)
arostm 0:4af3ca173992 129 {
arostm 0:4af3ca173992 130 return MSD_ERROR_SD_NOT_PRESENT;
arostm 0:4af3ca173992 131 }
arostm 0:4af3ca173992 132
arostm 0:4af3ca173992 133 /* Msp SD initialization */
arostm 0:4af3ca173992 134 BSP_SD_MspInit(&uSdHandle, NULL);
arostm 0:4af3ca173992 135
arostm 0:4af3ca173992 136 /* HAL SD initialization */
arostm 0:4af3ca173992 137 if(HAL_SD_Init(&uSdHandle) != HAL_OK)
arostm 0:4af3ca173992 138 {
arostm 0:4af3ca173992 139 sd_state = MSD_ERROR;
arostm 0:4af3ca173992 140 }
arostm 0:4af3ca173992 141
arostm 0:4af3ca173992 142 /* Configure SD Bus width */
arostm 0:4af3ca173992 143 if(sd_state == MSD_OK)
arostm 0:4af3ca173992 144 {
arostm 0:4af3ca173992 145 /* Enable wide operation */
arostm 0:4af3ca173992 146 if(HAL_SD_ConfigWideBusOperation(&uSdHandle, SDIO_BUS_WIDE_4B) != HAL_OK)
arostm 0:4af3ca173992 147 {
arostm 0:4af3ca173992 148 sd_state = MSD_ERROR;
arostm 0:4af3ca173992 149 }
arostm 0:4af3ca173992 150 else
arostm 0:4af3ca173992 151 {
arostm 0:4af3ca173992 152 sd_state = MSD_OK;
arostm 0:4af3ca173992 153 }
arostm 0:4af3ca173992 154 }
arostm 0:4af3ca173992 155
arostm 0:4af3ca173992 156 return sd_state;
arostm 0:4af3ca173992 157 }
arostm 0:4af3ca173992 158
arostm 0:4af3ca173992 159 /**
arostm 0:4af3ca173992 160 * @brief DeInitializes the SD card device.
arostm 0:4af3ca173992 161 * @retval SD status
arostm 0:4af3ca173992 162 */
arostm 0:4af3ca173992 163 uint8_t BSP_SD_DeInit(void)
arostm 0:4af3ca173992 164 {
arostm 0:4af3ca173992 165 uint8_t sd_state = MSD_OK;
arostm 0:4af3ca173992 166
arostm 0:4af3ca173992 167 uSdHandle.Instance = SDIO;
arostm 0:4af3ca173992 168
arostm 0:4af3ca173992 169 /* HAL SD deinitialization */
arostm 0:4af3ca173992 170 if(HAL_SD_DeInit(&uSdHandle) != HAL_OK)
arostm 0:4af3ca173992 171 {
arostm 0:4af3ca173992 172 sd_state = MSD_ERROR;
arostm 0:4af3ca173992 173 }
arostm 0:4af3ca173992 174
arostm 0:4af3ca173992 175 /* Msp SD deinitialization */
arostm 0:4af3ca173992 176 uSdHandle.Instance = SDIO;
arostm 0:4af3ca173992 177 BSP_SD_MspDeInit(&uSdHandle, NULL);
arostm 0:4af3ca173992 178
arostm 0:4af3ca173992 179 return sd_state;
arostm 0:4af3ca173992 180 }
arostm 0:4af3ca173992 181
arostm 0:4af3ca173992 182 /**
arostm 0:4af3ca173992 183 * @brief Configures Interrupt mode for SD detection pin.
arostm 0:4af3ca173992 184 * @retval Returns MSD_OK
arostm 0:4af3ca173992 185 */
arostm 0:4af3ca173992 186 uint8_t BSP_SD_ITConfig(void)
arostm 0:4af3ca173992 187 {
arostm 0:4af3ca173992 188 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 189
arostm 0:4af3ca173992 190 /* Configure Interrupt mode for SD detection pin */
arostm 0:4af3ca173992 191 gpio_init_structure.Pin = SD_DETECT_PIN;
arostm 0:4af3ca173992 192 gpio_init_structure.Pull = GPIO_PULLUP;
arostm 0:4af3ca173992 193 gpio_init_structure.Speed = GPIO_SPEED_FAST;
arostm 0:4af3ca173992 194 gpio_init_structure.Mode = GPIO_MODE_IT_RISING_FALLING;
arostm 0:4af3ca173992 195 HAL_GPIO_Init(SD_DETECT_GPIO_PORT, &gpio_init_structure);
arostm 0:4af3ca173992 196
arostm 0:4af3ca173992 197 /* Enable and set SD detect EXTI Interrupt to the lowest priority */
arostm 0:4af3ca173992 198 HAL_NVIC_SetPriority((IRQn_Type)(SD_DETECT_EXTI_IRQn), 0x0F, 0x00);
arostm 0:4af3ca173992 199 HAL_NVIC_EnableIRQ((IRQn_Type)(SD_DETECT_EXTI_IRQn));
arostm 0:4af3ca173992 200
arostm 0:4af3ca173992 201 return MSD_OK;
arostm 0:4af3ca173992 202 }
arostm 0:4af3ca173992 203
arostm 0:4af3ca173992 204 /**
arostm 0:4af3ca173992 205 * @brief Detects if SD card is correctly plugged in the memory slot or not.
arostm 0:4af3ca173992 206 * @retval Returns if SD is detected or not
arostm 0:4af3ca173992 207 */
arostm 0:4af3ca173992 208 uint8_t BSP_SD_IsDetected(void)
arostm 0:4af3ca173992 209 {
arostm 0:4af3ca173992 210 __IO uint8_t status = SD_PRESENT;
arostm 0:4af3ca173992 211
arostm 0:4af3ca173992 212 /* Check SD card detect pin */
arostm 0:4af3ca173992 213 if (HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) == GPIO_PIN_SET)
arostm 0:4af3ca173992 214 {
arostm 0:4af3ca173992 215 status = SD_NOT_PRESENT;
arostm 0:4af3ca173992 216 }
arostm 0:4af3ca173992 217
arostm 0:4af3ca173992 218 return status;
arostm 0:4af3ca173992 219 }
arostm 0:4af3ca173992 220
arostm 0:4af3ca173992 221 /**
arostm 0:4af3ca173992 222 * @brief Reads block(s) from a specified address in an SD card, in polling mode.
arostm 0:4af3ca173992 223 * @param pData: Pointer to the buffer that will contain the data to transmit
arostm 0:4af3ca173992 224 * @param ReadAddr: Address from where data is to be read
arostm 0:4af3ca173992 225 * @param NumOfBlocks: Number of SD blocks to read
arostm 0:4af3ca173992 226 * @param Timeout: Timeout for read operation
arostm 0:4af3ca173992 227 * @retval SD status
arostm 0:4af3ca173992 228 */
arostm 0:4af3ca173992 229 uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout)
arostm 0:4af3ca173992 230 {
arostm 0:4af3ca173992 231 if(HAL_SD_ReadBlocks(&uSdHandle, (uint8_t *)pData, ReadAddr, NumOfBlocks, Timeout) != HAL_OK)
arostm 0:4af3ca173992 232 {
arostm 0:4af3ca173992 233 return MSD_ERROR;
arostm 0:4af3ca173992 234 }
arostm 0:4af3ca173992 235 else
arostm 0:4af3ca173992 236 {
arostm 0:4af3ca173992 237 return MSD_OK;
arostm 0:4af3ca173992 238 }
arostm 0:4af3ca173992 239 }
arostm 0:4af3ca173992 240
arostm 0:4af3ca173992 241 /**
arostm 0:4af3ca173992 242 * @brief Writes block(s) to a specified address in an SD card, in polling mode.
arostm 0:4af3ca173992 243 * @param pData: Pointer to the buffer that will contain the data to transmit
arostm 0:4af3ca173992 244 * @param WriteAddr: Address from where data is to be written
arostm 0:4af3ca173992 245 * @param NumOfBlocks: Number of SD blocks to write
arostm 0:4af3ca173992 246 * @param Timeout: Timeout for write operation
arostm 0:4af3ca173992 247 * @retval SD status
arostm 0:4af3ca173992 248 */
arostm 0:4af3ca173992 249 uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout)
arostm 0:4af3ca173992 250 {
arostm 0:4af3ca173992 251 if(HAL_SD_WriteBlocks(&uSdHandle, (uint8_t *)pData, WriteAddr, NumOfBlocks, Timeout) != HAL_OK)
arostm 0:4af3ca173992 252 {
arostm 0:4af3ca173992 253 return MSD_ERROR;
arostm 0:4af3ca173992 254 }
arostm 0:4af3ca173992 255 else
arostm 0:4af3ca173992 256 {
arostm 0:4af3ca173992 257 return MSD_OK;
arostm 0:4af3ca173992 258 }
arostm 0:4af3ca173992 259 }
arostm 0:4af3ca173992 260
arostm 0:4af3ca173992 261 /**
arostm 0:4af3ca173992 262 * @brief Reads block(s) from a specified address in an SD card, in DMA mode.
arostm 0:4af3ca173992 263 * @param pData: Pointer to the buffer that will contain the data to transmit
arostm 0:4af3ca173992 264 * @param ReadAddr: Address from where data is to be read
arostm 0:4af3ca173992 265 * @param NumOfBlocks: Number of SD blocks to read
arostm 0:4af3ca173992 266 * @retval SD status
arostm 0:4af3ca173992 267 */
arostm 0:4af3ca173992 268 uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks)
arostm 0:4af3ca173992 269 {
arostm 0:4af3ca173992 270 /* Read block(s) in DMA transfer mode */
arostm 0:4af3ca173992 271 if(HAL_SD_ReadBlocks_DMA(&uSdHandle, (uint8_t *)pData, ReadAddr, NumOfBlocks) != HAL_OK)
arostm 0:4af3ca173992 272 {
arostm 0:4af3ca173992 273 return MSD_ERROR;
arostm 0:4af3ca173992 274 }
arostm 0:4af3ca173992 275 else
arostm 0:4af3ca173992 276 {
arostm 0:4af3ca173992 277 return MSD_OK;
arostm 0:4af3ca173992 278 }
arostm 0:4af3ca173992 279 }
arostm 0:4af3ca173992 280
arostm 0:4af3ca173992 281 /**
arostm 0:4af3ca173992 282 * @brief Writes block(s) to a specified address in an SD card, in DMA mode.
arostm 0:4af3ca173992 283 * @param pData: Pointer to the buffer that will contain the data to transmit
arostm 0:4af3ca173992 284 * @param WriteAddr: Address from where data is to be written
arostm 0:4af3ca173992 285 * @param NumOfBlocks: Number of SD blocks to write
arostm 0:4af3ca173992 286 * @retval SD status
arostm 0:4af3ca173992 287 */
arostm 0:4af3ca173992 288 uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks)
arostm 0:4af3ca173992 289 {
arostm 0:4af3ca173992 290 /* Write block(s) in DMA transfer mode */
arostm 0:4af3ca173992 291 if(HAL_SD_WriteBlocks_DMA(&uSdHandle, (uint8_t *)pData, WriteAddr, NumOfBlocks) != HAL_OK)
arostm 0:4af3ca173992 292 {
arostm 0:4af3ca173992 293 return MSD_ERROR;
arostm 0:4af3ca173992 294 }
arostm 0:4af3ca173992 295 else
arostm 0:4af3ca173992 296 {
arostm 0:4af3ca173992 297 return MSD_OK;
arostm 0:4af3ca173992 298 }
arostm 0:4af3ca173992 299 }
arostm 0:4af3ca173992 300
arostm 0:4af3ca173992 301 /**
arostm 0:4af3ca173992 302 * @brief Erases the specified memory area of the given SD card.
arostm 0:4af3ca173992 303 * @param StartAddr: Start byte address
arostm 0:4af3ca173992 304 * @param EndAddr: End byte address
arostm 0:4af3ca173992 305 * @retval SD status
arostm 0:4af3ca173992 306 */
arostm 0:4af3ca173992 307 uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr)
arostm 0:4af3ca173992 308 {
arostm 0:4af3ca173992 309 if(HAL_SD_Erase(&uSdHandle, StartAddr, EndAddr) != HAL_OK)
arostm 0:4af3ca173992 310 {
arostm 0:4af3ca173992 311 return MSD_ERROR;
arostm 0:4af3ca173992 312 }
arostm 0:4af3ca173992 313 else
arostm 0:4af3ca173992 314 {
arostm 0:4af3ca173992 315 return MSD_OK;
arostm 0:4af3ca173992 316 }
arostm 0:4af3ca173992 317 }
arostm 0:4af3ca173992 318
arostm 0:4af3ca173992 319 /**
arostm 0:4af3ca173992 320 * @brief Initializes the SD MSP.
arostm 0:4af3ca173992 321 * @param hsd: SD handle
arostm 0:4af3ca173992 322 * @param Params : pointer on additional configuration parameters, can be NULL.
arostm 0:4af3ca173992 323 */
arostm 0:4af3ca173992 324 __weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params)
arostm 0:4af3ca173992 325 {
arostm 0:4af3ca173992 326 static DMA_HandleTypeDef dma_rx_handle;
arostm 0:4af3ca173992 327 static DMA_HandleTypeDef dma_tx_handle;
arostm 0:4af3ca173992 328 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 329
arostm 0:4af3ca173992 330 /* Prevent unused argument(s) compilation warning */
arostm 0:4af3ca173992 331 UNUSED(Params);
arostm 0:4af3ca173992 332
arostm 0:4af3ca173992 333 /* Enable SDIO clock */
arostm 0:4af3ca173992 334 __HAL_RCC_SDIO_CLK_ENABLE();
arostm 0:4af3ca173992 335
arostm 0:4af3ca173992 336 /* Enable DMA2 clocks */
arostm 0:4af3ca173992 337 __DMAx_TxRx_CLK_ENABLE();
arostm 0:4af3ca173992 338
arostm 0:4af3ca173992 339 /* Enable GPIOs clock */
arostm 0:4af3ca173992 340 __HAL_RCC_GPIOC_CLK_ENABLE();
arostm 0:4af3ca173992 341 __HAL_RCC_GPIOA_CLK_ENABLE();
arostm 0:4af3ca173992 342
arostm 0:4af3ca173992 343 /* Common GPIO configuration */
arostm 0:4af3ca173992 344 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
arostm 0:4af3ca173992 345 gpio_init_structure.Pull = GPIO_PULLUP;
arostm 0:4af3ca173992 346 gpio_init_structure.Speed = GPIO_SPEED_HIGH;
arostm 0:4af3ca173992 347 gpio_init_structure.Alternate = GPIO_AF12_SDIO;
arostm 0:4af3ca173992 348
arostm 0:4af3ca173992 349 /* GPIOC configuration: SD_D[0..3] and SD_clk */
arostm 0:4af3ca173992 350 gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
arostm 0:4af3ca173992 351
arostm 0:4af3ca173992 352 HAL_GPIO_Init(GPIOC, &gpio_init_structure);
arostm 0:4af3ca173992 353
arostm 0:4af3ca173992 354 /* GPIOA configuration: SD cmd */
arostm 0:4af3ca173992 355 gpio_init_structure.Pin = GPIO_PIN_6;
arostm 0:4af3ca173992 356 HAL_GPIO_Init(GPIOA, &gpio_init_structure);
arostm 0:4af3ca173992 357
arostm 0:4af3ca173992 358 /* NVIC configuration for SDIO interrupts */
arostm 0:4af3ca173992 359 HAL_NVIC_SetPriority(SDIO_IRQn, 0x0E, 0x00);
arostm 0:4af3ca173992 360 HAL_NVIC_EnableIRQ(SDIO_IRQn);
arostm 0:4af3ca173992 361
arostm 0:4af3ca173992 362 /* Configure DMA Rx parameters */
arostm 0:4af3ca173992 363 dma_rx_handle.Init.Channel = SD_DMAx_Rx_CHANNEL;
arostm 0:4af3ca173992 364 dma_rx_handle.Init.Direction = DMA_PERIPH_TO_MEMORY;
arostm 0:4af3ca173992 365 dma_rx_handle.Init.PeriphInc = DMA_PINC_DISABLE;
arostm 0:4af3ca173992 366 dma_rx_handle.Init.MemInc = DMA_MINC_ENABLE;
arostm 0:4af3ca173992 367 dma_rx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
arostm 0:4af3ca173992 368 dma_rx_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
arostm 0:4af3ca173992 369 dma_rx_handle.Init.Mode = DMA_PFCTRL;
arostm 0:4af3ca173992 370 dma_rx_handle.Init.Priority = DMA_PRIORITY_VERY_HIGH;
arostm 0:4af3ca173992 371 dma_rx_handle.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
arostm 0:4af3ca173992 372 dma_rx_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
arostm 0:4af3ca173992 373 dma_rx_handle.Init.MemBurst = DMA_MBURST_INC4;
arostm 0:4af3ca173992 374 dma_rx_handle.Init.PeriphBurst = DMA_PBURST_INC4;
arostm 0:4af3ca173992 375
arostm 0:4af3ca173992 376 dma_rx_handle.Instance = SD_DMAx_Rx_STREAM;
arostm 0:4af3ca173992 377
arostm 0:4af3ca173992 378 /* Associate the DMA handle */
arostm 0:4af3ca173992 379 __HAL_LINKDMA(hsd, hdmarx, dma_rx_handle);
arostm 0:4af3ca173992 380
arostm 0:4af3ca173992 381 /* Deinitialize the stream for new transfer */
arostm 0:4af3ca173992 382 HAL_DMA_DeInit(&dma_rx_handle);
arostm 0:4af3ca173992 383
arostm 0:4af3ca173992 384 /* Configure the DMA stream */
arostm 0:4af3ca173992 385 HAL_DMA_Init(&dma_rx_handle);
arostm 0:4af3ca173992 386
arostm 0:4af3ca173992 387 /* Configure DMA Tx parameters */
arostm 0:4af3ca173992 388 dma_tx_handle.Init.Channel = SD_DMAx_Tx_CHANNEL;
arostm 0:4af3ca173992 389 dma_tx_handle.Init.Direction = DMA_MEMORY_TO_PERIPH;
arostm 0:4af3ca173992 390 dma_tx_handle.Init.PeriphInc = DMA_PINC_DISABLE;
arostm 0:4af3ca173992 391 dma_tx_handle.Init.MemInc = DMA_MINC_ENABLE;
arostm 0:4af3ca173992 392 dma_tx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
arostm 0:4af3ca173992 393 dma_tx_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
arostm 0:4af3ca173992 394 dma_tx_handle.Init.Mode = DMA_PFCTRL;
arostm 0:4af3ca173992 395 dma_tx_handle.Init.Priority = DMA_PRIORITY_VERY_HIGH;
arostm 0:4af3ca173992 396 dma_tx_handle.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
arostm 0:4af3ca173992 397 dma_tx_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
arostm 0:4af3ca173992 398 dma_tx_handle.Init.MemBurst = DMA_MBURST_INC4;
arostm 0:4af3ca173992 399 dma_tx_handle.Init.PeriphBurst = DMA_PBURST_INC4;
arostm 0:4af3ca173992 400
arostm 0:4af3ca173992 401 dma_tx_handle.Instance = SD_DMAx_Tx_STREAM;
arostm 0:4af3ca173992 402
arostm 0:4af3ca173992 403 /* Associate the DMA handle */
arostm 0:4af3ca173992 404 __HAL_LINKDMA(hsd, hdmatx, dma_tx_handle);
arostm 0:4af3ca173992 405
arostm 0:4af3ca173992 406 /* Deinitialize the stream for new transfer */
arostm 0:4af3ca173992 407 HAL_DMA_DeInit(&dma_tx_handle);
arostm 0:4af3ca173992 408
arostm 0:4af3ca173992 409 /* Configure the DMA stream */
arostm 0:4af3ca173992 410 HAL_DMA_Init(&dma_tx_handle);
arostm 0:4af3ca173992 411
arostm 0:4af3ca173992 412 /* NVIC configuration for DMA transfer complete interrupt */
arostm 0:4af3ca173992 413 HAL_NVIC_SetPriority(SD_DMAx_Rx_IRQn, 0x0F, 0x00);
arostm 0:4af3ca173992 414 HAL_NVIC_EnableIRQ(SD_DMAx_Rx_IRQn);
arostm 0:4af3ca173992 415
arostm 0:4af3ca173992 416 /* NVIC configuration for DMA transfer complete interrupt */
arostm 0:4af3ca173992 417 HAL_NVIC_SetPriority(SD_DMAx_Tx_IRQn, 0x0F, 0x00);
arostm 0:4af3ca173992 418 HAL_NVIC_EnableIRQ(SD_DMAx_Tx_IRQn);
arostm 0:4af3ca173992 419 }
arostm 0:4af3ca173992 420
arostm 0:4af3ca173992 421 /**
arostm 0:4af3ca173992 422 * @brief Initializes the SD Detect pin MSP.
arostm 0:4af3ca173992 423 * @param hsd: SD handle
arostm 0:4af3ca173992 424 * @param Params : pointer on additional configuration parameters, can be NULL.
arostm 0:4af3ca173992 425 */
arostm 0:4af3ca173992 426 __weak void BSP_SD_Detect_MspInit(SD_HandleTypeDef *hsd, void *Params)
arostm 0:4af3ca173992 427 {
arostm 0:4af3ca173992 428 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 429
arostm 0:4af3ca173992 430 /* Prevent unused argument(s) compilation warning */
arostm 0:4af3ca173992 431 UNUSED(Params);
arostm 0:4af3ca173992 432
arostm 0:4af3ca173992 433 SD_DETECT_GPIO_CLK_ENABLE();
arostm 0:4af3ca173992 434
arostm 0:4af3ca173992 435 /* GPIO configuration in input for uSD_Detect signal */
arostm 0:4af3ca173992 436 gpio_init_structure.Pin = SD_DETECT_PIN;
arostm 0:4af3ca173992 437 gpio_init_structure.Mode = GPIO_MODE_INPUT;
arostm 0:4af3ca173992 438 gpio_init_structure.Pull = GPIO_PULLUP;
arostm 0:4af3ca173992 439 gpio_init_structure.Speed = GPIO_SPEED_HIGH;
arostm 0:4af3ca173992 440 HAL_GPIO_Init(SD_DETECT_GPIO_PORT, &gpio_init_structure);
arostm 0:4af3ca173992 441 }
arostm 0:4af3ca173992 442
arostm 0:4af3ca173992 443 /**
arostm 0:4af3ca173992 444 * @brief DeInitializes the SD MSP.
arostm 0:4af3ca173992 445 * @param hsd: SD handle
arostm 0:4af3ca173992 446 * @param Params : pointer on additional configuration parameters, can be NULL.
arostm 0:4af3ca173992 447 */
arostm 0:4af3ca173992 448 __weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params)
arostm 0:4af3ca173992 449 {
arostm 0:4af3ca173992 450 static DMA_HandleTypeDef dma_rx_handle;
arostm 0:4af3ca173992 451 static DMA_HandleTypeDef dma_tx_handle;
arostm 0:4af3ca173992 452
arostm 0:4af3ca173992 453 /* Prevent unused argument(s) compilation warning */
arostm 0:4af3ca173992 454 UNUSED(Params);
arostm 0:4af3ca173992 455
arostm 0:4af3ca173992 456 /* Disable NVIC for DMA transfer complete interrupts */
arostm 0:4af3ca173992 457 HAL_NVIC_DisableIRQ(SD_DMAx_Rx_IRQn);
arostm 0:4af3ca173992 458 HAL_NVIC_DisableIRQ(SD_DMAx_Tx_IRQn);
arostm 0:4af3ca173992 459
arostm 0:4af3ca173992 460 /* Deinitialize the stream for new transfer */
arostm 0:4af3ca173992 461 dma_rx_handle.Instance = SD_DMAx_Rx_STREAM;
arostm 0:4af3ca173992 462 HAL_DMA_DeInit(&dma_rx_handle);
arostm 0:4af3ca173992 463
arostm 0:4af3ca173992 464 /* Deinitialize the stream for new transfer */
arostm 0:4af3ca173992 465 dma_tx_handle.Instance = SD_DMAx_Tx_STREAM;
arostm 0:4af3ca173992 466 HAL_DMA_DeInit(&dma_tx_handle);
arostm 0:4af3ca173992 467
arostm 0:4af3ca173992 468 /* Disable NVIC for SDIO interrupts */
arostm 0:4af3ca173992 469 HAL_NVIC_DisableIRQ(SDIO_IRQn);
arostm 0:4af3ca173992 470
arostm 0:4af3ca173992 471 /* DeInit GPIO pins can be done in the application
arostm 0:4af3ca173992 472 (by surcharging this __weak function) */
arostm 0:4af3ca173992 473
arostm 0:4af3ca173992 474 /* Disable SDIO clock */
arostm 0:4af3ca173992 475 __HAL_RCC_SDIO_CLK_DISABLE();
arostm 0:4af3ca173992 476
arostm 0:4af3ca173992 477 /* GPIO pins clock and DMA clocks can be shut down in the application
arostm 0:4af3ca173992 478 by surcharging this __weak function */
arostm 0:4af3ca173992 479 }
arostm 0:4af3ca173992 480
arostm 0:4af3ca173992 481 /**
arostm 0:4af3ca173992 482 * @brief Gets the current SD card data status.
arostm 0:4af3ca173992 483 * @retval Data transfer state.
arostm 0:4af3ca173992 484 * This value can be one of the following values:
arostm 0:4af3ca173992 485 * @arg SD_TRANSFER_OK: No data transfer is acting
arostm 0:4af3ca173992 486 * @arg SD_TRANSFER_BUSY: Data transfer is acting
arostm 0:4af3ca173992 487 */
arostm 0:4af3ca173992 488 uint8_t BSP_SD_GetCardState(void)
arostm 0:4af3ca173992 489 {
arostm 0:4af3ca173992 490 return((HAL_SD_GetCardState(&uSdHandle) == HAL_SD_CARD_TRANSFER ) ? SD_TRANSFER_OK : SD_TRANSFER_BUSY);
arostm 0:4af3ca173992 491 }
arostm 0:4af3ca173992 492
arostm 0:4af3ca173992 493
arostm 0:4af3ca173992 494 /**
arostm 0:4af3ca173992 495 * @brief Get SD information about specific SD card.
arostm 0:4af3ca173992 496 * @param CardInfo: Pointer to HAL_SD_CardInfoTypedef structure
arostm 0:4af3ca173992 497 */
arostm 0:4af3ca173992 498 void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypeDef *CardInfo)
arostm 0:4af3ca173992 499 {
arostm 0:4af3ca173992 500 /* Get SD card Information */
arostm 0:4af3ca173992 501 HAL_SD_GetCardInfo(&uSdHandle, CardInfo);
arostm 0:4af3ca173992 502 }
arostm 0:4af3ca173992 503
arostm 0:4af3ca173992 504 /**
arostm 0:4af3ca173992 505 * @brief SD Abort callbacks
arostm 0:4af3ca173992 506 * @param hsd: SD handle
arostm 0:4af3ca173992 507 */
arostm 0:4af3ca173992 508 void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd)
arostm 0:4af3ca173992 509 {
arostm 0:4af3ca173992 510 BSP_SD_AbortCallback();
arostm 0:4af3ca173992 511 }
arostm 0:4af3ca173992 512
arostm 0:4af3ca173992 513 /**
arostm 0:4af3ca173992 514 * @brief Tx Transfer completed callbacks
arostm 0:4af3ca173992 515 * @param hsd: SD handle
arostm 0:4af3ca173992 516 */
arostm 0:4af3ca173992 517 void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
arostm 0:4af3ca173992 518 {
arostm 0:4af3ca173992 519 BSP_SD_WriteCpltCallback();
arostm 0:4af3ca173992 520 }
arostm 0:4af3ca173992 521
arostm 0:4af3ca173992 522 /**
arostm 0:4af3ca173992 523 * @brief Rx Transfer completed callbacks
arostm 0:4af3ca173992 524 * @param hsd: SD handle
arostm 0:4af3ca173992 525 */
arostm 0:4af3ca173992 526 void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
arostm 0:4af3ca173992 527 {
arostm 0:4af3ca173992 528 BSP_SD_ReadCpltCallback();
arostm 0:4af3ca173992 529 }
arostm 0:4af3ca173992 530
arostm 0:4af3ca173992 531 /**
arostm 0:4af3ca173992 532 * @brief BSP SD Abort callbacks
arostm 0:4af3ca173992 533 */
arostm 0:4af3ca173992 534 __weak void BSP_SD_AbortCallback(void)
arostm 0:4af3ca173992 535 {
arostm 0:4af3ca173992 536
arostm 0:4af3ca173992 537 }
arostm 0:4af3ca173992 538
arostm 0:4af3ca173992 539 /**
arostm 0:4af3ca173992 540 * @brief BSP Tx Transfer completed callbacks
arostm 0:4af3ca173992 541 */
arostm 0:4af3ca173992 542 __weak void BSP_SD_WriteCpltCallback(void)
arostm 0:4af3ca173992 543 {
arostm 0:4af3ca173992 544
arostm 0:4af3ca173992 545 }
arostm 0:4af3ca173992 546
arostm 0:4af3ca173992 547 /**
arostm 0:4af3ca173992 548 * @brief BSP Rx Transfer completed callbacks
arostm 0:4af3ca173992 549 */
arostm 0:4af3ca173992 550 __weak void BSP_SD_ReadCpltCallback(void)
arostm 0:4af3ca173992 551 {
arostm 0:4af3ca173992 552
arostm 0:4af3ca173992 553 }
arostm 0:4af3ca173992 554
arostm 0:4af3ca173992 555 /**
arostm 0:4af3ca173992 556 * @}
arostm 0:4af3ca173992 557 */
arostm 0:4af3ca173992 558
arostm 0:4af3ca173992 559 /**
arostm 0:4af3ca173992 560 * @}
arostm 0:4af3ca173992 561 */
arostm 0:4af3ca173992 562
arostm 0:4af3ca173992 563 /**
arostm 0:4af3ca173992 564 * @}
arostm 0:4af3ca173992 565 */
arostm 0:4af3ca173992 566
arostm 0:4af3ca173992 567 /**
arostm 0:4af3ca173992 568 * @}
arostm 0:4af3ca173992 569 */
arostm 0:4af3ca173992 570
arostm 0:4af3ca173992 571 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/