Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 9 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /** |
1 | /** |
| 2 | ****************************************************************************** |
2 | ****************************************************************************** |
| 3 | * @file stm32f1xx_hal_mmc.c |
3 | * @file stm32f1xx_hal_mmc.c |
| 4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
| 5 | * @brief MMC card HAL module driver. |
5 | * @brief MMC card HAL module driver. |
| 6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
| 7 | * functionalities of the Secure Digital (MMC) peripheral: |
7 | * functionalities of the Secure Digital (MMC) peripheral: |
| 8 | * + Initialization and de-initialization functions |
8 | * + Initialization and de-initialization functions |
| 9 | * + IO operation functions |
9 | * + IO operation functions |
| 10 | * + Peripheral Control functions |
10 | * + Peripheral Control functions |
| 11 | * + MMC card Control functions |
11 | * + MMC card Control functions |
| 12 | * |
12 | * |
| 13 | @verbatim |
13 | @verbatim |
| 14 | ============================================================================== |
14 | ============================================================================== |
| 15 | ##### How to use this driver ##### |
15 | ##### How to use this driver ##### |
| 16 | ============================================================================== |
16 | ============================================================================== |
| 17 | [..] |
17 | [..] |
| 18 | This driver implements a high level communication layer for read and write from/to |
18 | This driver implements a high level communication layer for read and write from/to |
| 19 | this memory. The needed STM32 hardware resources (SDMMC and GPIO) are performed by |
19 | this memory. The needed STM32 hardware resources (SDMMC and GPIO) are performed by |
| 20 | the user in HAL_MMC_MspInit() function (MSP layer). |
20 | the user in HAL_MMC_MspInit() function (MSP layer). |
| 21 | Basically, the MSP layer configuration should be the same as we provide in the |
21 | Basically, the MSP layer configuration should be the same as we provide in the |
| 22 | examples. |
22 | examples. |
| 23 | You can easily tailor this configuration according to hardware resources. |
23 | You can easily tailor this configuration according to hardware resources. |
| 24 | 24 | ||
| 25 | [..] |
25 | [..] |
| 26 | This driver is a generic layered driver for SDMMC memories which uses the HAL |
26 | This driver is a generic layered driver for SDMMC memories which uses the HAL |
| 27 | SDMMC driver functions to interface with MMC and eMMC cards devices. |
27 | SDMMC driver functions to interface with MMC and eMMC cards devices. |
| 28 | It is used as follows: |
28 | It is used as follows: |
| 29 | |
29 | |
| 30 | (#)Initialize the SDMMC low level resources by implement the HAL_MMC_MspInit() API: |
30 | (#)Initialize the SDMMC low level resources by implement the HAL_MMC_MspInit() API: |
| 31 | (##) Enable the SDMMC interface clock using __HAL_RCC_SDMMC_CLK_ENABLE(); |
31 | (##) Enable the SDMMC interface clock using __HAL_RCC_SDMMC_CLK_ENABLE(); |
| 32 | (##) SDMMC pins configuration for MMC card |
32 | (##) SDMMC pins configuration for MMC card |
| 33 | (+++) Enable the clock for the SDMMC GPIOs using the functions __HAL_RCC_GPIOx_CLK_ENABLE(); |
33 | (+++) Enable the clock for the SDMMC GPIOs using the functions __HAL_RCC_GPIOx_CLK_ENABLE(); |
| 34 | (+++) Configure these SDMMC pins as alternate function pull-up using HAL_GPIO_Init() |
34 | (+++) Configure these SDMMC pins as alternate function pull-up using HAL_GPIO_Init() |
| 35 | and according to your pin assignment; |
35 | and according to your pin assignment; |
| 36 | (##) DMA Configuration if you need to use DMA process (HAL_MMC_ReadBlocks_DMA() |
36 | (##) DMA Configuration if you need to use DMA process (HAL_MMC_ReadBlocks_DMA() |
| 37 | and HAL_MMC_WriteBlocks_DMA() APIs). |
37 | and HAL_MMC_WriteBlocks_DMA() APIs). |
| 38 | (+++) Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE(); |
38 | (+++) Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE(); |
| 39 | (+++) Configure the DMA using the function HAL_DMA_Init() with predeclared and filled. |
39 | (+++) Configure the DMA using the function HAL_DMA_Init() with predeclared and filled. |
| 40 | (##) NVIC configuration if you need to use interrupt process when using DMA transfer. |
40 | (##) NVIC configuration if you need to use interrupt process when using DMA transfer. |
| 41 | (+++) Configure the SDMMC and DMA interrupt priorities using functions |
41 | (+++) Configure the SDMMC and DMA interrupt priorities using function HAL_NVIC_SetPriority(); |
| 42 | HAL_NVIC_SetPriority(); DMA priority is superior to SDMMC's priority |
42 | DMA priority is superior to SDMMC's priority |
| 43 | (+++) Enable the NVIC DMA and SDMMC IRQs using function HAL_NVIC_EnableIRQ() |
43 | (+++) Enable the NVIC DMA and SDMMC IRQs using function HAL_NVIC_EnableIRQ() |
| 44 | (+++) SDMMC interrupts are managed using the macros __HAL_MMC_ENABLE_IT() |
44 | (+++) SDMMC interrupts are managed using the macros __HAL_MMC_ENABLE_IT() |
| 45 | and __HAL_MMC_DISABLE_IT() inside the communication process. |
45 | and __HAL_MMC_DISABLE_IT() inside the communication process. |
| 46 | (+++) SDMMC interrupts pending bits are managed using the macros __HAL_MMC_GET_IT() |
46 | (+++) SDMMC interrupts pending bits are managed using the macros __HAL_MMC_GET_IT() |
| 47 | and __HAL_MMC_CLEAR_IT() |
47 | and __HAL_MMC_CLEAR_IT() |
| 48 | (##) NVIC configuration if you need to use interrupt process (HAL_MMC_ReadBlocks_IT() |
48 | (##) NVIC configuration if you need to use interrupt process (HAL_MMC_ReadBlocks_IT() |
| 49 | and HAL_MMC_WriteBlocks_IT() APIs). |
49 | and HAL_MMC_WriteBlocks_IT() APIs). |
| 50 | (+++) Configure the SDMMC interrupt priorities using function |
50 | (+++) Configure the SDMMC interrupt priorities using function HAL_NVIC_SetPriority(); |
| 51 | HAL_NVIC_SetPriority(); |
- | |
| 52 | (+++) Enable the NVIC SDMMC IRQs using function HAL_NVIC_EnableIRQ() |
51 | (+++) Enable the NVIC SDMMC IRQs using function HAL_NVIC_EnableIRQ() |
| 53 | (+++) SDMMC interrupts are managed using the macros __HAL_MMC_ENABLE_IT() |
52 | (+++) SDMMC interrupts are managed using the macros __HAL_MMC_ENABLE_IT() |
| 54 | and __HAL_MMC_DISABLE_IT() inside the communication process. |
53 | and __HAL_MMC_DISABLE_IT() inside the communication process. |
| 55 | (+++) SDMMC interrupts pending bits are managed using the macros __HAL_MMC_GET_IT() |
54 | (+++) SDMMC interrupts pending bits are managed using the macros __HAL_MMC_GET_IT() |
| 56 | and __HAL_MMC_CLEAR_IT() |
55 | and __HAL_MMC_CLEAR_IT() |
| 57 | (#) At this stage, you can perform MMC read/write/erase operations after MMC card initialization |
56 | (#) At this stage, you can perform MMC read/write/erase operations after MMC card initialization |
| - | 57 | ||
| 58 | 58 | ||
| 59 | |
- | |
| 60 | *** MMC Card Initialization and configuration *** |
59 | *** MMC Card Initialization and configuration *** |
| 61 | ================================================ |
60 | ================================================ |
| 62 | [..] |
61 | [..] |
| 63 | To initialize the MMC Card, use the HAL_MMC_Init() function. It Initializes |
62 | To initialize the MMC Card, use the HAL_MMC_Init() function. It Initializes |
| 64 | SDMMC IP (STM32 side) and the MMC Card, and put it into StandBy State (Ready for data transfer). |
63 | SDMMC Peripheral (STM32 side) and the MMC Card, and put it into StandBy State (Ready for data transfer). |
| 65 | This function provide the following operations: |
64 | This function provide the following operations: |
| 66 | 65 | ||
| 67 | (#) Initialize the SDMMC peripheral interface with defaullt configuration. |
66 | (#) Initialize the SDMMC peripheral interface with defaullt configuration. |
| 68 | The initialization process is done at 400KHz. You can change or adapt |
67 | The initialization process is done at 400KHz. You can change or adapt |
| 69 | this frequency by adjusting the "ClockDiv" field. |
68 | this frequency by adjusting the "ClockDiv" field. |
| 70 | The MMC Card frequency (SDMMC_CK) is computed as follows: |
69 | The MMC Card frequency (SDMMC_CK) is computed as follows: |
| 71 | |
70 | |
| 72 | SDMMC_CK = SDMMCCLK / (ClockDiv + 2) |
71 | SDMMC_CK = SDMMCCLK / (ClockDiv + 2) |
| 73 | |
72 | |
| 74 | In initialization mode and according to the MMC Card standard, |
73 | In initialization mode and according to the MMC Card standard, |
| 75 | make sure that the SDMMC_CK frequency doesn't exceed 400KHz. |
74 | make sure that the SDMMC_CK frequency doesn't exceed 400KHz. |
| 76 | 75 | ||
| 77 | This phase of initialization is done through SDMMC_Init() and |
76 | This phase of initialization is done through SDMMC_Init() and |
| 78 | SDMMC_PowerState_ON() SDMMC low level APIs. |
77 | SDMMC_PowerState_ON() SDMMC low level APIs. |
| 79 | 78 | ||
| 80 | (#) Initialize the MMC card. The API used is HAL_MMC_InitCard(). |
79 | (#) Initialize the MMC card. The API used is HAL_MMC_InitCard(). |
| 81 | This phase allows the card initialization and identification |
80 | This phase allows the card initialization and identification |
| 82 | and check the MMC Card type (Standard Capacity or High Capacity) |
81 | and check the MMC Card type (Standard Capacity or High Capacity) |
| 83 | The initialization flow is compatible with MMC standard. |
82 | The initialization flow is compatible with MMC standard. |
| 84 | 83 | ||
| 85 | This API (HAL_MMC_InitCard()) could be used also to reinitialize the card in case |
84 | This API (HAL_MMC_InitCard()) could be used also to reinitialize the card in case |
| 86 | of plug-off plug-in. |
85 | of plug-off plug-in. |
| 87 | |
86 | |
| 88 | (#) Configure the MMC Card Data transfer frequency. By Default, the card transfer |
87 | (#) Configure the MMC Card Data transfer frequency. By Default, the card transfer |
| 89 | frequency is set to 24MHz. You can change or adapt this frequency by adjusting |
88 | frequency is set to 24MHz. You can change or adapt this frequency by adjusting |
| 90 | the "ClockDiv" field. |
89 | the "ClockDiv" field. |
| 91 | In transfer mode and according to the MMC Card standard, make sure that the |
90 | In transfer mode and according to the MMC Card standard, make sure that the |
| 92 | SDMMC_CK frequency doesn't exceed 25MHz and 50MHz in High-speed mode switch. |
91 | SDMMC_CK frequency doesn't exceed 25MHz and 50MHz in High-speed mode switch. |
| 93 | To be able to use a frequency higher than 24MHz, you should use the SDMMC |
92 | To be able to use a frequency higher than 24MHz, you should use the SDMMC |
| 94 | peripheral in bypass mode. Refer to the corresponding reference manual |
93 | peripheral in bypass mode. Refer to the corresponding reference manual |
| 95 | for more details. |
94 | for more details. |
| 96 | |
95 | |
| 97 | (#) Select the corresponding MMC Card according to the address read with the step 2. |
96 | (#) Select the corresponding MMC Card according to the address read with the step 2. |
| 98 | |
97 | |
| 99 | (#) Configure the MMC Card in wide bus mode: 4-bits data. |
98 | (#) Configure the MMC Card in wide bus mode: 4-bits data. |
| 100 | |
99 | |
| 101 | *** MMC Card Read operation *** |
100 | *** MMC Card Read operation *** |
| 102 | ============================== |
101 | ============================== |
| 103 | [..] |
102 | [..] |
| 104 | (+) You can read from MMC card in polling mode by using function HAL_MMC_ReadBlocks(). |
103 | (+) You can read from MMC card in polling mode by using function HAL_MMC_ReadBlocks(). |
| 105 | This function allows the read of 512 bytes blocks. |
104 | This function support only 512-bytes block length (the block size should be |
| - | 105 | chosen as 512 bytes). |
|
| 106 | You can choose either one block read operation or multiple block read operation |
106 | You can choose either one block read operation or multiple block read operation |
| 107 | by adjusting the "NumberOfBlocks" parameter. |
107 | by adjusting the "NumberOfBlocks" parameter. |
| 108 | After this, you have to ensure that the transfer is done correctly. The check is done |
108 | After this, you have to ensure that the transfer is done correctly. The check is done |
| 109 | through HAL_MMC_GetCardState() function for MMC card state. |
109 | through HAL_MMC_GetCardState() function for MMC card state. |
| 110 | 110 | ||
| 111 | (+) You can read from MMC card in DMA mode by using function HAL_MMC_ReadBlocks_DMA(). |
111 | (+) You can read from MMC card in DMA mode by using function HAL_MMC_ReadBlocks_DMA(). |
| 112 | This function allows the read of 512 bytes blocks. |
112 | This function support only 512-bytes block length (the block size should be |
| - | 113 | chosen as 512 bytes). |
|
| 113 | You can choose either one block read operation or multiple block read operation |
114 | You can choose either one block read operation or multiple block read operation |
| 114 | by adjusting the "NumberOfBlocks" parameter. |
115 | by adjusting the "NumberOfBlocks" parameter. |
| 115 | After this, you have to ensure that the transfer is done correctly. The check is done |
116 | After this, you have to ensure that the transfer is done correctly. The check is done |
| 116 | through HAL_MMC_GetCardState() function for MMC card state. |
117 | through HAL_MMC_GetCardState() function for MMC card state. |
| 117 | You could also check the DMA transfer process through the MMC Rx interrupt event. |
118 | You could also check the DMA transfer process through the MMC Rx interrupt event. |
| 118 | 119 | ||
| Line 121... | Line 122... | ||
| 121 | You can choose either one block read operation or multiple block read operation |
122 | You can choose either one block read operation or multiple block read operation |
| 122 | by adjusting the "NumberOfBlocks" parameter. |
123 | by adjusting the "NumberOfBlocks" parameter. |
| 123 | After this, you have to ensure that the transfer is done correctly. The check is done |
124 | After this, you have to ensure that the transfer is done correctly. The check is done |
| 124 | through HAL_MMC_GetCardState() function for MMC card state. |
125 | through HAL_MMC_GetCardState() function for MMC card state. |
| 125 | You could also check the IT transfer process through the MMC Rx interrupt event. |
126 | You could also check the IT transfer process through the MMC Rx interrupt event. |
| 126 | |
127 | |
| 127 | *** MMC Card Write operation *** |
128 | *** MMC Card Write operation *** |
| 128 | =============================== |
129 | =============================== |
| 129 | [..] |
130 | [..] |
| 130 | (+) You can write to MMC card in polling mode by using function HAL_MMC_WriteBlocks(). |
131 | (+) You can write to MMC card in polling mode by using function HAL_MMC_WriteBlocks(). |
| 131 | This function allows the read of 512 bytes blocks. |
132 | This function support only 512-bytes block length (the block size should be |
| - | 133 | chosen as 512 bytes). |
|
| 132 | You can choose either one block read operation or multiple block read operation |
134 | You can choose either one block read operation or multiple block read operation |
| 133 | by adjusting the "NumberOfBlocks" parameter. |
135 | by adjusting the "NumberOfBlocks" parameter. |
| 134 | After this, you have to ensure that the transfer is done correctly. The check is done |
136 | After this, you have to ensure that the transfer is done correctly. The check is done |
| 135 | through HAL_MMC_GetCardState() function for MMC card state. |
137 | through HAL_MMC_GetCardState() function for MMC card state. |
| 136 | 138 | ||
| 137 | (+) You can write to MMC card in DMA mode by using function HAL_MMC_WriteBlocks_DMA(). |
139 | (+) You can write to MMC card in DMA mode by using function HAL_MMC_WriteBlocks_DMA(). |
| 138 | This function allows the read of 512 bytes blocks. |
140 | This function support only 512-bytes block length (the block size should be |
| - | 141 | chosen as 512 byte). |
|
| 139 | You can choose either one block read operation or multiple block read operation |
142 | You can choose either one block read operation or multiple block read operation |
| 140 | by adjusting the "NumberOfBlocks" parameter. |
143 | by adjusting the "NumberOfBlocks" parameter. |
| 141 | After this, you have to ensure that the transfer is done correctly. The check is done |
144 | After this, you have to ensure that the transfer is done correctly. The check is done |
| 142 | through HAL_MMC_GetCardState() function for MMC card state. |
145 | through HAL_MMC_GetCardState() function for MMC card state. |
| 143 | You could also check the DMA transfer process through the MMC Tx interrupt event. |
146 | You could also check the DMA transfer process through the MMC Tx interrupt event. |
| 144 | 147 | ||
| Line 147... | Line 150... | ||
| 147 | You can choose either one block read operation or multiple block read operation |
150 | You can choose either one block read operation or multiple block read operation |
| 148 | by adjusting the "NumberOfBlocks" parameter. |
151 | by adjusting the "NumberOfBlocks" parameter. |
| 149 | After this, you have to ensure that the transfer is done correctly. The check is done |
152 | After this, you have to ensure that the transfer is done correctly. The check is done |
| 150 | through HAL_MMC_GetCardState() function for MMC card state. |
153 | through HAL_MMC_GetCardState() function for MMC card state. |
| 151 | You could also check the IT transfer process through the MMC Tx interrupt event. |
154 | You could also check the IT transfer process through the MMC Tx interrupt event. |
| 152 | |
- | |
| 153 | *** MMC card status *** |
- | |
| 154 | ====================== |
- | |
| 155 | [..] |
- | |
| 156 | (+) The MMC Status contains status bits that are related to the MMC Memory |
- | |
| 157 | Card proprietary features. To get MMC card status use the HAL_MMC_GetCardStatus(). |
- | |
| 158 | 155 | ||
| 159 | *** MMC card information *** |
156 | *** MMC card information *** |
| 160 | =========================== |
157 | =========================== |
| 161 | [..] |
158 | [..] |
| 162 | (+) To get MMC card information, you can use the function HAL_MMC_GetCardInfo(). |
159 | (+) To get MMC card information, you can use the function HAL_MMC_GetCardInfo(). |
| Line 177... | Line 174... | ||
| 177 | 174 | ||
| 178 | *** MMC HAL driver macros list *** |
175 | *** MMC HAL driver macros list *** |
| 179 | ================================== |
176 | ================================== |
| 180 | [..] |
177 | [..] |
| 181 | Below the list of most used macros in MMC HAL driver. |
178 | Below the list of most used macros in MMC HAL driver. |
| 182 | |
179 | |
| 183 | (+) __HAL_MMC_ENABLE : Enable the MMC device |
180 | (+) __HAL_MMC_ENABLE : Enable the MMC device |
| 184 | (+) __HAL_MMC_DISABLE : Disable the MMC device |
181 | (+) __HAL_MMC_DISABLE : Disable the MMC device |
| 185 | (+) __HAL_MMC_DMA_ENABLE: Enable the SDMMC DMA transfer |
182 | (+) __HAL_MMC_DMA_ENABLE: Enable the SDMMC DMA transfer |
| 186 | (+) __HAL_MMC_DMA_DISABLE: Disable the SDMMC DMA transfer |
183 | (+) __HAL_MMC_DMA_DISABLE: Disable the SDMMC DMA transfer |
| 187 | (+) __HAL_MMC_ENABLE_IT: Enable the MMC device interrupt |
184 | (+) __HAL_MMC_ENABLE_IT: Enable the MMC device interrupt |
| 188 | (+) __HAL_MMC_DISABLE_IT: Disable the MMC device interrupt |
185 | (+) __HAL_MMC_DISABLE_IT: Disable the MMC device interrupt |
| 189 | (+) __HAL_MMC_GET_FLAG:Check whether the specified MMC flag is set or not |
186 | (+) __HAL_MMC_GET_FLAG:Check whether the specified MMC flag is set or not |
| 190 | (+) __HAL_MMC_CLEAR_FLAG: Clear the MMC's pending flags |
187 | (+) __HAL_MMC_CLEAR_FLAG: Clear the MMC's pending flags |
| 191 | |
188 | |
| 192 | [..] |
189 | [..] |
| 193 | (@) You can refer to the MMC HAL driver header file for more useful macros |
190 | (@) You can refer to the MMC HAL driver header file for more useful macros |
| - | 191 | ||
| - | 192 | *** Callback registration *** |
|
| - | 193 | ============================================= |
|
| 194 | |
194 | [..] |
| - | 195 | The compilation define USE_HAL_MMC_REGISTER_CALLBACKS when set to 1 |
|
| - | 196 | allows the user to configure dynamically the driver callbacks. |
|
| - | 197 | ||
| - | 198 | Use Functions @ref HAL_MMC_RegisterCallback() to register a user callback, |
|
| - | 199 | it allows to register following callbacks: |
|
| - | 200 | (+) TxCpltCallback : callback when a transmission transfer is completed. |
|
| - | 201 | (+) RxCpltCallback : callback when a reception transfer is completed. |
|
| - | 202 | (+) ErrorCallback : callback when error occurs. |
|
| - | 203 | (+) AbortCpltCallback : callback when abort is completed. |
|
| - | 204 | (+) MspInitCallback : MMC MspInit. |
|
| - | 205 | (+) MspDeInitCallback : MMC MspDeInit. |
|
| - | 206 | This function takes as parameters the HAL peripheral handle, the Callback ID |
|
| - | 207 | and a pointer to the user callback function. |
|
| - | 208 | ||
| - | 209 | Use function @ref HAL_MMC_UnRegisterCallback() to reset a callback to the default |
|
| - | 210 | weak (surcharged) function. It allows to reset following callbacks: |
|
| - | 211 | (+) TxCpltCallback : callback when a transmission transfer is completed. |
|
| - | 212 | (+) RxCpltCallback : callback when a reception transfer is completed. |
|
| - | 213 | (+) ErrorCallback : callback when error occurs. |
|
| - | 214 | (+) AbortCpltCallback : callback when abort is completed. |
|
| - | 215 | (+) MspInitCallback : MMC MspInit. |
|
| - | 216 | (+) MspDeInitCallback : MMC MspDeInit. |
|
| - | 217 | This function) takes as parameters the HAL peripheral handle and the Callback ID. |
|
| - | 218 | ||
| - | 219 | By default, after the @ref HAL_MMC_Init and if the state is HAL_MMC_STATE_RESET |
|
| - | 220 | all callbacks are reset to the corresponding legacy weak (surcharged) functions. |
|
| - | 221 | Exception done for MspInit and MspDeInit callbacks that are respectively |
|
| - | 222 | reset to the legacy weak (surcharged) functions in the @ref HAL_MMC_Init |
|
| - | 223 | and @ref HAL_MMC_DeInit only when these callbacks are null (not registered beforehand). |
|
| - | 224 | If not, MspInit or MspDeInit are not null, the @ref HAL_MMC_Init and @ref HAL_MMC_DeInit |
|
| - | 225 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand) |
|
| - | 226 | ||
| - | 227 | Callbacks can be registered/unregistered in READY state only. |
|
| - | 228 | Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered |
|
| - | 229 | in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used |
|
| - | 230 | during the Init/DeInit. |
|
| - | 231 | In that case first register the MspInit/MspDeInit user callbacks |
|
| - | 232 | using @ref HAL_MMC_RegisterCallback before calling @ref HAL_MMC_DeInit |
|
| - | 233 | or @ref HAL_MMC_Init function. |
|
| - | 234 | ||
| - | 235 | When The compilation define USE_HAL_MMC_REGISTER_CALLBACKS is set to 0 or |
|
| - | 236 | not defined, the callback registering feature is not available |
|
| - | 237 | and weak (surcharged) callbacks are used. |
|
| - | 238 | ||
| 195 | @endverbatim |
239 | @endverbatim |
| 196 | ****************************************************************************** |
240 | ****************************************************************************** |
| 197 | * @attention |
241 | * @attention |
| 198 | * |
242 | * |
| 199 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
243 | * <h2><center>© Copyright (c) 2018 STMicroelectronics. |
| 200 | * |
- | |
| 201 | * Redistribution and use in source and binary forms, with or without modification, |
- | |
| 202 | * are permitted provided that the following conditions are met: |
- | |
| 203 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
| 204 | * this list of conditions and the following disclaimer. |
- | |
| 205 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
| 206 | * this list of conditions and the following disclaimer in the documentation |
- | |
| 207 | * and/or other materials provided with the distribution. |
- | |
| 208 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
| 209 | * may be used to endorse or promote products derived from this software |
- | |
| 210 | * without specific prior written permission. |
244 | * All rights reserved.</center></h2> |
| 211 | * |
245 | * |
| 212 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
246 | * This software component is licensed by ST under BSD 3-Clause license, |
| 213 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
| 214 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
| 215 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
| 216 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
| 217 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
247 | * the "License"; You may not use this file except in compliance with the |
| 218 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
248 | * License. You may obtain a copy of the License at: |
| 219 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
| 220 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
| 221 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
249 | * opensource.org/licenses/BSD-3-Clause |
| 222 | * |
250 | * |
| 223 | ****************************************************************************** |
251 | ****************************************************************************** |
| 224 | */ |
252 | */ |
| 225 | 253 | ||
| 226 | /* Includes ------------------------------------------------------------------*/ |
254 | /* Includes ------------------------------------------------------------------*/ |
| 227 | #include "stm32f1xx_hal.h" |
255 | #include "stm32f1xx_hal.h" |
| 228 | 256 | ||
| 229 | /** @addtogroup STM32F1xx_HAL_Driver |
257 | /** @addtogroup STM32F1xx_HAL_Driver |
| 230 | * @{ |
258 | * @{ |
| 231 | */ |
259 | */ |
| 232 | 260 | ||
| 233 | /** @addtogroup MMC |
261 | /** @defgroup MMC MMC |
| - | 262 | * @brief MMC HAL module driver |
|
| 234 | * @{ |
263 | * @{ |
| 235 | */ |
264 | */ |
| 236 | 265 | ||
| 237 | #ifdef HAL_MMC_MODULE_ENABLED |
266 | #ifdef HAL_MMC_MODULE_ENABLED |
| 238 | 267 | ||
| 239 | #if defined(STM32F103xE) || defined(STM32F103xG) |
268 | #if defined(SDIO) |
| 240 | 269 | ||
| 241 | /* Private typedef -----------------------------------------------------------*/ |
270 | /* Private typedef -----------------------------------------------------------*/ |
| 242 | /* Private define ------------------------------------------------------------*/ |
271 | /* Private define ------------------------------------------------------------*/ |
| 243 | /** @addtogroup MMC_Private_Defines |
272 | /** @addtogroup MMC_Private_Defines |
| 244 | * @{ |
273 | * @{ |
| 245 | */ |
274 | */ |
| 246 | 275 | ||
| 247 | /** |
276 | /** |
| 248 | * @} |
277 | * @} |
| 249 | */ |
278 | */ |
| 250 | 279 | ||
| 251 | /* Private macro -------------------------------------------------------------*/ |
280 | /* Private macro -------------------------------------------------------------*/ |
| 252 | /* Private variables ---------------------------------------------------------*/ |
281 | /* Private variables ---------------------------------------------------------*/ |
| 253 | /* Private function prototypes -----------------------------------------------*/ |
282 | /* Private function prototypes -----------------------------------------------*/ |
| 254 | /* Private functions ---------------------------------------------------------*/ |
283 | /* Private functions ---------------------------------------------------------*/ |
| 255 | /** @defgroup MMC_Private_Functions MMC Private Functions |
284 | /** @defgroup MMC_Private_Functions MMC Private Functions |
| 256 | * @{ |
285 | * @{ |
| 257 | */ |
286 | */ |
| 258 | static uint32_t MMC_InitCard(MMC_HandleTypeDef *hmmc); |
287 | static uint32_t MMC_InitCard(MMC_HandleTypeDef *hmmc); |
| 259 | static uint32_t MMC_PowerON(MMC_HandleTypeDef *hmmc); |
288 | static uint32_t MMC_PowerON(MMC_HandleTypeDef *hmmc); |
| 260 | static uint32_t MMC_SendStatus(MMC_HandleTypeDef *hmmc, uint32_t *pCardStatus); |
289 | static uint32_t MMC_SendStatus(MMC_HandleTypeDef *hmmc, uint32_t *pCardStatus); |
| 261 | static HAL_StatusTypeDef MMC_PowerOFF(MMC_HandleTypeDef *hmmc); |
290 | static void MMC_PowerOFF(MMC_HandleTypeDef *hmmc); |
| 262 | static HAL_StatusTypeDef MMC_Write_IT(MMC_HandleTypeDef *hmmc); |
291 | static void MMC_Write_IT(MMC_HandleTypeDef *hmmc); |
| 263 | static HAL_StatusTypeDef MMC_Read_IT(MMC_HandleTypeDef *hmmc); |
292 | static void MMC_Read_IT(MMC_HandleTypeDef *hmmc); |
| 264 | static void MMC_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
293 | static void MMC_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
| 265 | static void MMC_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
294 | static void MMC_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
| 266 | static void MMC_DMAError(DMA_HandleTypeDef *hdma); |
295 | static void MMC_DMAError(DMA_HandleTypeDef *hdma); |
| 267 | static void MMC_DMATxAbort(DMA_HandleTypeDef *hdma); |
296 | static void MMC_DMATxAbort(DMA_HandleTypeDef *hdma); |
| 268 | static void MMC_DMARxAbort(DMA_HandleTypeDef *hdma); |
297 | static void MMC_DMARxAbort(DMA_HandleTypeDef *hdma); |
| 269 | /** |
298 | /** |
| 270 | * @} |
299 | * @} |
| 271 | */ |
300 | */ |
| 272 | - | ||
| 273 | /* Exported functions --------------------------------------------------------*/ |
301 | /* Exported functions --------------------------------------------------------*/ |
| 274 | /** @addtogroup MMC_Exported_Functions |
302 | /** @addtogroup MMC_Exported_Functions |
| 275 | * @{ |
303 | * @{ |
| 276 | */ |
304 | */ |
| 277 | 305 | ||
| 278 | /** @addtogroup MMC_Exported_Functions_Group1 |
306 | /** @addtogroup MMC_Exported_Functions_Group1 |
| 279 | * @brief Initialization and de-initialization functions |
307 | * @brief Initialization and de-initialization functions |
| 280 | * |
308 | * |
| 281 | @verbatim |
309 | @verbatim |
| 282 | ============================================================================== |
310 | ============================================================================== |
| 283 | ##### Initialization and de-initialization functions ##### |
311 | ##### Initialization and de-initialization functions ##### |
| 284 | ============================================================================== |
312 | ============================================================================== |
| 285 | [..] |
313 | [..] |
| 286 | This section provides functions allowing to initialize/de-initialize the MMC |
314 | This section provides functions allowing to initialize/de-initialize the MMC |
| 287 | card device to be ready for use. |
315 | card device to be ready for use. |
| 288 | 316 | ||
| 289 | @endverbatim |
317 | @endverbatim |
| 290 | * @{ |
318 | * @{ |
| 291 | */ |
319 | */ |
| 292 | 320 | ||
| 293 | /** |
321 | /** |
| 294 | * @brief Initializes the MMC according to the specified parameters in the |
322 | * @brief Initializes the MMC according to the specified parameters in the |
| 295 | MMC_HandleTypeDef and create the associated handle. |
323 | MMC_HandleTypeDef and create the associated handle. |
| 296 | * @param hmmc: Pointer to the MMC handle |
324 | * @param hmmc: Pointer to the MMC handle |
| 297 | * @retval HAL status |
325 | * @retval HAL status |
| 298 | */ |
326 | */ |
| 299 | HAL_StatusTypeDef HAL_MMC_Init(MMC_HandleTypeDef *hmmc) |
327 | HAL_StatusTypeDef HAL_MMC_Init(MMC_HandleTypeDef *hmmc) |
| 300 | { |
328 | { |
| 301 | /* Check the MMC handle allocation */ |
329 | /* Check the MMC handle allocation */ |
| Line 315... | Line 343... | ||
| 315 | 343 | ||
| 316 | if(hmmc->State == HAL_MMC_STATE_RESET) |
344 | if(hmmc->State == HAL_MMC_STATE_RESET) |
| 317 | { |
345 | { |
| 318 | /* Allocate lock resource and initialize it */ |
346 | /* Allocate lock resource and initialize it */ |
| 319 | hmmc->Lock = HAL_UNLOCKED; |
347 | hmmc->Lock = HAL_UNLOCKED; |
| - | 348 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 349 | /* Reset Callback pointers in HAL_MMC_STATE_RESET only */ |
|
| - | 350 | hmmc->TxCpltCallback = HAL_MMC_TxCpltCallback; |
|
| - | 351 | hmmc->RxCpltCallback = HAL_MMC_RxCpltCallback; |
|
| - | 352 | hmmc->ErrorCallback = HAL_MMC_ErrorCallback; |
|
| - | 353 | hmmc->AbortCpltCallback = HAL_MMC_AbortCallback; |
|
| - | 354 | ||
| - | 355 | if(hmmc->MspInitCallback == NULL) |
|
| - | 356 | { |
|
| - | 357 | hmmc->MspInitCallback = HAL_MMC_MspInit; |
|
| - | 358 | } |
|
| - | 359 | ||
| - | 360 | /* Init the low level hardware */ |
|
| - | 361 | hmmc->MspInitCallback(hmmc); |
|
| - | 362 | #else |
|
| 320 | /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */ |
363 | /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */ |
| 321 | HAL_MMC_MspInit(hmmc); |
364 | HAL_MMC_MspInit(hmmc); |
| - | 365 | #endif |
|
| 322 | } |
366 | } |
| 323 | 367 | ||
| 324 | hmmc->State = HAL_MMC_STATE_BUSY; |
368 | hmmc->State = HAL_MMC_STATE_BUSY; |
| 325 | 369 | ||
| 326 | /* Initialize the Card parameters */ |
370 | /* Initialize the Card parameters */ |
| 327 | HAL_MMC_InitCard(hmmc); |
371 | if(HAL_MMC_InitCard(hmmc) == HAL_ERROR) |
| - | 372 | { |
|
| - | 373 | return HAL_ERROR; |
|
| - | 374 | } |
|
| 328 | 375 | ||
| 329 | /* Initialize the error code */ |
376 | /* Initialize the error code */ |
| 330 | hmmc->ErrorCode = HAL_DMA_ERROR_NONE; |
377 | hmmc->ErrorCode = HAL_DMA_ERROR_NONE; |
| 331 | 378 | ||
| 332 | /* Initialize the MMC operation */ |
379 | /* Initialize the MMC operation */ |
| 333 | hmmc->Context = MMC_CONTEXT_NONE; |
380 | hmmc->Context = MMC_CONTEXT_NONE; |
| 334 | - | ||
| - | 381 | ||
| 335 | /* Initialize the MMC state */ |
382 | /* Initialize the MMC state */ |
| 336 | hmmc->State = HAL_MMC_STATE_READY; |
383 | hmmc->State = HAL_MMC_STATE_READY; |
| 337 | 384 | ||
| 338 | return HAL_OK; |
385 | return HAL_OK; |
| 339 | } |
386 | } |
| 340 | 387 | ||
| 341 | /** |
388 | /** |
| 342 | * @brief Initializes the MMC Card. |
389 | * @brief Initializes the MMC Card. |
| 343 | * @param hmmc: Pointer to MMC handle |
390 | * @param hmmc: Pointer to MMC handle |
| 344 | * @note This function initializes the MMC card. It could be used when a card |
391 | * @note This function initializes the MMC card. It could be used when a card |
| 345 | re-initialization is needed. |
392 | re-initialization is needed. |
| 346 | * @retval HAL status |
393 | * @retval HAL status |
| 347 | */ |
394 | */ |
| 348 | HAL_StatusTypeDef HAL_MMC_InitCard(MMC_HandleTypeDef *hmmc) |
395 | HAL_StatusTypeDef HAL_MMC_InitCard(MMC_HandleTypeDef *hmmc) |
| 349 | { |
396 | { |
| 350 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
397 | uint32_t errorstate; |
| 351 | MMC_InitTypeDef Init; |
398 | MMC_InitTypeDef Init; |
| - | 399 | HAL_StatusTypeDef status; |
|
| 352 | 400 | ||
| 353 | /* Default SDMMC peripheral configuration for MMC card initialization */ |
401 | /* Default SDIO peripheral configuration for MMC card initialization */ |
| 354 | Init.ClockEdge = SDIO_CLOCK_EDGE_RISING; |
402 | Init.ClockEdge = SDIO_CLOCK_EDGE_RISING; |
| 355 | Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE; |
403 | Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE; |
| 356 | Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE; |
404 | Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE; |
| 357 | Init.BusWide = SDIO_BUS_WIDE_1B; |
405 | Init.BusWide = SDIO_BUS_WIDE_1B; |
| 358 | Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE; |
406 | Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE; |
| 359 | Init.ClockDiv = SDIO_INIT_CLK_DIV; |
407 | Init.ClockDiv = SDIO_INIT_CLK_DIV; |
| 360 | 408 | ||
| 361 | /* Initialize SDMMC peripheral interface with default configuration */ |
409 | /* Initialize SDIO peripheral interface with default configuration */ |
| 362 | SDIO_Init(hmmc->Instance, Init); |
410 | status = SDIO_Init(hmmc->Instance, Init); |
| - | 411 | if(status == HAL_ERROR) |
|
| - | 412 | { |
|
| - | 413 | return HAL_ERROR; |
|
| - | 414 | } |
|
| 363 | 415 | ||
| 364 | /* Disable SDMMC Clock */ |
416 | /* Disable SDIO Clock */ |
| 365 | __HAL_MMC_DISABLE(hmmc); |
417 | __HAL_MMC_DISABLE(hmmc); |
| 366 | 418 | ||
| 367 | /* Set Power State to ON */ |
419 | /* Set Power State to ON */ |
| 368 | SDIO_PowerState_ON(hmmc->Instance); |
420 | status = SDIO_PowerState_ON(hmmc->Instance); |
| - | 421 | if(status == HAL_ERROR) |
|
| 369 | 422 | { |
|
| - | 423 | return HAL_ERROR; |
|
| - | 424 | } |
|
| - | 425 | ||
| 370 | /* Enable SDMMC Clock */ |
426 | /* Enable MMC Clock */ |
| 371 | __HAL_MMC_ENABLE(hmmc); |
427 | __HAL_MMC_ENABLE(hmmc); |
| 372 | - | ||
| 373 | /* Required power up waiting time before starting the SD initialization |
- | |
| 374 | sequence */ |
- | |
| 375 | HAL_Delay(2U); |
- | |
| 376 | 428 | ||
| 377 | /* Identify card operating voltage */ |
429 | /* Identify card operating voltage */ |
| 378 | errorstate = MMC_PowerON(hmmc); |
430 | errorstate = MMC_PowerON(hmmc); |
| 379 | if(errorstate != HAL_MMC_ERROR_NONE) |
431 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 380 | { |
432 | { |
| 381 | hmmc->State = HAL_MMC_STATE_READY; |
433 | hmmc->State = HAL_MMC_STATE_READY; |
| Line 405... | Line 457... | ||
| 405 | /* Check the MMC handle allocation */ |
457 | /* Check the MMC handle allocation */ |
| 406 | if(hmmc == NULL) |
458 | if(hmmc == NULL) |
| 407 | { |
459 | { |
| 408 | return HAL_ERROR; |
460 | return HAL_ERROR; |
| 409 | } |
461 | } |
| 410 | 462 | ||
| 411 | /* Check the parameters */ |
463 | /* Check the parameters */ |
| 412 | assert_param(IS_SDIO_ALL_INSTANCE(hmmc->Instance)); |
464 | assert_param(IS_SDIO_ALL_INSTANCE(hmmc->Instance)); |
| 413 | 465 | ||
| 414 | hmmc->State = HAL_MMC_STATE_BUSY; |
466 | hmmc->State = HAL_MMC_STATE_BUSY; |
| 415 | 467 | ||
| 416 | /* Set SD power state to off */ |
468 | /* Set MMC power state to off */ |
| 417 | MMC_PowerOFF(hmmc); |
469 | MMC_PowerOFF(hmmc); |
| - | 470 | ||
| - | 471 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 472 | if(hmmc->MspDeInitCallback == NULL) |
|
| 418 | 473 | { |
|
| - | 474 | hmmc->MspDeInitCallback = HAL_MMC_MspDeInit; |
|
| - | 475 | } |
|
| - | 476 | ||
| - | 477 | /* DeInit the low level hardware */ |
|
| - | 478 | hmmc->MspDeInitCallback(hmmc); |
|
| - | 479 | #else |
|
| 419 | /* De-Initialize the MSP layer */ |
480 | /* De-Initialize the MSP layer */ |
| 420 | HAL_MMC_MspDeInit(hmmc); |
481 | HAL_MMC_MspDeInit(hmmc); |
| - | 482 | #endif |
|
| 421 | 483 | ||
| 422 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
484 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
| 423 | hmmc->State = HAL_MMC_STATE_RESET; |
485 | hmmc->State = HAL_MMC_STATE_RESET; |
| 424 | 486 | ||
| 425 | return HAL_OK; |
487 | return HAL_OK; |
| 426 | } |
488 | } |
| 427 | 489 | ||
| 428 | 490 | ||
| 429 | /** |
491 | /** |
| Line 433... | Line 495... | ||
| 433 | */ |
495 | */ |
| 434 | __weak void HAL_MMC_MspInit(MMC_HandleTypeDef *hmmc) |
496 | __weak void HAL_MMC_MspInit(MMC_HandleTypeDef *hmmc) |
| 435 | { |
497 | { |
| 436 | /* Prevent unused argument(s) compilation warning */ |
498 | /* Prevent unused argument(s) compilation warning */ |
| 437 | UNUSED(hmmc); |
499 | UNUSED(hmmc); |
| 438 | 500 | ||
| 439 | /* NOTE : This function Should not be modified, when the callback is needed, |
501 | /* NOTE : This function Should not be modified, when the callback is needed, |
| 440 | the HAL_MMC_MspInit could be implemented in the user file |
502 | the HAL_MMC_MspInit could be implemented in the user file |
| 441 | */ |
503 | */ |
| 442 | } |
504 | } |
| 443 | 505 | ||
| Line 448... | Line 510... | ||
| 448 | */ |
510 | */ |
| 449 | __weak void HAL_MMC_MspDeInit(MMC_HandleTypeDef *hmmc) |
511 | __weak void HAL_MMC_MspDeInit(MMC_HandleTypeDef *hmmc) |
| 450 | { |
512 | { |
| 451 | /* Prevent unused argument(s) compilation warning */ |
513 | /* Prevent unused argument(s) compilation warning */ |
| 452 | UNUSED(hmmc); |
514 | UNUSED(hmmc); |
| 453 | 515 | ||
| 454 | /* NOTE : This function Should not be modified, when the callback is needed, |
516 | /* NOTE : This function Should not be modified, when the callback is needed, |
| 455 | the HAL_MMC_MspDeInit could be implemented in the user file |
517 | the HAL_MMC_MspDeInit could be implemented in the user file |
| 456 | */ |
518 | */ |
| 457 | } |
519 | } |
| 458 | 520 | ||
| 459 | /** |
521 | /** |
| 460 | * @} |
522 | * @} |
| 461 | */ |
523 | */ |
| 462 | 524 | ||
| 463 | /** @addtogroup MMC_Exported_Functions_Group2 |
525 | /** @addtogroup MMC_Exported_Functions_Group2 |
| 464 | * @brief Data transfer functions |
526 | * @brief Data transfer functions |
| 465 | * |
527 | * |
| 466 | @verbatim |
528 | @verbatim |
| 467 | ============================================================================== |
529 | ============================================================================== |
| 468 | ##### IO operation functions ##### |
530 | ##### IO operation functions ##### |
| 469 | ============================================================================== |
531 | ============================================================================== |
| 470 | [..] |
532 | [..] |
| 471 | This subsection provides a set of functions allowing to manage the data |
533 | This subsection provides a set of functions allowing to manage the data |
| 472 | transfer from/to MMC card. |
534 | transfer from/to MMC card. |
| 473 | 535 | ||
| 474 | @endverbatim |
536 | @endverbatim |
| 475 | * @{ |
537 | * @{ |
| 476 | */ |
538 | */ |
| 477 | 539 | ||
| 478 | /** |
540 | /** |
| 479 | * @brief Reads block(s) from a specified address in a card. The Data transfer |
541 | * @brief Reads block(s) from a specified address in a card. The Data transfer |
| 480 | * is managed by polling mode. |
542 | * is managed by polling mode. |
| 481 | * @note This API should be followed by a check on the card state through |
543 | * @note This API should be followed by a check on the card state through |
| 482 | * HAL_MMC_GetCardState(). |
544 | * HAL_MMC_GetCardState(). |
| 483 | * @param hmmc: Pointer to MMC handle |
545 | * @param hmmc: Pointer to MMC handle |
| 484 | * @param pData: pointer to the buffer that will contain the received data |
546 | * @param pData: pointer to the buffer that will contain the received data |
| 485 | * @param BlockAdd: Block Address from where data is to be read |
547 | * @param BlockAdd: Block Address from where data is to be read |
| 486 | * @param NumberOfBlocks: Number of MMC blocks to read |
548 | * @param NumberOfBlocks: Number of MMC blocks to read |
| 487 | * @param Timeout: Specify timeout value |
549 | * @param Timeout: Specify timeout value |
| 488 | * @retval HAL status |
550 | * @retval HAL status |
| 489 | */ |
551 | */ |
| 490 | HAL_StatusTypeDef HAL_MMC_ReadBlocks(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout) |
552 | HAL_StatusTypeDef HAL_MMC_ReadBlocks(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout) |
| 491 | { |
553 | { |
| 492 | SDIO_DataInitTypeDef config; |
554 | SDIO_DataInitTypeDef config; |
| 493 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
555 | uint32_t errorstate; |
| 494 | uint32_t tickstart = HAL_GetTick(); |
556 | uint32_t tickstart = HAL_GetTick(); |
| - | 557 | uint32_t count, data, dataremaining; |
|
| - | 558 | uint32_t add = BlockAdd; |
|
| 495 | uint32_t count = 0U, *tempbuff = (uint32_t *)pData; |
559 | uint8_t *tempbuff = pData; |
| 496 | 560 | ||
| 497 | if(NULL == pData) |
561 | if(NULL == pData) |
| 498 | { |
562 | { |
| 499 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
563 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
| 500 | return HAL_ERROR; |
564 | return HAL_ERROR; |
| 501 | } |
565 | } |
| 502 | 566 | ||
| 503 | if(hmmc->State == HAL_MMC_STATE_READY) |
567 | if(hmmc->State == HAL_MMC_STATE_READY) |
| 504 | { |
568 | { |
| 505 | hmmc->ErrorCode = HAL_DMA_ERROR_NONE; |
569 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
| 506 | 570 | ||
| 507 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
571 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
| 508 | { |
572 | { |
| 509 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
573 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
| 510 | return HAL_ERROR; |
574 | return HAL_ERROR; |
| 511 | } |
575 | } |
| 512 | 576 | ||
| 513 | hmmc->State = HAL_MMC_STATE_BUSY; |
577 | hmmc->State = HAL_MMC_STATE_BUSY; |
| 514 | 578 | ||
| 515 | /* Initialize data control register */ |
579 | /* Initialize data control register */ |
| 516 | hmmc->Instance->DCTRL = 0U; |
580 | hmmc->Instance->DCTRL = 0U; |
| 517 | 581 | ||
| 518 | /* Check the Card capacity in term of Logical number of blocks */ |
- | |
| 519 | if ((hmmc->MmcCard.LogBlockNbr) < CAPACITY) |
582 | if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD) |
| 520 | { |
583 | { |
| 521 | BlockAdd *= 512U; |
584 | add *= 512U; |
| 522 | } |
585 | } |
| 523 | 586 | ||
| 524 | /* Set Block Size for Card */ |
587 | /* Set Block Size for Card */ |
| 525 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, BLOCKSIZE); |
588 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, MMC_BLOCKSIZE); |
| 526 | if(errorstate != HAL_MMC_ERROR_NONE) |
589 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 527 | { |
590 | { |
| 528 | /* Clear all the static flags */ |
591 | /* Clear all the static flags */ |
| 529 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
592 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 530 | hmmc->ErrorCode |= errorstate; |
593 | hmmc->ErrorCode |= errorstate; |
| 531 | hmmc->State = HAL_MMC_STATE_READY; |
594 | hmmc->State = HAL_MMC_STATE_READY; |
| 532 | return HAL_ERROR; |
595 | return HAL_ERROR; |
| 533 | } |
596 | } |
| 534 | 597 | ||
| 535 | /* Configure the MMC DPSM (Data Path State Machine) */ |
598 | /* Configure the MMC DPSM (Data Path State Machine) */ |
| 536 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
599 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
| 537 | config.DataLength = NumberOfBlocks * BLOCKSIZE; |
600 | config.DataLength = NumberOfBlocks * MMC_BLOCKSIZE; |
| 538 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
601 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
| 539 | config.TransferDir = SDIO_TRANSFER_DIR_TO_SDIO; |
602 | config.TransferDir = SDIO_TRANSFER_DIR_TO_SDIO; |
| 540 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
603 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
| 541 | config.DPSM = SDIO_DPSM_ENABLE; |
604 | config.DPSM = SDIO_DPSM_ENABLE; |
| 542 | SDIO_ConfigData(hmmc->Instance, &config); |
605 | (void)SDIO_ConfigData(hmmc->Instance, &config); |
| 543 | 606 | ||
| 544 | /* Read block(s) in polling mode */ |
607 | /* Read block(s) in polling mode */ |
| 545 | if(NumberOfBlocks > 1U) |
608 | if(NumberOfBlocks > 1U) |
| 546 | { |
609 | { |
| 547 | hmmc->Context = MMC_CONTEXT_READ_MULTIPLE_BLOCK; |
610 | hmmc->Context = MMC_CONTEXT_READ_MULTIPLE_BLOCK; |
| 548 | 611 | ||
| 549 | /* Read Multi Block command */ |
612 | /* Read Multi Block command */ |
| 550 | errorstate = SDMMC_CmdReadMultiBlock(hmmc->Instance, BlockAdd); |
613 | errorstate = SDMMC_CmdReadMultiBlock(hmmc->Instance, add); |
| 551 | } |
614 | } |
| 552 | else |
615 | else |
| 553 | { |
616 | { |
| 554 | hmmc->Context = MMC_CONTEXT_READ_SINGLE_BLOCK; |
617 | hmmc->Context = MMC_CONTEXT_READ_SINGLE_BLOCK; |
| 555 | 618 | ||
| 556 | /* Read Single Block command */ |
619 | /* Read Single Block command */ |
| 557 | errorstate = SDMMC_CmdReadSingleBlock(hmmc->Instance, BlockAdd); |
620 | errorstate = SDMMC_CmdReadSingleBlock(hmmc->Instance, add); |
| 558 | } |
621 | } |
| 559 | if(errorstate != HAL_MMC_ERROR_NONE) |
622 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 560 | { |
623 | { |
| 561 | /* Clear all the static flags */ |
624 | /* Clear all the static flags */ |
| 562 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
625 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 563 | hmmc->ErrorCode |= errorstate; |
626 | hmmc->ErrorCode |= errorstate; |
| 564 | hmmc->State = HAL_MMC_STATE_READY; |
627 | hmmc->State = HAL_MMC_STATE_READY; |
| 565 | return HAL_ERROR; |
628 | return HAL_ERROR; |
| 566 | } |
629 | } |
| 567 | 630 | ||
| 568 | /* Poll on SDMMC flags */ |
631 | /* Poll on SDIO flags */ |
| 569 | #ifdef SDIO_STA_STBITERR |
- | |
| 570 | while(!__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DATAEND | SDIO_STA_STBITERR)) |
- | |
| 571 | #else /* SDIO_STA_STBITERR not defined */ |
632 | dataremaining = config.DataLength; |
| 572 | while(!__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DATAEND)) |
633 | while(!__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DATAEND | SDIO_FLAG_STBITERR)) |
| 573 | #endif /* SDIO_STA_STBITERR */ |
- | |
| 574 | { |
634 | { |
| 575 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXFIFOHF)) |
635 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXFIFOHF) && (dataremaining > 0U)) |
| 576 | { |
636 | { |
| 577 | /* Read data from SDMMC Rx FIFO */ |
637 | /* Read data from SDIO Rx FIFO */ |
| 578 | for(count = 0U; count < 8U; count++) |
638 | for(count = 0U; count < 8U; count++) |
| 579 | { |
639 | { |
| 580 | *(tempbuff + count) = SDIO_ReadFIFO(hmmc->Instance); |
640 | data = SDIO_ReadFIFO(hmmc->Instance); |
| - | 641 | *tempbuff = (uint8_t)(data & 0xFFU); |
|
| - | 642 | tempbuff++; |
|
| - | 643 | dataremaining--; |
|
| - | 644 | *tempbuff = (uint8_t)((data >> 8U) & 0xFFU); |
|
| - | 645 | tempbuff++; |
|
| - | 646 | dataremaining--; |
|
| - | 647 | *tempbuff = (uint8_t)((data >> 16U) & 0xFFU); |
|
| - | 648 | tempbuff++; |
|
| - | 649 | dataremaining--; |
|
| - | 650 | *tempbuff = (uint8_t)((data >> 24U) & 0xFFU); |
|
| - | 651 | tempbuff++; |
|
| - | 652 | dataremaining--; |
|
| 581 | } |
653 | } |
| 582 | tempbuff += 8U; |
- | |
| 583 | } |
654 | } |
| 584 | 655 | ||
| 585 | if((Timeout == 0U)||((HAL_GetTick()-tickstart) >= Timeout)) |
656 | if(((HAL_GetTick()-tickstart) >= Timeout) || (Timeout == 0U)) |
| 586 | { |
657 | { |
| 587 | /* Clear all the static flags */ |
658 | /* Clear all the static flags */ |
| 588 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
659 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 589 | hmmc->ErrorCode |= HAL_MMC_ERROR_TIMEOUT; |
660 | hmmc->ErrorCode |= HAL_MMC_ERROR_TIMEOUT; |
| 590 | hmmc->State= HAL_MMC_STATE_READY; |
661 | hmmc->State= HAL_MMC_STATE_READY; |
| 591 | return HAL_TIMEOUT; |
662 | return HAL_TIMEOUT; |
| 592 | } |
663 | } |
| 593 | } |
664 | } |
| 594 | 665 | ||
| 595 | /* Send stop transmission command in case of multiblock read */ |
666 | /* Send stop transmission command in case of multiblock read */ |
| 596 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DATAEND) && (NumberOfBlocks > 1U)) |
667 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DATAEND) && (NumberOfBlocks > 1U)) |
| 597 | { |
668 | { |
| 598 | /* Send stop transmission command */ |
669 | /* Send stop transmission command */ |
| 599 | errorstate = SDMMC_CmdStopTransfer(hmmc->Instance); |
670 | errorstate = SDMMC_CmdStopTransfer(hmmc->Instance); |
| 600 | if(errorstate != HAL_MMC_ERROR_NONE) |
671 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 601 | { |
672 | { |
| 602 | /* Clear all the static flags */ |
673 | /* Clear all the static flags */ |
| Line 604... | Line 675... | ||
| 604 | hmmc->ErrorCode |= errorstate; |
675 | hmmc->ErrorCode |= errorstate; |
| 605 | hmmc->State = HAL_MMC_STATE_READY; |
676 | hmmc->State = HAL_MMC_STATE_READY; |
| 606 | return HAL_ERROR; |
677 | return HAL_ERROR; |
| 607 | } |
678 | } |
| 608 | } |
679 | } |
| 609 | 680 | ||
| 610 | /* Get error state */ |
681 | /* Get error state */ |
| 611 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DTIMEOUT)) |
682 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DTIMEOUT)) |
| 612 | { |
683 | { |
| 613 | /* Clear all the static flags */ |
684 | /* Clear all the static flags */ |
| 614 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
685 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| Line 630... | Line 701... | ||
| 630 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
701 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 631 | hmmc->ErrorCode |= HAL_MMC_ERROR_RX_OVERRUN; |
702 | hmmc->ErrorCode |= HAL_MMC_ERROR_RX_OVERRUN; |
| 632 | hmmc->State = HAL_MMC_STATE_READY; |
703 | hmmc->State = HAL_MMC_STATE_READY; |
| 633 | return HAL_ERROR; |
704 | return HAL_ERROR; |
| 634 | } |
705 | } |
| - | 706 | else |
|
| 635 | 707 | { |
|
| - | 708 | /* Nothing to do */ |
|
| - | 709 | } |
|
| - | 710 | ||
| 636 | /* Empty FIFO if there is still any data */ |
711 | /* Empty FIFO if there is still any data */ |
| 637 | while ((__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXDAVL))) |
712 | while ((__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXDAVL)) && (dataremaining > 0U)) |
| 638 | { |
713 | { |
| 639 | *tempbuff = SDIO_ReadFIFO(hmmc->Instance); |
714 | data = SDIO_ReadFIFO(hmmc->Instance); |
| - | 715 | *tempbuff = (uint8_t)(data & 0xFFU); |
|
| 640 | tempbuff++; |
716 | tempbuff++; |
| - | 717 | dataremaining--; |
|
| - | 718 | *tempbuff = (uint8_t)((data >> 8U) & 0xFFU); |
|
| - | 719 | tempbuff++; |
|
| - | 720 | dataremaining--; |
|
| - | 721 | *tempbuff = (uint8_t)((data >> 16U) & 0xFFU); |
|
| 641 | 722 | tempbuff++; |
|
| - | 723 | dataremaining--; |
|
| - | 724 | *tempbuff = (uint8_t)((data >> 24U) & 0xFFU); |
|
| - | 725 | tempbuff++; |
|
| - | 726 | dataremaining--; |
|
| - | 727 | ||
| 642 | if((Timeout == 0U)||((HAL_GetTick()-tickstart) >= Timeout)) |
728 | if(((HAL_GetTick()-tickstart) >= Timeout) || (Timeout == 0U)) |
| 643 | { |
729 | { |
| 644 | /* Clear all the static flags */ |
730 | /* Clear all the static flags */ |
| 645 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
731 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 646 | hmmc->ErrorCode |= HAL_MMC_ERROR_TIMEOUT; |
732 | hmmc->ErrorCode |= HAL_MMC_ERROR_TIMEOUT; |
| 647 | hmmc->State= HAL_MMC_STATE_READY; |
733 | hmmc->State= HAL_MMC_STATE_READY; |
| 648 | return HAL_ERROR; |
734 | return HAL_ERROR; |
| 649 | } |
735 | } |
| 650 | } |
736 | } |
| 651 | 737 | ||
| 652 | /* Clear all the static flags */ |
738 | /* Clear all the static flags */ |
| 653 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
739 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_DATA_FLAGS); |
| 654 | 740 | ||
| 655 | hmmc->State = HAL_MMC_STATE_READY; |
741 | hmmc->State = HAL_MMC_STATE_READY; |
| 656 | 742 | ||
| 657 | return HAL_OK; |
743 | return HAL_OK; |
| 658 | } |
744 | } |
| 659 | else |
745 | else |
| 660 | { |
746 | { |
| 661 | hmmc->ErrorCode |= HAL_MMC_ERROR_BUSY; |
747 | hmmc->ErrorCode |= HAL_MMC_ERROR_BUSY; |
| Line 668... | Line 754... | ||
| 668 | * transfer is managed by polling mode. |
754 | * transfer is managed by polling mode. |
| 669 | * @note This API should be followed by a check on the card state through |
755 | * @note This API should be followed by a check on the card state through |
| 670 | * HAL_MMC_GetCardState(). |
756 | * HAL_MMC_GetCardState(). |
| 671 | * @param hmmc: Pointer to MMC handle |
757 | * @param hmmc: Pointer to MMC handle |
| 672 | * @param pData: pointer to the buffer that will contain the data to transmit |
758 | * @param pData: pointer to the buffer that will contain the data to transmit |
| 673 | * @param BlockAdd: Block Address where data will be written |
759 | * @param BlockAdd: Block Address where data will be written |
| 674 | * @param NumberOfBlocks: Number of MMC blocks to write |
760 | * @param NumberOfBlocks: Number of MMC blocks to write |
| 675 | * @param Timeout: Specify timeout value |
761 | * @param Timeout: Specify timeout value |
| 676 | * @retval HAL status |
762 | * @retval HAL status |
| 677 | */ |
763 | */ |
| 678 | HAL_StatusTypeDef HAL_MMC_WriteBlocks(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout) |
764 | HAL_StatusTypeDef HAL_MMC_WriteBlocks(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout) |
| 679 | { |
765 | { |
| 680 | SDIO_DataInitTypeDef config; |
766 | SDIO_DataInitTypeDef config; |
| 681 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
767 | uint32_t errorstate; |
| 682 | uint32_t tickstart = HAL_GetTick(); |
768 | uint32_t tickstart = HAL_GetTick(); |
| - | 769 | uint32_t count, data, dataremaining; |
|
| 683 | uint32_t count = 0U; |
770 | uint32_t add = BlockAdd; |
| 684 | uint32_t *tempbuff = (uint32_t *)pData; |
771 | uint8_t *tempbuff = pData; |
| 685 | 772 | ||
| 686 | if(NULL == pData) |
773 | if(NULL == pData) |
| 687 | { |
774 | { |
| 688 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
775 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
| 689 | return HAL_ERROR; |
776 | return HAL_ERROR; |
| 690 | } |
777 | } |
| 691 | 778 | ||
| 692 | if(hmmc->State == HAL_MMC_STATE_READY) |
779 | if(hmmc->State == HAL_MMC_STATE_READY) |
| 693 | { |
780 | { |
| 694 | hmmc->ErrorCode = HAL_DMA_ERROR_NONE; |
781 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
| 695 | 782 | ||
| 696 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
783 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
| 697 | { |
784 | { |
| 698 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
785 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
| 699 | return HAL_ERROR; |
786 | return HAL_ERROR; |
| 700 | } |
787 | } |
| 701 | 788 | ||
| 702 | hmmc->State = HAL_MMC_STATE_BUSY; |
789 | hmmc->State = HAL_MMC_STATE_BUSY; |
| 703 | 790 | ||
| 704 | /* Initialize data control register */ |
791 | /* Initialize data control register */ |
| 705 | hmmc->Instance->DCTRL = 0U; |
792 | hmmc->Instance->DCTRL = 0U; |
| 706 | 793 | ||
| 707 | /* Check the Card capacity in term of Logical number of blocks */ |
- | |
| 708 | if ((hmmc->MmcCard.LogBlockNbr) < CAPACITY) |
794 | if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD) |
| 709 | { |
795 | { |
| 710 | BlockAdd *= 512U; |
796 | add *= 512U; |
| 711 | } |
797 | } |
| 712 | 798 | ||
| 713 | /* Set Block Size for Card */ |
799 | /* Set Block Size for Card */ |
| 714 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, BLOCKSIZE); |
800 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, MMC_BLOCKSIZE); |
| 715 | if(errorstate != HAL_MMC_ERROR_NONE) |
801 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 716 | { |
802 | { |
| 717 | /* Clear all the static flags */ |
803 | /* Clear all the static flags */ |
| 718 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
804 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 719 | hmmc->ErrorCode |= errorstate; |
805 | hmmc->ErrorCode |= errorstate; |
| 720 | hmmc->State = HAL_MMC_STATE_READY; |
806 | hmmc->State = HAL_MMC_STATE_READY; |
| 721 | return HAL_ERROR; |
807 | return HAL_ERROR; |
| 722 | } |
808 | } |
| 723 | 809 | ||
| 724 | /* Write Blocks in Polling mode */ |
810 | /* Write Blocks in Polling mode */ |
| 725 | if(NumberOfBlocks > 1U) |
811 | if(NumberOfBlocks > 1U) |
| 726 | { |
812 | { |
| 727 | hmmc->Context = MMC_CONTEXT_WRITE_MULTIPLE_BLOCK; |
813 | hmmc->Context = MMC_CONTEXT_WRITE_MULTIPLE_BLOCK; |
| 728 | 814 | ||
| 729 | /* Write Multi Block command */ |
815 | /* Write Multi Block command */ |
| 730 | errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, BlockAdd); |
816 | errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, add); |
| 731 | } |
817 | } |
| 732 | else |
818 | else |
| 733 | { |
819 | { |
| 734 | hmmc->Context = MMC_CONTEXT_WRITE_SINGLE_BLOCK; |
820 | hmmc->Context = MMC_CONTEXT_WRITE_SINGLE_BLOCK; |
| 735 | 821 | ||
| 736 | /* Write Single Block command */ |
822 | /* Write Single Block command */ |
| 737 | errorstate = SDMMC_CmdWriteSingleBlock(hmmc->Instance, BlockAdd); |
823 | errorstate = SDMMC_CmdWriteSingleBlock(hmmc->Instance, add); |
| 738 | } |
824 | } |
| 739 | if(errorstate != HAL_MMC_ERROR_NONE) |
825 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 740 | { |
826 | { |
| 741 | /* Clear all the static flags */ |
827 | /* Clear all the static flags */ |
| 742 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
828 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 743 | hmmc->ErrorCode |= errorstate; |
829 | hmmc->ErrorCode |= errorstate; |
| 744 | hmmc->State = HAL_MMC_STATE_READY; |
830 | hmmc->State = HAL_MMC_STATE_READY; |
| 745 | return HAL_ERROR; |
831 | return HAL_ERROR; |
| 746 | } |
832 | } |
| 747 | 833 | ||
| 748 | /* Configure the MMC DPSM (Data Path State Machine) */ |
834 | /* Configure the MMC DPSM (Data Path State Machine) */ |
| 749 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
835 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
| 750 | config.DataLength = NumberOfBlocks * BLOCKSIZE; |
836 | config.DataLength = NumberOfBlocks * MMC_BLOCKSIZE; |
| 751 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
837 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
| 752 | config.TransferDir = SDIO_TRANSFER_DIR_TO_CARD; |
838 | config.TransferDir = SDIO_TRANSFER_DIR_TO_CARD; |
| 753 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
839 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
| 754 | config.DPSM = SDIO_DPSM_ENABLE; |
840 | config.DPSM = SDIO_DPSM_ENABLE; |
| 755 | SDIO_ConfigData(hmmc->Instance, &config); |
841 | (void)SDIO_ConfigData(hmmc->Instance, &config); |
| 756 | 842 | ||
| 757 | /* Write block(s) in polling mode */ |
843 | /* Write block(s) in polling mode */ |
| 758 | #ifdef SDIO_STA_STBITERR |
844 | dataremaining = config.DataLength; |
| 759 | while(!__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_TXUNDERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DATAEND | SDIO_FLAG_STBITERR)) |
845 | while(!__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_TXUNDERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DATAEND | SDIO_FLAG_STBITERR)) |
| 760 | #else /* SDIO_STA_STBITERR not defined */ |
- | |
| 761 | while(!__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_TXUNDERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DATAEND)) |
- | |
| 762 | #endif /* SDIO_STA_STBITERR */ |
- | |
| 763 | { |
846 | { |
| 764 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_TXFIFOHE)) |
847 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_TXFIFOHE) && (dataremaining > 0U)) |
| 765 | { |
848 | { |
| 766 | /* Write data to SDIO Tx FIFO */ |
849 | /* Write data to SDIO Tx FIFO */ |
| 767 | for(count = 0U; count < 8U; count++) |
850 | for(count = 0U; count < 8U; count++) |
| 768 | { |
851 | { |
| - | 852 | data = (uint32_t)(*tempbuff); |
|
| - | 853 | tempbuff++; |
|
| - | 854 | dataremaining--; |
|
| - | 855 | data |= ((uint32_t)(*tempbuff) << 8U); |
|
| - | 856 | tempbuff++; |
|
| - | 857 | dataremaining--; |
|
| - | 858 | data |= ((uint32_t)(*tempbuff) << 16U); |
|
| - | 859 | tempbuff++; |
|
| - | 860 | dataremaining--; |
|
| - | 861 | data |= ((uint32_t)(*tempbuff) << 24U); |
|
| - | 862 | tempbuff++; |
|
| - | 863 | dataremaining--; |
|
| 769 | SDIO_WriteFIFO(hmmc->Instance, (tempbuff + count)); |
864 | (void)SDIO_WriteFIFO(hmmc->Instance, &data); |
| 770 | } |
865 | } |
| 771 | tempbuff += 8U; |
- | |
| 772 | } |
866 | } |
| 773 | 867 | ||
| 774 | if((Timeout == 0U)||((HAL_GetTick()-tickstart) >= Timeout)) |
868 | if(((HAL_GetTick()-tickstart) >= Timeout) || (Timeout == 0U)) |
| 775 | { |
869 | { |
| 776 | /* Clear all the static flags */ |
870 | /* Clear all the static flags */ |
| 777 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
871 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 778 | hmmc->ErrorCode |= errorstate; |
872 | hmmc->ErrorCode |= errorstate; |
| 779 | hmmc->State = HAL_MMC_STATE_READY; |
873 | hmmc->State = HAL_MMC_STATE_READY; |
| 780 | return HAL_TIMEOUT; |
874 | return HAL_TIMEOUT; |
| 781 | } |
875 | } |
| 782 | } |
876 | } |
| 783 | 877 | ||
| 784 | /* Send stop transmission command in case of multiblock write */ |
878 | /* Send stop transmission command in case of multiblock write */ |
| 785 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DATAEND) && (NumberOfBlocks > 1U)) |
879 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DATAEND) && (NumberOfBlocks > 1U)) |
| 786 | { |
880 | { |
| 787 | /* Send stop transmission command */ |
881 | /* Send stop transmission command */ |
| 788 | errorstate = SDMMC_CmdStopTransfer(hmmc->Instance); |
882 | errorstate = SDMMC_CmdStopTransfer(hmmc->Instance); |
| 789 | if(errorstate != HAL_MMC_ERROR_NONE) |
883 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 790 | { |
884 | { |
| 791 | /* Clear all the static flags */ |
885 | /* Clear all the static flags */ |
| 792 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
886 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 793 | hmmc->ErrorCode |= errorstate; |
887 | hmmc->ErrorCode |= errorstate; |
| 794 | hmmc->State = HAL_MMC_STATE_READY; |
888 | hmmc->State = HAL_MMC_STATE_READY; |
| 795 | return HAL_ERROR; |
889 | return HAL_ERROR; |
| 796 | } |
890 | } |
| 797 | } |
891 | } |
| 798 | 892 | ||
| 799 | /* Get error state */ |
893 | /* Get error state */ |
| 800 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DTIMEOUT)) |
894 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DTIMEOUT)) |
| 801 | { |
895 | { |
| 802 | /* Clear all the static flags */ |
896 | /* Clear all the static flags */ |
| 803 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
897 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| Line 807... | Line 901... | ||
| 807 | } |
901 | } |
| 808 | else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DCRCFAIL)) |
902 | else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DCRCFAIL)) |
| 809 | { |
903 | { |
| 810 | /* Clear all the static flags */ |
904 | /* Clear all the static flags */ |
| 811 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
905 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 812 | hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_CRC_FAIL; |
906 | hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_CRC_FAIL; |
| 813 | hmmc->State = HAL_MMC_STATE_READY; |
907 | hmmc->State = HAL_MMC_STATE_READY; |
| 814 | return HAL_ERROR; |
908 | return HAL_ERROR; |
| 815 | } |
909 | } |
| 816 | else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_TXUNDERR)) |
910 | else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_TXUNDERR)) |
| 817 | { |
911 | { |
| Line 819... | Line 913... | ||
| 819 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
913 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 820 | hmmc->ErrorCode |= HAL_MMC_ERROR_TX_UNDERRUN; |
914 | hmmc->ErrorCode |= HAL_MMC_ERROR_TX_UNDERRUN; |
| 821 | hmmc->State = HAL_MMC_STATE_READY; |
915 | hmmc->State = HAL_MMC_STATE_READY; |
| 822 | return HAL_ERROR; |
916 | return HAL_ERROR; |
| 823 | } |
917 | } |
| - | 918 | else |
|
| 824 | 919 | { |
|
| - | 920 | /* Nothing to do */ |
|
| - | 921 | } |
|
| - | 922 | ||
| 825 | /* Clear all the static flags */ |
923 | /* Clear all the static flags */ |
| 826 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
924 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_DATA_FLAGS); |
| 827 | 925 | ||
| 828 | hmmc->State = HAL_MMC_STATE_READY; |
926 | hmmc->State = HAL_MMC_STATE_READY; |
| 829 | 927 | ||
| 830 | return HAL_OK; |
928 | return HAL_OK; |
| 831 | } |
929 | } |
| 832 | else |
930 | else |
| 833 | { |
931 | { |
| 834 | hmmc->ErrorCode |= HAL_MMC_ERROR_BUSY; |
932 | hmmc->ErrorCode |= HAL_MMC_ERROR_BUSY; |
| 835 | return HAL_ERROR; |
933 | return HAL_ERROR; |
| 836 | } |
934 | } |
| 837 | } |
935 | } |
| 838 | 936 | ||
| 839 | /** |
937 | /** |
| 840 | * @brief Reads block(s) from a specified address in a card. The Data transfer |
938 | * @brief Reads block(s) from a specified address in a card. The Data transfer |
| 841 | * is managed in interrupt mode. |
939 | * is managed in interrupt mode. |
| 842 | * @note This API should be followed by a check on the card state through |
940 | * @note This API should be followed by a check on the card state through |
| 843 | * HAL_MMC_GetCardState(). |
941 | * HAL_MMC_GetCardState(). |
| 844 | * @note You could also check the IT transfer process through the MMC Rx |
942 | * @note You could also check the IT transfer process through the MMC Rx |
| 845 | * interrupt event. |
943 | * interrupt event. |
| 846 | * @param hmmc: Pointer to MMC handle |
944 | * @param hmmc: Pointer to MMC handle |
| 847 | * @param pData: Pointer to the buffer that will contain the received data |
945 | * @param pData: Pointer to the buffer that will contain the received data |
| 848 | * @param BlockAdd: Block Address from where data is to be read |
946 | * @param BlockAdd: Block Address from where data is to be read |
| 849 | * @param NumberOfBlocks: Number of blocks to read. |
947 | * @param NumberOfBlocks: Number of blocks to read. |
| 850 | * @retval HAL status |
948 | * @retval HAL status |
| 851 | */ |
949 | */ |
| 852 | HAL_StatusTypeDef HAL_MMC_ReadBlocks_IT(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks) |
950 | HAL_StatusTypeDef HAL_MMC_ReadBlocks_IT(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks) |
| 853 | { |
951 | { |
| 854 | SDIO_DataInitTypeDef config; |
952 | SDIO_DataInitTypeDef config; |
| 855 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
953 | uint32_t errorstate; |
| - | 954 | uint32_t add = BlockAdd; |
|
| 856 | 955 | ||
| 857 | if(NULL == pData) |
956 | if(NULL == pData) |
| 858 | { |
957 | { |
| 859 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
958 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
| 860 | return HAL_ERROR; |
959 | return HAL_ERROR; |
| 861 | } |
960 | } |
| 862 | 961 | ||
| 863 | if(hmmc->State == HAL_MMC_STATE_READY) |
962 | if(hmmc->State == HAL_MMC_STATE_READY) |
| 864 | { |
963 | { |
| 865 | hmmc->ErrorCode = HAL_DMA_ERROR_NONE; |
964 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
| 866 | 965 | ||
| 867 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
966 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
| 868 | { |
967 | { |
| 869 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
968 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
| 870 | return HAL_ERROR; |
969 | return HAL_ERROR; |
| 871 | } |
970 | } |
| 872 | 971 | ||
| 873 | hmmc->State = HAL_MMC_STATE_BUSY; |
972 | hmmc->State = HAL_MMC_STATE_BUSY; |
| 874 | 973 | ||
| 875 | /* Initialize data control register */ |
974 | /* Initialize data control register */ |
| 876 | hmmc->Instance->DCTRL = 0U; |
975 | hmmc->Instance->DCTRL = 0U; |
| 877 | - | ||
| 878 | hmmc->pRxBuffPtr = (uint32_t *)pData; |
- | |
| 879 | hmmc->RxXferSize = BLOCKSIZE * NumberOfBlocks; |
- | |
| 880 | - | ||
| 881 | __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_RXOVERR | SDIO_IT_DATAEND | SDIO_FLAG_RXFIFOHF)); |
- | |
| 882 | 976 | ||
| - | 977 | hmmc->pRxBuffPtr = pData; |
|
| 883 | /* Check the Card capacity in term of Logical number of blocks */ |
978 | hmmc->RxXferSize = MMC_BLOCKSIZE * NumberOfBlocks; |
| - | 979 | ||
| - | 980 | __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_RXOVERR | SDIO_IT_DATAEND | SDIO_FLAG_RXFIFOHF | SDIO_IT_STBITERR)); |
|
| - | 981 | ||
| 884 | if ((hmmc->MmcCard.LogBlockNbr) < CAPACITY) |
982 | if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD) |
| 885 | { |
983 | { |
| 886 | BlockAdd *= 512U; |
984 | add *= 512U; |
| 887 | } |
985 | } |
| 888 | 986 | ||
| 889 | /* Configure the MMC DPSM (Data Path State Machine) */ |
- | |
| 890 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
- | |
| 891 | config.DataLength = BLOCKSIZE * NumberOfBlocks; |
- | |
| 892 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
- | |
| 893 | config.TransferDir = SDIO_TRANSFER_DIR_TO_SDIO; |
- | |
| 894 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
- | |
| 895 | config.DPSM = SDIO_DPSM_ENABLE; |
- | |
| 896 | SDIO_ConfigData(hmmc->Instance, &config); |
- | |
| 897 | - | ||
| 898 | /* Set Block Size for Card */ |
987 | /* Set Block Size for Card */ |
| 899 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, BLOCKSIZE); |
988 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, MMC_BLOCKSIZE); |
| 900 | if(errorstate != HAL_MMC_ERROR_NONE) |
989 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 901 | { |
990 | { |
| 902 | /* Clear all the static flags */ |
991 | /* Clear all the static flags */ |
| 903 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
992 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 904 | hmmc->ErrorCode |= errorstate; |
993 | hmmc->ErrorCode |= errorstate; |
| 905 | hmmc->State = HAL_MMC_STATE_READY; |
994 | hmmc->State = HAL_MMC_STATE_READY; |
| 906 | return HAL_ERROR; |
995 | return HAL_ERROR; |
| 907 | } |
996 | } |
| 908 | 997 | ||
| - | 998 | /* Configure the MMC DPSM (Data Path State Machine) */ |
|
| - | 999 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
|
| - | 1000 | config.DataLength = MMC_BLOCKSIZE * NumberOfBlocks; |
|
| - | 1001 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
|
| - | 1002 | config.TransferDir = SDIO_TRANSFER_DIR_TO_SDIO; |
|
| - | 1003 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
|
| - | 1004 | config.DPSM = SDIO_DPSM_ENABLE; |
|
| - | 1005 | (void)SDIO_ConfigData(hmmc->Instance, &config); |
|
| - | 1006 | ||
| 909 | /* Read Blocks in IT mode */ |
1007 | /* Read Blocks in IT mode */ |
| 910 | if(NumberOfBlocks > 1U) |
1008 | if(NumberOfBlocks > 1U) |
| 911 | { |
1009 | { |
| 912 | hmmc->Context = (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_IT); |
1010 | hmmc->Context = (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_IT); |
| 913 | 1011 | ||
| 914 | /* Read Multi Block command */ |
1012 | /* Read Multi Block command */ |
| 915 | errorstate = SDMMC_CmdReadMultiBlock(hmmc->Instance, BlockAdd); |
1013 | errorstate = SDMMC_CmdReadMultiBlock(hmmc->Instance, add); |
| 916 | } |
1014 | } |
| 917 | else |
1015 | else |
| 918 | { |
1016 | { |
| 919 | hmmc->Context = (MMC_CONTEXT_READ_SINGLE_BLOCK | MMC_CONTEXT_IT); |
1017 | hmmc->Context = (MMC_CONTEXT_READ_SINGLE_BLOCK | MMC_CONTEXT_IT); |
| 920 | 1018 | ||
| 921 | /* Read Single Block command */ |
1019 | /* Read Single Block command */ |
| 922 | errorstate = SDMMC_CmdReadSingleBlock(hmmc->Instance, BlockAdd); |
1020 | errorstate = SDMMC_CmdReadSingleBlock(hmmc->Instance, add); |
| 923 | } |
1021 | } |
| - | 1022 | ||
| 924 | if(errorstate != HAL_MMC_ERROR_NONE) |
1023 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 925 | { |
1024 | { |
| 926 | /* Clear all the static flags */ |
1025 | /* Clear all the static flags */ |
| 927 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1026 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 928 | hmmc->ErrorCode |= errorstate; |
1027 | hmmc->ErrorCode |= errorstate; |
| 929 | hmmc->State = HAL_MMC_STATE_READY; |
1028 | hmmc->State = HAL_MMC_STATE_READY; |
| 930 | return HAL_ERROR; |
1029 | return HAL_ERROR; |
| 931 | } |
1030 | } |
| 932 | 1031 | ||
| 933 | return HAL_OK; |
1032 | return HAL_OK; |
| 934 | } |
1033 | } |
| 935 | else |
1034 | else |
| 936 | { |
1035 | { |
| 937 | return HAL_BUSY; |
1036 | return HAL_BUSY; |
| 938 | } |
1037 | } |
| 939 | } |
1038 | } |
| 940 | 1039 | ||
| 941 | /** |
1040 | /** |
| 942 | * @brief Writes block(s) to a specified address in a card. The Data transfer |
1041 | * @brief Writes block(s) to a specified address in a card. The Data transfer |
| 943 | * is managed in interrupt mode. |
1042 | * is managed in interrupt mode. |
| 944 | * @note This API should be followed by a check on the card state through |
1043 | * @note This API should be followed by a check on the card state through |
| 945 | * HAL_MMC_GetCardState(). |
1044 | * HAL_MMC_GetCardState(). |
| 946 | * @note You could also check the IT transfer process through the MMC Tx |
1045 | * @note You could also check the IT transfer process through the MMC Tx |
| 947 | * interrupt event. |
1046 | * interrupt event. |
| 948 | * @param hmmc: Pointer to MMC handle |
1047 | * @param hmmc: Pointer to MMC handle |
| 949 | * @param pData: Pointer to the buffer that will contain the data to transmit |
1048 | * @param pData: Pointer to the buffer that will contain the data to transmit |
| 950 | * @param BlockAdd: Block Address where data will be written |
1049 | * @param BlockAdd: Block Address where data will be written |
| 951 | * @param NumberOfBlocks: Number of blocks to write |
1050 | * @param NumberOfBlocks: Number of blocks to write |
| 952 | * @retval HAL status |
1051 | * @retval HAL status |
| 953 | */ |
1052 | */ |
| 954 | HAL_StatusTypeDef HAL_MMC_WriteBlocks_IT(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks) |
1053 | HAL_StatusTypeDef HAL_MMC_WriteBlocks_IT(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks) |
| 955 | { |
1054 | { |
| 956 | SDIO_DataInitTypeDef config; |
1055 | SDIO_DataInitTypeDef config; |
| 957 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
1056 | uint32_t errorstate; |
| - | 1057 | uint32_t add = BlockAdd; |
|
| 958 | 1058 | ||
| 959 | if(NULL == pData) |
1059 | if(NULL == pData) |
| 960 | { |
1060 | { |
| 961 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
1061 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
| 962 | return HAL_ERROR; |
1062 | return HAL_ERROR; |
| 963 | } |
1063 | } |
| 964 | 1064 | ||
| 965 | if(hmmc->State == HAL_MMC_STATE_READY) |
1065 | if(hmmc->State == HAL_MMC_STATE_READY) |
| 966 | { |
1066 | { |
| 967 | hmmc->ErrorCode = HAL_DMA_ERROR_NONE; |
1067 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
| 968 | 1068 | ||
| 969 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
1069 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
| 970 | { |
1070 | { |
| 971 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
1071 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
| 972 | return HAL_ERROR; |
1072 | return HAL_ERROR; |
| 973 | } |
1073 | } |
| 974 | 1074 | ||
| 975 | hmmc->State = HAL_MMC_STATE_BUSY; |
1075 | hmmc->State = HAL_MMC_STATE_BUSY; |
| 976 | 1076 | ||
| 977 | /* Initialize data control register */ |
1077 | /* Initialize data control register */ |
| 978 | hmmc->Instance->DCTRL = 0U; |
1078 | hmmc->Instance->DCTRL = 0U; |
| 979 | 1079 | ||
| 980 | hmmc->pTxBuffPtr = (uint32_t *)pData; |
1080 | hmmc->pTxBuffPtr = pData; |
| 981 | hmmc->TxXferSize = BLOCKSIZE * NumberOfBlocks; |
1081 | hmmc->TxXferSize = MMC_BLOCKSIZE * NumberOfBlocks; |
| 982 | 1082 | ||
| 983 | /* Enable transfer interrupts */ |
1083 | /* Enable transfer interrupts */ |
| 984 | __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_DATAEND | SDIO_FLAG_TXFIFOHE)); |
1084 | __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_DATAEND | SDIO_FLAG_TXFIFOHE | SDIO_IT_STBITERR)); |
| 985 | 1085 | ||
| 986 | /* Check the Card capacity in term of Logical number of blocks */ |
- | |
| 987 | if ((hmmc->MmcCard.LogBlockNbr) < CAPACITY) |
1086 | if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD) |
| 988 | { |
1087 | { |
| 989 | BlockAdd *= 512U; |
1088 | add *= 512U; |
| 990 | } |
1089 | } |
| 991 | 1090 | ||
| 992 | /* Set Block Size for Card */ |
1091 | /* Set Block Size for Card */ |
| 993 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, BLOCKSIZE); |
1092 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, MMC_BLOCKSIZE); |
| 994 | if(errorstate != HAL_MMC_ERROR_NONE) |
1093 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 995 | { |
1094 | { |
| 996 | /* Clear all the static flags */ |
1095 | /* Clear all the static flags */ |
| 997 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1096 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 998 | hmmc->ErrorCode |= errorstate; |
1097 | hmmc->ErrorCode |= errorstate; |
| 999 | hmmc->State = HAL_MMC_STATE_READY; |
1098 | hmmc->State = HAL_MMC_STATE_READY; |
| 1000 | return HAL_ERROR; |
1099 | return HAL_ERROR; |
| 1001 | } |
1100 | } |
| 1002 | 1101 | ||
| 1003 | /* Write Blocks in Polling mode */ |
1102 | /* Write Blocks in Polling mode */ |
| 1004 | if(NumberOfBlocks > 1U) |
1103 | if(NumberOfBlocks > 1U) |
| 1005 | { |
1104 | { |
| 1006 | hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK| MMC_CONTEXT_IT); |
1105 | hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK| MMC_CONTEXT_IT); |
| 1007 | 1106 | ||
| 1008 | /* Write Multi Block command */ |
1107 | /* Write Multi Block command */ |
| 1009 | errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, BlockAdd); |
1108 | errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, add); |
| 1010 | } |
1109 | } |
| 1011 | else |
1110 | else |
| 1012 | { |
1111 | { |
| 1013 | hmmc->Context = (MMC_CONTEXT_WRITE_SINGLE_BLOCK | MMC_CONTEXT_IT); |
1112 | hmmc->Context = (MMC_CONTEXT_WRITE_SINGLE_BLOCK | MMC_CONTEXT_IT); |
| 1014 | 1113 | ||
| 1015 | /* Write Single Block command */ |
1114 | /* Write Single Block command */ |
| 1016 | errorstate = SDMMC_CmdWriteSingleBlock(hmmc->Instance, BlockAdd); |
1115 | errorstate = SDMMC_CmdWriteSingleBlock(hmmc->Instance, add); |
| 1017 | } |
1116 | } |
| 1018 | if(errorstate != HAL_MMC_ERROR_NONE) |
1117 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1019 | { |
1118 | { |
| 1020 | /* Clear all the static flags */ |
1119 | /* Clear all the static flags */ |
| 1021 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1120 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 1022 | hmmc->ErrorCode |= errorstate; |
1121 | hmmc->ErrorCode |= errorstate; |
| 1023 | hmmc->State = HAL_MMC_STATE_READY; |
1122 | hmmc->State = HAL_MMC_STATE_READY; |
| 1024 | return HAL_ERROR; |
1123 | return HAL_ERROR; |
| 1025 | } |
1124 | } |
| 1026 | 1125 | ||
| 1027 | /* Configure the MMC DPSM (Data Path State Machine) */ |
1126 | /* Configure the MMC DPSM (Data Path State Machine) */ |
| 1028 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
1127 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
| 1029 | config.DataLength = BLOCKSIZE * NumberOfBlocks; |
1128 | config.DataLength = MMC_BLOCKSIZE * NumberOfBlocks; |
| 1030 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
1129 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
| 1031 | config.TransferDir = SDIO_TRANSFER_DIR_TO_CARD; |
1130 | config.TransferDir = SDIO_TRANSFER_DIR_TO_CARD; |
| 1032 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
1131 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
| 1033 | config.DPSM = SDIO_DPSM_ENABLE; |
1132 | config.DPSM = SDIO_DPSM_ENABLE; |
| 1034 | SDIO_ConfigData(hmmc->Instance, &config); |
1133 | (void)SDIO_ConfigData(hmmc->Instance, &config); |
| 1035 | 1134 | ||
| 1036 | return HAL_OK; |
1135 | return HAL_OK; |
| 1037 | } |
1136 | } |
| 1038 | else |
1137 | else |
| 1039 | { |
1138 | { |
| 1040 | return HAL_BUSY; |
1139 | return HAL_BUSY; |
| 1041 | } |
1140 | } |
| 1042 | } |
1141 | } |
| 1043 | 1142 | ||
| 1044 | /** |
1143 | /** |
| 1045 | * @brief Reads block(s) from a specified address in a card. The Data transfer |
1144 | * @brief Reads block(s) from a specified address in a card. The Data transfer |
| 1046 | * is managed by DMA mode. |
1145 | * is managed by DMA mode. |
| 1047 | * @note This API should be followed by a check on the card state through |
1146 | * @note This API should be followed by a check on the card state through |
| 1048 | * HAL_MMC_GetCardState(). |
1147 | * HAL_MMC_GetCardState(). |
| 1049 | * @note You could also check the DMA transfer process through the MMC Rx |
1148 | * @note You could also check the DMA transfer process through the MMC Rx |
| 1050 | * interrupt event. |
1149 | * interrupt event. |
| 1051 | * @param hmmc: Pointer MMC handle |
1150 | * @param hmmc: Pointer MMC handle |
| 1052 | * @param pData: Pointer to the buffer that will contain the received data |
1151 | * @param pData: Pointer to the buffer that will contain the received data |
| 1053 | * @param BlockAdd: Block Address from where data is to be read |
1152 | * @param BlockAdd: Block Address from where data is to be read |
| 1054 | * @param NumberOfBlocks: Number of blocks to read. |
1153 | * @param NumberOfBlocks: Number of blocks to read. |
| 1055 | * @retval HAL status |
1154 | * @retval HAL status |
| 1056 | */ |
1155 | */ |
| 1057 | HAL_StatusTypeDef HAL_MMC_ReadBlocks_DMA(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks) |
1156 | HAL_StatusTypeDef HAL_MMC_ReadBlocks_DMA(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks) |
| 1058 | { |
1157 | { |
| 1059 | SDIO_DataInitTypeDef config; |
1158 | SDIO_DataInitTypeDef config; |
| 1060 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
1159 | uint32_t errorstate; |
| - | 1160 | uint32_t add = BlockAdd; |
|
| 1061 | 1161 | ||
| 1062 | if(NULL == pData) |
1162 | if(NULL == pData) |
| 1063 | { |
1163 | { |
| 1064 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
1164 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
| 1065 | return HAL_ERROR; |
1165 | return HAL_ERROR; |
| 1066 | } |
1166 | } |
| 1067 | 1167 | ||
| 1068 | if(hmmc->State == HAL_MMC_STATE_READY) |
1168 | if(hmmc->State == HAL_MMC_STATE_READY) |
| 1069 | { |
1169 | { |
| 1070 | hmmc->ErrorCode = HAL_DMA_ERROR_NONE; |
1170 | hmmc->ErrorCode = HAL_DMA_ERROR_NONE; |
| 1071 | 1171 | ||
| 1072 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
1172 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
| 1073 | { |
1173 | { |
| 1074 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
1174 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
| 1075 | return HAL_ERROR; |
1175 | return HAL_ERROR; |
| 1076 | } |
1176 | } |
| 1077 | 1177 | ||
| 1078 | hmmc->State = HAL_MMC_STATE_BUSY; |
1178 | hmmc->State = HAL_MMC_STATE_BUSY; |
| 1079 | 1179 | ||
| 1080 | /* Initialize data control register */ |
1180 | /* Initialize data control register */ |
| 1081 | hmmc->Instance->DCTRL = 0U; |
1181 | hmmc->Instance->DCTRL = 0U; |
| 1082 | 1182 | ||
| 1083 | #ifdef SDIO_STA_STBITER |
- | |
| 1084 | __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_RXOVERR | SDIO_IT_DATAEND | SDIO_IT_STBITERR)); |
1183 | __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_RXOVERR | SDIO_IT_DATAEND | SDIO_IT_STBITERR)); |
| 1085 | #else /* SDIO_STA_STBITERR not defined */ |
- | |
| 1086 | __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_RXOVERR | SDIO_IT_DATAEND)); |
- | |
| 1087 | #endif /* SDIO_STA_STBITERR */ |
- | |
| 1088 | 1184 | ||
| 1089 | /* Set the DMA transfer complete callback */ |
1185 | /* Set the DMA transfer complete callback */ |
| 1090 | hmmc->hdmarx->XferCpltCallback = MMC_DMAReceiveCplt; |
1186 | hmmc->hdmarx->XferCpltCallback = MMC_DMAReceiveCplt; |
| 1091 | 1187 | ||
| 1092 | /* Set the DMA error callback */ |
1188 | /* Set the DMA error callback */ |
| 1093 | hmmc->hdmarx->XferErrorCallback = MMC_DMAError; |
1189 | hmmc->hdmarx->XferErrorCallback = MMC_DMAError; |
| 1094 | 1190 | ||
| 1095 | /* Set the DMA Abort callback */ |
1191 | /* Set the DMA Abort callback */ |
| 1096 | hmmc->hdmarx->XferAbortCallback = NULL; |
1192 | hmmc->hdmarx->XferAbortCallback = NULL; |
| 1097 | - | ||
| 1098 | /* Enable the DMA Channel */ |
- | |
| 1099 | HAL_DMA_Start_IT(hmmc->hdmarx, (uint32_t)&hmmc->Instance->FIFO, (uint32_t)pData, (uint32_t)(BLOCKSIZE * NumberOfBlocks)/4); |
- | |
| 1100 | - | ||
| 1101 | /* Enable MMC DMA transfer */ |
- | |
| 1102 | __HAL_MMC_DMA_ENABLE(hmmc); |
- | |
| 1103 | 1193 | ||
| 1104 | /* Check the Card capacity in term of Logical number of blocks */ |
- | |
| 1105 | if ((hmmc->MmcCard.LogBlockNbr) < CAPACITY) |
1194 | if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD) |
| 1106 | { |
1195 | { |
| 1107 | BlockAdd *= 512U; |
1196 | add *= 512U; |
| 1108 | } |
1197 | } |
| 1109 | - | ||
| 1110 | /* Configure the MMC DPSM (Data Path State Machine) */ |
- | |
| 1111 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
- | |
| 1112 | config.DataLength = BLOCKSIZE * NumberOfBlocks; |
- | |
| 1113 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
- | |
| 1114 | config.TransferDir = SDIO_TRANSFER_DIR_TO_SDIO; |
- | |
| 1115 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
- | |
| 1116 | config.DPSM = SDIO_DPSM_ENABLE; |
- | |
| 1117 | SDIO_ConfigData(hmmc->Instance, &config); |
- | |
| 1118 | 1198 | ||
| 1119 | /* Set Block Size for Card */ |
1199 | /* Set Block Size for Card */ |
| 1120 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, BLOCKSIZE); |
1200 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, MMC_BLOCKSIZE); |
| 1121 | if(errorstate != HAL_MMC_ERROR_NONE) |
1201 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1122 | { |
1202 | { |
| 1123 | /* Clear all the static flags */ |
1203 | /* Clear all the static flags */ |
| 1124 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1204 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 1125 | hmmc->ErrorCode |= errorstate; |
1205 | hmmc->ErrorCode = errorstate; |
| 1126 | hmmc->State = HAL_MMC_STATE_READY; |
1206 | hmmc->State = HAL_MMC_STATE_READY; |
| 1127 | return HAL_ERROR; |
1207 | return HAL_ERROR; |
| 1128 | } |
1208 | } |
| 1129 | - | ||
| 1130 | /* Read Blocks in DMA mode */ |
- | |
| 1131 | if(NumberOfBlocks > 1U) |
- | |
| 1132 | { |
1209 | |
| 1133 | hmmc->Context = (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA); |
- | |
| 1134 | - | ||
| 1135 | /* Read Multi Block command */ |
- | |
| 1136 | errorstate = SDMMC_CmdReadMultiBlock(hmmc->Instance, BlockAdd); |
- | |
| 1137 | } |
- | |
| 1138 | else |
- | |
| 1139 | { |
- | |
| 1140 | hmmc->Context = (MMC_CONTEXT_READ_SINGLE_BLOCK | MMC_CONTEXT_DMA); |
- | |
| 1141 | - | ||
| 1142 | /* Read Single Block command */ |
1210 | /* Enable the DMA Channel */ |
| 1143 | errorstate = SDMMC_CmdReadSingleBlock(hmmc->Instance, BlockAdd); |
1211 | if(HAL_DMA_Start_IT(hmmc->hdmarx, (uint32_t)&hmmc->Instance->FIFO, (uint32_t)pData, (uint32_t)(MMC_BLOCKSIZE * NumberOfBlocks)/4) != HAL_OK) |
| 1144 | } |
- | |
| 1145 | if(errorstate != HAL_MMC_ERROR_NONE) |
- | |
| 1146 | { |
1212 | { |
| 1147 | /* Clear all the static flags */ |
1213 | __HAL_MMC_DISABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_RXOVERR | SDIO_IT_DATAEND)); |
| 1148 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1214 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 1149 | hmmc->ErrorCode |= errorstate; |
1215 | hmmc->ErrorCode = HAL_MMC_ERROR_DMA; |
| 1150 | hmmc->State = HAL_MMC_STATE_READY; |
1216 | hmmc->State = HAL_MMC_STATE_READY; |
| 1151 | return HAL_ERROR; |
1217 | return HAL_ERROR; |
| 1152 | } |
1218 | } |
| - | 1219 | else |
|
| - | 1220 | { |
|
| - | 1221 | /* Enable MMC DMA transfer */ |
|
| - | 1222 | __HAL_MMC_DMA_ENABLE(hmmc); |
|
| 1153 | 1223 | ||
| - | 1224 | /* Configure the MMC DPSM (Data Path State Machine) */ |
|
| - | 1225 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
|
| - | 1226 | config.DataLength = MMC_BLOCKSIZE * NumberOfBlocks; |
|
| - | 1227 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
|
| - | 1228 | config.TransferDir = SDIO_TRANSFER_DIR_TO_SDIO; |
|
| - | 1229 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
|
| - | 1230 | config.DPSM = SDIO_DPSM_ENABLE; |
|
| - | 1231 | (void)SDIO_ConfigData(hmmc->Instance, &config); |
|
| - | 1232 | ||
| - | 1233 | /* Read Blocks in DMA mode */ |
|
| - | 1234 | if(NumberOfBlocks > 1U) |
|
| - | 1235 | { |
|
| - | 1236 | hmmc->Context = (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA); |
|
| - | 1237 | ||
| - | 1238 | /* Read Multi Block command */ |
|
| - | 1239 | errorstate = SDMMC_CmdReadMultiBlock(hmmc->Instance, add); |
|
| - | 1240 | } |
|
| - | 1241 | else |
|
| - | 1242 | { |
|
| - | 1243 | hmmc->Context = (MMC_CONTEXT_READ_SINGLE_BLOCK | MMC_CONTEXT_DMA); |
|
| - | 1244 | ||
| - | 1245 | /* Read Single Block command */ |
|
| - | 1246 | errorstate = SDMMC_CmdReadSingleBlock(hmmc->Instance, add); |
|
| - | 1247 | } |
|
| - | 1248 | if(errorstate != HAL_MMC_ERROR_NONE) |
|
| - | 1249 | { |
|
| - | 1250 | /* Clear all the static flags */ |
|
| - | 1251 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
|
| - | 1252 | __HAL_MMC_DISABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_RXOVERR | SDIO_IT_DATAEND)); |
|
| - | 1253 | hmmc->ErrorCode = errorstate; |
|
| - | 1254 | hmmc->State = HAL_MMC_STATE_READY; |
|
| - | 1255 | return HAL_ERROR; |
|
| - | 1256 | } |
|
| - | 1257 | ||
| 1154 | return HAL_OK; |
1258 | return HAL_OK; |
| - | 1259 | } |
|
| 1155 | } |
1260 | } |
| 1156 | else |
1261 | else |
| 1157 | { |
1262 | { |
| 1158 | return HAL_BUSY; |
1263 | return HAL_BUSY; |
| 1159 | } |
1264 | } |
| 1160 | } |
1265 | } |
| 1161 | 1266 | ||
| 1162 | /** |
1267 | /** |
| 1163 | * @brief Writes block(s) to a specified address in a card. The Data transfer |
1268 | * @brief Writes block(s) to a specified address in a card. The Data transfer |
| 1164 | * is managed by DMA mode. |
1269 | * is managed by DMA mode. |
| 1165 | * @note This API should be followed by a check on the card state through |
1270 | * @note This API should be followed by a check on the card state through |
| 1166 | * HAL_MMC_GetCardState(). |
1271 | * HAL_MMC_GetCardState(). |
| 1167 | * @note You could also check the DMA transfer process through the MMC Tx |
1272 | * @note You could also check the DMA transfer process through the MMC Tx |
| 1168 | * interrupt event. |
1273 | * interrupt event. |
| 1169 | * @param hmmc: Pointer to MMC handle |
1274 | * @param hmmc: Pointer to MMC handle |
| 1170 | * @param pData: Pointer to the buffer that will contain the data to transmit |
1275 | * @param pData: Pointer to the buffer that will contain the data to transmit |
| 1171 | * @param BlockAdd: Block Address where data will be written |
1276 | * @param BlockAdd: Block Address where data will be written |
| 1172 | * @param NumberOfBlocks: Number of blocks to write |
1277 | * @param NumberOfBlocks: Number of blocks to write |
| 1173 | * @retval HAL status |
1278 | * @retval HAL status |
| 1174 | */ |
1279 | */ |
| 1175 | HAL_StatusTypeDef HAL_MMC_WriteBlocks_DMA(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks) |
1280 | HAL_StatusTypeDef HAL_MMC_WriteBlocks_DMA(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks) |
| 1176 | { |
1281 | { |
| 1177 | SDIO_DataInitTypeDef config; |
1282 | SDIO_DataInitTypeDef config; |
| 1178 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
1283 | uint32_t errorstate; |
| - | 1284 | uint32_t add = BlockAdd; |
|
| 1179 | 1285 | ||
| 1180 | if(NULL == pData) |
1286 | if(NULL == pData) |
| 1181 | { |
1287 | { |
| 1182 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
1288 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
| 1183 | return HAL_ERROR; |
1289 | return HAL_ERROR; |
| 1184 | } |
1290 | } |
| 1185 | 1291 | ||
| 1186 | if(hmmc->State == HAL_MMC_STATE_READY) |
1292 | if(hmmc->State == HAL_MMC_STATE_READY) |
| 1187 | { |
1293 | { |
| 1188 | hmmc->ErrorCode = HAL_DMA_ERROR_NONE; |
1294 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
| 1189 | 1295 | ||
| 1190 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
1296 | if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr)) |
| 1191 | { |
1297 | { |
| 1192 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
1298 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
| 1193 | return HAL_ERROR; |
1299 | return HAL_ERROR; |
| 1194 | } |
1300 | } |
| 1195 | 1301 | ||
| 1196 | hmmc->State = HAL_MMC_STATE_BUSY; |
1302 | hmmc->State = HAL_MMC_STATE_BUSY; |
| 1197 | 1303 | ||
| 1198 | /* Initialize data control register */ |
1304 | /* Initialize data control register */ |
| 1199 | hmmc->Instance->DCTRL = 0U; |
1305 | hmmc->Instance->DCTRL = 0U; |
| 1200 | 1306 | ||
| 1201 | /* Enable MMC Error interrupts */ |
1307 | /* Enable MMC Error interrupts */ |
| 1202 | #ifdef SDIO_STA_STBITER |
- | |
| 1203 | __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_STBITERR)); |
1308 | __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_STBITERR)); |
| 1204 | #else /* SDIO_STA_STBITERR not defined */ |
- | |
| 1205 | __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR)); |
- | |
| 1206 | #endif /* SDIO_STA_STBITERR */ |
- | |
| 1207 | 1309 | ||
| 1208 | /* Set the DMA transfer complete callback */ |
1310 | /* Set the DMA transfer complete callback */ |
| 1209 | hmmc->hdmatx->XferCpltCallback = MMC_DMATransmitCplt; |
1311 | hmmc->hdmatx->XferCpltCallback = MMC_DMATransmitCplt; |
| 1210 | 1312 | ||
| 1211 | /* Set the DMA error callback */ |
1313 | /* Set the DMA error callback */ |
| 1212 | hmmc->hdmatx->XferErrorCallback = MMC_DMAError; |
1314 | hmmc->hdmatx->XferErrorCallback = MMC_DMAError; |
| 1213 | 1315 | ||
| 1214 | /* Set the DMA Abort callback */ |
1316 | /* Set the DMA Abort callback */ |
| 1215 | hmmc->hdmatx->XferAbortCallback = NULL; |
1317 | hmmc->hdmatx->XferAbortCallback = NULL; |
| 1216 | 1318 | ||
| 1217 | /* Check the Card capacity in term of Logical number of blocks */ |
- | |
| 1218 | if ((hmmc->MmcCard.LogBlockNbr) < CAPACITY) |
1319 | if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD) |
| 1219 | { |
1320 | { |
| 1220 | BlockAdd *= 512U; |
1321 | add *= 512U; |
| 1221 | } |
1322 | } |
| 1222 | 1323 | ||
| 1223 | /* Set Block Size for Card */ |
1324 | /* Set Block Size for Card */ |
| 1224 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, BLOCKSIZE); |
1325 | errorstate = SDMMC_CmdBlockLength(hmmc->Instance, MMC_BLOCKSIZE); |
| 1225 | if(errorstate != HAL_MMC_ERROR_NONE) |
1326 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1226 | { |
1327 | { |
| 1227 | /* Clear all the static flags */ |
1328 | /* Clear all the static flags */ |
| 1228 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1329 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 1229 | hmmc->ErrorCode |= errorstate; |
1330 | hmmc->ErrorCode |= errorstate; |
| 1230 | hmmc->State = HAL_MMC_STATE_READY; |
1331 | hmmc->State = HAL_MMC_STATE_READY; |
| 1231 | return HAL_ERROR; |
1332 | return HAL_ERROR; |
| 1232 | } |
1333 | } |
| 1233 | 1334 | ||
| 1234 | /* Write Blocks in Polling mode */ |
1335 | /* Write Blocks in Polling mode */ |
| 1235 | if(NumberOfBlocks > 1U) |
1336 | if(NumberOfBlocks > 1U) |
| 1236 | { |
1337 | { |
| 1237 | hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK | MMC_CONTEXT_DMA); |
1338 | hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK | MMC_CONTEXT_DMA); |
| 1238 | 1339 | ||
| 1239 | /* Write Multi Block command */ |
1340 | /* Write Multi Block command */ |
| 1240 | errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, BlockAdd); |
1341 | errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, add); |
| 1241 | } |
1342 | } |
| 1242 | else |
1343 | else |
| 1243 | { |
1344 | { |
| 1244 | hmmc->Context = (MMC_CONTEXT_WRITE_SINGLE_BLOCK | MMC_CONTEXT_DMA); |
1345 | hmmc->Context = (MMC_CONTEXT_WRITE_SINGLE_BLOCK | MMC_CONTEXT_DMA); |
| 1245 | 1346 | ||
| 1246 | /* Write Single Block command */ |
1347 | /* Write Single Block command */ |
| 1247 | errorstate = SDMMC_CmdWriteSingleBlock(hmmc->Instance, BlockAdd); |
1348 | errorstate = SDMMC_CmdWriteSingleBlock(hmmc->Instance, add); |
| 1248 | } |
1349 | } |
| 1249 | if(errorstate != HAL_MMC_ERROR_NONE) |
1350 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1250 | { |
1351 | { |
| 1251 | /* Clear all the static flags */ |
1352 | /* Clear all the static flags */ |
| 1252 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1353 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| - | 1354 | __HAL_MMC_DISABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_DATAEND)); |
|
| 1253 | hmmc->ErrorCode |= errorstate; |
1355 | hmmc->ErrorCode |= errorstate; |
| 1254 | hmmc->State = HAL_MMC_STATE_READY; |
1356 | hmmc->State = HAL_MMC_STATE_READY; |
| 1255 | return HAL_ERROR; |
1357 | return HAL_ERROR; |
| 1256 | } |
1358 | } |
| 1257 | 1359 | ||
| 1258 | /* Enable SDIO DMA transfer */ |
1360 | /* Enable SDIO DMA transfer */ |
| 1259 | __HAL_MMC_DMA_ENABLE(hmmc); |
1361 | __HAL_MMC_DMA_ENABLE(hmmc); |
| 1260 | 1362 | ||
| 1261 | /* Enable the DMA Channel */ |
1363 | /* Enable the DMA Channel */ |
| 1262 | HAL_DMA_Start_IT(hmmc->hdmatx, (uint32_t)pData, (uint32_t)&hmmc->Instance->FIFO, (uint32_t)(BLOCKSIZE * NumberOfBlocks)/4); |
1364 | if(HAL_DMA_Start_IT(hmmc->hdmatx, (uint32_t)pData, (uint32_t)&hmmc->Instance->FIFO, (uint32_t)(MMC_BLOCKSIZE * NumberOfBlocks)/4) != HAL_OK) |
| - | 1365 | { |
|
| - | 1366 | __HAL_MMC_DISABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_DATAEND)); |
|
| - | 1367 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
|
| - | 1368 | hmmc->ErrorCode |= HAL_MMC_ERROR_DMA; |
|
| - | 1369 | hmmc->State = HAL_MMC_STATE_READY; |
|
| - | 1370 | return HAL_ERROR; |
|
| 1263 | 1371 | } |
|
| - | 1372 | else |
|
| - | 1373 | { |
|
| 1264 | /* Configure the MMC DPSM (Data Path State Machine) */ |
1374 | /* Configure the MMC DPSM (Data Path State Machine) */ |
| 1265 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
1375 | config.DataTimeOut = SDMMC_DATATIMEOUT; |
| 1266 | config.DataLength = BLOCKSIZE * NumberOfBlocks; |
1376 | config.DataLength = MMC_BLOCKSIZE * NumberOfBlocks; |
| 1267 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
1377 | config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B; |
| 1268 | config.TransferDir = SDIO_TRANSFER_DIR_TO_CARD; |
1378 | config.TransferDir = SDIO_TRANSFER_DIR_TO_CARD; |
| 1269 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
1379 | config.TransferMode = SDIO_TRANSFER_MODE_BLOCK; |
| 1270 | config.DPSM = SDIO_DPSM_ENABLE; |
1380 | config.DPSM = SDIO_DPSM_ENABLE; |
| 1271 | SDIO_ConfigData(hmmc->Instance, &config); |
1381 | (void)SDIO_ConfigData(hmmc->Instance, &config); |
| 1272 | 1382 | ||
| 1273 | return HAL_OK; |
1383 | return HAL_OK; |
| - | 1384 | } |
|
| 1274 | } |
1385 | } |
| 1275 | else |
1386 | else |
| 1276 | { |
1387 | { |
| 1277 | return HAL_BUSY; |
1388 | return HAL_BUSY; |
| 1278 | } |
1389 | } |
| Line 1280... | Line 1391... | ||
| 1280 | 1391 | ||
| 1281 | /** |
1392 | /** |
| 1282 | * @brief Erases the specified memory area of the given MMC card. |
1393 | * @brief Erases the specified memory area of the given MMC card. |
| 1283 | * @note This API should be followed by a check on the card state through |
1394 | * @note This API should be followed by a check on the card state through |
| 1284 | * HAL_MMC_GetCardState(). |
1395 | * HAL_MMC_GetCardState(). |
| 1285 | * @param hmmc: Pointer to MMC handle |
1396 | * @param hmmc: Pointer to MMC handle |
| 1286 | * @param BlockStartAdd: Start Block address |
1397 | * @param BlockStartAdd: Start Block address |
| 1287 | * @param BlockEndAdd: End Block address |
1398 | * @param BlockEndAdd: End Block address |
| 1288 | * @retval HAL status |
1399 | * @retval HAL status |
| 1289 | */ |
1400 | */ |
| 1290 | HAL_StatusTypeDef HAL_MMC_Erase(MMC_HandleTypeDef *hmmc, uint32_t BlockStartAdd, uint32_t BlockEndAdd) |
1401 | HAL_StatusTypeDef HAL_MMC_Erase(MMC_HandleTypeDef *hmmc, uint32_t BlockStartAdd, uint32_t BlockEndAdd) |
| 1291 | { |
1402 | { |
| 1292 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
1403 | uint32_t errorstate; |
| - | 1404 | uint32_t start_add = BlockStartAdd; |
|
| - | 1405 | uint32_t end_add = BlockEndAdd; |
|
| 1293 | 1406 | ||
| 1294 | if(hmmc->State == HAL_MMC_STATE_READY) |
1407 | if(hmmc->State == HAL_MMC_STATE_READY) |
| 1295 | { |
1408 | { |
| 1296 | hmmc->ErrorCode = HAL_DMA_ERROR_NONE; |
1409 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
| 1297 | 1410 | ||
| 1298 | if(BlockEndAdd < BlockStartAdd) |
1411 | if(end_add < start_add) |
| 1299 | { |
1412 | { |
| 1300 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
1413 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
| 1301 | return HAL_ERROR; |
1414 | return HAL_ERROR; |
| 1302 | } |
1415 | } |
| 1303 | 1416 | ||
| 1304 | if(BlockEndAdd > (hmmc->MmcCard.LogBlockNbr)) |
1417 | if(end_add > (hmmc->MmcCard.LogBlockNbr)) |
| 1305 | { |
1418 | { |
| 1306 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
1419 | hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE; |
| 1307 | return HAL_ERROR; |
1420 | return HAL_ERROR; |
| 1308 | } |
1421 | } |
| 1309 | 1422 | ||
| 1310 | hmmc->State = HAL_MMC_STATE_BUSY; |
1423 | hmmc->State = HAL_MMC_STATE_BUSY; |
| 1311 | 1424 | ||
| 1312 | /* Check if the card command class supports erase command */ |
1425 | /* Check if the card command class supports erase command */ |
| 1313 | if(((hmmc->MmcCard.Class) & SDIO_CCCC_ERASE) == 0U) |
1426 | if(((hmmc->MmcCard.Class) & SDIO_CCCC_ERASE) == 0U) |
| 1314 | { |
1427 | { |
| 1315 | /* Clear all the static flags */ |
1428 | /* Clear all the static flags */ |
| 1316 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1429 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 1317 | hmmc->ErrorCode |= HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE; |
1430 | hmmc->ErrorCode |= HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE; |
| 1318 | hmmc->State = HAL_MMC_STATE_READY; |
1431 | hmmc->State = HAL_MMC_STATE_READY; |
| 1319 | return HAL_ERROR; |
1432 | return HAL_ERROR; |
| 1320 | } |
1433 | } |
| 1321 | 1434 | ||
| 1322 | if((SDIO_GetResponse(hmmc->Instance, SDIO_RESP1) & SDMMC_CARD_LOCKED) == SDMMC_CARD_LOCKED) |
1435 | if((SDIO_GetResponse(hmmc->Instance, SDIO_RESP1) & SDMMC_CARD_LOCKED) == SDMMC_CARD_LOCKED) |
| 1323 | { |
1436 | { |
| 1324 | /* Clear all the static flags */ |
1437 | /* Clear all the static flags */ |
| 1325 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1438 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 1326 | hmmc->ErrorCode |= HAL_MMC_ERROR_LOCK_UNLOCK_FAILED; |
1439 | hmmc->ErrorCode |= HAL_MMC_ERROR_LOCK_UNLOCK_FAILED; |
| 1327 | hmmc->State = HAL_MMC_STATE_READY; |
1440 | hmmc->State = HAL_MMC_STATE_READY; |
| 1328 | return HAL_ERROR; |
1441 | return HAL_ERROR; |
| 1329 | } |
1442 | } |
| 1330 | 1443 | ||
| 1331 | /* Check the Card capacity in term of Logical number of blocks */ |
- | |
| 1332 | if ((hmmc->MmcCard.LogBlockNbr) < CAPACITY) |
1444 | if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD) |
| 1333 | { |
1445 | { |
| 1334 | BlockStartAdd *= 512U; |
1446 | start_add *= 512U; |
| 1335 | BlockEndAdd *= 512U; |
1447 | end_add *= 512U; |
| 1336 | } |
1448 | } |
| 1337 | 1449 | ||
| 1338 | /* Send CMD35 MMC_ERASE_GRP_START with argument as addr */ |
1450 | /* Send CMD35 MMC_ERASE_GRP_START with argument as addr */ |
| 1339 | errorstate = SDMMC_CmdEraseStartAdd(hmmc->Instance, BlockStartAdd); |
1451 | errorstate = SDMMC_CmdEraseStartAdd(hmmc->Instance, start_add); |
| 1340 | if(errorstate != HAL_MMC_ERROR_NONE) |
1452 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1341 | { |
1453 | { |
| 1342 | /* Clear all the static flags */ |
1454 | /* Clear all the static flags */ |
| 1343 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1455 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 1344 | hmmc->ErrorCode |= errorstate; |
1456 | hmmc->ErrorCode |= errorstate; |
| 1345 | hmmc->State = HAL_MMC_STATE_READY; |
1457 | hmmc->State = HAL_MMC_STATE_READY; |
| 1346 | return HAL_ERROR; |
1458 | return HAL_ERROR; |
| 1347 | } |
1459 | } |
| 1348 | 1460 | ||
| 1349 | /* Send CMD36 MMC_ERASE_GRP_END with argument as addr */ |
1461 | /* Send CMD36 MMC_ERASE_GRP_END with argument as addr */ |
| 1350 | errorstate = SDMMC_CmdEraseEndAdd(hmmc->Instance, BlockEndAdd); |
1462 | errorstate = SDMMC_CmdEraseEndAdd(hmmc->Instance, end_add); |
| 1351 | if(errorstate != HAL_MMC_ERROR_NONE) |
1463 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1352 | { |
1464 | { |
| 1353 | /* Clear all the static flags */ |
1465 | /* Clear all the static flags */ |
| 1354 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1466 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 1355 | hmmc->ErrorCode |= errorstate; |
1467 | hmmc->ErrorCode |= errorstate; |
| 1356 | hmmc->State = HAL_MMC_STATE_READY; |
1468 | hmmc->State = HAL_MMC_STATE_READY; |
| 1357 | return HAL_ERROR; |
1469 | return HAL_ERROR; |
| 1358 | } |
1470 | } |
| 1359 | 1471 | ||
| 1360 | /* Send CMD38 ERASE */ |
1472 | /* Send CMD38 ERASE */ |
| 1361 | errorstate = SDMMC_CmdErase(hmmc->Instance); |
1473 | errorstate = SDMMC_CmdErase(hmmc->Instance); |
| 1362 | if(errorstate != HAL_MMC_ERROR_NONE) |
1474 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1363 | { |
1475 | { |
| 1364 | /* Clear all the static flags */ |
1476 | /* Clear all the static flags */ |
| 1365 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
1477 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 1366 | hmmc->ErrorCode |= errorstate; |
1478 | hmmc->ErrorCode |= errorstate; |
| 1367 | hmmc->State = HAL_MMC_STATE_READY; |
1479 | hmmc->State = HAL_MMC_STATE_READY; |
| 1368 | return HAL_ERROR; |
1480 | return HAL_ERROR; |
| 1369 | } |
1481 | } |
| 1370 | 1482 | ||
| 1371 | hmmc->State = HAL_MMC_STATE_READY; |
1483 | hmmc->State = HAL_MMC_STATE_READY; |
| 1372 | 1484 | ||
| 1373 | return HAL_OK; |
1485 | return HAL_OK; |
| 1374 | } |
1486 | } |
| 1375 | else |
1487 | else |
| 1376 | { |
1488 | { |
| 1377 | return HAL_BUSY; |
1489 | return HAL_BUSY; |
| Line 1383... | Line 1495... | ||
| 1383 | * @param hmmc: Pointer to MMC handle |
1495 | * @param hmmc: Pointer to MMC handle |
| 1384 | * @retval None |
1496 | * @retval None |
| 1385 | */ |
1497 | */ |
| 1386 | void HAL_MMC_IRQHandler(MMC_HandleTypeDef *hmmc) |
1498 | void HAL_MMC_IRQHandler(MMC_HandleTypeDef *hmmc) |
| 1387 | { |
1499 | { |
| 1388 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
1500 | uint32_t errorstate; |
| - | 1501 | uint32_t context = hmmc->Context; |
|
| 1389 | 1502 | ||
| 1390 | /* Check for SDIO interrupt flags */ |
1503 | /* Check for SDIO interrupt flags */ |
| 1391 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_DATAEND) != RESET) |
1504 | if((__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXFIFOHF) != RESET) && ((context & MMC_CONTEXT_IT) != 0U)) |
| 1392 | { |
1505 | { |
| 1393 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_FLAG_DATAEND); |
1506 | MMC_Read_IT(hmmc); |
| 1394 | 1507 | } |
|
| 1395 | #ifdef SDIO_STA_STBITERR |
- | |
| - | 1508 | ||
| 1396 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
1509 | else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DATAEND) != RESET) |
| 1397 | SDIO_IT_TXUNDERR | SDIO_IT_RXOVERR | SDIO_IT_STBITERR); |
- | |
| - | 1510 | { |
|
| 1398 | #else /* SDIO_STA_STBITERR not defined */ |
1511 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_FLAG_DATAEND); |
| - | 1512 | ||
| 1399 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
1513 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
| 1400 | SDIO_IT_TXUNDERR | SDIO_IT_RXOVERR); |
1514 | SDIO_IT_TXUNDERR| SDIO_IT_RXOVERR | SDIO_IT_STBITERR); |
| 1401 | #endif |
- | |
| 1402 | 1515 | ||
| - | 1516 | hmmc->Instance->DCTRL &= ~(SDIO_DCTRL_DTEN); |
|
| - | 1517 | ||
| 1403 | if((hmmc->Context & MMC_CONTEXT_IT) != RESET) |
1518 | if((context & MMC_CONTEXT_DMA) != 0U) |
| 1404 | { |
1519 | { |
| 1405 | if(((hmmc->Context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) != RESET) || ((hmmc->Context & MMC_CONTEXT_WRITE_MULTIPLE_BLOCK) != RESET)) |
1520 | if((context & MMC_CONTEXT_WRITE_MULTIPLE_BLOCK) != 0U) |
| 1406 | { |
1521 | { |
| 1407 | errorstate = SDMMC_CmdStopTransfer(hmmc->Instance); |
1522 | errorstate = SDMMC_CmdStopTransfer(hmmc->Instance); |
| 1408 | if(errorstate != HAL_MMC_ERROR_NONE) |
1523 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1409 | { |
1524 | { |
| 1410 | hmmc->ErrorCode |= errorstate; |
1525 | hmmc->ErrorCode |= errorstate; |
| - | 1526 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 1527 | hmmc->ErrorCallback(hmmc); |
|
| - | 1528 | #else |
|
| 1411 | HAL_MMC_ErrorCallback(hmmc); |
1529 | HAL_MMC_ErrorCallback(hmmc); |
| - | 1530 | #endif |
|
| 1412 | } |
1531 | } |
| 1413 | } |
1532 | } |
| 1414 | - | ||
| 1415 | /* Clear all the static flags */ |
- | |
| 1416 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
- | |
| 1417 | - | ||
| 1418 | hmmc->State = HAL_MMC_STATE_READY; |
- | |
| 1419 | if(((hmmc->Context & MMC_CONTEXT_READ_SINGLE_BLOCK) != RESET) || ((hmmc->Context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) != RESET)) |
1533 | if(((context & MMC_CONTEXT_READ_SINGLE_BLOCK) == 0U) && ((context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) == 0U)) |
| 1420 | { |
- | |
| 1421 | HAL_MMC_RxCpltCallback(hmmc); |
- | |
| 1422 | } |
- | |
| 1423 | else |
- | |
| 1424 | { |
1534 | { |
| - | 1535 | /* Disable the DMA transfer for transmit request by setting the DMAEN bit |
|
| - | 1536 | in the MMC DCTRL register */ |
|
| - | 1537 | hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDIO_DCTRL_DMAEN); |
|
| - | 1538 | ||
| - | 1539 | hmmc->State = HAL_MMC_STATE_READY; |
|
| - | 1540 | ||
| - | 1541 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 1542 | hmmc->TxCpltCallback(hmmc); |
|
| - | 1543 | #else |
|
| 1425 | HAL_MMC_TxCpltCallback(hmmc); |
1544 | HAL_MMC_TxCpltCallback(hmmc); |
| - | 1545 | #endif |
|
| 1426 | } |
1546 | } |
| 1427 | } |
1547 | } |
| 1428 | else if((hmmc->Context & MMC_CONTEXT_DMA) != RESET) |
1548 | else if((context & MMC_CONTEXT_IT) != 0U) |
| 1429 | { |
1549 | { |
| - | 1550 | /* Stop Transfer for Write Multi blocks or Read Multi blocks */ |
|
| 1430 | if((hmmc->Context & MMC_CONTEXT_WRITE_MULTIPLE_BLOCK) != RESET) |
1551 | if(((context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) != 0U) || ((context & MMC_CONTEXT_WRITE_MULTIPLE_BLOCK) != 0U)) |
| 1431 | { |
1552 | { |
| 1432 | errorstate = SDMMC_CmdStopTransfer(hmmc->Instance); |
1553 | errorstate = SDMMC_CmdStopTransfer(hmmc->Instance); |
| 1433 | if(errorstate != HAL_MMC_ERROR_NONE) |
1554 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1434 | { |
1555 | { |
| 1435 | hmmc->ErrorCode |= errorstate; |
1556 | hmmc->ErrorCode |= errorstate; |
| - | 1557 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 1558 | hmmc->ErrorCallback(hmmc); |
|
| - | 1559 | #else |
|
| 1436 | HAL_MMC_ErrorCallback(hmmc); |
1560 | HAL_MMC_ErrorCallback(hmmc); |
| - | 1561 | #endif |
|
| 1437 | } |
1562 | } |
| 1438 | } |
1563 | } |
| - | 1564 | ||
| - | 1565 | /* Clear all the static flags */ |
|
| - | 1566 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_DATA_FLAGS); |
|
| - | 1567 | ||
| - | 1568 | hmmc->State = HAL_MMC_STATE_READY; |
|
| 1439 | if(((hmmc->Context & MMC_CONTEXT_READ_SINGLE_BLOCK) == RESET) && ((hmmc->Context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) == RESET)) |
1569 | if(((context & MMC_CONTEXT_READ_SINGLE_BLOCK) != 0U) || ((context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) != 0U)) |
| - | 1570 | { |
|
| - | 1571 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 1572 | hmmc->RxCpltCallback(hmmc); |
|
| - | 1573 | #else |
|
| - | 1574 | HAL_MMC_RxCpltCallback(hmmc); |
|
| - | 1575 | #endif |
|
| - | 1576 | } |
|
| - | 1577 | else |
|
| 1440 | { |
1578 | { |
| 1441 | /* Disable the DMA transfer for transmit request by setting the DMAEN bit |
- | |
| 1442 | in the MMC DCTRL register */ |
- | |
| 1443 | hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDIO_DCTRL_DMAEN); |
1579 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
| 1444 | - | ||
| 1445 | hmmc->State = HAL_MMC_STATE_READY; |
1580 | hmmc->TxCpltCallback(hmmc); |
| 1446 | 1581 | #else |
|
| 1447 | HAL_MMC_TxCpltCallback(hmmc); |
1582 | HAL_MMC_TxCpltCallback(hmmc); |
| - | 1583 | #endif |
|
| 1448 | } |
1584 | } |
| 1449 | } |
1585 | } |
| - | 1586 | else |
|
| - | 1587 | { |
|
| - | 1588 | /* Nothing to do */ |
|
| - | 1589 | } |
|
| 1450 | } |
1590 | } |
| 1451 | 1591 | ||
| 1452 | else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_TXFIFOHE) != RESET) |
1592 | else if((__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_TXFIFOHE) != RESET) && ((context & MMC_CONTEXT_IT) != 0U)) |
| 1453 | { |
1593 | { |
| 1454 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_FLAG_TXFIFOHE); |
- | |
| 1455 | - | ||
| 1456 | MMC_Write_IT(hmmc); |
1594 | MMC_Write_IT(hmmc); |
| 1457 | } |
1595 | } |
| 1458 | 1596 | ||
| 1459 | else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_RXFIFOHF) != RESET) |
- | |
| 1460 | { |
- | |
| 1461 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_FLAG_RXFIFOHF); |
- | |
| 1462 | - | ||
| 1463 | MMC_Read_IT(hmmc); |
- | |
| 1464 | } |
- | |
| 1465 | - | ||
| 1466 | #ifdef SDIO_STA_STBITERR |
- | |
| 1467 | else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_RXOVERR | SDIO_IT_TXUNDERR | SDIO_IT_STBITERR) != RESET) |
1597 | else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_RXOVERR | SDIO_FLAG_TXUNDERR | SDIO_FLAG_STBITERR) != RESET) |
| 1468 | { |
1598 | { |
| 1469 | /* Set Error code */ |
1599 | /* Set Error code */ |
| 1470 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_DCRCFAIL) != RESET) |
1600 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DCRCFAIL) != RESET) |
| 1471 | { |
1601 | { |
| 1472 | hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_CRC_FAIL; |
1602 | hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_CRC_FAIL; |
| 1473 | } |
1603 | } |
| 1474 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_DTIMEOUT) != RESET) |
1604 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DTIMEOUT) != RESET) |
| 1475 | { |
1605 | { |
| 1476 | hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_TIMEOUT; |
1606 | hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_TIMEOUT; |
| 1477 | } |
1607 | } |
| 1478 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_RXOVERR) != RESET) |
1608 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXOVERR) != RESET) |
| 1479 | { |
1609 | { |
| 1480 | hmmc->ErrorCode |= HAL_MMC_ERROR_RX_OVERRUN; |
1610 | hmmc->ErrorCode |= HAL_MMC_ERROR_RX_OVERRUN; |
| 1481 | } |
1611 | } |
| 1482 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_TXUNDERR) != RESET) |
1612 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_TXUNDERR) != RESET) |
| 1483 | { |
1613 | { |
| 1484 | hmmc->ErrorCode |= HAL_MMC_ERROR_TX_UNDERRUN; |
1614 | hmmc->ErrorCode |= HAL_MMC_ERROR_TX_UNDERRUN; |
| 1485 | } |
1615 | } |
| 1486 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_STBITERR) != RESET) |
1616 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_STBITERR) != RESET) |
| 1487 | { |
1617 | { |
| 1488 | hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_TIMEOUT; |
1618 | hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_TIMEOUT; |
| 1489 | } |
1619 | } |
| 1490 | 1620 | ||
| 1491 | /* Clear All flags */ |
1621 | /* Clear All flags */ |
| 1492 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS | SDIO_FLAG_STBITERR); |
1622 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_DATA_FLAGS | SDIO_FLAG_STBITERR); |
| 1493 | 1623 | ||
| 1494 | /* Disable all interrupts */ |
1624 | /* Disable all interrupts */ |
| 1495 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
1625 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
| 1496 | SDIO_IT_TXUNDERR| SDIO_IT_RXOVERR |SDIO_IT_STBITERR); |
1626 | SDIO_IT_TXUNDERR| SDIO_IT_RXOVERR | SDIO_IT_STBITERR); |
| 1497 | 1627 | ||
| 1498 | if((hmmc->Context & MMC_CONTEXT_DMA) != RESET) |
- | |
| 1499 | { |
- | |
| 1500 | /* Abort the MMC DMA Streams */ |
- | |
| 1501 | if(hmmc->hdmatx != NULL) |
- | |
| 1502 | { |
- | |
| 1503 | /* Set the DMA Tx abort callback */ |
- | |
| 1504 | hmmc->hdmatx->XferAbortCallback = MMC_DMATxAbort; |
- | |
| 1505 | /* Abort DMA in IT mode */ |
- | |
| 1506 | if(HAL_DMA_Abort_IT(hmmc->hdmatx) != HAL_OK) |
- | |
| 1507 | { |
- | |
| 1508 | MMC_DMATxAbort(hmmc->hdmatx); |
- | |
| 1509 | } |
- | |
| 1510 | } |
- | |
| 1511 | else if(hmmc->hdmarx != NULL) |
- | |
| 1512 | { |
- | |
| 1513 | /* Set the DMA Rx abort callback */ |
- | |
| 1514 | hmmc->hdmarx->XferAbortCallback = MMC_DMARxAbort; |
- | |
| 1515 | /* Abort DMA in IT mode */ |
- | |
| 1516 | if(HAL_DMA_Abort_IT(hmmc->hdmarx) != HAL_OK) |
- | |
| 1517 | { |
- | |
| 1518 | MMC_DMARxAbort(hmmc->hdmarx); |
- | |
| 1519 | } |
- | |
| 1520 | } |
- | |
| 1521 | else |
- | |
| 1522 | { |
- | |
| 1523 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
1628 | hmmc->ErrorCode |= SDMMC_CmdStopTransfer(hmmc->Instance); |
| 1524 | hmmc->State = HAL_MMC_STATE_READY; |
- | |
| 1525 | HAL_MMC_AbortCallback(hmmc); |
- | |
| 1526 | } |
- | |
| 1527 | } |
1629 | |
| 1528 | else if((hmmc->Context & MMC_CONTEXT_IT) != RESET) |
1630 | if((context & MMC_CONTEXT_IT) != 0U) |
| 1529 | { |
1631 | { |
| 1530 | /* Set the MMC state to ready to be able to start again the process */ |
1632 | /* Set the MMC state to ready to be able to start again the process */ |
| 1531 | hmmc->State = HAL_MMC_STATE_READY; |
1633 | hmmc->State = HAL_MMC_STATE_READY; |
| - | 1634 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 1635 | hmmc->ErrorCallback(hmmc); |
|
| - | 1636 | #else |
|
| 1532 | HAL_MMC_ErrorCallback(hmmc); |
1637 | HAL_MMC_ErrorCallback(hmmc); |
| - | 1638 | #endif /* USE_HAL_MMC_REGISTER_CALLBACKS */ |
|
| 1533 | } |
1639 | } |
| 1534 | } |
- | |
| 1535 | #else /* SDIO_STA_STBITERR not defined */ |
- | |
| 1536 | else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_RXOVERR | SDIO_IT_TXUNDERR) != RESET) |
- | |
| 1537 | { |
- | |
| 1538 | /* Set Error code */ |
- | |
| 1539 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_DCRCFAIL) != RESET) |
- | |
| 1540 | { |
- | |
| 1541 | hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_CRC_FAIL; |
- | |
| 1542 | } |
- | |
| 1543 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_DTIMEOUT) != RESET) |
- | |
| 1544 | { |
- | |
| 1545 | hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_TIMEOUT; |
- | |
| 1546 | } |
- | |
| 1547 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_RXOVERR) != RESET) |
- | |
| 1548 | { |
- | |
| 1549 | hmmc->ErrorCode |= HAL_MMC_ERROR_RX_OVERRUN; |
- | |
| 1550 | } |
- | |
| 1551 | if(__HAL_MMC_GET_FLAG(hmmc, SDIO_IT_TXUNDERR) != RESET) |
- | |
| 1552 | { |
- | |
| 1553 | hmmc->ErrorCode |= HAL_MMC_ERROR_TX_UNDERRUN; |
- | |
| 1554 | } |
- | |
| 1555 | - | ||
| 1556 | /* Clear All flags */ |
- | |
| 1557 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
- | |
| 1558 | - | ||
| 1559 | /* Disable all interrupts */ |
- | |
| 1560 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
- | |
| 1561 | SDIO_IT_TXUNDERR| SDIO_IT_RXOVERR); |
- | |
| 1562 | - | ||
| 1563 | if((hmmc->Context & MMC_CONTEXT_DMA) != RESET) |
1640 | else if((context & MMC_CONTEXT_DMA) != 0U) |
| 1564 | { |
1641 | { |
| 1565 | /* Abort the MMC DMA Streams */ |
1642 | /* Abort the MMC DMA Streams */ |
| 1566 | if(hmmc->hdmatx != NULL) |
1643 | if(hmmc->hdmatx != NULL) |
| 1567 | { |
1644 | { |
| 1568 | /* Set the DMA Tx abort callback */ |
1645 | /* Set the DMA Tx abort callback */ |
| Line 1585... | Line 1662... | ||
| 1585 | } |
1662 | } |
| 1586 | else |
1663 | else |
| 1587 | { |
1664 | { |
| 1588 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
1665 | hmmc->ErrorCode = HAL_MMC_ERROR_NONE; |
| 1589 | hmmc->State = HAL_MMC_STATE_READY; |
1666 | hmmc->State = HAL_MMC_STATE_READY; |
| - | 1667 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 1668 | hmmc->AbortCpltCallback(hmmc); |
|
| - | 1669 | #else |
|
| 1590 | HAL_MMC_AbortCallback(hmmc); |
1670 | HAL_MMC_AbortCallback(hmmc); |
| - | 1671 | #endif |
|
| 1591 | } |
1672 | } |
| 1592 | } |
1673 | } |
| 1593 | else if((hmmc->Context & MMC_CONTEXT_IT) != RESET) |
1674 | else |
| 1594 | { |
1675 | { |
| 1595 | /* Set the MMC state to ready to be able to start again the process */ |
- | |
| 1596 | hmmc->State = HAL_MMC_STATE_READY; |
- | |
| 1597 | HAL_MMC_ErrorCallback(hmmc); |
1676 | /* Nothing to do */ |
| 1598 | } |
1677 | } |
| 1599 | } |
1678 | } |
| - | 1679 | ||
| - | 1680 | else |
|
| - | 1681 | { |
|
| 1600 | #endif /* SDIO_STA_STBITERR */ |
1682 | /* Nothing to do */ |
| - | 1683 | } |
|
| 1601 | } |
1684 | } |
| 1602 | 1685 | ||
| 1603 | /** |
1686 | /** |
| 1604 | * @brief return the MMC state |
1687 | * @brief return the MMC state |
| 1605 | * @param hmmc: Pointer to mmc handle |
1688 | * @param hmmc: Pointer to mmc handle |
| Line 1624... | Line 1707... | ||
| 1624 | /** |
1707 | /** |
| 1625 | * @brief Tx Transfer completed callbacks |
1708 | * @brief Tx Transfer completed callbacks |
| 1626 | * @param hmmc: Pointer to MMC handle |
1709 | * @param hmmc: Pointer to MMC handle |
| 1627 | * @retval None |
1710 | * @retval None |
| 1628 | */ |
1711 | */ |
| 1629 | __weak void HAL_MMC_TxCpltCallback(MMC_HandleTypeDef *hmmc) |
1712 | __weak void HAL_MMC_TxCpltCallback(MMC_HandleTypeDef *hmmc) |
| 1630 | { |
1713 | { |
| 1631 | /* Prevent unused argument(s) compilation warning */ |
1714 | /* Prevent unused argument(s) compilation warning */ |
| 1632 | UNUSED(hmmc); |
1715 | UNUSED(hmmc); |
| 1633 | 1716 | ||
| 1634 | /* NOTE : This function should not be modified, when the callback is needed, |
1717 | /* NOTE : This function should not be modified, when the callback is needed, |
| Line 1643... | Line 1726... | ||
| 1643 | */ |
1726 | */ |
| 1644 | __weak void HAL_MMC_RxCpltCallback(MMC_HandleTypeDef *hmmc) |
1727 | __weak void HAL_MMC_RxCpltCallback(MMC_HandleTypeDef *hmmc) |
| 1645 | { |
1728 | { |
| 1646 | /* Prevent unused argument(s) compilation warning */ |
1729 | /* Prevent unused argument(s) compilation warning */ |
| 1647 | UNUSED(hmmc); |
1730 | UNUSED(hmmc); |
| 1648 | 1731 | ||
| 1649 | /* NOTE : This function should not be modified, when the callback is needed, |
1732 | /* NOTE : This function should not be modified, when the callback is needed, |
| 1650 | the HAL_MMC_RxCpltCallback can be implemented in the user file |
1733 | the HAL_MMC_RxCpltCallback can be implemented in the user file |
| 1651 | */ |
1734 | */ |
| 1652 | } |
1735 | } |
| 1653 | 1736 | ||
| Line 1658... | Line 1741... | ||
| 1658 | */ |
1741 | */ |
| 1659 | __weak void HAL_MMC_ErrorCallback(MMC_HandleTypeDef *hmmc) |
1742 | __weak void HAL_MMC_ErrorCallback(MMC_HandleTypeDef *hmmc) |
| 1660 | { |
1743 | { |
| 1661 | /* Prevent unused argument(s) compilation warning */ |
1744 | /* Prevent unused argument(s) compilation warning */ |
| 1662 | UNUSED(hmmc); |
1745 | UNUSED(hmmc); |
| 1663 | 1746 | ||
| 1664 | /* NOTE : This function should not be modified, when the callback is needed, |
1747 | /* NOTE : This function should not be modified, when the callback is needed, |
| 1665 | the HAL_MMC_ErrorCallback can be implemented in the user file |
1748 | the HAL_MMC_ErrorCallback can be implemented in the user file |
| 1666 | */ |
1749 | */ |
| 1667 | } |
1750 | } |
| 1668 | 1751 | ||
| 1669 | /** |
1752 | /** |
| 1670 | * @brief MMC Abort callbacks |
1753 | * @brief MMC Abort callbacks |
| 1671 | * @param hmmc: Pointer MMC handle |
1754 | * @param hmmc: Pointer MMC handle |
| Line 1673... | Line 1756... | ||
| 1673 | */ |
1756 | */ |
| 1674 | __weak void HAL_MMC_AbortCallback(MMC_HandleTypeDef *hmmc) |
1757 | __weak void HAL_MMC_AbortCallback(MMC_HandleTypeDef *hmmc) |
| 1675 | { |
1758 | { |
| 1676 | /* Prevent unused argument(s) compilation warning */ |
1759 | /* Prevent unused argument(s) compilation warning */ |
| 1677 | UNUSED(hmmc); |
1760 | UNUSED(hmmc); |
| 1678 | 1761 | ||
| 1679 | /* NOTE : This function should not be modified, when the callback is needed, |
1762 | /* NOTE : This function should not be modified, when the callback is needed, |
| 1680 | the HAL_MMC_ErrorCallback can be implemented in the user file |
1763 | the HAL_MMC_AbortCallback can be implemented in the user file |
| 1681 | */ |
1764 | */ |
| - | 1765 | } |
|
| - | 1766 | ||
| - | 1767 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 1768 | /** |
|
| - | 1769 | * @brief Register a User MMC Callback |
|
| - | 1770 | * To be used instead of the weak (surcharged) predefined callback |
|
| - | 1771 | * @param hmmc : MMC handle |
|
| - | 1772 | * @param CallbackId : ID of the callback to be registered |
|
| - | 1773 | * This parameter can be one of the following values: |
|
| - | 1774 | * @arg @ref HAL_MMC_TX_CPLT_CB_ID MMC Tx Complete Callback ID |
|
| - | 1775 | * @arg @ref HAL_MMC_RX_CPLT_CB_ID MMC Rx Complete Callback ID |
|
| - | 1776 | * @arg @ref HAL_MMC_ERROR_CB_ID MMC Error Callback ID |
|
| - | 1777 | * @arg @ref HAL_MMC_ABORT_CB_ID MMC Abort Callback ID |
|
| - | 1778 | * @arg @ref HAL_MMC_MSP_INIT_CB_ID MMC MspInit Callback ID |
|
| - | 1779 | * @arg @ref HAL_MMC_MSP_DEINIT_CB_ID MMC MspDeInit Callback ID |
|
| - | 1780 | * @param pCallback : pointer to the Callback function |
|
| - | 1781 | * @retval status |
|
| - | 1782 | */ |
|
| - | 1783 | HAL_StatusTypeDef HAL_MMC_RegisterCallback(MMC_HandleTypeDef *hmmc, HAL_MMC_CallbackIDTypeDef CallbackId, pMMC_CallbackTypeDef pCallback) |
|
| - | 1784 | { |
|
| - | 1785 | HAL_StatusTypeDef status = HAL_OK; |
|
| - | 1786 | ||
| - | 1787 | if(pCallback == NULL) |
|
| - | 1788 | { |
|
| - | 1789 | /* Update the error code */ |
|
| - | 1790 | hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK; |
|
| - | 1791 | return HAL_ERROR; |
|
| - | 1792 | } |
|
| - | 1793 | ||
| - | 1794 | /* Process locked */ |
|
| - | 1795 | __HAL_LOCK(hmmc); |
|
| - | 1796 | ||
| - | 1797 | if(hmmc->State == HAL_MMC_STATE_READY) |
|
| - | 1798 | { |
|
| - | 1799 | switch (CallbackId) |
|
| - | 1800 | { |
|
| - | 1801 | case HAL_MMC_TX_CPLT_CB_ID : |
|
| - | 1802 | hmmc->TxCpltCallback = pCallback; |
|
| - | 1803 | break; |
|
| - | 1804 | case HAL_MMC_RX_CPLT_CB_ID : |
|
| - | 1805 | hmmc->RxCpltCallback = pCallback; |
|
| - | 1806 | break; |
|
| - | 1807 | case HAL_MMC_ERROR_CB_ID : |
|
| - | 1808 | hmmc->ErrorCallback = pCallback; |
|
| - | 1809 | break; |
|
| - | 1810 | case HAL_MMC_ABORT_CB_ID : |
|
| - | 1811 | hmmc->AbortCpltCallback = pCallback; |
|
| - | 1812 | break; |
|
| - | 1813 | case HAL_MMC_MSP_INIT_CB_ID : |
|
| - | 1814 | hmmc->MspInitCallback = pCallback; |
|
| - | 1815 | break; |
|
| - | 1816 | case HAL_MMC_MSP_DEINIT_CB_ID : |
|
| - | 1817 | hmmc->MspDeInitCallback = pCallback; |
|
| - | 1818 | break; |
|
| - | 1819 | default : |
|
| - | 1820 | /* Update the error code */ |
|
| - | 1821 | hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK; |
|
| - | 1822 | /* update return status */ |
|
| - | 1823 | status = HAL_ERROR; |
|
| - | 1824 | break; |
|
| - | 1825 | } |
|
| - | 1826 | } |
|
| - | 1827 | else if (hmmc->State == HAL_MMC_STATE_RESET) |
|
| - | 1828 | { |
|
| - | 1829 | switch (CallbackId) |
|
| - | 1830 | { |
|
| - | 1831 | case HAL_MMC_MSP_INIT_CB_ID : |
|
| - | 1832 | hmmc->MspInitCallback = pCallback; |
|
| - | 1833 | break; |
|
| - | 1834 | case HAL_MMC_MSP_DEINIT_CB_ID : |
|
| - | 1835 | hmmc->MspDeInitCallback = pCallback; |
|
| - | 1836 | break; |
|
| - | 1837 | default : |
|
| - | 1838 | /* Update the error code */ |
|
| - | 1839 | hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK; |
|
| - | 1840 | /* update return status */ |
|
| - | 1841 | status = HAL_ERROR; |
|
| - | 1842 | break; |
|
| - | 1843 | } |
|
| - | 1844 | } |
|
| - | 1845 | else |
|
| - | 1846 | { |
|
| - | 1847 | /* Update the error code */ |
|
| - | 1848 | hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK; |
|
| - | 1849 | /* update return status */ |
|
| - | 1850 | status = HAL_ERROR; |
|
| - | 1851 | } |
|
| - | 1852 | ||
| - | 1853 | /* Release Lock */ |
|
| - | 1854 | __HAL_UNLOCK(hmmc); |
|
| - | 1855 | return status; |
|
| 1682 | } |
1856 | } |
| 1683 | 1857 | ||
| - | 1858 | /** |
|
| - | 1859 | * @brief Unregister a User MMC Callback |
|
| - | 1860 | * MMC Callback is redirected to the weak (surcharged) predefined callback |
|
| - | 1861 | * @param hmmc : MMC handle |
|
| - | 1862 | * @param CallbackId : ID of the callback to be unregistered |
|
| - | 1863 | * This parameter can be one of the following values: |
|
| - | 1864 | * @arg @ref HAL_MMC_TX_CPLT_CB_ID MMC Tx Complete Callback ID |
|
| - | 1865 | * @arg @ref HAL_MMC_RX_CPLT_CB_ID MMC Rx Complete Callback ID |
|
| - | 1866 | * @arg @ref HAL_MMC_ERROR_CB_ID MMC Error Callback ID |
|
| - | 1867 | * @arg @ref HAL_MMC_ABORT_CB_ID MMC Abort Callback ID |
|
| - | 1868 | * @arg @ref HAL_MMC_MSP_INIT_CB_ID MMC MspInit Callback ID |
|
| - | 1869 | * @arg @ref HAL_MMC_MSP_DEINIT_CB_ID MMC MspDeInit Callback ID |
|
| - | 1870 | * @retval status |
|
| - | 1871 | */ |
|
| - | 1872 | HAL_StatusTypeDef HAL_MMC_UnRegisterCallback(MMC_HandleTypeDef *hmmc, HAL_MMC_CallbackIDTypeDef CallbackId) |
|
| - | 1873 | { |
|
| - | 1874 | HAL_StatusTypeDef status = HAL_OK; |
|
| - | 1875 | ||
| - | 1876 | /* Process locked */ |
|
| - | 1877 | __HAL_LOCK(hmmc); |
|
| - | 1878 | ||
| - | 1879 | if(hmmc->State == HAL_MMC_STATE_READY) |
|
| - | 1880 | { |
|
| - | 1881 | switch (CallbackId) |
|
| - | 1882 | { |
|
| - | 1883 | case HAL_MMC_TX_CPLT_CB_ID : |
|
| - | 1884 | hmmc->TxCpltCallback = HAL_MMC_TxCpltCallback; |
|
| - | 1885 | break; |
|
| - | 1886 | case HAL_MMC_RX_CPLT_CB_ID : |
|
| - | 1887 | hmmc->RxCpltCallback = HAL_MMC_RxCpltCallback; |
|
| - | 1888 | break; |
|
| - | 1889 | case HAL_MMC_ERROR_CB_ID : |
|
| - | 1890 | hmmc->ErrorCallback = HAL_MMC_ErrorCallback; |
|
| - | 1891 | break; |
|
| - | 1892 | case HAL_MMC_ABORT_CB_ID : |
|
| - | 1893 | hmmc->AbortCpltCallback = HAL_MMC_AbortCallback; |
|
| - | 1894 | break; |
|
| - | 1895 | case HAL_MMC_MSP_INIT_CB_ID : |
|
| - | 1896 | hmmc->MspInitCallback = HAL_MMC_MspInit; |
|
| - | 1897 | break; |
|
| - | 1898 | case HAL_MMC_MSP_DEINIT_CB_ID : |
|
| - | 1899 | hmmc->MspDeInitCallback = HAL_MMC_MspDeInit; |
|
| - | 1900 | break; |
|
| - | 1901 | default : |
|
| - | 1902 | /* Update the error code */ |
|
| - | 1903 | hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK; |
|
| - | 1904 | /* update return status */ |
|
| - | 1905 | status = HAL_ERROR; |
|
| - | 1906 | break; |
|
| - | 1907 | } |
|
| - | 1908 | } |
|
| - | 1909 | else if (hmmc->State == HAL_MMC_STATE_RESET) |
|
| - | 1910 | { |
|
| - | 1911 | switch (CallbackId) |
|
| - | 1912 | { |
|
| - | 1913 | case HAL_MMC_MSP_INIT_CB_ID : |
|
| - | 1914 | hmmc->MspInitCallback = HAL_MMC_MspInit; |
|
| - | 1915 | break; |
|
| - | 1916 | case HAL_MMC_MSP_DEINIT_CB_ID : |
|
| - | 1917 | hmmc->MspDeInitCallback = HAL_MMC_MspDeInit; |
|
| - | 1918 | break; |
|
| - | 1919 | default : |
|
| - | 1920 | /* Update the error code */ |
|
| - | 1921 | hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK; |
|
| - | 1922 | /* update return status */ |
|
| - | 1923 | status = HAL_ERROR; |
|
| - | 1924 | break; |
|
| - | 1925 | } |
|
| - | 1926 | } |
|
| - | 1927 | else |
|
| - | 1928 | { |
|
| - | 1929 | /* Update the error code */ |
|
| - | 1930 | hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK; |
|
| - | 1931 | /* update return status */ |
|
| - | 1932 | status = HAL_ERROR; |
|
| - | 1933 | } |
|
| - | 1934 | ||
| - | 1935 | /* Release Lock */ |
|
| - | 1936 | __HAL_UNLOCK(hmmc); |
|
| - | 1937 | return status; |
|
| - | 1938 | } |
|
| - | 1939 | #endif |
|
| 1684 | 1940 | ||
| 1685 | /** |
1941 | /** |
| 1686 | * @} |
1942 | * @} |
| 1687 | */ |
1943 | */ |
| 1688 | 1944 | ||
| 1689 | /** @addtogroup MMC_Exported_Functions_Group3 |
1945 | /** @addtogroup MMC_Exported_Functions_Group3 |
| 1690 | * @brief management functions |
1946 | * @brief management functions |
| 1691 | * |
1947 | * |
| 1692 | @verbatim |
1948 | @verbatim |
| 1693 | ============================================================================== |
1949 | ============================================================================== |
| 1694 | ##### Peripheral Control functions ##### |
1950 | ##### Peripheral Control functions ##### |
| 1695 | ============================================================================== |
1951 | ============================================================================== |
| 1696 | [..] |
1952 | [..] |
| 1697 | This subsection provides a set of functions allowing to control the MMC card |
1953 | This subsection provides a set of functions allowing to control the MMC card |
| 1698 | operations and get the related information |
1954 | operations and get the related information |
| 1699 | 1955 | ||
| 1700 | @endverbatim |
1956 | @endverbatim |
| 1701 | * @{ |
1957 | * @{ |
| 1702 | */ |
1958 | */ |
| 1703 | 1959 | ||
| 1704 | /** |
1960 | /** |
| 1705 | * @brief Returns information the information of the card which are stored on |
1961 | * @brief Returns information the information of the card which are stored on |
| 1706 | * the CID register. |
1962 | * the CID register. |
| 1707 | * @param hmmc: Pointer to MMC handle |
1963 | * @param hmmc: Pointer to MMC handle |
| 1708 | * @param pCID: Pointer to a HAL_MMC_CIDTypedef structure that |
1964 | * @param pCID: Pointer to a HAL_MMC_CIDTypedef structure that |
| 1709 | * contains all CID register parameters |
1965 | * contains all CID register parameters |
| 1710 | * @retval HAL status |
1966 | * @retval HAL status |
| 1711 | */ |
1967 | */ |
| 1712 | HAL_StatusTypeDef HAL_MMC_GetCardCID(MMC_HandleTypeDef *hmmc, HAL_MMC_CardCIDTypeDef *pCID) |
1968 | HAL_StatusTypeDef HAL_MMC_GetCardCID(MMC_HandleTypeDef *hmmc, HAL_MMC_CardCIDTypeDef *pCID) |
| 1713 | { |
1969 | { |
| 1714 | uint32_t tmp = 0U; |
- | |
| 1715 | - | ||
| 1716 | /* Byte 0 */ |
- | |
| 1717 | tmp = (uint8_t)((hmmc->CID[0U] & 0xFF000000U) >> 24U); |
1970 | pCID->ManufacturerID = (uint8_t)((hmmc->CID[0] & 0xFF000000U) >> 24U); |
| 1718 | pCID->ManufacturerID = tmp; |
- | |
| 1719 | 1971 | ||
| 1720 | /* Byte 1 */ |
- | |
| 1721 | tmp = (uint8_t)((hmmc->CID[0U] & 0x00FF0000U) >> 16U); |
1972 | pCID->OEM_AppliID = (uint16_t)((hmmc->CID[0] & 0x00FFFF00U) >> 8U); |
| 1722 | pCID->OEM_AppliID = tmp << 8U; |
- | |
| 1723 | 1973 | ||
| 1724 | /* Byte 2 */ |
- | |
| 1725 | tmp = (uint8_t)((hmmc->CID[0U] & 0x000000FF00U) >> 8U); |
1974 | pCID->ProdName1 = (((hmmc->CID[0] & 0x000000FFU) << 24U) | ((hmmc->CID[1] & 0xFFFFFF00U) >> 8U)); |
| 1726 | pCID->OEM_AppliID |= tmp; |
- | |
| 1727 | 1975 | ||
| 1728 | /* Byte 3 */ |
- | |
| 1729 | tmp = (uint8_t)(hmmc->CID[0U] & 0x000000FFU); |
1976 | pCID->ProdName2 = (uint8_t)(hmmc->CID[1] & 0x000000FFU); |
| 1730 | pCID->ProdName1 = tmp << 24U; |
- | |
| 1731 | 1977 | ||
| 1732 | /* Byte 4 */ |
- | |
| 1733 | tmp = (uint8_t)((hmmc->CID[1U] & 0xFF000000U) >> 24U); |
1978 | pCID->ProdRev = (uint8_t)((hmmc->CID[2] & 0xFF000000U) >> 24U); |
| 1734 | pCID->ProdName1 |= tmp << 16U; |
- | |
| 1735 | - | ||
| 1736 | /* Byte 5 */ |
- | |
| 1737 | tmp = (uint8_t)((hmmc->CID[1U] & 0x00FF0000U) >> 16U); |
- | |
| 1738 | pCID->ProdName1 |= tmp << 8U; |
- | |
| 1739 | - | ||
| 1740 | /* Byte 6 */ |
- | |
| 1741 | tmp = (uint8_t)((hmmc->CID[1U] & 0x0000FF00U) >> 8U); |
- | |
| 1742 | pCID->ProdName1 |= tmp; |
- | |
| 1743 | - | ||
| 1744 | /* Byte 7 */ |
- | |
| 1745 | tmp = (uint8_t)(hmmc->CID[1U] & 0x000000FFU); |
- | |
| 1746 | pCID->ProdName2 = tmp; |
- | |
| 1747 | 1979 | ||
| 1748 | /* Byte 8 */ |
- | |
| 1749 | tmp = (uint8_t)((hmmc->CID[2U] & 0xFF000000U) >> 24U); |
1980 | pCID->ProdSN = (((hmmc->CID[2] & 0x00FFFFFFU) << 8U) | ((hmmc->CID[3] & 0xFF000000U) >> 24U)); |
| 1750 | pCID->ProdRev = tmp; |
- | |
| 1751 | 1981 | ||
| 1752 | /* Byte 9 */ |
- | |
| 1753 | tmp = (uint8_t)((hmmc->CID[2U] & 0x00FF0000U) >> 16U); |
1982 | pCID->Reserved1 = (uint8_t)((hmmc->CID[3] & 0x00F00000U) >> 20U); |
| 1754 | pCID->ProdSN = tmp << 24U; |
- | |
| 1755 | 1983 | ||
| 1756 | /* Byte 10 */ |
- | |
| 1757 | tmp = (uint8_t)((hmmc->CID[2U] & 0x0000FF00U) >> 8U); |
1984 | pCID->ManufactDate = (uint16_t)((hmmc->CID[3] & 0x000FFF00U) >> 8U); |
| 1758 | pCID->ProdSN |= tmp << 16U; |
- | |
| 1759 | - | ||
| 1760 | /* Byte 11 */ |
- | |
| 1761 | tmp = (uint8_t)(hmmc->CID[2U] & 0x000000FFU); |
- | |
| 1762 | pCID->ProdSN |= tmp << 8U; |
- | |
| 1763 | - | ||
| 1764 | /* Byte 12 */ |
- | |
| 1765 | tmp = (uint8_t)((hmmc->CID[3U] & 0xFF000000U) >> 24U); |
- | |
| 1766 | pCID->ProdSN |= tmp; |
- | |
| 1767 | 1985 | ||
| 1768 | /* Byte 13 */ |
- | |
| 1769 | tmp = (uint8_t)((hmmc->CID[3U] & 0x00FF0000U) >> 16U); |
1986 | pCID->CID_CRC = (uint8_t)((hmmc->CID[3] & 0x000000FEU) >> 1U); |
| 1770 | pCID->Reserved1 |= (tmp & 0xF0U) >> 4U; |
- | |
| 1771 | pCID->ManufactDate = (tmp & 0x0FU) << 8U; |
- | |
| 1772 | - | ||
| 1773 | /* Byte 14 */ |
- | |
| 1774 | tmp = (uint8_t)((hmmc->CID[3U] & 0x0000FF00U) >> 8U); |
- | |
| 1775 | pCID->ManufactDate |= tmp; |
- | |
| 1776 | 1987 | ||
| 1777 | /* Byte 15 */ |
- | |
| 1778 | tmp = (uint8_t)(hmmc->CID[3U] & 0x000000FFU); |
- | |
| 1779 | pCID->CID_CRC = (tmp & 0xFEU) >> 1U; |
- | |
| 1780 | pCID->Reserved2 = 1U; |
1988 | pCID->Reserved2 = 1U; |
| 1781 | 1989 | ||
| 1782 | return HAL_OK; |
1990 | return HAL_OK; |
| 1783 | } |
1991 | } |
| 1784 | 1992 | ||
| 1785 | /** |
1993 | /** |
| 1786 | * @brief Returns information the information of the card which are stored on |
1994 | * @brief Returns information the information of the card which are stored on |
| 1787 | * the CSD register. |
1995 | * the CSD register. |
| 1788 | * @param hmmc: Pointer to MMC handle |
1996 | * @param hmmc: Pointer to MMC handle |
| 1789 | * @param pCSD: Pointer to a HAL_MMC_CardInfoTypeDef structure that |
1997 | * @param pCSD: Pointer to a HAL_MMC_CardCSDTypeDef structure that |
| 1790 | * contains all CSD register parameters |
1998 | * contains all CSD register parameters |
| 1791 | * @retval HAL status |
1999 | * @retval HAL status |
| 1792 | */ |
2000 | */ |
| 1793 | HAL_StatusTypeDef HAL_MMC_GetCardCSD(MMC_HandleTypeDef *hmmc, HAL_MMC_CardCSDTypeDef *pCSD) |
2001 | HAL_StatusTypeDef HAL_MMC_GetCardCSD(MMC_HandleTypeDef *hmmc, HAL_MMC_CardCSDTypeDef *pCSD) |
| 1794 | { |
2002 | { |
| 1795 | uint32_t tmp = 0U; |
2003 | pCSD->CSDStruct = (uint8_t)((hmmc->CSD[0] & 0xC0000000U) >> 30U); |
| 1796 | 2004 | ||
| 1797 | /* Byte 0 */ |
- | |
| 1798 | tmp = (hmmc->CSD[0U] & 0xFF000000U) >> 24U; |
- | |
| 1799 | pCSD->CSDStruct = (uint8_t)((tmp & 0xC0U) >> 6U); |
2005 | pCSD->SysSpecVersion = (uint8_t)((hmmc->CSD[0] & 0x3C000000U) >> 26U); |
| - | 2006 | ||
| 1800 | pCSD->SysSpecVersion = (uint8_t)((tmp & 0x3CU) >> 2U); |
2007 | pCSD->Reserved1 = (uint8_t)((hmmc->CSD[0] & 0x03000000U) >> 24U); |
| 1801 | pCSD->Reserved1 = tmp & 0x03U; |
- | |
| 1802 | 2008 | ||
| 1803 | /* Byte 1 */ |
- | |
| 1804 | tmp = (hmmc->CSD[0U] & 0x00FF0000U) >> 16U; |
2009 | pCSD->TAAC = (uint8_t)((hmmc->CSD[0] & 0x00FF0000U) >> 16U); |
| 1805 | pCSD->TAAC = (uint8_t)tmp; |
- | |
| 1806 | 2010 | ||
| 1807 | /* Byte 2 */ |
- | |
| 1808 | tmp = (hmmc->CSD[0U] & 0x0000FF00U) >> 8U; |
2011 | pCSD->NSAC = (uint8_t)((hmmc->CSD[0] & 0x0000FF00U) >> 8U); |
| 1809 | pCSD->NSAC = (uint8_t)tmp; |
- | |
| 1810 | 2012 | ||
| 1811 | /* Byte 3 */ |
- | |
| 1812 | tmp = hmmc->CSD[0U] & 0x000000FFU; |
- | |
| 1813 | pCSD->MaxBusClkFrec = (uint8_t)tmp; |
2013 | pCSD->MaxBusClkFrec = (uint8_t)(hmmc->CSD[0] & 0x000000FFU); |
| 1814 | 2014 | ||
| 1815 | /* Byte 4 */ |
- | |
| 1816 | tmp = (hmmc->CSD[1U] & 0xFF000000U) >> 24U; |
- | |
| 1817 | pCSD->CardComdClasses = (uint16_t)(tmp << 4U); |
2015 | pCSD->CardComdClasses = (uint16_t)((hmmc->CSD[1] & 0xFFF00000U) >> 20U); |
| 1818 | 2016 | ||
| 1819 | /* Byte 5 */ |
- | |
| 1820 | tmp = (hmmc->CSD[1U] & 0x00FF0000U) >> 16U; |
2017 | pCSD->RdBlockLen = (uint8_t)((hmmc->CSD[1] & 0x000F0000U) >> 16U); |
| 1821 | pCSD->CardComdClasses |= (uint16_t)((tmp & 0xF0U) >> 4U); |
- | |
| 1822 | pCSD->RdBlockLen = (uint8_t)(tmp & 0x0FU); |
- | |
| 1823 | 2018 | ||
| 1824 | /* Byte 6 */ |
- | |
| 1825 | tmp = (hmmc->CSD[1U] & 0x0000FF00U) >> 8U; |
- | |
| 1826 | pCSD->PartBlockRead = (uint8_t)((tmp & 0x80U) >> 7U); |
2019 | pCSD->PartBlockRead = (uint8_t)((hmmc->CSD[1] & 0x00008000U) >> 15U); |
| - | 2020 | ||
| 1827 | pCSD->WrBlockMisalign = (uint8_t)((tmp & 0x40U) >> 6U); |
2021 | pCSD->WrBlockMisalign = (uint8_t)((hmmc->CSD[1] & 0x00004000U) >> 14U); |
| - | 2022 | ||
| 1828 | pCSD->RdBlockMisalign = (uint8_t)((tmp & 0x20U) >> 5U); |
2023 | pCSD->RdBlockMisalign = (uint8_t)((hmmc->CSD[1] & 0x00002000U) >> 13U); |
| - | 2024 | ||
| 1829 | pCSD->DSRImpl = (uint8_t)((tmp & 0x10U) >> 4U); |
2025 | pCSD->DSRImpl = (uint8_t)((hmmc->CSD[1] & 0x00001000U) >> 12U); |
| - | 2026 | ||
| 1830 | pCSD->Reserved2 = 0; /*!< Reserved */ |
2027 | pCSD->Reserved2 = 0U; /*!< Reserved */ |
| 1831 | 2028 | ||
| 1832 | pCSD->DeviceSize = (tmp & 0x03U) << 10U; |
2029 | pCSD->DeviceSize = (((hmmc->CSD[1] & 0x000003FFU) << 2U) | ((hmmc->CSD[2] & 0xC0000000U) >> 30U)); |
| 1833 | 2030 | ||
| 1834 | /* Byte 7 */ |
- | |
| 1835 | tmp = (uint8_t)(hmmc->CSD[1U] & 0x000000FFU); |
2031 | pCSD->MaxRdCurrentVDDMin = (uint8_t)((hmmc->CSD[2] & 0x38000000U) >> 27U); |
| 1836 | pCSD->DeviceSize |= (tmp) << 2U; |
- | |
| 1837 | 2032 | ||
| 1838 | /* Byte 8 */ |
- | |
| 1839 | tmp = (uint8_t)((hmmc->CSD[2U] & 0xFF000000U) >> 24U); |
2033 | pCSD->MaxRdCurrentVDDMax = (uint8_t)((hmmc->CSD[2] & 0x07000000U) >> 24U); |
| 1840 | pCSD->DeviceSize |= (tmp & 0xC0U) >> 6U; |
- | |
| 1841 | 2034 | ||
| 1842 | pCSD->MaxRdCurrentVDDMin = (tmp & 0x38U) >> 3U; |
2035 | pCSD->MaxWrCurrentVDDMin = (uint8_t)((hmmc->CSD[2] & 0x00E00000U) >> 21U); |
| 1843 | pCSD->MaxRdCurrentVDDMax = (tmp & 0x07U); |
- | |
| 1844 | 2036 | ||
| 1845 | /* Byte 9 */ |
- | |
| 1846 | tmp = (uint8_t)((hmmc->CSD[2U] & 0x00FF0000U) >> 16U); |
2037 | pCSD->MaxWrCurrentVDDMax = (uint8_t)((hmmc->CSD[2] & 0x001C0000U) >> 18U); |
| 1847 | pCSD->MaxWrCurrentVDDMin = (tmp & 0xE0U) >> 5U; |
- | |
| 1848 | pCSD->MaxWrCurrentVDDMax = (tmp & 0x1CU) >> 2U; |
- | |
| 1849 | pCSD->DeviceSizeMul = (tmp & 0x03U) << 1U; |
- | |
| 1850 | /* Byte 10 */ |
2038 | |
| 1851 | tmp = (uint8_t)((hmmc->CSD[2] & 0x0000FF00U) >> 8U); |
2039 | pCSD->DeviceSizeMul = (uint8_t)((hmmc->CSD[2] & 0x00038000U) >> 15U); |
| 1852 | pCSD->DeviceSizeMul |= (tmp & 0x80U) >> 7U; |
- | |
| 1853 | 2040 | ||
| 1854 | hmmc->MmcCard.BlockNbr = (pCSD->DeviceSize + 1U) ; |
2041 | hmmc->MmcCard.BlockNbr = (pCSD->DeviceSize + 1U) ; |
| 1855 | hmmc->MmcCard.BlockNbr *= (1U << (pCSD->DeviceSizeMul + 2U)); |
2042 | hmmc->MmcCard.BlockNbr *= (1UL << ((pCSD->DeviceSizeMul & 0x07U) + 2U)); |
| 1856 | hmmc->MmcCard.BlockSize = 1U << (pCSD->RdBlockLen); |
2043 | hmmc->MmcCard.BlockSize = (1UL << (pCSD->RdBlockLen & 0x0FU)); |
| 1857 | 2044 | ||
| 1858 | hmmc->MmcCard.LogBlockNbr = (hmmc->MmcCard.BlockNbr) * ((hmmc->MmcCard.BlockSize) / 512U); |
2045 | hmmc->MmcCard.LogBlockNbr = (hmmc->MmcCard.BlockNbr) * ((hmmc->MmcCard.BlockSize) / 512U); |
| 1859 | hmmc->MmcCard.LogBlockSize = 512U; |
2046 | hmmc->MmcCard.LogBlockSize = 512U; |
| 1860 | 2047 | ||
| 1861 | pCSD->EraseGrSize = (tmp & 0x40U) >> 6U; |
2048 | pCSD->EraseGrSize = (uint8_t)((hmmc->CSD[2] & 0x00004000U) >> 14U); |
| - | 2049 | ||
| 1862 | pCSD->EraseGrMul = (tmp & 0x3FU) << 1U; |
2050 | pCSD->EraseGrMul = (uint8_t)((hmmc->CSD[2] & 0x00003F80U) >> 7U); |
| 1863 | 2051 | ||
| 1864 | /* Byte 11 */ |
- | |
| 1865 | tmp = (uint8_t)(hmmc->CSD[2U] & 0x000000FFU); |
2052 | pCSD->WrProtectGrSize = (uint8_t)(hmmc->CSD[2] & 0x0000007FU); |
| 1866 | pCSD->EraseGrMul |= (tmp & 0x80U) >> 7U; |
- | |
| 1867 | pCSD->WrProtectGrSize = (tmp & 0x7FU); |
- | |
| 1868 | 2053 | ||
| 1869 | /* Byte 12 */ |
- | |
| 1870 | tmp = (uint8_t)((hmmc->CSD[3U] & 0xFF000000U) >> 24U); |
2054 | pCSD->WrProtectGrEnable = (uint8_t)((hmmc->CSD[3] & 0x80000000U) >> 31U); |
| 1871 | pCSD->WrProtectGrEnable = (tmp & 0x80U) >> 7U; |
- | |
| - | 2055 | ||
| 1872 | pCSD->ManDeflECC = (tmp & 0x60U) >> 5U; |
2056 | pCSD->ManDeflECC = (uint8_t)((hmmc->CSD[3] & 0x60000000U) >> 29U); |
| 1873 | pCSD->WrSpeedFact = (tmp & 0x1CU) >> 2U; |
- | |
| 1874 | pCSD->MaxWrBlockLen = (tmp & 0x03U) << 2U; |
- | |
| 1875 | 2057 | ||
| 1876 | /* Byte 13 */ |
- | |
| 1877 | tmp = (uint8_t)((hmmc->CSD[3U] & 0x00FF0000U) >> 16U); |
2058 | pCSD->WrSpeedFact = (uint8_t)((hmmc->CSD[3] & 0x1C000000U) >> 26U); |
| - | 2059 | ||
| 1878 | pCSD->MaxWrBlockLen |= (tmp & 0xC0U) >> 6U; |
2060 | pCSD->MaxWrBlockLen= (uint8_t)((hmmc->CSD[3] & 0x03C00000U) >> 22U); |
| - | 2061 | ||
| 1879 | pCSD->WriteBlockPaPartial = (tmp & 0x20U) >> 5U; |
2062 | pCSD->WriteBlockPaPartial = (uint8_t)((hmmc->CSD[3] & 0x00200000U) >> 21U); |
| - | 2063 | ||
| 1880 | pCSD->Reserved3 = 0U; |
2064 | pCSD->Reserved3 = 0; |
| - | 2065 | ||
| 1881 | pCSD->ContentProtectAppli = (tmp & 0x01U); |
2066 | pCSD->ContentProtectAppli = (uint8_t)((hmmc->CSD[3] & 0x00010000U) >> 16U); |
| 1882 | 2067 | ||
| 1883 | /* Byte 14 */ |
- | |
| 1884 | tmp = (uint8_t)((hmmc->CSD[3U] & 0x0000FF00U) >> 8U); |
2068 | pCSD->FileFormatGroup = (uint8_t)((hmmc->CSD[3] & 0x00008000U) >> 15U); |
| 1885 | pCSD->FileFormatGrouop = (tmp & 0x80U) >> 7U; |
- | |
| - | 2069 | ||
| 1886 | pCSD->CopyFlag = (tmp & 0x40U) >> 6U; |
2070 | pCSD->CopyFlag = (uint8_t)((hmmc->CSD[3] & 0x00004000U) >> 14U); |
| - | 2071 | ||
| 1887 | pCSD->PermWrProtect = (tmp & 0x20U) >> 5U; |
2072 | pCSD->PermWrProtect = (uint8_t)((hmmc->CSD[3] & 0x00002000U) >> 13U); |
| - | 2073 | ||
| 1888 | pCSD->TempWrProtect = (tmp & 0x10U) >> 4U; |
2074 | pCSD->TempWrProtect = (uint8_t)((hmmc->CSD[3] & 0x00001000U) >> 12U); |
| - | 2075 | ||
| 1889 | pCSD->FileFormat = (tmp & 0x0CU) >> 2U; |
2076 | pCSD->FileFormat = (uint8_t)((hmmc->CSD[3] & 0x00000C00U) >> 10U); |
| 1890 | pCSD->ECC = (tmp & 0x03U); |
- | |
| 1891 | 2077 | ||
| 1892 | /* Byte 15 */ |
- | |
| 1893 | tmp = (uint8_t)(hmmc->CSD[3U] & 0x000000FFU); |
2078 | pCSD->ECC= (uint8_t)((hmmc->CSD[3] & 0x00000300U) >> 8U); |
| - | 2079 | ||
| 1894 | pCSD->CSD_CRC = (tmp & 0xFEU) >> 1U; |
2080 | pCSD->CSD_CRC = (uint8_t)((hmmc->CSD[3] & 0x000000FEU) >> 1U); |
| - | 2081 | ||
| 1895 | pCSD->Reserved4 = 1U; |
2082 | pCSD->Reserved4 = 1; |
| 1896 | 2083 | ||
| 1897 | return HAL_OK; |
2084 | return HAL_OK; |
| 1898 | } |
2085 | } |
| 1899 | 2086 | ||
| 1900 | /** |
2087 | /** |
| 1901 | * @brief Gets the MMC card info. |
2088 | * @brief Gets the MMC card info. |
| 1902 | * @param hmmc: Pointer to MMC handle |
2089 | * @param hmmc: Pointer to MMC handle |
| 1903 | * @param pCardInfo: Pointer to the HAL_MMC_CardInfoTypeDef structure that |
2090 | * @param pCardInfo: Pointer to the HAL_MMC_CardInfoTypeDef structure that |
| 1904 | * will contain the MMC card status information |
2091 | * will contain the MMC card status information |
| 1905 | * @retval HAL status |
2092 | * @retval HAL status |
| 1906 | */ |
2093 | */ |
| 1907 | HAL_StatusTypeDef HAL_MMC_GetCardInfo(MMC_HandleTypeDef *hmmc, HAL_MMC_CardInfoTypeDef *pCardInfo) |
2094 | HAL_StatusTypeDef HAL_MMC_GetCardInfo(MMC_HandleTypeDef *hmmc, HAL_MMC_CardInfoTypeDef *pCardInfo) |
| 1908 | { |
2095 | { |
| 1909 | pCardInfo->CardType = (uint32_t)(hmmc->MmcCard.CardType); |
2096 | pCardInfo->CardType = (uint32_t)(hmmc->MmcCard.CardType); |
| Line 1911... | Line 2098... | ||
| 1911 | pCardInfo->RelCardAdd = (uint32_t)(hmmc->MmcCard.RelCardAdd); |
2098 | pCardInfo->RelCardAdd = (uint32_t)(hmmc->MmcCard.RelCardAdd); |
| 1912 | pCardInfo->BlockNbr = (uint32_t)(hmmc->MmcCard.BlockNbr); |
2099 | pCardInfo->BlockNbr = (uint32_t)(hmmc->MmcCard.BlockNbr); |
| 1913 | pCardInfo->BlockSize = (uint32_t)(hmmc->MmcCard.BlockSize); |
2100 | pCardInfo->BlockSize = (uint32_t)(hmmc->MmcCard.BlockSize); |
| 1914 | pCardInfo->LogBlockNbr = (uint32_t)(hmmc->MmcCard.LogBlockNbr); |
2101 | pCardInfo->LogBlockNbr = (uint32_t)(hmmc->MmcCard.LogBlockNbr); |
| 1915 | pCardInfo->LogBlockSize = (uint32_t)(hmmc->MmcCard.LogBlockSize); |
2102 | pCardInfo->LogBlockSize = (uint32_t)(hmmc->MmcCard.LogBlockSize); |
| 1916 | 2103 | ||
| 1917 | return HAL_OK; |
2104 | return HAL_OK; |
| 1918 | } |
2105 | } |
| 1919 | 2106 | ||
| 1920 | /** |
2107 | /** |
| 1921 | * @brief Enables wide bus operation for the requested card if supported by |
2108 | * @brief Enables wide bus operation for the requested card if supported by |
| 1922 | * card. |
2109 | * card. |
| 1923 | * @param hmmc: Pointer to MMC handle |
2110 | * @param hmmc: Pointer to MMC handle |
| 1924 | * @param WideMode: Specifies the MMC card wide bus mode |
2111 | * @param WideMode: Specifies the MMC card wide bus mode |
| 1925 | * This parameter can be one of the following values: |
2112 | * This parameter can be one of the following values: |
| 1926 | * @arg SDIO_BUS_WIDE_8B: 8-bit data transfer |
2113 | * @arg SDIO_BUS_WIDE_8B: 8-bit data transfer |
| 1927 | * @arg SDIO_BUS_WIDE_4B: 4-bit data transfer |
2114 | * @arg SDIO_BUS_WIDE_4B: 4-bit data transfer |
| 1928 | * @arg SDIO_BUS_WIDE_1B: 1-bit data transfer |
2115 | * @arg SDIO_BUS_WIDE_1B: 1-bit data transfer |
| 1929 | * @retval HAL status |
2116 | * @retval HAL status |
| 1930 | */ |
2117 | */ |
| 1931 | HAL_StatusTypeDef HAL_MMC_ConfigWideBusOperation(MMC_HandleTypeDef *hmmc, uint32_t WideMode) |
2118 | HAL_StatusTypeDef HAL_MMC_ConfigWideBusOperation(MMC_HandleTypeDef *hmmc, uint32_t WideMode) |
| 1932 | { |
2119 | { |
| 1933 | __IO uint32_t count = 0U; |
2120 | __IO uint32_t count = 0U; |
| 1934 | SDIO_InitTypeDef Init; |
2121 | SDIO_InitTypeDef Init; |
| 1935 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
2122 | uint32_t errorstate; |
| 1936 | uint32_t response = 0U, busy = 0U; |
2123 | uint32_t response = 0U, busy = 0U; |
| 1937 | 2124 | ||
| 1938 | /* Check the parameters */ |
2125 | /* Check the parameters */ |
| 1939 | assert_param(IS_SDIO_BUS_WIDE(WideMode)); |
2126 | assert_param(IS_SDIO_BUS_WIDE(WideMode)); |
| 1940 | 2127 | ||
| 1941 | /* Chnage Satte */ |
2128 | /* Chnage Satte */ |
| 1942 | hmmc->State = HAL_MMC_STATE_BUSY; |
2129 | hmmc->State = HAL_MMC_STATE_BUSY; |
| 1943 | 2130 | ||
| 1944 | /* Update Clock for Bus mode update */ |
2131 | /* Update Clock for Bus mode update */ |
| 1945 | Init.ClockEdge = SDIO_CLOCK_EDGE_RISING; |
2132 | Init.ClockEdge = SDIO_CLOCK_EDGE_RISING; |
| 1946 | Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE; |
2133 | Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE; |
| 1947 | Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE; |
2134 | Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE; |
| 1948 | Init.BusWide = WideMode; |
2135 | Init.BusWide = WideMode; |
| 1949 | Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE; |
2136 | Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE; |
| 1950 | Init.ClockDiv = SDIO_INIT_CLK_DIV; |
2137 | Init.ClockDiv = SDIO_INIT_CLK_DIV; |
| 1951 | /* Initialize SDIO*/ |
2138 | /* Initialize SDIO*/ |
| 1952 | SDIO_Init(hmmc->Instance, Init); |
2139 | (void)SDIO_Init(hmmc->Instance, Init); |
| 1953 | 2140 | ||
| 1954 | if(WideMode == SDIO_BUS_WIDE_8B) |
2141 | if(WideMode == SDIO_BUS_WIDE_8B) |
| 1955 | { |
2142 | { |
| 1956 | errorstate = SDMMC_CmdSwitch(hmmc->Instance, 0x03B70200U); |
2143 | errorstate = SDMMC_CmdSwitch(hmmc->Instance, 0x03B70200U); |
| 1957 | if(errorstate != HAL_MMC_ERROR_NONE) |
2144 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1958 | { |
2145 | { |
| Line 1978... | Line 2165... | ||
| 1978 | else |
2165 | else |
| 1979 | { |
2166 | { |
| 1980 | /* WideMode is not a valid argument*/ |
2167 | /* WideMode is not a valid argument*/ |
| 1981 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
2168 | hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM; |
| 1982 | } |
2169 | } |
| 1983 | 2170 | ||
| 1984 | /* Check for switch error and violation of the trial number of sending CMD 13 */ |
2171 | /* Check for switch error and violation of the trial number of sending CMD 13 */ |
| 1985 | while(busy == 0U) |
2172 | while(busy == 0U) |
| 1986 | { |
2173 | { |
| 1987 | if(count++ == SDMMC_MAX_TRIAL) |
2174 | if(count == SDMMC_MAX_TRIAL) |
| 1988 | { |
2175 | { |
| 1989 | hmmc->State = HAL_MMC_STATE_READY; |
2176 | hmmc->State = HAL_MMC_STATE_READY; |
| 1990 | hmmc->ErrorCode |= HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE; |
2177 | hmmc->ErrorCode |= HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE; |
| 1991 | return HAL_ERROR; |
2178 | return HAL_ERROR; |
| 1992 | } |
2179 | } |
| 1993 | 2180 | count++; |
|
| - | 2181 | ||
| 1994 | /* While card is not ready for data and trial number for sending CMD13 is not exceeded */ |
2182 | /* While card is not ready for data and trial number for sending CMD13 is not exceeded */ |
| 1995 | errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U)); |
2183 | errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U)); |
| 1996 | if(errorstate != HAL_MMC_ERROR_NONE) |
2184 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 1997 | { |
2185 | { |
| 1998 | hmmc->ErrorCode |= errorstate; |
2186 | hmmc->ErrorCode |= errorstate; |
| 1999 | } |
2187 | } |
| 2000 | 2188 | ||
| 2001 | /* Get command response */ |
2189 | /* Get command response */ |
| 2002 | response = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
2190 | response = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
| 2003 | 2191 | ||
| 2004 | /* Get operating voltage*/ |
2192 | /* Get operating voltage*/ |
| 2005 | busy = (((response >> 7U) == 1U) ? 0U : 1U); |
2193 | busy = (((response >> 7U) == 1U) ? 0U : 1U); |
| 2006 | } |
2194 | } |
| 2007 | 2195 | ||
| 2008 | /* While card is not ready for data and trial number for sending CMD13 is not exceeded */ |
2196 | /* While card is not ready for data and trial number for sending CMD13 is not exceeded */ |
| 2009 | count = SDMMC_DATATIMEOUT; |
2197 | count = SDMMC_DATATIMEOUT; |
| 2010 | while((response & 0x00000100U) == 0U) |
2198 | while((response & 0x00000100U) == 0U) |
| 2011 | { |
2199 | { |
| 2012 | if(count-- == 0U) |
2200 | if(count == 0U) |
| 2013 | { |
2201 | { |
| 2014 | hmmc->State = HAL_MMC_STATE_READY; |
2202 | hmmc->State = HAL_MMC_STATE_READY; |
| 2015 | hmmc->ErrorCode |= HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE; |
2203 | hmmc->ErrorCode |= HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE; |
| 2016 | return HAL_ERROR; |
2204 | return HAL_ERROR; |
| 2017 | } |
2205 | } |
| 2018 | 2206 | count--; |
|
| - | 2207 | ||
| 2019 | /* While card is not ready for data and trial number for sending CMD13 is not exceeded */ |
2208 | /* While card is not ready for data and trial number for sending CMD13 is not exceeded */ |
| 2020 | errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U)); |
2209 | errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U)); |
| 2021 | if(errorstate != HAL_MMC_ERROR_NONE) |
2210 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 2022 | { |
2211 | { |
| 2023 | hmmc->ErrorCode |= errorstate; |
2212 | hmmc->ErrorCode |= errorstate; |
| 2024 | } |
2213 | } |
| 2025 | 2214 | ||
| 2026 | /* Get command response */ |
2215 | /* Get command response */ |
| 2027 | response = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
2216 | response = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
| 2028 | } |
2217 | } |
| 2029 | 2218 | ||
| 2030 | if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE) |
2219 | if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE) |
| 2031 | { |
2220 | { |
| 2032 | /* Clear all the static flags */ |
2221 | /* Clear all the static flags */ |
| 2033 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
2222 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
| 2034 | hmmc->State = HAL_MMC_STATE_READY; |
2223 | hmmc->State = HAL_MMC_STATE_READY; |
| Line 2041... | Line 2230... | ||
| 2041 | Init.ClockBypass = hmmc->Init.ClockBypass; |
2230 | Init.ClockBypass = hmmc->Init.ClockBypass; |
| 2042 | Init.ClockPowerSave = hmmc->Init.ClockPowerSave; |
2231 | Init.ClockPowerSave = hmmc->Init.ClockPowerSave; |
| 2043 | Init.BusWide = WideMode; |
2232 | Init.BusWide = WideMode; |
| 2044 | Init.HardwareFlowControl = hmmc->Init.HardwareFlowControl; |
2233 | Init.HardwareFlowControl = hmmc->Init.HardwareFlowControl; |
| 2045 | Init.ClockDiv = hmmc->Init.ClockDiv; |
2234 | Init.ClockDiv = hmmc->Init.ClockDiv; |
| 2046 | SDIO_Init(hmmc->Instance, Init); |
2235 | (void)SDIO_Init(hmmc->Instance, Init); |
| 2047 | } |
2236 | } |
| 2048 | 2237 | ||
| 2049 | /* Change State */ |
2238 | /* Change State */ |
| 2050 | hmmc->State = HAL_MMC_STATE_READY; |
2239 | hmmc->State = HAL_MMC_STATE_READY; |
| 2051 | 2240 | ||
| 2052 | return HAL_OK; |
2241 | return HAL_OK; |
| 2053 | } |
2242 | } |
| 2054 | 2243 | ||
| 2055 | - | ||
| 2056 | /** |
2244 | /** |
| 2057 | * @brief Gets the current mmc card data state. |
2245 | * @brief Gets the current mmc card data state. |
| 2058 | * @param hmmc: pointer to MMC handle |
2246 | * @param hmmc: pointer to MMC handle |
| 2059 | * @retval Card state |
2247 | * @retval Card state |
| 2060 | */ |
2248 | */ |
| 2061 | HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState(MMC_HandleTypeDef *hmmc) |
2249 | HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState(MMC_HandleTypeDef *hmmc) |
| 2062 | { |
2250 | { |
| 2063 | HAL_MMC_CardStateTypeDef cardstate = HAL_MMC_CARD_TRANSFER; |
2251 | uint32_t cardstate; |
| 2064 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
2252 | uint32_t errorstate; |
| 2065 | uint32_t resp1 = 0U; |
2253 | uint32_t resp1 = 0U; |
| 2066 | 2254 | ||
| 2067 | errorstate = MMC_SendStatus(hmmc, &resp1); |
2255 | errorstate = MMC_SendStatus(hmmc, &resp1); |
| 2068 | if(errorstate != HAL_OK) |
2256 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 2069 | { |
2257 | { |
| 2070 | hmmc->ErrorCode |= errorstate; |
2258 | hmmc->ErrorCode |= errorstate; |
| 2071 | } |
2259 | } |
| 2072 | 2260 | ||
| 2073 | cardstate = (HAL_MMC_CardStateTypeDef)((resp1 >> 9U) & 0x0FU); |
2261 | cardstate = ((resp1 >> 9U) & 0x0FU); |
| 2074 | 2262 | ||
| 2075 | return cardstate; |
2263 | return (HAL_MMC_CardStateTypeDef)cardstate; |
| 2076 | } |
2264 | } |
| 2077 | 2265 | ||
| 2078 | /** |
2266 | /** |
| 2079 | * @brief Abort the current transfer and disable the MMC. |
2267 | * @brief Abort the current transfer and disable the MMC. |
| 2080 | * @param hmmc: pointer to a MMC_HandleTypeDef structure that contains |
2268 | * @param hmmc: pointer to a MMC_HandleTypeDef structure that contains |
| Line 2082... | Line 2270... | ||
| 2082 | * @retval HAL status |
2270 | * @retval HAL status |
| 2083 | */ |
2271 | */ |
| 2084 | HAL_StatusTypeDef HAL_MMC_Abort(MMC_HandleTypeDef *hmmc) |
2272 | HAL_StatusTypeDef HAL_MMC_Abort(MMC_HandleTypeDef *hmmc) |
| 2085 | { |
2273 | { |
| 2086 | HAL_MMC_CardStateTypeDef CardState; |
2274 | HAL_MMC_CardStateTypeDef CardState; |
| 2087 | 2275 | ||
| 2088 | /* DIsable All interrupts */ |
2276 | /* DIsable All interrupts */ |
| 2089 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
2277 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
| 2090 | SDIO_IT_TXUNDERR| SDIO_IT_RXOVERR); |
2278 | SDIO_IT_TXUNDERR| SDIO_IT_RXOVERR); |
| 2091 | 2279 | ||
| 2092 | /* Clear All flags */ |
2280 | /* Clear All flags */ |
| 2093 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
2281 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_DATA_FLAGS); |
| 2094 | 2282 | ||
| 2095 | if((hmmc->hdmatx != NULL) || (hmmc->hdmarx != NULL)) |
2283 | if((hmmc->hdmatx != NULL) || (hmmc->hdmarx != NULL)) |
| 2096 | { |
2284 | { |
| 2097 | /* Disable the MMC DMA request */ |
2285 | /* Disable the MMC DMA request */ |
| 2098 | hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDIO_DCTRL_DMAEN); |
2286 | hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDIO_DCTRL_DMAEN); |
| 2099 | 2287 | ||
| 2100 | /* Abort the MMC DMA Tx Stream */ |
2288 | /* Abort the MMC DMA Tx Stream */ |
| 2101 | if(hmmc->hdmatx != NULL) |
2289 | if(hmmc->hdmatx != NULL) |
| 2102 | { |
2290 | { |
| 2103 | HAL_DMA_Abort(hmmc->hdmatx); |
2291 | if(HAL_DMA_Abort(hmmc->hdmatx) != HAL_OK) |
| - | 2292 | { |
|
| - | 2293 | hmmc->ErrorCode |= HAL_MMC_ERROR_DMA; |
|
| - | 2294 | } |
|
| 2104 | } |
2295 | } |
| 2105 | /* Abort the MMC DMA Rx Stream */ |
2296 | /* Abort the MMC DMA Rx Stream */ |
| 2106 | if(hmmc->hdmarx != NULL) |
2297 | if(hmmc->hdmarx != NULL) |
| 2107 | { |
2298 | { |
| 2108 | HAL_DMA_Abort(hmmc->hdmarx); |
2299 | if(HAL_DMA_Abort(hmmc->hdmarx) != HAL_OK) |
| - | 2300 | { |
|
| - | 2301 | hmmc->ErrorCode |= HAL_MMC_ERROR_DMA; |
|
| - | 2302 | } |
|
| 2109 | } |
2303 | } |
| 2110 | } |
2304 | } |
| 2111 | 2305 | ||
| 2112 | hmmc->State = HAL_MMC_STATE_READY; |
2306 | hmmc->State = HAL_MMC_STATE_READY; |
| - | 2307 | ||
| - | 2308 | /* Initialize the MMC operation */ |
|
| - | 2309 | hmmc->Context = MMC_CONTEXT_NONE; |
|
| - | 2310 | ||
| 2113 | CardState = HAL_MMC_GetCardState(hmmc); |
2311 | CardState = HAL_MMC_GetCardState(hmmc); |
| 2114 | if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING)) |
2312 | if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING)) |
| 2115 | { |
2313 | { |
| 2116 | hmmc->ErrorCode = SDMMC_CmdStopTransfer(hmmc->Instance); |
2314 | hmmc->ErrorCode = SDMMC_CmdStopTransfer(hmmc->Instance); |
| 2117 | } |
2315 | } |
| Line 2129... | Line 2327... | ||
| 2129 | * @retval HAL status |
2327 | * @retval HAL status |
| 2130 | */ |
2328 | */ |
| 2131 | HAL_StatusTypeDef HAL_MMC_Abort_IT(MMC_HandleTypeDef *hmmc) |
2329 | HAL_StatusTypeDef HAL_MMC_Abort_IT(MMC_HandleTypeDef *hmmc) |
| 2132 | { |
2330 | { |
| 2133 | HAL_MMC_CardStateTypeDef CardState; |
2331 | HAL_MMC_CardStateTypeDef CardState; |
| 2134 | 2332 | ||
| 2135 | /* DIsable All interrupts */ |
2333 | /* DIsable All interrupts */ |
| 2136 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
2334 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
| 2137 | SDIO_IT_TXUNDERR| SDIO_IT_RXOVERR); |
2335 | SDIO_IT_TXUNDERR| SDIO_IT_RXOVERR); |
| 2138 | 2336 | ||
| 2139 | /* Clear All flags */ |
2337 | /* Clear All flags */ |
| 2140 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
2338 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_DATA_FLAGS); |
| 2141 | 2339 | ||
| 2142 | if((hmmc->hdmatx != NULL) || (hmmc->hdmarx != NULL)) |
2340 | if((hmmc->hdmatx != NULL) || (hmmc->hdmarx != NULL)) |
| 2143 | { |
2341 | { |
| 2144 | /* Disable the MMC DMA request */ |
2342 | /* Disable the MMC DMA request */ |
| 2145 | hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDIO_DCTRL_DMAEN); |
2343 | hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDIO_DCTRL_DMAEN); |
| 2146 | 2344 | ||
| Line 2167... | Line 2365... | ||
| 2167 | /* No transfer ongoing on both DMA channels*/ |
2365 | /* No transfer ongoing on both DMA channels*/ |
| 2168 | if((hmmc->hdmatx == NULL) && (hmmc->hdmarx == NULL)) |
2366 | if((hmmc->hdmatx == NULL) && (hmmc->hdmarx == NULL)) |
| 2169 | { |
2367 | { |
| 2170 | CardState = HAL_MMC_GetCardState(hmmc); |
2368 | CardState = HAL_MMC_GetCardState(hmmc); |
| 2171 | hmmc->State = HAL_MMC_STATE_READY; |
2369 | hmmc->State = HAL_MMC_STATE_READY; |
| - | 2370 | ||
| 2172 | if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING)) |
2371 | if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING)) |
| 2173 | { |
2372 | { |
| 2174 | hmmc->ErrorCode = SDMMC_CmdStopTransfer(hmmc->Instance); |
2373 | hmmc->ErrorCode = SDMMC_CmdStopTransfer(hmmc->Instance); |
| 2175 | } |
2374 | } |
| 2176 | if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE) |
2375 | if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE) |
| 2177 | { |
2376 | { |
| 2178 | return HAL_ERROR; |
2377 | return HAL_ERROR; |
| 2179 | } |
2378 | } |
| 2180 | else |
2379 | else |
| 2181 | { |
2380 | { |
| - | 2381 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 2382 | hmmc->AbortCpltCallback(hmmc); |
|
| - | 2383 | #else |
|
| 2182 | HAL_MMC_AbortCallback(hmmc); |
2384 | HAL_MMC_AbortCallback(hmmc); |
| - | 2385 | #endif |
|
| 2183 | } |
2386 | } |
| 2184 | } |
2387 | } |
| 2185 | 2388 | ||
| 2186 | return HAL_OK; |
2389 | return HAL_OK; |
| 2187 | } |
2390 | } |
| 2188 | 2391 | ||
| 2189 | /** |
2392 | /** |
| 2190 | * @} |
2393 | * @} |
| 2191 | */ |
2394 | */ |
| 2192 | 2395 | ||
| 2193 | /** |
2396 | /** |
| 2194 | * @} |
2397 | * @} |
| 2195 | */ |
2398 | */ |
| 2196 | 2399 | ||
| 2197 | /* Private function ----------------------------------------------------------*/ |
2400 | /* Private function ----------------------------------------------------------*/ |
| 2198 | /** @addtogroup MMC_Private_Functions |
2401 | /** @addtogroup MMC_Private_Functions |
| 2199 | * @{ |
2402 | * @{ |
| 2200 | */ |
2403 | */ |
| 2201 | 2404 | ||
| 2202 | /** |
2405 | /** |
| Line 2218... | Line 2421... | ||
| 2218 | * @retval None |
2421 | * @retval None |
| 2219 | */ |
2422 | */ |
| 2220 | static void MMC_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
2423 | static void MMC_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
| 2221 | { |
2424 | { |
| 2222 | MMC_HandleTypeDef* hmmc = (MMC_HandleTypeDef* )(hdma->Parent); |
2425 | MMC_HandleTypeDef* hmmc = (MMC_HandleTypeDef* )(hdma->Parent); |
| 2223 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
2426 | uint32_t errorstate; |
| 2224 | 2427 | ||
| 2225 | /* Send stop command in multiblock write */ |
2428 | /* Send stop command in multiblock write */ |
| 2226 | if(hmmc->Context == (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA)) |
2429 | if(hmmc->Context == (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA)) |
| 2227 | { |
2430 | { |
| 2228 | errorstate = SDMMC_CmdStopTransfer(hmmc->Instance); |
2431 | errorstate = SDMMC_CmdStopTransfer(hmmc->Instance); |
| 2229 | if(errorstate != HAL_MMC_ERROR_NONE) |
2432 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 2230 | { |
2433 | { |
| 2231 | hmmc->ErrorCode |= errorstate; |
2434 | hmmc->ErrorCode |= errorstate; |
| - | 2435 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 2436 | hmmc->ErrorCallback(hmmc); |
|
| - | 2437 | #else |
|
| 2232 | HAL_MMC_ErrorCallback(hmmc); |
2438 | HAL_MMC_ErrorCallback(hmmc); |
| - | 2439 | #endif |
|
| 2233 | } |
2440 | } |
| 2234 | } |
2441 | } |
| 2235 | 2442 | ||
| 2236 | /* Disable the DMA transfer for transmit request by setting the DMAEN bit |
2443 | /* Disable the DMA transfer for transmit request by setting the DMAEN bit |
| 2237 | in the MMC DCTRL register */ |
2444 | in the MMC DCTRL register */ |
| 2238 | hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDIO_DCTRL_DMAEN); |
2445 | hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDIO_DCTRL_DMAEN); |
| 2239 | 2446 | ||
| 2240 | /* Clear all the static flags */ |
2447 | /* Clear all the static flags */ |
| 2241 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
2448 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_DATA_FLAGS); |
| 2242 | 2449 | ||
| 2243 | hmmc->State = HAL_MMC_STATE_READY; |
2450 | hmmc->State = HAL_MMC_STATE_READY; |
| 2244 | 2451 | ||
| - | 2452 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 2453 | hmmc->RxCpltCallback(hmmc); |
|
| - | 2454 | #else |
|
| 2245 | HAL_MMC_RxCpltCallback(hmmc); |
2455 | HAL_MMC_RxCpltCallback(hmmc); |
| - | 2456 | #endif |
|
| 2246 | } |
2457 | } |
| 2247 | 2458 | ||
| 2248 | /** |
2459 | /** |
| 2249 | * @brief DMA MMC communication error callback |
2460 | * @brief DMA MMC communication error callback |
| 2250 | * @param hdma: DMA handle |
2461 | * @param hdma: DMA handle |
| Line 2252... | Line 2463... | ||
| 2252 | */ |
2463 | */ |
| 2253 | static void MMC_DMAError(DMA_HandleTypeDef *hdma) |
2464 | static void MMC_DMAError(DMA_HandleTypeDef *hdma) |
| 2254 | { |
2465 | { |
| 2255 | MMC_HandleTypeDef* hmmc = (MMC_HandleTypeDef* )(hdma->Parent); |
2466 | MMC_HandleTypeDef* hmmc = (MMC_HandleTypeDef* )(hdma->Parent); |
| 2256 | HAL_MMC_CardStateTypeDef CardState; |
2467 | HAL_MMC_CardStateTypeDef CardState; |
| - | 2468 | uint32_t RxErrorCode, TxErrorCode; |
|
| 2257 | 2469 | ||
| 2258 | if((hmmc->hdmarx->ErrorCode == HAL_DMA_ERROR_TE) || (hmmc->hdmatx->ErrorCode == HAL_DMA_ERROR_TE)) |
- | |
| 2259 | { |
- | |
| 2260 | /* Clear All flags */ |
- | |
| 2261 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
- | |
| 2262 | - | ||
| 2263 | /* Disable All interrupts */ |
- | |
| 2264 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
- | |
| 2265 | SDIO_IT_TXUNDERR| SDIO_IT_RXOVERR); |
- | |
| 2266 | - | ||
| 2267 | hmmc->ErrorCode |= HAL_MMC_ERROR_DMA; |
2470 | RxErrorCode = hmmc->hdmarx->ErrorCode; |
| 2268 | CardState = HAL_MMC_GetCardState(hmmc); |
2471 | TxErrorCode = hmmc->hdmatx->ErrorCode; |
| 2269 | if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING)) |
2472 | if((RxErrorCode == HAL_DMA_ERROR_TE) || (TxErrorCode == HAL_DMA_ERROR_TE)) |
| 2270 | { |
2473 | { |
| - | 2474 | /* Clear All flags */ |
|
| - | 2475 | __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS); |
|
| - | 2476 | ||
| - | 2477 | /* Disable All interrupts */ |
|
| - | 2478 | __HAL_MMC_DISABLE_IT(hmmc, SDIO_IT_DATAEND | SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT|\ |
|
| - | 2479 | SDIO_IT_TXUNDERR| SDIO_IT_RXOVERR); |
|
| - | 2480 | ||
| - | 2481 | hmmc->ErrorCode |= HAL_MMC_ERROR_DMA; |
|
| - | 2482 | CardState = HAL_MMC_GetCardState(hmmc); |
|
| - | 2483 | if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING)) |
|
| - | 2484 | { |
|
| 2271 | hmmc->ErrorCode |= SDMMC_CmdStopTransfer(hmmc->Instance); |
2485 | hmmc->ErrorCode |= SDMMC_CmdStopTransfer(hmmc->Instance); |
| - | 2486 | } |
|
| - | 2487 | ||
| - | 2488 | hmmc->State= HAL_MMC_STATE_READY; |
|
| 2272 | } |
2489 | } |
| 2273 | 2490 | ||
| - | 2491 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| 2274 | hmmc->State= HAL_MMC_STATE_READY; |
2492 | hmmc->ErrorCallback(hmmc); |
| 2275 | } |
2493 | #else |
| 2276 | - | ||
| 2277 | HAL_MMC_ErrorCallback(hmmc); |
2494 | HAL_MMC_ErrorCallback(hmmc); |
| - | 2495 | #endif |
|
| 2278 | } |
2496 | } |
| 2279 | 2497 | ||
| 2280 | /** |
2498 | /** |
| 2281 | * @brief DMA MMC Tx Abort callback |
2499 | * @brief DMA MMC Tx Abort callback |
| 2282 | * @param hdma: DMA handle |
2500 | * @param hdma: DMA handle |
| Line 2302... | Line 2520... | ||
| 2302 | { |
2520 | { |
| 2303 | hmmc->ErrorCode |= SDMMC_CmdStopTransfer(hmmc->Instance); |
2521 | hmmc->ErrorCode |= SDMMC_CmdStopTransfer(hmmc->Instance); |
| 2304 | 2522 | ||
| 2305 | if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE) |
2523 | if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE) |
| 2306 | { |
2524 | { |
| - | 2525 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 2526 | hmmc->AbortCpltCallback(hmmc); |
|
| - | 2527 | #else |
|
| 2307 | HAL_MMC_AbortCallback(hmmc); |
2528 | HAL_MMC_AbortCallback(hmmc); |
| - | 2529 | #endif |
|
| 2308 | } |
2530 | } |
| 2309 | else |
2531 | else |
| 2310 | { |
2532 | { |
| - | 2533 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 2534 | hmmc->ErrorCallback(hmmc); |
|
| - | 2535 | #else |
|
| 2311 | HAL_MMC_ErrorCallback(hmmc); |
2536 | HAL_MMC_ErrorCallback(hmmc); |
| - | 2537 | #endif |
|
| 2312 | } |
2538 | } |
| 2313 | } |
2539 | } |
| 2314 | } |
2540 | } |
| 2315 | } |
2541 | } |
| 2316 | 2542 | ||
| Line 2339... | Line 2565... | ||
| 2339 | { |
2565 | { |
| 2340 | hmmc->ErrorCode |= SDMMC_CmdStopTransfer(hmmc->Instance); |
2566 | hmmc->ErrorCode |= SDMMC_CmdStopTransfer(hmmc->Instance); |
| 2341 | 2567 | ||
| 2342 | if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE) |
2568 | if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE) |
| 2343 | { |
2569 | { |
| - | 2570 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 2571 | hmmc->AbortCpltCallback(hmmc); |
|
| - | 2572 | #else |
|
| 2344 | HAL_MMC_AbortCallback(hmmc); |
2573 | HAL_MMC_AbortCallback(hmmc); |
| - | 2574 | #endif |
|
| 2345 | } |
2575 | } |
| 2346 | else |
2576 | else |
| 2347 | { |
2577 | { |
| - | 2578 | #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) |
|
| - | 2579 | hmmc->ErrorCallback(hmmc); |
|
| - | 2580 | #else |
|
| 2348 | HAL_MMC_ErrorCallback(hmmc); |
2581 | HAL_MMC_ErrorCallback(hmmc); |
| - | 2582 | #endif |
|
| 2349 | } |
2583 | } |
| 2350 | } |
2584 | } |
| 2351 | } |
2585 | } |
| 2352 | } |
2586 | } |
| 2353 | 2587 | ||
| 2354 | - | ||
| 2355 | /** |
2588 | /** |
| 2356 | * @brief Initializes the mmc card. |
2589 | * @brief Initializes the mmc card. |
| 2357 | * @param hmmc: Pointer to MMC handle |
2590 | * @param hmmc: Pointer to MMC handle |
| 2358 | * @retval MMC Card error state |
2591 | * @retval MMC Card error state |
| 2359 | */ |
2592 | */ |
| 2360 | static uint32_t MMC_InitCard(MMC_HandleTypeDef *hmmc) |
2593 | static uint32_t MMC_InitCard(MMC_HandleTypeDef *hmmc) |
| 2361 | { |
2594 | { |
| 2362 | HAL_MMC_CardCSDTypeDef CSD; |
2595 | HAL_MMC_CardCSDTypeDef CSD; |
| 2363 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
2596 | uint32_t errorstate; |
| 2364 | uint16_t mmc_rca = 1; |
2597 | uint16_t mmc_rca = 1U; |
| 2365 | 2598 | ||
| 2366 | /* Check the power State */ |
2599 | /* Check the power State */ |
| 2367 | if(SDIO_GetPowerState(hmmc->Instance) == 0U) |
2600 | if(SDIO_GetPowerState(hmmc->Instance) == 0U) |
| 2368 | { |
2601 | { |
| 2369 | /* Power off */ |
2602 | /* Power off */ |
| 2370 | return HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE; |
2603 | return HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE; |
| 2371 | } |
2604 | } |
| 2372 | 2605 | ||
| 2373 | /* Send CMD2 ALL_SEND_CID */ |
2606 | /* Send CMD2 ALL_SEND_CID */ |
| 2374 | errorstate = SDMMC_CmdSendCID(hmmc->Instance); |
2607 | errorstate = SDMMC_CmdSendCID(hmmc->Instance); |
| 2375 | if(errorstate != HAL_MMC_ERROR_NONE) |
2608 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 2376 | { |
2609 | { |
| 2377 | return errorstate; |
2610 | return errorstate; |
| Line 2382... | Line 2615... | ||
| 2382 | hmmc->CID[0U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
2615 | hmmc->CID[0U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
| 2383 | hmmc->CID[1U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP2); |
2616 | hmmc->CID[1U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP2); |
| 2384 | hmmc->CID[2U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP3); |
2617 | hmmc->CID[2U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP3); |
| 2385 | hmmc->CID[3U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP4); |
2618 | hmmc->CID[3U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP4); |
| 2386 | } |
2619 | } |
| 2387 | 2620 | ||
| 2388 | /* Send CMD3 SET_REL_ADDR with argument 0 */ |
2621 | /* Send CMD3 SET_REL_ADDR with argument 0 */ |
| 2389 | /* MMC Card publishes its RCA. */ |
2622 | /* MMC Card publishes its RCA. */ |
| 2390 | errorstate = SDMMC_CmdSetRelAdd(hmmc->Instance, &mmc_rca); |
2623 | errorstate = SDMMC_CmdSetRelAdd(hmmc->Instance, &mmc_rca); |
| 2391 | if(errorstate != HAL_MMC_ERROR_NONE) |
2624 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 2392 | { |
2625 | { |
| 2393 | return errorstate; |
2626 | return errorstate; |
| 2394 | } |
2627 | } |
| 2395 | 2628 | ||
| 2396 | /* Get the MMC card RCA */ |
2629 | /* Get the MMC card RCA */ |
| 2397 | hmmc->MmcCard.RelCardAdd = mmc_rca; |
2630 | hmmc->MmcCard.RelCardAdd = mmc_rca; |
| 2398 | 2631 | ||
| 2399 | /* Send CMD9 SEND_CSD with argument as card's RCA */ |
2632 | /* Send CMD9 SEND_CSD with argument as card's RCA */ |
| 2400 | errorstate = SDMMC_CmdSendCSD(hmmc->Instance, (uint32_t)(hmmc->MmcCard.RelCardAdd << 16U)); |
2633 | errorstate = SDMMC_CmdSendCSD(hmmc->Instance, (uint32_t)(hmmc->MmcCard.RelCardAdd << 16U)); |
| 2401 | if(errorstate != HAL_MMC_ERROR_NONE) |
2634 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 2402 | { |
2635 | { |
| 2403 | return errorstate; |
2636 | return errorstate; |
| Line 2408... | Line 2641... | ||
| 2408 | hmmc->CSD[0U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
2641 | hmmc->CSD[0U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
| 2409 | hmmc->CSD[1U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP2); |
2642 | hmmc->CSD[1U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP2); |
| 2410 | hmmc->CSD[2U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP3); |
2643 | hmmc->CSD[2U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP3); |
| 2411 | hmmc->CSD[3U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP4); |
2644 | hmmc->CSD[3U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP4); |
| 2412 | } |
2645 | } |
| 2413 | 2646 | ||
| 2414 | /* Get the Card Class */ |
2647 | /* Get the Card Class */ |
| 2415 | hmmc->MmcCard.Class = (SDIO_GetResponse(hmmc->Instance, SDIO_RESP2) >> 20U); |
2648 | hmmc->MmcCard.Class = (SDIO_GetResponse(hmmc->Instance, SDIO_RESP2) >> 20U); |
| 2416 | 2649 | ||
| 2417 | /* Get CSD parameters */ |
2650 | /* Get CSD parameters */ |
| 2418 | HAL_MMC_GetCardCSD(hmmc, &CSD); |
2651 | if (HAL_MMC_GetCardCSD(hmmc, &CSD) != HAL_OK) |
| - | 2652 | { |
|
| - | 2653 | return hmmc->ErrorCode; |
|
| - | 2654 | } |
|
| 2419 | 2655 | ||
| 2420 | /* Select the Card */ |
2656 | /* Select the Card */ |
| 2421 | errorstate = SDMMC_CmdSelDesel(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U)); |
2657 | errorstate = SDMMC_CmdSelDesel(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U)); |
| 2422 | if(errorstate != HAL_MMC_ERROR_NONE) |
2658 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 2423 | { |
2659 | { |
| 2424 | return errorstate; |
2660 | return errorstate; |
| 2425 | } |
2661 | } |
| 2426 | 2662 | ||
| 2427 | /* Configure SDIO peripheral interface */ |
2663 | /* Configure SDIO peripheral interface */ |
| 2428 | SDIO_Init(hmmc->Instance, hmmc->Init); |
2664 | (void)SDIO_Init(hmmc->Instance, hmmc->Init); |
| 2429 | 2665 | ||
| 2430 | /* All cards are initialized */ |
2666 | /* All cards are initialized */ |
| 2431 | return HAL_MMC_ERROR_NONE; |
2667 | return HAL_MMC_ERROR_NONE; |
| 2432 | } |
2668 | } |
| 2433 | 2669 | ||
| Line 2440... | Line 2676... | ||
| 2440 | */ |
2676 | */ |
| 2441 | static uint32_t MMC_PowerON(MMC_HandleTypeDef *hmmc) |
2677 | static uint32_t MMC_PowerON(MMC_HandleTypeDef *hmmc) |
| 2442 | { |
2678 | { |
| 2443 | __IO uint32_t count = 0U; |
2679 | __IO uint32_t count = 0U; |
| 2444 | uint32_t response = 0U, validvoltage = 0U; |
2680 | uint32_t response = 0U, validvoltage = 0U; |
| 2445 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
2681 | uint32_t errorstate; |
| 2446 | 2682 | ||
| 2447 | /* CMD0: GO_IDLE_STATE */ |
2683 | /* CMD0: GO_IDLE_STATE */ |
| 2448 | errorstate = SDMMC_CmdGoIdleState(hmmc->Instance); |
2684 | errorstate = SDMMC_CmdGoIdleState(hmmc->Instance); |
| 2449 | if(errorstate != HAL_MMC_ERROR_NONE) |
2685 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 2450 | { |
2686 | { |
| 2451 | return errorstate; |
2687 | return errorstate; |
| Line 2455... | Line 2691... | ||
| 2455 | { |
2691 | { |
| 2456 | if(count++ == SDMMC_MAX_VOLT_TRIAL) |
2692 | if(count++ == SDMMC_MAX_VOLT_TRIAL) |
| 2457 | { |
2693 | { |
| 2458 | return HAL_MMC_ERROR_INVALID_VOLTRANGE; |
2694 | return HAL_MMC_ERROR_INVALID_VOLTRANGE; |
| 2459 | } |
2695 | } |
| 2460 | 2696 | ||
| 2461 | /* SEND CMD1 APP_CMD with MMC_HIGH_VOLTAGE_RANGE(0xC0FF8000) as argument */ |
2697 | /* SEND CMD1 APP_CMD with MMC_HIGH_VOLTAGE_RANGE(0xC0FF8000) as argument */ |
| 2462 | errorstate = SDMMC_CmdOpCondition(hmmc->Instance, eMMC_HIGH_VOLTAGE_RANGE); |
2698 | errorstate = SDMMC_CmdOpCondition(hmmc->Instance, eMMC_HIGH_VOLTAGE_RANGE); |
| 2463 | if(errorstate != HAL_MMC_ERROR_NONE) |
2699 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 2464 | { |
2700 | { |
| 2465 | return HAL_MMC_ERROR_UNSUPPORTED_FEATURE; |
2701 | return HAL_MMC_ERROR_UNSUPPORTED_FEATURE; |
| 2466 | } |
2702 | } |
| 2467 | 2703 | ||
| 2468 | /* Get command response */ |
2704 | /* Get command response */ |
| 2469 | response = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
2705 | response = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
| 2470 | 2706 | ||
| 2471 | /* Get operating voltage*/ |
2707 | /* Get operating voltage*/ |
| 2472 | validvoltage = (((response >> 31U) == 1U) ? 1U : 0U); |
2708 | validvoltage = (((response >> 31U) == 1U) ? 1U : 0U); |
| 2473 | } |
2709 | } |
| 2474 | 2710 | ||
| 2475 | /* When power routine is finished and command returns valid voltage */ |
2711 | /* When power routine is finished and command returns valid voltage */ |
| 2476 | if ((response & eMMC_HIGH_VOLTAGE_RANGE) == MMC_HIGH_VOLTAGE_RANGE) |
2712 | if (((response & (0xFF000000U)) >> 24) == 0xC0U) |
| 2477 | { |
2713 | { |
| 2478 | /* When voltage range of the card is within 2.7V and 3.6V */ |
- | |
| 2479 | hmmc->MmcCard.CardType = MMC_HIGH_VOLTAGE_CARD; |
2714 | hmmc->MmcCard.CardType = MMC_HIGH_CAPACITY_CARD; |
| 2480 | } |
2715 | } |
| 2481 | else |
2716 | else |
| 2482 | { |
2717 | { |
| 2483 | /* When voltage range of the card is within 1.65V and 1.95V or 2.7V and 3.6V */ |
- | |
| 2484 | hmmc->MmcCard.CardType = MMC_DUAL_VOLTAGE_CARD; |
2718 | hmmc->MmcCard.CardType = MMC_LOW_CAPACITY_CARD; |
| 2485 | } |
2719 | } |
| 2486 | 2720 | ||
| 2487 | return HAL_MMC_ERROR_NONE; |
2721 | return HAL_MMC_ERROR_NONE; |
| 2488 | } |
2722 | } |
| 2489 | 2723 | ||
| 2490 | /** |
2724 | /** |
| 2491 | * @brief Turns the SDIO output signals off. |
2725 | * @brief Turns the SDIO output signals off. |
| 2492 | * @param hmmc: Pointer to MMC handle |
2726 | * @param hmmc: Pointer to MMC handle |
| 2493 | * @retval HAL status |
2727 | * @retval None |
| 2494 | */ |
2728 | */ |
| 2495 | static HAL_StatusTypeDef MMC_PowerOFF(MMC_HandleTypeDef *hmmc) |
2729 | static void MMC_PowerOFF(MMC_HandleTypeDef *hmmc) |
| 2496 | { |
2730 | { |
| 2497 | /* Set Power State to OFF */ |
2731 | /* Set Power State to OFF */ |
| 2498 | SDIO_PowerState_OFF(hmmc->Instance); |
2732 | (void)SDIO_PowerState_OFF(hmmc->Instance); |
| 2499 | - | ||
| 2500 | return HAL_OK; |
- | |
| 2501 | } |
2733 | } |
| 2502 | 2734 | ||
| 2503 | /** |
2735 | /** |
| 2504 | * @brief Returns the current card's status. |
2736 | * @brief Returns the current card's status. |
| 2505 | * @param hmmc: Pointer to MMC handle |
2737 | * @param hmmc: Pointer to MMC handle |
| 2506 | * @param pCardStatus: pointer to the buffer that will contain the MMC card |
2738 | * @param pCardStatus: pointer to the buffer that will contain the MMC card |
| 2507 | * status (Card Status register) |
2739 | * status (Card Status register) |
| 2508 | * @retval error state |
2740 | * @retval error state |
| 2509 | */ |
2741 | */ |
| 2510 | static uint32_t MMC_SendStatus(MMC_HandleTypeDef *hmmc, uint32_t *pCardStatus) |
2742 | static uint32_t MMC_SendStatus(MMC_HandleTypeDef *hmmc, uint32_t *pCardStatus) |
| 2511 | { |
2743 | { |
| 2512 | uint32_t errorstate = HAL_MMC_ERROR_NONE; |
2744 | uint32_t errorstate; |
| 2513 | 2745 | ||
| 2514 | if(pCardStatus == NULL) |
2746 | if(pCardStatus == NULL) |
| 2515 | { |
2747 | { |
| 2516 | return HAL_MMC_ERROR_PARAM; |
2748 | return HAL_MMC_ERROR_PARAM; |
| 2517 | } |
2749 | } |
| 2518 | 2750 | ||
| 2519 | /* Send Status command */ |
2751 | /* Send Status command */ |
| 2520 | errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(hmmc->MmcCard.RelCardAdd << 16U)); |
2752 | errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(hmmc->MmcCard.RelCardAdd << 16U)); |
| 2521 | if(errorstate != HAL_OK) |
2753 | if(errorstate != HAL_MMC_ERROR_NONE) |
| 2522 | { |
2754 | { |
| 2523 | return errorstate; |
2755 | return errorstate; |
| 2524 | } |
2756 | } |
| 2525 | 2757 | ||
| 2526 | /* Get MMC card status */ |
2758 | /* Get MMC card status */ |
| 2527 | *pCardStatus = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
2759 | *pCardStatus = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1); |
| 2528 | 2760 | ||
| 2529 | return HAL_MMC_ERROR_NONE; |
2761 | return HAL_MMC_ERROR_NONE; |
| 2530 | } |
2762 | } |
| 2531 | 2763 | ||
| 2532 | /** |
2764 | /** |
| 2533 | * @brief Wrap up reading in non-blocking mode. |
2765 | * @brief Wrap up reading in non-blocking mode. |
| 2534 | * @param hmmc: pointer to a MMC_HandleTypeDef structure that contains |
2766 | * @param hmmc: pointer to a MMC_HandleTypeDef structure that contains |
| 2535 | * the configuration information. |
2767 | * the configuration information. |
| 2536 | * @retval HAL status |
2768 | * @retval None |
| 2537 | */ |
2769 | */ |
| 2538 | static HAL_StatusTypeDef MMC_Read_IT(MMC_HandleTypeDef *hmmc) |
2770 | static void MMC_Read_IT(MMC_HandleTypeDef *hmmc) |
| 2539 | { |
2771 | { |
| 2540 | uint32_t count = 0U; |
2772 | uint32_t count, data, dataremaining; |
| 2541 | uint32_t* tmp; |
2773 | uint8_t* tmp; |
| 2542 | 2774 | ||
| 2543 | tmp = (uint32_t*)hmmc->pRxBuffPtr; |
2775 | tmp = hmmc->pRxBuffPtr; |
| - | 2776 | dataremaining = hmmc->RxXferSize; |
|
| - | 2777 | ||
| - | 2778 | if (dataremaining > 0U) |
|
| 2544 | 2779 | { |
|
| 2545 | /* Read data from SDMMC Rx FIFO */ |
2780 | /* Read data from SDIO Rx FIFO */ |
| 2546 | for(count = 0U; count < 8U; count++) |
2781 | for(count = 0U; count < 8U; count++) |
| 2547 | { |
2782 | { |
| 2548 | *(tmp + count) = SDIO_ReadFIFO(hmmc->Instance); |
2783 | data = SDIO_ReadFIFO(hmmc->Instance); |
| - | 2784 | *tmp = (uint8_t)(data & 0xFFU); |
|
| - | 2785 | tmp++; |
|
| - | 2786 | dataremaining--; |
|
| - | 2787 | *tmp = (uint8_t)((data >> 8U) & 0xFFU); |
|
| - | 2788 | tmp++; |
|
| - | 2789 | dataremaining--; |
|
| - | 2790 | *tmp = (uint8_t)((data >> 16U) & 0xFFU); |
|
| - | 2791 | tmp++; |
|
| - | 2792 | dataremaining--; |
|
| - | 2793 | *tmp = (uint8_t)((data >> 24U) & 0xFFU); |
|
| - | 2794 | tmp++; |
|
| - | 2795 | dataremaining--; |
|
| - | 2796 | } |
|
| - | 2797 | ||
| - | 2798 | hmmc->pRxBuffPtr = tmp; |
|
| - | 2799 | hmmc->RxXferSize = dataremaining; |
|
| 2549 | } |
2800 | } |
| 2550 | - | ||
| 2551 | hmmc->pRxBuffPtr += 8U; |
- | |
| 2552 | - | ||
| 2553 | return HAL_OK; |
- | |
| 2554 | } |
2801 | } |
| 2555 | 2802 | ||
| 2556 | /** |
2803 | /** |
| 2557 | * @brief Wrap up writing in non-blocking mode. |
2804 | * @brief Wrap up writing in non-blocking mode. |
| 2558 | * @param hmmc: pointer to a MMC_HandleTypeDef structure that contains |
2805 | * @param hmmc: pointer to a MMC_HandleTypeDef structure that contains |
| 2559 | * the configuration information. |
2806 | * the configuration information. |
| 2560 | * @retval HAL status |
2807 | * @retval None |
| 2561 | */ |
2808 | */ |
| 2562 | static HAL_StatusTypeDef MMC_Write_IT(MMC_HandleTypeDef *hmmc) |
2809 | static void MMC_Write_IT(MMC_HandleTypeDef *hmmc) |
| 2563 | { |
2810 | { |
| 2564 | uint32_t count = 0U; |
2811 | uint32_t count, data, dataremaining; |
| 2565 | uint32_t* tmp; |
2812 | uint8_t* tmp; |
| 2566 | 2813 | ||
| 2567 | tmp = (uint32_t*)hmmc->pTxBuffPtr; |
2814 | tmp = hmmc->pTxBuffPtr; |
| - | 2815 | dataremaining = hmmc->TxXferSize; |
|
| - | 2816 | ||
| - | 2817 | if (dataremaining > 0U) |
|
| 2568 | 2818 | { |
|
| 2569 | /* Write data to SDMMC Tx FIFO */ |
2819 | /* Write data to SDIO Tx FIFO */ |
| 2570 | for(count = 0U; count < 8U; count++) |
2820 | for(count = 0U; count < 8U; count++) |
| 2571 | { |
2821 | { |
| - | 2822 | data = (uint32_t)(*tmp); |
|
| - | 2823 | tmp++; |
|
| - | 2824 | dataremaining--; |
|
| - | 2825 | data |= ((uint32_t)(*tmp) << 8U); |
|
| - | 2826 | tmp++; |
|
| - | 2827 | dataremaining--; |
|
| - | 2828 | data |= ((uint32_t)(*tmp) << 16U); |
|
| - | 2829 | tmp++; |
|
| - | 2830 | dataremaining--; |
|
| - | 2831 | data |= ((uint32_t)(*tmp) << 24U); |
|
| - | 2832 | tmp++; |
|
| - | 2833 | dataremaining--; |
|
| 2572 | SDIO_WriteFIFO(hmmc->Instance, (tmp + count)); |
2834 | (void)SDIO_WriteFIFO(hmmc->Instance, &data); |
| - | 2835 | } |
|
| - | 2836 | ||
| - | 2837 | hmmc->pTxBuffPtr = tmp; |
|
| - | 2838 | hmmc->TxXferSize = dataremaining; |
|
| 2573 | } |
2839 | } |
| 2574 | - | ||
| 2575 | hmmc->pTxBuffPtr += 8U; |
- | |
| 2576 | - | ||
| 2577 | return HAL_OK; |
- | |
| 2578 | } |
2840 | } |
| 2579 | 2841 | ||
| 2580 | /** |
2842 | /** |
| 2581 | * @} |
2843 | * @} |
| 2582 | */ |
2844 | */ |
| 2583 | 2845 | ||
| 2584 | #endif /* STM32F103xE || STM32F103xG */ |
2846 | #endif /* SDIO */ |
| 2585 | 2847 | ||
| 2586 | #endif /* HAL_MMC_MODULE_ENABLED */ |
2848 | #endif /* HAL_MMC_MODULE_ENABLED */ |
| 2587 | 2849 | ||
| 2588 | /** |
2850 | /** |
| 2589 | * @} |
2851 | * @} |