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