]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L1/stm32l1xx_hal_dma.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32L1 / stm32l1xx_hal_dma.c
1 /**
2 ******************************************************************************
3 * @file stm32l1xx_hal_dma.c
4 * @author MCD Application Team
5 * @version V1.0.0
6 * @date 5-September-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, Normal or peripheral flow control mode, Channel Priority level,
27 Source and Destination Increment mode, FIFO mode and its Threshold (if needed),
28 Burst mode for Source and/or Destination (if needed) using HAL_DMA_Init() function.
29
30 *** Polling mode IO operation ***
31 =================================
32 [..]
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.
37
38 *** Interrupt mode IO operation ***
39 ===================================
40 [..]
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).
50
51 (#) Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error
52 detection.
53
54 (#) Use HAL_DMA_Abort() function to abort the current transfer
55
56 -@- In Memory-to-Memory transfer mode, Circular mode is not allowed.
57
58 *** DMA HAL driver macros list ***
59 =============================================
60 [..]
61 Below the list of most used macros in DMA HAL driver.
62
63 (+) __HAL_DMA_ENABLE: Enable the specified DMA Channel.
64 (+) __HAL_DMA_DISABLE: Disable the specified DMA Channel.
65 (+) __HAL_DMA_GET_FLAG: Get the DMA Channel pending flags.
66 (+) __HAL_DMA_CLEAR_FLAG: Clear the DMA Channel pending flags.
67 (+) __HAL_DMA_ENABLE_IT: Enable the specified DMA Channel interrupts.
68 (+) __HAL_DMA_DISABLE_IT: Disable the specified DMA Channel interrupts.
69 (+) __HAL_DMA_GET_IT_SOURCE: Check whether the specified DMA Channel interrupt has occurred or not.
70
71 [..]
72 (@) You can refer to the DMA HAL driver header file for more useful macros
73
74 @endverbatim
75 ******************************************************************************
76 * @attention
77 *
78 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
79 *
80 * Redistribution and use in source and binary forms, with or without modification,
81 * are permitted provided that the following conditions are met:
82 * 1. Redistributions of source code must retain the above copyright notice,
83 * this list of conditions and the following disclaimer.
84 * 2. Redistributions in binary form must reproduce the above copyright notice,
85 * this list of conditions and the following disclaimer in the documentation
86 * and/or other materials provided with the distribution.
87 * 3. Neither the name of STMicroelectronics nor the names of its contributors
88 * may be used to endorse or promote products derived from this software
89 * without specific prior written permission.
90 *
91 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
92 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
94 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
95 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
96 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
97 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
98 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
99 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
100 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
101 *
102 ******************************************************************************
103 */
104
105 /* Includes ------------------------------------------------------------------*/
106 #include "stm32l1xx_hal.h"
107
108 /** @addtogroup STM32L1xx_HAL_Driver
109 * @{
110 */
111
112 /** @defgroup DMA DMA
113 * @brief DMA HAL module driver
114 * @{
115 */
116
117 #ifdef HAL_DMA_MODULE_ENABLED
118
119 /* Private typedef -----------------------------------------------------------*/
120 /* Private define ------------------------------------------------------------*/
121 /** @defgroup DMA_Private_Constants DMA Private Constants
122 * @{
123 */
124 #define HAL_TIMEOUT_DMA_ABORT ((uint32_t)1000) /* 1s */
125 /**
126 * @}
127 */
128
129
130 /* Private macro -------------------------------------------------------------*/
131 /* Private variables ---------------------------------------------------------*/
132 /* Private function prototypes -----------------------------------------------*/
133 /** @defgroup DMA_Private_Functions DMA Private Functions
134 * @{
135 */
136 static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
137 /**
138 * @}
139 */
140
141 /* Private functions ---------------------------------------------------------*/
142
143 /** @defgroup DMA_Exported_Functions DMA Exported Functions
144 * @{
145 */
146
147 /** @defgroup DMA_Group1 Initialization and de-initialization functions
148 * @brief Initialization and de-initialization functions
149 *
150 @verbatim
151 ===============================================================================
152 ##### Initialization and de-initialization functions #####
153 ===============================================================================
154 [..]
155 This section provides functions allowing to initialize the DMA Channel source
156 and destination addresses, incrementation and data sizes, transfer direction,
157 circular/normal mode selection, memory-to-memory mode selection and Channel priority value.
158 [..]
159 The HAL_DMA_Init() function follows the DMA configuration procedures as described in
160 reference manual.
161
162 @endverbatim
163 * @{
164 */
165
166 /**
167 * @brief Initializes the DMA according to the specified
168 * parameters in the DMA_InitTypeDef and create the associated handle.
169 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
170 * the configuration information for the specified DMA Channel.
171 * @retval HAL status
172 */
173 HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
174 {
175 uint32_t tmp = 0;
176
177 /* Check the DMA peripheral state */
178 if(hdma == HAL_NULL)
179 {
180 return HAL_ERROR;
181 }
182
183 /* Check the parameters */
184 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
185 assert_param(IS_DMA_DIRECTION(hdma->Init.Direction));
186 assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc));
187 assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc));
188 assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment));
189 assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment));
190 assert_param(IS_DMA_MODE(hdma->Init.Mode));
191 assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
192
193 /* Change DMA peripheral state */
194 hdma->State = HAL_DMA_STATE_BUSY;
195
196 /* Get the CR register value */
197 tmp = hdma->Instance->CCR;
198
199 /* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR bits */
200 tmp &= ((uint32_t)~(DMA_CCR_PL | DMA_CCR_MSIZE | DMA_CCR_PSIZE | \
201 DMA_CCR_MINC | DMA_CCR_PINC | DMA_CCR_CIRC | \
202 DMA_CCR_DIR));
203
204 /* Prepare the DMA Channel configuration */
205 tmp |= hdma->Init.Direction |
206 hdma->Init.PeriphInc | hdma->Init.MemInc |
207 hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
208 hdma->Init.Mode | hdma->Init.Priority;
209
210 /* Write to DMA Channel CR register */
211 hdma->Instance->CCR = tmp;
212
213 /* Initialise the error code */
214 hdma->ErrorCode = HAL_DMA_ERROR_NONE;
215
216 /* Initialize the DMA state*/
217 hdma->State = HAL_DMA_STATE_READY;
218
219 return HAL_OK;
220 }
221
222 /**
223 * @brief DeInitializes the DMA peripheral
224 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
225 * the configuration information for the specified DMA Channel.
226 * @retval HAL status
227 */
228 HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
229 {
230 /* Check the DMA peripheral state */
231 if(hdma == HAL_NULL)
232 {
233 return HAL_ERROR;
234 }
235
236 /* Check the DMA peripheral handle */
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_Group2 I/O 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 /* Process Unlocked */
402 __HAL_UNLOCK(hdma);
403
404 /* Change the DMA state */
405 hdma->State = HAL_DMA_STATE_TIMEOUT;
406
407 return HAL_TIMEOUT;
408 }
409 }
410 /* Process Unlocked */
411 __HAL_UNLOCK(hdma);
412
413 /* Change the DMA state*/
414 hdma->State = HAL_DMA_STATE_READY;
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 /* Process unlocked */
494 __HAL_UNLOCK(hdma);
495 }
496 else
497 {
498 /* Clear the half transfer complete flag */
499 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
500
501 /* The selected Channelx EN bit is cleared (DMA is disabled and
502 all transfers are complete) */
503 hdma->State = HAL_DMA_STATE_READY_HALF;
504 /* Process unlocked */
505 __HAL_UNLOCK(hdma);
506 }
507
508 return HAL_OK;
509 }
510
511 /**
512 * @brief Handles DMA interrupt request.
513 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
514 * the configuration information for the specified DMA Channel.
515 * @retval None
516 */
517 void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
518 {
519 /* Transfer Error Interrupt management ***************************************/
520 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET)
521 {
522 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TE) != RESET)
523 {
524 /* Disable the transfer error interrupt */
525 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE);
526
527 /* Clear the transfer error flag */
528 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
529
530 /* Update error code */
531 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE);
532
533 /* Change the DMA state */
534 hdma->State = HAL_DMA_STATE_ERROR;
535
536 /* Process Unlocked */
537 __HAL_UNLOCK(hdma);
538
539 if (hdma->XferErrorCallback != HAL_NULL)
540 {
541 /* Transfer error callback */
542 hdma->XferErrorCallback(hdma);
543 }
544 }
545 }
546
547 /* Half Transfer Complete Interrupt management ******************************/
548 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)) != RESET)
549 {
550 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_HT) != RESET)
551 {
552 /* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
553 if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0)
554 {
555 /* Disable the half transfer interrupt */
556 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
557 }
558 /* Clear the half transfer complete flag */
559 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
560
561 /* Change DMA peripheral state */
562 hdma->State = HAL_DMA_STATE_READY_HALF;
563
564 if(hdma->XferHalfCpltCallback != HAL_NULL)
565 {
566 /* Half transfer callback */
567 hdma->XferHalfCpltCallback(hdma);
568 }
569 }
570 }
571
572 /* Transfer Complete Interrupt management ***********************************/
573 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)) != RESET)
574 {
575 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TC) != RESET)
576 {
577 if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0)
578 {
579 /* Disable the transfer complete interrupt */
580 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TC);
581 }
582 /* Clear the transfer complete flag */
583 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
584
585 /* Update error code */
586 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_NONE);
587
588 /* Change the DMA state */
589 hdma->State = HAL_DMA_STATE_READY;
590
591 /* Process Unlocked */
592 __HAL_UNLOCK(hdma);
593
594 if(hdma->XferCpltCallback != HAL_NULL)
595 {
596 /* Transfer complete callback */
597 hdma->XferCpltCallback(hdma);
598 }
599 }
600 }
601 }
602
603 /**
604 * @}
605 */
606
607 /** @defgroup DMA_Group3 Peripheral State functions
608 * @brief Peripheral State functions
609 *
610 @verbatim
611 ===============================================================================
612 ##### State and Errors functions #####
613 ===============================================================================
614 [..]
615 This subsection provides functions allowing to
616 (+) Check the DMA state
617 (+) Get error code
618
619 @endverbatim
620 * @{
621 */
622
623 /**
624 * @brief Returns the DMA state.
625 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
626 * the configuration information for the specified DMA Channel.
627 * @retval HAL state
628 */
629 HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
630 {
631 return hdma->State;
632 }
633
634 /**
635 * @brief Return the DMA error code
636 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
637 * the configuration information for the specified DMA Channel.
638 * @retval DMA Error Code
639 */
640 uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
641 {
642 return hdma->ErrorCode;
643 }
644
645 /**
646 * @}
647 */
648
649 /**
650 * @}
651 */
652
653 /** @addtogroup DMA_Private_Functions
654 * @{
655 */
656
657 /**
658 * @brief Sets the DMA Transfer parameter.
659 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
660 * the configuration information for the specified DMA Channel.
661 * @param SrcAddress: The source memory Buffer address
662 * @param DstAddress: The destination memory Buffer address
663 * @param DataLength: The length of data to be transferred from source to destination
664 * @retval HAL status
665 */
666 static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
667 {
668 /* Configure DMA Channel data length */
669 hdma->Instance->CNDTR = DataLength;
670
671 /* Peripheral to Memory */
672 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
673 {
674 /* Configure DMA Channel destination address */
675 hdma->Instance->CPAR = DstAddress;
676
677 /* Configure DMA Channel source address */
678 hdma->Instance->CMAR = SrcAddress;
679 }
680 /* Memory to Peripheral */
681 else
682 {
683 /* Configure DMA Channel source address */
684 hdma->Instance->CPAR = SrcAddress;
685
686 /* Configure DMA Channel destination address */
687 hdma->Instance->CMAR = DstAddress;
688 }
689 }
690
691 /**
692 * @}
693 */
694
695
696 #endif /* HAL_DMA_MODULE_ENABLED */
697
698
699 /**
700 * @}
701 */
702
703 /**
704 * @}
705 */
706
707 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Imprint / Impressum