STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_mmc_ex.c
Go to the documentation of this file.
1 
35 /* Includes ------------------------------------------------------------------*/
36 #include "stm32l4xx_hal.h"
37 
38 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
39 
49 #ifdef HAL_MMC_MODULE_ENABLED
50 
51 /* Private typedef -----------------------------------------------------------*/
52 /* Private define ------------------------------------------------------------*/
53 /* Private macro -------------------------------------------------------------*/
54 /* Private variables ---------------------------------------------------------*/
55 /* Private function prototypes -----------------------------------------------*/
56 /* Private functions ---------------------------------------------------------*/
57 /* Exported functions --------------------------------------------------------*/
85 HAL_StatusTypeDef HAL_MMCEx_ConfigDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t * pDataBuffer0, uint32_t * pDataBuffer1, uint32_t BufferSize)
86 {
87  if(hmmc->State == HAL_MMC_STATE_READY)
88  {
89  hmmc->Instance->IDMABASE0= (uint32_t) pDataBuffer0 ;
90  hmmc->Instance->IDMABASE1= (uint32_t) pDataBuffer1 ;
91  hmmc->Instance->IDMABSIZE= (uint32_t) (BLOCKSIZE * BufferSize);
92 
93  return HAL_OK;
94  }
95  else
96  {
97  return HAL_BUSY;
98  }
99 }
100 
109 HAL_StatusTypeDef HAL_MMCEx_ReadBlocksDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t BlockAdd, uint32_t NumberOfBlocks)
110 {
111  SDMMC_DataInitTypeDef config;
112  uint32_t DmaBase0_reg, DmaBase1_reg;
113  uint32_t errorstate;
114  uint32_t add = BlockAdd;
115 
116  if(hmmc->State == HAL_MMC_STATE_READY)
117  {
118  if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
119  {
120  hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
121  return HAL_ERROR;
122  }
123 
124  DmaBase0_reg = hmmc->Instance->IDMABASE0;
125  DmaBase1_reg = hmmc->Instance->IDMABASE1;
126  if ((hmmc->Instance->IDMABSIZE == 0U) || (DmaBase0_reg == 0U) || (DmaBase1_reg == 0U))
127  {
128  hmmc->ErrorCode = HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
129  return HAL_ERROR;
130  }
131 
132  /* Initialize data control register */
133  hmmc->Instance->DCTRL = 0;
134 
135  hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
136  hmmc->State = HAL_MMC_STATE_BUSY;
137 
138  if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
139  {
140  add *= 512U;
141  }
142 
143  /* Configure the MMC DPSM (Data Path State Machine) */
144  config.DataTimeOut = SDMMC_DATATIMEOUT;
145  config.DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
146  config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
147  config.TransferDir = SDMMC_TRANSFER_DIR_TO_SDMMC;
148  config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
149  config.DPSM = SDMMC_DPSM_DISABLE;
150  (void)SDMMC_ConfigData(hmmc->Instance, &config);
151 
152  hmmc->Instance->DCTRL |= SDMMC_DCTRL_FIFORST;
153 
154  __SDMMC_CMDTRANS_ENABLE( hmmc->Instance);
155 
156  hmmc->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
157 
158  __HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND | SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC));
159 
160  /* Read Blocks in DMA mode */
161  hmmc->Context = (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA);
162 
163  /* Read Multi Block command */
164  errorstate = SDMMC_CmdReadMultiBlock(hmmc->Instance, add);
165  if(errorstate != HAL_MMC_ERROR_NONE)
166  {
167  hmmc->State = HAL_MMC_STATE_READY;
168  hmmc->ErrorCode |= errorstate;
169  return HAL_ERROR;
170  }
171 
172  return HAL_OK;
173  }
174  else
175  {
176  return HAL_BUSY;
177  }
178 
179 }
180 
189 HAL_StatusTypeDef HAL_MMCEx_WriteBlocksDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t BlockAdd, uint32_t NumberOfBlocks)
190 {
191  SDMMC_DataInitTypeDef config;
192  uint32_t errorstate;
193  uint32_t DmaBase0_reg, DmaBase1_reg;
194  uint32_t add = BlockAdd;
195 
196  if(hmmc->State == HAL_MMC_STATE_READY)
197  {
198  if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
199  {
200  hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
201  return HAL_ERROR;
202  }
203 
204  DmaBase0_reg = hmmc->Instance->IDMABASE0;
205  DmaBase1_reg = hmmc->Instance->IDMABASE1;
206  if ((hmmc->Instance->IDMABSIZE == 0U) || (DmaBase0_reg == 0U) || (DmaBase1_reg == 0U))
207  {
208  hmmc->ErrorCode = HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
209  return HAL_ERROR;
210  }
211 
212  /* Initialize data control register */
213  hmmc->Instance->DCTRL = 0;
214 
215  hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
216 
217  hmmc->State = HAL_MMC_STATE_BUSY;
218 
219  if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
220  {
221  add *= 512U;
222  }
223 
224  /* Configure the MMC DPSM (Data Path State Machine) */
225  config.DataTimeOut = SDMMC_DATATIMEOUT;
226  config.DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
227  config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
228  config.TransferDir = SDMMC_TRANSFER_DIR_TO_CARD;
229  config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
230  config.DPSM = SDMMC_DPSM_DISABLE;
231  (void)SDMMC_ConfigData(hmmc->Instance, &config);
232 
233  __SDMMC_CMDTRANS_ENABLE( hmmc->Instance);
234 
235  hmmc->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
236 
237  __HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND | SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC));
238 
239  /* Write Blocks in DMA mode */
240  hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK | MMC_CONTEXT_DMA);
241 
242  /* Write Multi Block command */
243  errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, add);
244  if(errorstate != HAL_MMC_ERROR_NONE)
245  {
246  hmmc->State = HAL_MMC_STATE_READY;
247  hmmc->ErrorCode |= errorstate;
248  return HAL_ERROR;
249  }
250 
251  return HAL_OK;
252  }
253  else
254  {
255  return HAL_BUSY;
256  }
257 }
258 
259 
271 HAL_StatusTypeDef HAL_MMCEx_ChangeDMABuffer(MMC_HandleTypeDef *hmmc, HAL_MMCEx_DMABuffer_MemoryTypeDef Buffer, uint32_t *pDataBuffer)
272 {
273  if(Buffer == MMC_DMA_BUFFER0)
274  {
275  /* change the buffer0 address */
276  hmmc->Instance->IDMABASE0 = (uint32_t)pDataBuffer;
277  }
278  else
279  {
280  /* change the memory1 address */
281  hmmc->Instance->IDMABASE1 = (uint32_t)pDataBuffer;
282  }
283 
284  return HAL_OK;
285 }
286 
293 {
294  /* Prevent unused argument(s) compilation warning */
295  UNUSED(hmmc);
296 
297  /* NOTE : This function should not be modified, when the callback is needed,
298  the HAL_MMCEx_Read_DMADoubleBuffer0CpltCallback can be implemented in the user file
299  */
300 }
301 
308 {
309  /* Prevent unused argument(s) compilation warning */
310  UNUSED(hmmc);
311 
312  /* NOTE : This function should not be modified, when the callback is needed,
313  the HAL_MMCEx_Read_DMADoubleBuffer1CpltCallback can be implemented in the user file
314  */
315 }
316 
323 {
324  /* Prevent unused argument(s) compilation warning */
325  UNUSED(hmmc);
326 
327  /* NOTE : This function should not be modified, when the callback is needed,
328  the HAL_MMCEx_Write_DMADoubleBuffer0CpltCallback can be implemented in the user file
329  */
330 }
331 
338 {
339  /* Prevent unused argument(s) compilation warning */
340  UNUSED(hmmc);
341 
342  /* NOTE : This function should not be modified, when the callback is needed,
343  the HAL_MMCEx_Write_DMADoubleBuffer0CpltCallback can be implemented in the user file
344  */
345 }
346 
355 #endif /* HAL_MMC_MODULE_ENABLED */
356 
365 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
366 
367 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
__weak void HAL_MMCEx_Write_DMADoubleBuffer1CpltCallback(MMC_HandleTypeDef *hmmc)
Write DMA Buffer 1 Transfer completed callbacks.
struct __MMC_HandleTypeDef else typedef struct endif MMC_HandleTypeDef
MMC handle Structure definition.
uint32_t SDMMC_CmdWriteMultiBlock(SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd)
Send the Write Multi Block command and check the response.
This file contains all the functions prototypes for the HAL module driver.
__weak void HAL_MMCEx_Write_DMADoubleBuffer0CpltCallback(MMC_HandleTypeDef *hmmc)
Write DMA Buffer 0 Transfer completed callbacks.
SDMMC Data Control structure.
HAL_StatusTypeDef HAL_MMCEx_ChangeDMABuffer(MMC_HandleTypeDef *hmmc, HAL_MMCEx_DMABuffer_MemoryTypeDef Buffer, uint32_t *pDataBuffer)
Change the DMA Buffer0 or Buffer1 address on the fly.
__weak void HAL_MMCEx_Read_DMADoubleBuffer0CpltCallback(MMC_HandleTypeDef *hmmc)
Read DMA Buffer 0 Transfer completed callbacks.
return HAL_OK
HAL_StatusTypeDef HAL_MMCEx_ConfigDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t *pDataBuffer0, uint32_t *pDataBuffer1, uint32_t BufferSize)
Configure DMA Dual Buffer mode. The Data transfer is managed by an Internal DMA.
HAL_StatusTypeDef HAL_MMCEx_ReadBlocksDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t BlockAdd, uint32_t NumberOfBlocks)
Reads block(s) from a specified address in a card. The received Data will be stored in Buffer0 and Bu...
__weak void HAL_MMCEx_Read_DMADoubleBuffer1CpltCallback(MMC_HandleTypeDef *hmmc)
Read DMA Buffer 1 Transfer completed callbacks.
HAL_StatusTypeDef HAL_MMCEx_WriteBlocksDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t BlockAdd, uint32_t NumberOfBlocks)
Write block(s) to a specified address in a card. The transfered Data are stored in Buffer0 and Buffer...
uint32_t SDMMC_CmdReadMultiBlock(SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd)
Send the Read Multi Block command and check the response.
HAL_StatusTypeDef SDMMC_ConfigData(SDMMC_TypeDef *SDMMCx, SDMMC_DataInitTypeDef *Data)
Configure the SDMMC data path according to the specified parameters in the SDMMC_DataInitTypeDef.