2 ******************************************************************************
3 * @file stm32l0xx_hal_dma.c
4 * @author MCD Application Team
6 * @date 06-February-2015
7 * @brief DMA HAL module driver.
9 * This file provides firmware functions to manage the following
10 * functionalities of the Direct Memory Access (DMA) peripheral:
11 * + Initialization/de-initialization functions
12 * + I/O operation functions
13 * + Peripheral State functions
17 ==============================================================================
18 ##### How to use this driver #####
19 ==============================================================================
21 (#) Enable and configure the peripheral to be connected to the DMA Channel
22 (except for internal SRAM / FLASH memories: no initialization is
25 (#) For a given Channel, program the required configuration through the following parameters:
26 Channel request, Transfer Direction, Source and Destination data formats,
27 Circular, Normal or peripheral flow control mode, Channel Priority level,
28 Source and Destination Increment mode using HAL_DMA_Init() function.
30 *** Polling mode IO operation ***
31 =================================
33 (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source
34 address and destination address and the Length of data to be transferred
35 (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this
36 case a fixed Timeout can be configured by User depending from his application.
38 *** Interrupt mode IO operation ***
39 ===================================
41 (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority()
42 (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ()
43 (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of
44 Source address and destination address and the Length of data to be transferred. In this
45 case the DMA interrupt is configured
46 (+) Use HAL_DMA_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine
47 (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can
48 add his own function by customization of function pointer XferCpltCallback and
49 XferErrorCallback (i.e a member of DMA handle structure).
51 (#) Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error
54 (#) Use HAL_DMA_Abort() function to abort the current transfer
56 -@- In Memory-to-Memory transfer mode, Circular mode is not allowed.
59 ******************************************************************************
62 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
64 * Redistribution and use in source and binary forms, with or without modification,
65 * are permitted provided that the following conditions are met:
66 * 1. Redistributions of source code must retain the above copyright notice,
67 * this list of conditions and the following disclaimer.
68 * 2. Redistributions in binary form must reproduce the above copyright notice,
69 * this list of conditions and the following disclaimer in the documentation
70 * and/or other materials provided with the distribution.
71 * 3. Neither the name of STMicroelectronics nor the names of its contributors
72 * may be used to endorse or promote products derived from this software
73 * without specific prior written permission.
75 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
76 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
77 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
78 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
79 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
80 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
81 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
82 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
83 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
84 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86 ******************************************************************************
89 /* Includes ------------------------------------------------------------------*/
90 #include "stm32l0xx_hal.h"
92 /** @addtogroup STM32L0xx_HAL_Driver
96 /** @addtogroup DMA DMA
97 * @brief DMA HAL module driver
101 #ifdef HAL_DMA_MODULE_ENABLED
103 /* Private typedef -----------------------------------------------------------*/
104 /** @defgroup DMA_Private_Types DMA Private Types
108 #define HAL_TIMEOUT_DMA_ABORT ((uint32_t)1000) /* 1s */
114 /* Private function prototypes -----------------------------------------------*/
115 /** @defgroup DMA_Private_Functions DMA Private Functions
118 static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
123 /** @addtogroup DMA_Exported_Functions DMA Exported Functions
127 /** @addtogroup DMA_Exported_Functions_Group1
128 * @brief Initialization/de-initialization functions
131 ===============================================================================
132 ##### Initialization and de-initialization functions #####
133 ===============================================================================
134 [..] This section provides functions allowing to:
135 (+) Initialize and configure the DMA
136 (+) De-Initialize the DMA
143 * @brief Initializes the DMA according to the specified
144 * parameters in the DMA_InitTypeDef and create the associated handle.
145 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
146 * the configuration information for the specified DMA Channel.
149 HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
153 /* Check the DMA peripheral state */
159 /* Check the parameters */
160 assert_param(IS_DMA_ALL_PERIPH(hdma->Instance));
161 assert_param(IS_DMA_ALL_REQUEST(hdma->Init.Request));
162 assert_param(IS_DMA_DIRECTION(hdma->Init.Direction));
163 assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc));
164 assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc));
165 assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment));
166 assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment));
167 assert_param(IS_DMA_MODE(hdma->Init.Mode));
168 assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
170 /* Change DMA peripheral state */
171 hdma->State = HAL_DMA_STATE_BUSY;
173 /* Get the CR register value */
174 tmp = hdma->Instance->CCR;
176 /* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR bits */
177 tmp &= ((uint32_t)~(DMA_CCR_PL | DMA_CCR_MSIZE | DMA_CCR_PSIZE | \
178 DMA_CCR_MINC | DMA_CCR_PINC | DMA_CCR_CIRC | \
181 /* Prepare the DMA Channel configuration */
182 tmp |= hdma->Init.Direction |
183 hdma->Init.PeriphInc | hdma->Init.MemInc |
184 hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
185 hdma->Init.Mode | hdma->Init.Priority;
187 /* Write to DMA Channel CR register */
188 hdma->Instance->CCR = tmp;
190 /* Write to DMA channel selection register */
191 if (hdma->Instance == DMA1_Channel1)
193 /*Reset request selection for DMA1 Channel1*/
194 DMA1_CSELR->CSELR &= ~DMA_CSELR_C1S;
196 /* Configure request selection for DMA1 Channel1 */
197 DMA1_CSELR->CSELR |= hdma->Init.Request;
199 else if (hdma->Instance == DMA1_Channel2)
201 /*Reset request selection for DMA1 Channel2*/
202 DMA1_CSELR->CSELR &= ~DMA_CSELR_C2S;
204 /* Configure request selection for DMA1 Channel2 */
205 DMA1_CSELR->CSELR |= (uint32_t)(hdma->Init.Request << 4);
207 else if (hdma->Instance == DMA1_Channel3)
209 /*Reset request selection for DMA1 Channel3*/
210 DMA1_CSELR->CSELR &= ~DMA_CSELR_C3S;
212 /* Configure request selection for DMA1 Channel3 */
213 DMA1_CSELR->CSELR |= (uint32_t) (hdma->Init.Request << 8);
215 else if (hdma->Instance == DMA1_Channel4)
217 /*Reset request selection for DMA1 Channel4*/
218 DMA1_CSELR->CSELR &= ~DMA_CSELR_C4S;
220 /* Configure request selection for DMA1 Channel4 */
221 DMA1_CSELR->CSELR |= (uint32_t) (hdma->Init.Request << 12);
223 else if (hdma->Instance == DMA1_Channel5)
225 /*Reset request selection for DMA1 Channel5*/
226 DMA1_CSELR->CSELR &= ~DMA_CSELR_C5S;
228 /* Configure request selection for DMA1 Channel5 */
229 DMA1_CSELR->CSELR |= (uint32_t) (hdma->Init.Request << 16);
231 else if (hdma->Instance == DMA1_Channel6)
233 /*Reset request selection for DMA1 Channel6*/
234 DMA1_CSELR->CSELR &= ~DMA_CSELR_C6S;
236 /* Configure request selection for DMA1 Channel6 */
237 DMA1_CSELR->CSELR |= (uint32_t) (hdma->Init.Request << 20);
239 else if (hdma->Instance == DMA1_Channel7)
241 /*Reset request selection for DMA1 Channel7*/
242 DMA1_CSELR->CSELR &= ~DMA_CSELR_C7S;
244 /* Configure request selection for DMA1 Channel7 */
245 DMA1_CSELR->CSELR |= (uint32_t) (hdma->Init.Request << 24);
248 /* Initialize the DMA state*/
249 hdma->State = HAL_DMA_STATE_READY;
255 * @brief DeInitializes the DMA peripheral
256 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
257 * the configuration information for the specified DMA Channel.
260 HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
262 /* Check the DMA peripheral state */
268 /* Check the DMA peripheral state */
269 if(hdma->State == HAL_DMA_STATE_BUSY)
274 /* Disable the selected DMA Channelx */
275 __HAL_DMA_DISABLE(hdma);
277 /* Reset DMA Channel control register */
278 hdma->Instance->CCR = 0;
280 /* Reset DMA Channel Number of Data to Transfer register */
281 hdma->Instance->CNDTR = 0;
283 /* Reset DMA Channel peripheral address register */
284 hdma->Instance->CPAR = 0;
286 /* Reset DMA Channel memory address register */
287 hdma->Instance->CMAR = 0;
289 /* Clear all flags */
290 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_GI_FLAG_INDEX(hdma));
291 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
292 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
293 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
295 /* Reset DMA channel selection register */
296 if (hdma->Instance == DMA1_Channel1)
298 /*Reset DMA request*/
299 DMA1_CSELR->CSELR &= ~DMA_CSELR_C1S;
301 else if (hdma->Instance == DMA1_Channel2)
303 /*Reset DMA request*/
304 DMA1_CSELR->CSELR &= ~DMA_CSELR_C2S;
306 else if (hdma->Instance == DMA1_Channel3)
308 /*Reset DMA request*/
309 DMA1_CSELR->CSELR &= ~DMA_CSELR_C3S;
311 else if (hdma->Instance == DMA1_Channel4)
313 /*Reset DMA request*/
314 DMA1_CSELR->CSELR &= ~DMA_CSELR_C4S;
316 else if (hdma->Instance == DMA1_Channel5)
318 /*Reset DMA request*/
319 DMA1_CSELR->CSELR &= ~DMA_CSELR_C5S;
321 else if (hdma->Instance == DMA1_Channel6)
323 /*Reset DMA request*/
324 DMA1_CSELR->CSELR &= ~DMA_CSELR_C6S;
326 else if (hdma->Instance == DMA1_Channel7)
328 /*Reset DMA request*/
329 DMA1_CSELR->CSELR &= ~DMA_CSELR_C7S;
332 /* Initialise the error code */
333 hdma->ErrorCode = HAL_DMA_ERROR_NONE;
335 /* Initialize the DMA state */
336 hdma->State = HAL_DMA_STATE_RESET;
348 /** @addtogroup DMA_Exported_Functions_Group2
349 * @brief I/O operation functions
352 ===============================================================================
353 ##### IO operation functions #####
354 ===============================================================================
355 [..] This section provides functions allowing to:
356 (+) Configure the source, destination address and data length and Start DMA transfer
357 (+) Configure the source, destination address and data length and
358 Start DMA transfer with interrupt
359 (+) Abort DMA transfer
360 (+) Poll for transfer complete
361 (+) Handle DMA interrupt request
368 * @brief Starts the DMA Transfer.
369 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
370 * the configuration information for the specified DMA Channel.
371 * @param SrcAddress: The source memory Buffer address
372 * @param DstAddress: The destination memory Buffer address
373 * @param DataLength: The length of data to be transferred from source to destination
376 HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
381 /* Change DMA peripheral state */
382 hdma->State = HAL_DMA_STATE_BUSY;
384 /* Check the parameters */
385 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
387 /* Disable the peripheral */
388 __HAL_DMA_DISABLE(hdma);
390 /* Configure the source, destination address and the data length */
391 DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
393 /* Enable the Peripheral */
394 __HAL_DMA_ENABLE(hdma);
400 * @brief Start the DMA Transfer with interrupt enabled.
401 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
402 * the configuration information for the specified DMA Channel.
403 * @param SrcAddress: The source memory Buffer address
404 * @param DstAddress: The destination memory Buffer address
405 * @param DataLength: The length of data to be transferred from source to destination
408 HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
413 /* Change DMA peripheral state */
414 hdma->State = HAL_DMA_STATE_BUSY;
416 /* Check the parameters */
417 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
419 /* Disable the peripheral */
420 __HAL_DMA_DISABLE(hdma);
422 /* Configure the source, destination address and the data length */
423 DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
425 /* Enable the transfer complete interrupt */
426 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TC);
428 /* Enable the Half transfer complete interrupt */
429 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_HT);
431 /* Enable the transfer Error interrupt */
432 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TE);
434 /* Enable the Peripheral */
435 __HAL_DMA_ENABLE(hdma);
441 * @brief Aborts the DMA Transfer.
442 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
443 * the configuration information for the specified DMA Channel.
444 * @param Timeout: Timeout duration
447 HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
449 uint32_t tickstart = 0;
451 /* Disable the channel */
452 __HAL_DMA_DISABLE(hdma);
455 tickstart = HAL_GetTick();
457 /* Check if the DMA Channel is effectively disabled */
458 while((hdma->Instance->CCR & DMA_CCR_EN) != 0)
460 /* Check for the Timeout */
461 if( (HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA_ABORT)
463 /* Update error code */
464 hdma->ErrorCode |= HAL_DMA_ERROR_TIMEOUT;
466 /* Process Unlocked */
469 /* Change the DMA state */
470 hdma->State = HAL_DMA_STATE_TIMEOUT;
475 /* Process Unlocked */
478 /* Change the DMA state*/
479 hdma->State = HAL_DMA_STATE_READY;
485 * @brief Polling for transfer complete.
486 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
487 * the configuration information for the specified DMA Channel.
488 * @param CompleteLevel: Specifies the DMA level complete.
489 * @param Timeout: Timeout duration.
492 HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout)
495 uint32_t tickstart = 0;
497 /* Get the level transfer complete flag */
498 if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
500 /* Transfer Complete flag */
501 temp = __HAL_DMA_GET_TC_FLAG_INDEX(hdma);
505 /* Half Transfer Complete flag */
506 temp = __HAL_DMA_GET_HT_FLAG_INDEX(hdma);
510 tickstart = HAL_GetTick();
512 while(__HAL_DMA_GET_FLAG(hdma, temp) == RESET)
514 if((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET))
516 /* Clear the transfer error flags */
517 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
519 /* Update error code */
520 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE);
522 /* Change the DMA state */
523 hdma->State= HAL_DMA_STATE_ERROR;
525 /* Process Unlocked */
530 /* Check for the Timeout */
531 if(Timeout != HAL_MAX_DELAY)
533 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
535 /* Update error code */
536 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT);
538 /* Change the DMA state */
539 hdma->State= HAL_DMA_STATE_TIMEOUT;
541 /* Process Unlocked */
549 if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
551 /* Clear the transfer complete flag */
552 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
554 /* The selected Channelx EN bit is cleared (DMA is disabled and
555 all transfers are complete) */
556 hdma->State = HAL_DMA_STATE_READY;
558 /* Process unlocked */
563 /* Clear the half transfer complete flag */
564 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
566 /* The selected Channelx EN bit is cleared (DMA is disabled and
567 all transfers are complete) */
568 hdma->State = HAL_DMA_STATE_READY_HALF;
570 /* Process unlocked */
577 * @brief Handles DMA interrupt request.
578 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
579 * the configuration information for the specified DMA Channel.
582 void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
584 /* Transfer Error Interrupt management ***************************************/
585 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET)
587 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TE) != RESET)
589 /* Disable the transfer error interrupt */
590 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE);
592 /* Clear the transfer error flag */
593 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
595 /* Update error code */
596 hdma->ErrorCode |= HAL_DMA_ERROR_TE;
598 /* Change the DMA state */
599 hdma->State = HAL_DMA_STATE_ERROR;
601 /* Process Unlocked */
604 if (hdma->XferErrorCallback != NULL)
606 /* Transfer error callback */
607 hdma->XferErrorCallback(hdma);
612 /* Half Transfer Complete Interrupt management ******************************/
613 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)) != RESET)
615 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_HT) != RESET)
617 /* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
618 if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0)
620 /* Disable the half transfer interrupt */
621 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
623 /* Clear the half transfer complete flag */
624 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
626 /* Change DMA peripheral state */
627 hdma->State = HAL_DMA_STATE_READY_HALF;
629 if(hdma->XferHalfCpltCallback != NULL)
631 /* Half transfer callback */
632 hdma->XferHalfCpltCallback(hdma);
637 /* Transfer Complete Interrupt management ***********************************/
638 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)) != RESET)
640 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TC) != RESET)
642 if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0)
644 /* Disable the transfer complete interrupt */
645 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TC);
647 /* Clear the transfer complete flag */
648 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
650 /* Update error code */
651 hdma->ErrorCode |= HAL_DMA_ERROR_NONE;
653 /* Change the DMA state */
654 hdma->State = HAL_DMA_STATE_READY;
656 /* Process Unlocked */
659 if(hdma->XferCpltCallback != NULL)
661 /* Transfer complete callback */
662 hdma->XferCpltCallback(hdma);
672 /** @addtogroup DMA_Exported_Functions_Group3
673 * @brief Peripheral State functions
676 ===============================================================================
677 ##### Peripheral State functions #####
678 ===============================================================================
680 This subsection provides functions allowing to
681 (+) Check the DMA state
689 * @brief Returns the DMA state.
690 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
691 * the configuration information for the specified DMA Channel.
694 HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
700 * @brief Return the DMA error code
701 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
702 * the configuration information for the specified DMA Channel.
703 * @retval DMA Error Code
705 uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
707 return hdma->ErrorCode;
717 /* Private macro -------------------------------------------------------------*/
718 /* Private variables ---------------------------------------------------------*/
721 /* Private function prototypes -----------------------------------------------*/
722 /** @addtogroup DMA_Private_Functions DMA Private Functions
727 * @brief Sets the DMA Transfer parameter.
728 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
729 * the configuration information for the specified DMA Channel.
730 * @param SrcAddress: The source memory Buffer address
731 * @param DstAddress: The destination memory Buffer address
732 * @param DataLength: The length of data to be transferred from source to destination
735 static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
737 /* Configure DMA Channel data length */
738 hdma->Instance->CNDTR = DataLength;
740 /* Peripheral to Memory */
741 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
743 /* Configure DMA Channel destination address */
744 hdma->Instance->CPAR = DstAddress;
746 /* Configure DMA Channel source address */
747 hdma->Instance->CMAR = SrcAddress;
749 /* Memory to Peripheral */
752 /* Configure DMA Channel source address */
753 hdma->Instance->CPAR = SrcAddress;
755 /* Configure DMA Channel destination address */
756 hdma->Instance->CMAR = DstAddress;
763 #endif /* HAL_DMA_MODULE_ENABLED */
772 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/