STM32F4xx_HAL_Driver  1.8.3
stm32f4xx_hal_dma_ex.c
Go to the documentation of this file.
1 
38 /* Includes ------------------------------------------------------------------*/
39 #include "stm32f4xx_hal.h"
40 
50 #ifdef HAL_DMA_MODULE_ENABLED
51 
52 /* Private types -------------------------------------------------------------*/
53 /* Private variables ---------------------------------------------------------*/
54 /* Private Constants ---------------------------------------------------------*/
55 /* Private macros ------------------------------------------------------------*/
56 /* Private functions ---------------------------------------------------------*/
60 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
65 /* Exported functions ---------------------------------------------------------*/
66 
100 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
101 {
102  HAL_StatusTypeDef status = HAL_OK;
103 
104  /* Check the parameters */
105  assert_param(IS_DMA_BUFFER_SIZE(DataLength));
106 
107  /* Memory-to-memory transfer not supported in double buffering mode */
108  if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
109  {
110  hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
111  status = HAL_ERROR;
112  }
113  else
114  {
115  /* Process Locked */
116  __HAL_LOCK(hdma);
117 
118  if(HAL_DMA_STATE_READY == hdma->State)
119  {
120  /* Change DMA peripheral state */
121  hdma->State = HAL_DMA_STATE_BUSY;
122 
123  /* Enable the double buffer mode */
124  hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM;
125 
126  /* Configure DMA Stream destination address */
127  hdma->Instance->M1AR = SecondMemAddress;
128 
129  /* Configure the source, destination address and the data length */
130  DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
131 
132  /* Enable the peripheral */
133  __HAL_DMA_ENABLE(hdma);
134  }
135  else
136  {
137  /* Return error status */
138  status = HAL_BUSY;
139  }
140  }
141  return status;
142 }
143 
154 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
155 {
156  HAL_StatusTypeDef status = HAL_OK;
157 
158  /* Check the parameters */
159  assert_param(IS_DMA_BUFFER_SIZE(DataLength));
160 
161  /* Memory-to-memory transfer not supported in double buffering mode */
162  if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
163  {
164  hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
165  return HAL_ERROR;
166  }
167 
168  /* Check callback functions */
169  if ((NULL == hdma->XferCpltCallback) || (NULL == hdma->XferM1CpltCallback) || (NULL == hdma->XferErrorCallback))
170  {
171  hdma->ErrorCode = HAL_DMA_ERROR_PARAM;
172  return HAL_ERROR;
173  }
174 
175  /* Process locked */
176  __HAL_LOCK(hdma);
177 
178  if(HAL_DMA_STATE_READY == hdma->State)
179  {
180  /* Change DMA peripheral state */
181  hdma->State = HAL_DMA_STATE_BUSY;
182 
183  /* Initialize the error code */
184  hdma->ErrorCode = HAL_DMA_ERROR_NONE;
185 
186  /* Enable the Double buffer mode */
187  hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM;
188 
189  /* Configure DMA Stream destination address */
190  hdma->Instance->M1AR = SecondMemAddress;
191 
192  /* Configure the source, destination address and the data length */
193  DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
194 
195  /* Clear all flags */
196  __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
197  __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
198  __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
199  __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_DME_FLAG_INDEX(hdma));
200  __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_FE_FLAG_INDEX(hdma));
201 
202  /* Enable Common interrupts*/
203  hdma->Instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME;
204  hdma->Instance->FCR |= DMA_IT_FE;
205 
206  if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
207  {
208  hdma->Instance->CR |= DMA_IT_HT;
209  }
210 
211  /* Enable the peripheral */
212  __HAL_DMA_ENABLE(hdma);
213  }
214  else
215  {
216  /* Process unlocked */
217  __HAL_UNLOCK(hdma);
218 
219  /* Return error status */
220  status = HAL_BUSY;
221  }
222  return status;
223 }
224 
239 HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
240 {
241  if(memory == MEMORY0)
242  {
243  /* change the memory0 address */
244  hdma->Instance->M0AR = Address;
245  }
246  else
247  {
248  /* change the memory1 address */
249  hdma->Instance->M1AR = Address;
250  }
251 
252  return HAL_OK;
253 }
254 
276 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
277 {
278  /* Configure DMA Stream data length */
279  hdma->Instance->NDTR = DataLength;
280 
281  /* Peripheral to Memory */
282  if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
283  {
284  /* Configure DMA Stream destination address */
285  hdma->Instance->PAR = DstAddress;
286 
287  /* Configure DMA Stream source address */
288  hdma->Instance->M0AR = SrcAddress;
289  }
290  /* Memory to Peripheral */
291  else
292  {
293  /* Configure DMA Stream source address */
294  hdma->Instance->PAR = SrcAddress;
295 
296  /* Configure DMA Stream destination address */
297  hdma->Instance->M0AR = DstAddress;
298  }
299 }
300 
305 #endif /* HAL_DMA_MODULE_ENABLED */
HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
Change the memory0 or memory1 address on the fly.
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
Starts the multi_buffer DMA Transfer.
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
Starts the multi_buffer DMA Transfer with interrupt enabled.
This file contains all the functions prototypes for the HAL module driver.
@ HAL_DMA_STATE_READY
@ HAL_DMA_STATE_BUSY
DMA handle Structure definition.
DMA_InitTypeDef Init
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
__IO HAL_DMA_StateTypeDef State
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA_Stream_TypeDef * Instance
void(* XferM1HalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferM1CpltCallback)(struct __DMA_HandleTypeDef *hdma)