STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f7xx_hal_dma_ex.c
Go to the documentation of this file.
1 
57 /* Includes ------------------------------------------------------------------*/
58 #include "stm32f7xx_hal.h"
59 
69 #ifdef HAL_DMA_MODULE_ENABLED
70 
71 /* Private types -------------------------------------------------------------*/
72 /* Private variables ---------------------------------------------------------*/
73 /* Private Constants ---------------------------------------------------------*/
74 /* Private macros ------------------------------------------------------------*/
75 /* Private functions ---------------------------------------------------------*/
80 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
81 
86 /* Exported functions ---------------------------------------------------------*/
87 
121 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
122 {
123  HAL_StatusTypeDef status = HAL_OK;
124 
125  /* Check the parameters */
126  assert_param(IS_DMA_BUFFER_SIZE(DataLength));
127 
128  /* Memory-to-memory transfer not supported in double buffering mode */
129  if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
130  {
132  status = HAL_ERROR;
133  }
134  else
135  {
136  /* Process Locked */
137  __HAL_LOCK(hdma);
138 
139  if(HAL_DMA_STATE_READY == hdma->State)
140  {
141  /* Change DMA peripheral state */
142  hdma->State = HAL_DMA_STATE_BUSY;
143 
144  /* Enable the double buffer mode */
145  hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM;
146 
147  /* Configure DMA Stream destination address */
148  hdma->Instance->M1AR = SecondMemAddress;
149 
150  /* Configure the source, destination address and the data length */
151  DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
152 
153  /* Enable the peripheral */
154  __HAL_DMA_ENABLE(hdma);
155  }
156  else
157  {
158  /* Return error status */
159  status = HAL_BUSY;
160  }
161  }
162  return status;
163 }
164 
175 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
176 {
177  HAL_StatusTypeDef status = HAL_OK;
178 
179  /* Check the parameters */
180  assert_param(IS_DMA_BUFFER_SIZE(DataLength));
181 
182  /* Memory-to-memory transfer not supported in double buffering mode */
183  if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
184  {
186  return HAL_ERROR;
187  }
188 
189  /* Process locked */
190  __HAL_LOCK(hdma);
191 
192  if(HAL_DMA_STATE_READY == hdma->State)
193  {
194  /* Change DMA peripheral state */
195  hdma->State = HAL_DMA_STATE_BUSY;
196 
197  /* Initialize the error code */
199 
200  /* Enable the Double buffer mode */
201  hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM;
202 
203  /* Configure DMA Stream destination address */
204  hdma->Instance->M1AR = SecondMemAddress;
205 
206  /* Configure the source, destination address and the data length */
207  DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
208 
209  /* Clear all flags */
215 
216  /* Enable Common interrupts*/
217  hdma->Instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME;
218  hdma->Instance->FCR |= DMA_IT_FE;
219 
220  if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
221  {
222  hdma->Instance->CR |= DMA_IT_HT;
223  }
224 
225  /* Enable the peripheral */
226  __HAL_DMA_ENABLE(hdma);
227  }
228  else
229  {
230  /* Process unlocked */
231  __HAL_UNLOCK(hdma);
232 
233  /* Return error status */
234  status = HAL_BUSY;
235  }
236  return status;
237 }
238 
254 {
255  if(memory == MEMORY0)
256  {
257  /* change the memory0 address */
258  hdma->Instance->M0AR = Address;
259  }
260  else
261  {
262  /* change the memory1 address */
263  hdma->Instance->M1AR = Address;
264  }
265 
266  return HAL_OK;
267 }
268 
290 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
291 {
292  /* Configure DMA Stream data length */
293  hdma->Instance->NDTR = DataLength;
294 
295  /* Peripheral to Memory */
296  if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
297  {
298  /* Configure DMA Stream destination address */
299  hdma->Instance->PAR = DstAddress;
300 
301  /* Configure DMA Stream source address */
302  hdma->Instance->M0AR = SrcAddress;
303  }
304  /* Memory to Peripheral */
305  else
306  {
307  /* Configure DMA Stream source address */
308  hdma->Instance->PAR = SrcAddress;
309 
310  /* Configure DMA Stream destination address */
311  hdma->Instance->M0AR = DstAddress;
312  }
313 }
314 
319 #endif /* HAL_DMA_MODULE_ENABLED */
320 
328 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define DMA_IT_FE
#define assert_param(expr)
Include module's header file.
HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
#define IS_DMA_BUFFER_SIZE(SIZE)
#define DMA_IT_DME
#define __HAL_DMA_ENABLE(__HANDLE__)
Enable the specified DMA Stream.
#define DMA_IT_TE
#define __HAL_UNLOCK(__HANDLE__)
__IO uint32_t NDTR
Definition: stm32f745xx.h:393
#define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)
Return the current DMA Stream transfer error flag.
DMA_InitTypeDef Init
__IO uint32_t M1AR
Definition: stm32f745xx.h:396
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
#define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the DMA Stream pending flags.
__IO HAL_DMA_StateTypeDef State
#define DMA_IT_TC
#define __HAL_LOCK(__HANDLE__)
__IO uint32_t M0AR
Definition: stm32f745xx.h:395
#define NULL
Definition: usbd_def.h:53
#define HAL_DMA_ERROR_NONE
#define DMA_SxCR_DBM
Definition: stm32f745xx.h:3300
This file contains all the functions prototypes for the HAL module driver.
#define __HAL_DMA_GET_FE_FLAG_INDEX(__HANDLE__)
Return the current DMA Stream FIFO error flag.
DMA_Stream_TypeDef * Instance
__IO uint32_t PAR
Definition: stm32f745xx.h:394
#define HAL_DMA_ERROR_NOT_SUPPORTED
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
__IO uint32_t CR
Definition: stm32f745xx.h:392
#define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__)
Return the current DMA Stream transfer complete flag.
void(* XferM1HalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA handle Structure definition.
#define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)
Return the current DMA Stream half transfer complete flag.
#define DMA_IT_HT
HAL_DMA_MemoryTypeDef
HAL DMA Memory definition.
#define __HAL_DMA_GET_DME_FLAG_INDEX(__HANDLE__)
Return the current DMA Stream direct mode error flag.
HAL_StatusTypeDef
HAL Status structures definition.
#define DMA_MEMORY_TO_MEMORY
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
#define DMA_MEMORY_TO_PERIPH
__IO uint32_t FCR
Definition: stm32f745xx.h:397