]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_dma.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F0 / stm32f0xx_hal_dma.c
1 /**
2   ******************************************************************************
3   * @file    stm32f0xx_hal_dma.c
4   * @author  MCD Application Team
5   * @version V1.2.0
6   * @date    11-December-2014
7   * @brief   DMA HAL module driver.
8   *    
9   *         This file provides firmware functions to manage the following 
10   *         functionalities of the Direct Memory Access (DMA) peripheral:
11   *           + Initialization and de-initialization functions
12   *           + IO operation functions
13   *           + Peripheral State and errors functions
14   @verbatim     
15   ==============================================================================      
16                         ##### How to use this driver #####
17   ============================================================================== 
18   [..]
19    (#) Enable and configure the peripheral to be connected to the DMA Channel
20        (except for internal SRAM / FLASH memories: no initialization is 
21        necessary) please refer to Reference manual for connection between peripherals
22        and DMA requests .
23
24    (#) For a given Channel, program the required configuration through the following parameters:   
25        Transfer Direction, Source and Destination data formats, 
26        Circular or Normal mode, Channel Priority level, Source and Destination Increment mode, 
27        using HAL_DMA_Init() function.
28
29    (#) Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error 
30        detection.
31                     
32    (#) Use HAL_DMA_Abort() function to abort the current transfer
33                    
34      -@-   In Memory-to-Memory transfer mode, Circular mode is not allowed.
35      *** Polling mode IO operation ***
36      =================================   
37     [..] 
38       (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source 
39           address and destination address and the Length of data to be transferred
40       (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this  
41           case a fixed Timeout can be configured by User depending from his application.
42
43      *** Interrupt mode IO operation ***    
44      =================================== 
45     [..]
46       (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority()
47       (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ() 
48       (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of  
49           Source address and destination address and the Length of data to be transferred. 
50           In this case the DMA interrupt is configured 
51       (+) Use HAL_DMAy_Channelx_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine
52       (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can 
53           add his own function by customization of function pointer XferCpltCallback and 
54           XferErrorCallback (i.e a member of DMA handle structure). 
55
56      *** DMA HAL driver macros list ***
57      ============================================= 
58      [..]
59        Below the list of most used macros in DMA HAL driver.
60
61        (+) __HAL_DMA_ENABLE: Enable the specified DMA Channel.
62        (+) __HAL_DMA_DISABLE: Disable the specified DMA Channel.
63        (+) __HAL_DMA_GET_FLAG: Get the DMA Channel pending flags.
64        (+) __HAL_DMA_CLEAR_FLAG: Clear the DMA Channel pending flags.
65        (+) __HAL_DMA_ENABLE_IT: Enable the specified DMA Channel interrupts.
66        (+) __HAL_DMA_DISABLE_IT: Disable the specified DMA Channel interrupts.
67        (+) __HAL_DMA_GET_IT_SOURCE: Check whether the specified DMA Channel interrupt has occurred or not. 
68
69      [..] 
70       (@) You can refer to the DMA HAL driver header file for more useful macros  
71
72   @endverbatim
73   ******************************************************************************
74   * @attention
75   *
76   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
77   *
78   * Redistribution and use in source and binary forms, with or without modification,
79   * are permitted provided that the following conditions are met:
80   *   1. Redistributions of source code must retain the above copyright notice,
81   *      this list of conditions and the following disclaimer.
82   *   2. Redistributions in binary form must reproduce the above copyright notice,
83   *      this list of conditions and the following disclaimer in the documentation
84   *      and/or other materials provided with the distribution.
85   *   3. Neither the name of STMicroelectronics nor the names of its contributors
86   *      may be used to endorse or promote products derived from this software
87   *      without specific prior written permission.
88   *
89   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
90   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
91   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
92   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
93   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
94   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
95   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
96   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
97   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
98   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
99   *
100   ******************************************************************************
101   */ 
102
103 /* Includes ------------------------------------------------------------------*/
104 #include "stm32f0xx_hal.h"
105
106 /** @addtogroup STM32F0xx_HAL_Driver
107   * @{
108   */
109
110 /** @defgroup DMA DMA
111   * @brief DMA HAL module driver
112   * @{
113   */
114
115 #ifdef HAL_DMA_MODULE_ENABLED
116
117 /* Private typedef -----------------------------------------------------------*/
118 /* Private define ------------------------------------------------------------*/
119 /** @defgroup DMA_Private_Constants DMA Private Constants
120   * @{
121   */
122 #define HAL_TIMEOUT_DMA_ABORT    ((uint32_t)1000)  /* 1s  */
123 /**
124   * @}
125   */
126
127 /* Private macro -------------------------------------------------------------*/
128 /* Private variables ---------------------------------------------------------*/
129 /* Private function prototypes -----------------------------------------------*/
130 /** @defgroup DMA_Private_Functions DMA Private Functions
131   * @{
132   */
133 static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
134 /**
135   * @}
136   */
137
138 /* Exported functions ---------------------------------------------------------*/
139
140 /** @defgroup DMA_Exported_Functions DMA Exported Functions
141   * @{
142   */
143
144 /** @defgroup DMA_Exported_Functions_Group1 Initialization and de-initialization functions 
145  *  @brief   Initialization and de-initialization functions 
146  *
147 @verbatim   
148  ===============================================================================
149              ##### Initialization and de-initialization functions  #####
150  ===============================================================================  
151     [..]
152     This section provides functions allowing to initialize the DMA Channel source
153     and destination addresses, incrementation and data sizes, transfer direction, 
154     circular/normal mode selection, memory-to-memory mode selection and Channel priority value.
155     [..]
156     The HAL_DMA_Init() function follows the DMA configuration procedures as described in
157     reference manual.  
158
159 @endverbatim
160   * @{
161   */
162   
163 /**
164   * @brief  Initializes the DMA according to the specified
165   *         parameters in the DMA_InitTypeDef and create the associated handle.
166   * @param  hdma: Pointer to a DMA_HandleTypeDef structure that contains
167   *               the configuration information for the specified DMA Channel.  
168   * @retval HAL status
169   */
170 HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
171
172   uint32_t tmp = 0;
173   
174   /* Check the DMA handle allocation */
175   if(hdma == NULL)
176   {
177     return HAL_ERROR;
178   }
179   
180   /* Check the parameters */
181   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
182   assert_param(IS_DMA_DIRECTION(hdma->Init.Direction));
183   assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc));
184   assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc));
185   assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment));
186   assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment));
187   assert_param(IS_DMA_MODE(hdma->Init.Mode));
188   assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
189   
190   /* Change DMA peripheral state */
191   hdma->State = HAL_DMA_STATE_BUSY;
192
193   /* Get the CR register value */
194   tmp = hdma->Instance->CCR;
195   
196   /* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR bits */
197   tmp &= ((uint32_t)~(DMA_CCR_PL    | DMA_CCR_MSIZE  | DMA_CCR_PSIZE  | \
198                       DMA_CCR_MINC  | DMA_CCR_PINC   | DMA_CCR_CIRC   | \
199                       DMA_CCR_DIR));
200   
201   /* Prepare the DMA Channel configuration */
202   tmp |=  hdma->Init.Direction        |
203           hdma->Init.PeriphInc           | hdma->Init.MemInc           |
204           hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
205           hdma->Init.Mode                | hdma->Init.Priority;
206
207   /* Write to DMA Channel CR register */
208   hdma->Instance->CCR = tmp;  
209   
210   /* Initialise the error code */
211   hdma->ErrorCode = HAL_DMA_ERROR_NONE;
212
213   /* Initialize the DMA state*/
214   hdma->State  = HAL_DMA_STATE_READY;
215   
216   return HAL_OK;
217 }  
218   
219 /**
220   * @brief  DeInitializes the DMA peripheral 
221   * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
222   *               the configuration information for the specified DMA Channel.  
223   * @retval HAL status
224   */
225 HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
226 {
227   /* Check the DMA handle allocation */
228   if(hdma == NULL)
229   {
230     return HAL_ERROR;
231   }
232   
233   /* Check the parameters */
234   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
235
236   /* Check the DMA peripheral state */
237   if(hdma->State == HAL_DMA_STATE_BUSY)
238   {
239      return HAL_ERROR;
240   }
241
242   /* Disable the selected DMA Channelx */
243   __HAL_DMA_DISABLE(hdma);
244   
245   /* Reset DMA Channel control register */
246   hdma->Instance->CCR  = 0;
247   
248   /* Reset DMA Channel Number of Data to Transfer register */
249   hdma->Instance->CNDTR = 0;
250   
251   /* Reset DMA Channel peripheral address register */
252   hdma->Instance->CPAR  = 0;
253   
254   /* Reset DMA Channel memory address register */
255   hdma->Instance->CMAR = 0;
256
257   /* Clear all flags */
258   __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
259   __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
260   __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
261   
262   /* Initialise the error code */
263   hdma->ErrorCode = HAL_DMA_ERROR_NONE;
264
265   /* Initialize the DMA state */
266   hdma->State = HAL_DMA_STATE_RESET;
267
268   /* Release Lock */
269   __HAL_UNLOCK(hdma);
270
271   return HAL_OK;
272 }
273
274 /**
275   * @}
276   */
277
278 /** @defgroup DMA_Exported_Functions_Group2 Input and Output operation functions 
279  *  @brief   I/O operation functions  
280  *
281 @verbatim   
282  ===============================================================================
283                       #####  IO operation functions  #####
284  ===============================================================================  
285     [..]  This section provides functions allowing to:
286       (+) Configure the source, destination address and data length and Start DMA transfer
287       (+) Configure the source, destination address and data length and 
288           Start DMA transfer with interrupt
289       (+) Abort DMA transfer
290       (+) Poll for transfer complete
291       (+) Handle DMA interrupt request  
292
293 @endverbatim
294   * @{
295   */
296
297 /**
298   * @brief  Starts the DMA Transfer.
299   * @param  hdma      : pointer to a DMA_HandleTypeDef structure that contains
300   *                     the configuration information for the specified DMA Channel.  
301   * @param  SrcAddress: The source memory Buffer address
302   * @param  DstAddress: The destination memory Buffer address
303   * @param  DataLength: The length of data to be transferred from source to destination
304   * @retval HAL status
305   */
306 HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
307
308   /* Process locked */
309   __HAL_LOCK(hdma);  
310
311   /* Change DMA peripheral state */  
312   hdma->State = HAL_DMA_STATE_BUSY;  
313
314    /* Check the parameters */
315   assert_param(IS_DMA_BUFFER_SIZE(DataLength));
316   
317   /* Disable the peripheral */
318   __HAL_DMA_DISABLE(hdma);  
319   
320   /* Configure the source, destination address and the data length */
321   DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
322
323   /* Enable the Peripheral */
324   __HAL_DMA_ENABLE(hdma);  
325
326   return HAL_OK; 
327
328
329 /**
330   * @brief  Start the DMA Transfer with interrupt enabled.
331   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains
332   *                     the configuration information for the specified DMA Channel.  
333   * @param  SrcAddress: The source memory Buffer address
334   * @param  DstAddress: The destination memory Buffer address
335   * @param  DataLength: The length of data to be transferred from source to destination
336   * @retval HAL status
337   */
338 HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
339 {
340   /* Process locked */
341   __HAL_LOCK(hdma);
342
343   /* Change DMA peripheral state */  
344   hdma->State = HAL_DMA_STATE_BUSY;  
345
346    /* Check the parameters */
347   assert_param(IS_DMA_BUFFER_SIZE(DataLength));
348   
349   /* Disable the peripheral */
350   __HAL_DMA_DISABLE(hdma);
351   
352   /* Configure the source, destination address and the data length */  
353   DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
354   
355   /* Enable the transfer complete interrupt */
356   __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TC);
357
358   /* Enable the Half transfer complete interrupt */
359   __HAL_DMA_ENABLE_IT(hdma, DMA_IT_HT);  
360
361   /* Enable the transfer Error interrupt */
362   __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TE);
363   
364    /* Enable the Peripheral */
365   __HAL_DMA_ENABLE(hdma);   
366   
367   return HAL_OK;    
368
369
370 /**
371   * @brief  Aborts the DMA Transfer.
372   * @param  hdma  : pointer to a DMA_HandleTypeDef structure that contains
373   *                 the configuration information for the specified DMA Channel.
374   *                   
375   * @note  After disabling a DMA Channel, a check for wait until the DMA Channel is 
376   *        effectively disabled is added. If a Channel is disabled 
377   *        while a data transfer is ongoing, the current data will be transferred
378   *        and the Channel will be effectively disabled only after the transfer of
379   *        this single data is finished.  
380   * @retval HAL status
381   */
382 HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
383 {
384   uint32_t tickstart = 0x00;
385   
386   /* Disable the channel */
387   __HAL_DMA_DISABLE(hdma);
388   
389   /* Get timeout */
390   tickstart = HAL_GetTick();
391   
392   /* Check if the DMA Channel is effectively disabled */
393   while((hdma->Instance->CCR & DMA_CCR_EN) != 0) 
394   {
395     /* Check for the Timeout */
396     if((HAL_GetTick() - tickstart) > HAL_TIMEOUT_DMA_ABORT)
397     {
398       /* Update error code */
399       SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT);
400
401       /* Change the DMA state */
402       hdma->State = HAL_DMA_STATE_TIMEOUT;
403
404       /* Process Unlocked */
405       __HAL_UNLOCK(hdma);
406
407       return HAL_TIMEOUT;
408     }
409   }
410   /* Change the DMA state*/
411   hdma->State = HAL_DMA_STATE_READY; 
412   
413   /* Process Unlocked */
414   __HAL_UNLOCK(hdma);
415   
416   return HAL_OK; 
417 }
418
419 /**
420   * @brief  Polling for transfer complete.
421   * @param  hdma:    pointer to a DMA_HandleTypeDef structure that contains
422   *                  the configuration information for the specified DMA Channel.
423   * @param  CompleteLevel: Specifies the DMA level complete.  
424   * @param  Timeout:       Timeout duration.
425   * @retval HAL status
426   */
427 HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout)
428 {
429   uint32_t temp;
430   uint32_t tickstart = 0x00;
431   
432   /* Get the level transfer complete flag */
433   if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
434   {
435     /* Transfer Complete flag */
436     temp = __HAL_DMA_GET_TC_FLAG_INDEX(hdma);
437   }
438   else
439   {
440     /* Half Transfer Complete flag */
441     temp = __HAL_DMA_GET_HT_FLAG_INDEX(hdma);
442   }
443
444   /* Get timeout */
445   tickstart = HAL_GetTick();
446
447   while(__HAL_DMA_GET_FLAG(hdma, temp) == RESET)
448   {
449     if((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET))
450     {      
451       /* Clear the transfer error flags */
452       __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
453       
454       /* Update error code */
455       SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE);
456
457       /* Change the DMA state */
458       hdma->State= HAL_DMA_STATE_ERROR;       
459       
460       /* Process Unlocked */
461       __HAL_UNLOCK(hdma);
462       
463       return HAL_ERROR;      
464     }      
465     /* Check for the Timeout */
466     if(Timeout != HAL_MAX_DELAY)
467     {
468       if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
469       {
470         /* Update error code */
471         SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT);
472         
473         /* Change the DMA state */
474         hdma->State = HAL_DMA_STATE_TIMEOUT;
475
476         /* Process Unlocked */
477         __HAL_UNLOCK(hdma);
478
479         return HAL_TIMEOUT;
480       }
481     }
482   }
483
484   if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
485   {
486     /* Clear the transfer complete flag */
487     __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
488
489     /* The selected Channelx EN bit is cleared (DMA is disabled and 
490     all transfers are complete) */
491     hdma->State = HAL_DMA_STATE_READY;
492
493   }
494   else
495   { 
496     /* Clear the half transfer complete flag */
497     __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
498   
499     /* The selected Channelx EN bit is cleared (DMA is disabled and 
500     all transfers of half buffer are complete) */
501     hdma->State = HAL_DMA_STATE_READY_HALF;
502   }
503   
504   /* Process unlocked */
505   __HAL_UNLOCK(hdma);  
506
507   return HAL_OK;
508 }
509
510 /**
511   * @brief  Handles DMA interrupt request.
512   * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
513   *               the configuration information for the specified DMA Channel.  
514   * @retval None
515   */
516 void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
517 {        
518   /* Transfer Error Interrupt management ***************************************/
519   if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET)
520   {
521     if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TE) != RESET)
522     {
523       /* Disable the transfer error interrupt */
524       __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE);
525     
526       /* Clear the transfer error flag */
527       __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
528     
529       /* Update error code */
530       SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE);
531
532       /* Change the DMA state */
533       hdma->State = HAL_DMA_STATE_ERROR;    
534     
535       /* Process Unlocked */
536       __HAL_UNLOCK(hdma); 
537     
538       if (hdma->XferErrorCallback != (void (*)(DMA_HandleTypeDef *))NULL)
539       {
540         /* Transfer error callback */
541         hdma->XferErrorCallback(hdma);
542       }
543     }
544   }
545
546   /* Half Transfer Complete Interrupt management ******************************/
547   if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)) != RESET)
548   {
549     if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_HT) != RESET)
550     { 
551       /* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
552       if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0)
553       {
554         /* Disable the half transfer interrupt */
555         __HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
556       }
557       /* Clear the half transfer complete flag */
558       __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
559
560       /* Change DMA peripheral state */
561       hdma->State = HAL_DMA_STATE_READY_HALF;
562
563       if(hdma->XferHalfCpltCallback != (void (*)(DMA_HandleTypeDef *))NULL)
564       {
565         /* Half transfer callback */
566         hdma->XferHalfCpltCallback(hdma);
567       }
568     }
569   }
570   
571   /* Transfer Complete Interrupt management ***********************************/
572   if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)) != RESET)
573   {
574     if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TC) != RESET)
575     {
576       if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0)
577       {
578         /* Disable the transfer complete interrupt */
579         __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TC);
580       }
581       /* Clear the transfer complete flag */
582       __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
583     
584       /* Update error code */
585       SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_NONE);
586
587       /* Change the DMA state */
588       hdma->State = HAL_DMA_STATE_READY;    
589     
590       /* Process Unlocked */
591       __HAL_UNLOCK(hdma);
592     
593       if(hdma->XferCpltCallback != (void (*)(DMA_HandleTypeDef *))NULL)
594       {       
595         /* Transfer complete callback */
596         hdma->XferCpltCallback(hdma);
597       }
598     }
599   }
600 }  
601
602 /**
603   * @}
604   */
605
606 /** @defgroup DMA_Exported_Functions_Group3 Peripheral State functions
607  *  @brief    Peripheral State functions 
608  *
609 @verbatim   
610  ===============================================================================
611                     ##### State and Errors functions #####
612  ===============================================================================  
613     [..]
614     This subsection provides functions allowing to
615       (+) Check the DMA state
616       (+) Get error code
617
618 @endverbatim
619   * @{
620   */  
621
622 /**
623   * @brief  Returns the DMA state.
624   * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
625   *               the configuration information for the specified DMA Channel.  
626   * @retval HAL state
627   */
628 HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
629 {
630   return hdma->State;
631 }
632
633 /**
634   * @brief  Return the DMA error code
635   * @param  hdma : pointer to a DMA_HandleTypeDef structure that contains
636   *              the configuration information for the specified DMA Channel.
637   * @retval DMA Error Code
638   */
639 uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
640 {
641   return hdma->ErrorCode;
642 }
643
644 /**
645   * @}
646   */
647
648 /**
649   * @}
650   */
651
652 /** @addtogroup DMA_Private_Functions DMA Private Functions
653   * @{
654   */
655
656 /**
657   * @brief  Sets the DMA Transfer parameter.
658   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains
659   *                     the configuration information for the specified DMA Channel.  
660   * @param  SrcAddress: The source memory Buffer address
661   * @param  DstAddress: The destination memory Buffer address
662   * @param  DataLength: The length of data to be transferred from source to destination
663   * @retval HAL status
664   */
665 static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
666 {  
667   /* Configure DMA Channel data length */
668   hdma->Instance->CNDTR = DataLength;
669   
670   /* Peripheral to Memory */
671   if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
672   {   
673     /* Configure DMA Channel destination address */
674     hdma->Instance->CPAR = DstAddress;
675     
676     /* Configure DMA Channel source address */
677     hdma->Instance->CMAR = SrcAddress;
678   }
679   /* Memory to Peripheral */
680   else
681   {
682     /* Configure DMA Channel source address */
683     hdma->Instance->CPAR = SrcAddress;
684     
685     /* Configure DMA Channel destination address */
686     hdma->Instance->CMAR = DstAddress;
687   }
688 }
689
690 /**
691   * @}
692   */
693
694 #endif /* HAL_DMA_MODULE_ENABLED */
695 /**
696   * @}
697   */
698
699 /**
700   * @}
701   */
702
703 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/