STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
stm32h7xx_hal_dma.c
Go to the documentation of this file.
1/**
2 ******************************************************************************
3 * @file stm32h7xx_hal_dma.c
4 * @author MCD Application Team
5 * @brief DMA HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Direct Memory Access (DMA) peripheral:
8 * + Initialization and de-initialization functions
9 * + IO operation functions
10 * + Peripheral State and errors functions
11 ******************************************************************************
12 * @attention
13 *
14 * Copyright (c) 2017 STMicroelectronics.
15 * All rights reserved.
16 *
17 * This software is licensed under terms that can be found in the LICENSE file
18 * in the root directory of this software component.
19 * If no LICENSE file comes with this software, it is provided AS-IS.
20 *
21 ******************************************************************************
22 @verbatim
23 ==============================================================================
24 ##### How to use this driver #####
25 ==============================================================================
26 [..]
27 (#) Enable and configure the peripheral to be connected to the DMA Stream
28 (except for internal SRAM/FLASH memories: no initialization is
29 necessary) please refer to Reference manual for connection between peripherals
30 and DMA requests .
31
32 (#) For a given Stream, program the required configuration through the following parameters:
33 Transfer Direction, Source and Destination data formats,
34 Circular, Normal or peripheral flow control mode, Stream Priority level,
35 Source and Destination Increment mode, FIFO mode and its Threshold (if needed),
36 Burst mode for Source and/or Destination (if needed) using HAL_DMA_Init() function.
37
38 *** Polling mode IO operation ***
39 =================================
40 [..]
41 (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source
42 address and destination address and the Length of data to be transferred
43 (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this
44 case a fixed Timeout can be configured by User depending from his application.
45
46 *** Interrupt mode IO operation ***
47 ===================================
48 [..]
49 (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority()
50 (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ()
51 (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of
52 Source address and destination address and the Length of data to be transferred. In this
53 case the DMA interrupt is configured
54 (+) Use HAL_DMA_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine
55 (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can
56 add his own function by customization of function pointer XferCpltCallback and
57 XferErrorCallback (i.e a member of DMA handle structure).
58 [..]
59 (#) Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error
60 detection.
61
62 (#) Use HAL_DMA_Abort() function to abort the current transfer
63
64 -@- In Memory-to-Memory transfer mode, Circular mode is not allowed.
65
66 -@- The FIFO is used mainly to reduce bus usage and to allow data packing/unpacking: it is
67 possible to set different Data Sizes for the Peripheral and the Memory (ie. you can set
68 Half-Word data size for the peripheral to access its data register and set Word data size
69 for the Memory to gain in access time. Each two half words will be packed and written in
70 a single access to a Word in the Memory).
71
72 -@- When FIFO is disabled, it is not allowed to configure different Data Sizes for Source
73 and Destination. In this case the Peripheral Data Size will be applied to both Source
74 and Destination.
75
76 *** DMA HAL driver macros list ***
77 =============================================
78 [..]
79 Below the list of most used macros in DMA HAL driver.
80
81 (+) __HAL_DMA_ENABLE: Enable the specified DMA Stream.
82 (+) __HAL_DMA_DISABLE: Disable the specified DMA Stream.
83 (+) __HAL_DMA_GET_FS: Return the current DMA Stream FIFO filled level.
84 (+) __HAL_DMA_ENABLE_IT: Enable the specified DMA Stream interrupts.
85 (+) __HAL_DMA_DISABLE_IT: Disable the specified DMA Stream interrupts.
86 (+) __HAL_DMA_GET_IT_SOURCE: Check whether the specified DMA Stream interrupt has occurred or not.
87
88 [..]
89 (@) You can refer to the DMA HAL driver header file for more useful macros.
90
91 @endverbatim
92 */
93
94/* Includes ------------------------------------------------------------------*/
95#include "stm32h7xx_hal.h"
96
97/** @addtogroup STM32H7xx_HAL_Driver
98 * @{
99 */
100
101/** @defgroup DMA DMA
102 * @brief DMA HAL module driver
103 * @{
104 */
105
106#ifdef HAL_DMA_MODULE_ENABLED
107
108/* Private types -------------------------------------------------------------*/
109/** @addtogroup DMA_Private_Types
110 * @{
111 */
112typedef struct
113{
114 __IO uint32_t ISR; /*!< DMA interrupt status register */
115 __IO uint32_t Reserved0;
116 __IO uint32_t IFCR; /*!< DMA interrupt flag clear register */
117} DMA_Base_Registers;
118
119typedef struct
120{
121 __IO uint32_t ISR; /*!< BDMA interrupt status register */
122 __IO uint32_t IFCR; /*!< BDMA interrupt flag clear register */
123} BDMA_Base_Registers;
124/**
125 * @}
126 */
127
128/* Private variables ---------------------------------------------------------*/
129/* Private constants ---------------------------------------------------------*/
130/** @addtogroup DMA_Private_Constants
131 * @{
132 */
133#define HAL_TIMEOUT_DMA_ABORT (5U) /* 5 ms */
134
135#define BDMA_PERIPH_TO_MEMORY (0x00000000U) /*!< Peripheral to memory direction */
136#define BDMA_MEMORY_TO_PERIPH ((uint32_t)BDMA_CCR_DIR) /*!< Memory to peripheral direction */
137#define BDMA_MEMORY_TO_MEMORY ((uint32_t)BDMA_CCR_MEM2MEM) /*!< Memory to memory direction */
138
139/* DMA to BDMA conversion */
140#define DMA_TO_BDMA_DIRECTION(__DMA_DIRECTION__) (((__DMA_DIRECTION__) == DMA_MEMORY_TO_PERIPH)? BDMA_MEMORY_TO_PERIPH: \
141 ((__DMA_DIRECTION__) == DMA_MEMORY_TO_MEMORY)? BDMA_MEMORY_TO_MEMORY: \
142 BDMA_PERIPH_TO_MEMORY)
143
144#define DMA_TO_BDMA_PERIPHERAL_INC(__DMA_PERIPHERAL_INC__) ((__DMA_PERIPHERAL_INC__) >> 3U)
145#define DMA_TO_BDMA_MEMORY_INC(__DMA_MEMORY_INC__) ((__DMA_MEMORY_INC__) >> 3U)
146
147#define DMA_TO_BDMA_PDATA_SIZE(__DMA_PDATA_SIZE__) ((__DMA_PDATA_SIZE__) >> 3U)
148#define DMA_TO_BDMA_MDATA_SIZE(__DMA_MDATA_SIZE__) ((__DMA_MDATA_SIZE__) >> 3U)
149
150#define DMA_TO_BDMA_MODE(__DMA_MODE__) ((__DMA_MODE__) >> 3U)
151
152#define DMA_TO_BDMA_PRIORITY(__DMA_PRIORITY__) ((__DMA_PRIORITY__) >> 4U)
153
154#if defined(UART9)
155#define IS_DMA_UART_USART_REQUEST(__REQUEST__) ((((__REQUEST__) >= DMA_REQUEST_USART1_RX) && ((__REQUEST__) <= DMA_REQUEST_USART3_TX)) || \
156 (((__REQUEST__) >= DMA_REQUEST_UART4_RX) && ((__REQUEST__) <= DMA_REQUEST_UART5_TX )) || \
157 (((__REQUEST__) >= DMA_REQUEST_USART6_RX) && ((__REQUEST__) <= DMA_REQUEST_USART6_TX)) || \
158 (((__REQUEST__) >= DMA_REQUEST_UART7_RX) && ((__REQUEST__) <= DMA_REQUEST_UART8_TX )) || \
159 (((__REQUEST__) >= DMA_REQUEST_UART9_RX) && ((__REQUEST__) <= DMA_REQUEST_USART10_TX )))
160#else
161#define IS_DMA_UART_USART_REQUEST(__REQUEST__) ((((__REQUEST__) >= DMA_REQUEST_USART1_RX) && ((__REQUEST__) <= DMA_REQUEST_USART3_TX)) || \
162 (((__REQUEST__) >= DMA_REQUEST_UART4_RX) && ((__REQUEST__) <= DMA_REQUEST_UART5_TX )) || \
163 (((__REQUEST__) >= DMA_REQUEST_USART6_RX) && ((__REQUEST__) <= DMA_REQUEST_USART6_TX)) || \
164 (((__REQUEST__) >= DMA_REQUEST_UART7_RX) && ((__REQUEST__) <= DMA_REQUEST_UART8_TX )))
165
166#endif
167/**
168 * @}
169 */
170/* Private macros ------------------------------------------------------------*/
171/* Private functions ---------------------------------------------------------*/
172/** @addtogroup DMA_Private_Functions
173 * @{
174 */
175static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
176static uint32_t DMA_CalcBaseAndBitshift(DMA_HandleTypeDef *hdma);
177static HAL_StatusTypeDef DMA_CheckFifoParam(const DMA_HandleTypeDef *hdma);
178static void DMA_CalcDMAMUXChannelBaseAndMask(DMA_HandleTypeDef *hdma);
179static void DMA_CalcDMAMUXRequestGenBaseAndMask(DMA_HandleTypeDef *hdma);
180
181/**
182 * @}
183 */
184
185/* Exported functions ---------------------------------------------------------*/
186/** @addtogroup DMA_Exported_Functions
187 * @{
188 */
189
190/** @addtogroup DMA_Exported_Functions_Group1
191 *
192@verbatim
193 ===============================================================================
194 ##### Initialization and de-initialization functions #####
195 ===============================================================================
196 [..]
197 This section provides functions allowing to initialize the DMA Stream source
198 and destination incrementation and data sizes, transfer direction,
199 circular/normal mode selection, memory-to-memory mode selection and Stream priority value.
200 [..]
201 The HAL_DMA_Init() function follows the DMA configuration procedures as described in
202 reference manual.
203 The HAL_DMA_DeInit function allows to deinitialize the DMA stream.
204
205@endverbatim
206 * @{
207 */
208
209/**
210 * @brief Initialize the DMA according to the specified
211 * parameters in the DMA_InitTypeDef and create the associated handle.
212 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
213 * the configuration information for the specified DMA Stream.
214 * @retval HAL status
215 */
217{
218 uint32_t registerValue;
219 uint32_t tickstart = HAL_GetTick();
220 DMA_Base_Registers *regs_dma;
221 BDMA_Base_Registers *regs_bdma;
222
223 /* Check the DMA peripheral handle */
224 if(hdma == NULL)
225 {
226 return HAL_ERROR;
227 }
228
229 /* Check the parameters */
238
239 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
240 {
243 /* Check the memory burst, peripheral burst and FIFO threshold parameters only
244 when FIFO mode is enabled */
246 {
250 }
251
252 /* Change DMA peripheral state */
254
255 /* Allocate lock resource */
256 __HAL_UNLOCK(hdma);
257
258 /* Disable the peripheral */
259 __HAL_DMA_DISABLE(hdma);
260
261 /* Check if the DMA Stream is effectively disabled */
262 while((((DMA_Stream_TypeDef *)hdma->Instance)->CR & DMA_SxCR_EN) != 0U)
263 {
264 /* Check for the Timeout */
265 if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA_ABORT)
266 {
267 /* Update error code */
269
270 /* Change the DMA state */
272
273 return HAL_ERROR;
274 }
275 }
276
277 /* Get the CR register value */
278 registerValue = ((DMA_Stream_TypeDef *)hdma->Instance)->CR;
279
280 /* Clear CHSEL, MBURST, PBURST, PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR, CT and DBM bits */
281 registerValue &= ((uint32_t)~(DMA_SxCR_MBURST | DMA_SxCR_PBURST | \
285
286 /* Prepare the DMA Stream configuration */
287 registerValue |= hdma->Init.Direction |
288 hdma->Init.PeriphInc | hdma->Init.MemInc |
290 hdma->Init.Mode | hdma->Init.Priority;
291
292 /* the Memory burst and peripheral burst are not used when the FIFO is disabled */
294 {
295 /* Get memory burst and peripheral burst */
296 registerValue |= hdma->Init.MemBurst | hdma->Init.PeriphBurst;
297 }
298
299 /* Work around for Errata 2.22: UART/USART- DMA transfer lock: DMA stream could be
300 lock when transferring data to/from USART/UART */
301#if (STM32H7_DEV_ID == 0x450UL)
302 if(((DBGMCU->IDCODE & 0xFFFF0000U) >= 0x20000000U) && (IS_DMA_UART_USART_REQUEST(hdma->Init.Request) != 0U))
303#else
304 if(IS_DMA_UART_USART_REQUEST(hdma->Init.Request) != 0U)
305#endif /* STM32H7_DEV_ID == 0x450UL */
306 {
307 registerValue |= DMA_SxCR_TRBUFF;
308 }
309
310 /* Write to DMA Stream CR register */
311 ((DMA_Stream_TypeDef *)hdma->Instance)->CR = registerValue;
312
313 /* Get the FCR register value */
314 registerValue = ((DMA_Stream_TypeDef *)hdma->Instance)->FCR;
315
316 /* Clear Direct mode and FIFO threshold bits */
317 registerValue &= (uint32_t)~(DMA_SxFCR_DMDIS | DMA_SxFCR_FTH);
318
319 /* Prepare the DMA Stream FIFO configuration */
320 registerValue |= hdma->Init.FIFOMode;
321
322 /* the FIFO threshold is not used when the FIFO mode is disabled */
324 {
325 /* Get the FIFO threshold */
326 registerValue |= hdma->Init.FIFOThreshold;
327
328 /* Check compatibility between FIFO threshold level and size of the memory burst */
329 /* for INCR4, INCR8, INCR16 */
330 if(hdma->Init.MemBurst != DMA_MBURST_SINGLE)
331 {
332 if (DMA_CheckFifoParam(hdma) != HAL_OK)
333 {
334 /* Update error code */
336
337 /* Change the DMA state */
339
340 return HAL_ERROR;
341 }
342 }
343 }
344
345 /* Write to DMA Stream FCR */
346 ((DMA_Stream_TypeDef *)hdma->Instance)->FCR = registerValue;
347
348 /* Initialize StreamBaseAddress and StreamIndex parameters to be used to calculate
349 DMA steam Base Address needed by HAL_DMA_IRQHandler() and HAL_DMA_PollForTransfer() */
350 regs_dma = (DMA_Base_Registers *)DMA_CalcBaseAndBitshift(hdma);
351
352 /* Clear all interrupt flags */
353 regs_dma->IFCR = 0x3FUL << (hdma->StreamIndex & 0x1FU);
354 }
355 else if(IS_BDMA_CHANNEL_INSTANCE(hdma->Instance) != 0U) /* BDMA instance(s) */
356 {
358 {
359 /* Check the request parameter */
361 }
362
363 /* Change DMA peripheral state */
365
366 /* Allocate lock resource */
367 __HAL_UNLOCK(hdma);
368
369 /* Get the CR register value */
370 registerValue = ((BDMA_Channel_TypeDef *)hdma->Instance)->CCR;
371
372 /* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR, MEM2MEM, DBM and CT bits */
373 registerValue &= ((uint32_t)~(BDMA_CCR_PL | BDMA_CCR_MSIZE | BDMA_CCR_PSIZE | \
376 BDMA_CCR_CT));
377
378 /* Prepare the DMA Channel configuration */
379 registerValue |= DMA_TO_BDMA_DIRECTION(hdma->Init.Direction) |
380 DMA_TO_BDMA_PERIPHERAL_INC(hdma->Init.PeriphInc) |
381 DMA_TO_BDMA_MEMORY_INC(hdma->Init.MemInc) |
382 DMA_TO_BDMA_PDATA_SIZE(hdma->Init.PeriphDataAlignment) |
383 DMA_TO_BDMA_MDATA_SIZE(hdma->Init.MemDataAlignment) |
384 DMA_TO_BDMA_MODE(hdma->Init.Mode) |
385 DMA_TO_BDMA_PRIORITY(hdma->Init.Priority);
386
387 /* Write to DMA Channel CR register */
388 ((BDMA_Channel_TypeDef *)hdma->Instance)->CCR = registerValue;
389
390 /* calculation of the channel index */
391 hdma->StreamIndex = (((uint32_t)((uint32_t*)hdma->Instance) - (uint32_t)BDMA_Channel0) / ((uint32_t)BDMA_Channel1 - (uint32_t)BDMA_Channel0)) << 2U;
392
393 /* Initialize StreamBaseAddress and StreamIndex parameters to be used to calculate
394 DMA steam Base Address needed by HAL_DMA_IRQHandler() and HAL_DMA_PollForTransfer() */
395 regs_bdma = (BDMA_Base_Registers *)DMA_CalcBaseAndBitshift(hdma);
396
397 /* Clear all interrupt flags */
398 regs_bdma->IFCR = ((BDMA_IFCR_CGIF0) << (hdma->StreamIndex & 0x1FU));
399 }
400 else
401 {
404
405 return HAL_ERROR;
406 }
407
408 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
409 {
410 /* Initialize parameters for DMAMUX channel :
411 DMAmuxChannel, DMAmuxChannelStatus and DMAmuxChannelStatusMask
412 */
413 DMA_CalcDMAMUXChannelBaseAndMask(hdma);
414
416 {
417 /* if memory to memory force the request to 0*/
419 }
420
421 /* Set peripheral request to DMAMUX channel */
423
424 /* Clear the DMAMUX synchro overrun flag */
426
427 /* Initialize parameters for DMAMUX request generator :
428 if the DMA request is DMA_REQUEST_GENERATOR0 to DMA_REQUEST_GENERATOR7
429 */
431 {
432 /* Initialize parameters for DMAMUX request generator :
433 DMAmuxRequestGen, DMAmuxRequestGenStatus and DMAmuxRequestGenStatusMask */
434 DMA_CalcDMAMUXRequestGenBaseAndMask(hdma);
435
436 /* Reset the DMAMUX request generator register */
437 hdma->DMAmuxRequestGen->RGCR = 0U;
438
439 /* Clear the DMAMUX request generator overrun flag */
441 }
442 else
443 {
444 hdma->DMAmuxRequestGen = 0U;
445 hdma->DMAmuxRequestGenStatus = 0U;
447 }
448 }
449
450 /* Initialize the error code */
452
453 /* Initialize the DMA state */
455
456 return HAL_OK;
457}
458
459/**
460 * @brief DeInitializes the DMA peripheral
461 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
462 * the configuration information for the specified DMA Stream.
463 * @retval HAL status
464 */
466{
467 DMA_Base_Registers *regs_dma;
468 BDMA_Base_Registers *regs_bdma;
469
470 /* Check the DMA peripheral handle */
471 if(hdma == NULL)
472 {
473 return HAL_ERROR;
474 }
475
476 /* Disable the selected DMA Streamx */
477 __HAL_DMA_DISABLE(hdma);
478
479 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
480 {
481 /* Reset DMA Streamx control register */
482 ((DMA_Stream_TypeDef *)hdma->Instance)->CR = 0U;
483
484 /* Reset DMA Streamx number of data to transfer register */
485 ((DMA_Stream_TypeDef *)hdma->Instance)->NDTR = 0U;
486
487 /* Reset DMA Streamx peripheral address register */
488 ((DMA_Stream_TypeDef *)hdma->Instance)->PAR = 0U;
489
490 /* Reset DMA Streamx memory 0 address register */
491 ((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = 0U;
492
493 /* Reset DMA Streamx memory 1 address register */
494 ((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = 0U;
495
496 /* Reset DMA Streamx FIFO control register */
497 ((DMA_Stream_TypeDef *)hdma->Instance)->FCR = (uint32_t)0x00000021U;
498
499 /* Get DMA steam Base Address */
500 regs_dma = (DMA_Base_Registers *)DMA_CalcBaseAndBitshift(hdma);
501
502 /* Clear all interrupt flags at correct offset within the register */
503 regs_dma->IFCR = 0x3FUL << (hdma->StreamIndex & 0x1FU);
504 }
505 else if(IS_BDMA_CHANNEL_INSTANCE(hdma->Instance) != 0U) /* BDMA instance(s) */
506 {
507 /* Reset DMA Channel control register */
508 ((BDMA_Channel_TypeDef *)hdma->Instance)->CCR = 0U;
509
510 /* Reset DMA Channel Number of Data to Transfer register */
511 ((BDMA_Channel_TypeDef *)hdma->Instance)->CNDTR = 0U;
512
513 /* Reset DMA Channel peripheral address register */
514 ((BDMA_Channel_TypeDef *)hdma->Instance)->CPAR = 0U;
515
516 /* Reset DMA Channel memory 0 address register */
517 ((BDMA_Channel_TypeDef *)hdma->Instance)->CM0AR = 0U;
518
519 /* Reset DMA Channel memory 1 address register */
520 ((BDMA_Channel_TypeDef *)hdma->Instance)->CM1AR = 0U;
521
522 /* Get DMA steam Base Address */
523 regs_bdma = (BDMA_Base_Registers *)DMA_CalcBaseAndBitshift(hdma);
524
525 /* Clear all interrupt flags at correct offset within the register */
526 regs_bdma->IFCR = ((BDMA_IFCR_CGIF0) << (hdma->StreamIndex & 0x1FU));
527 }
528 else
529 {
530 /* Return error status */
531 return HAL_ERROR;
532 }
533
534#if defined (BDMA1) /* No DMAMUX available for BDMA1 available on STM32H7Ax/Bx devices only */
535 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
536#endif /* BDMA1 */
537 {
538 /* Initialize parameters for DMAMUX channel :
539 DMAmuxChannel, DMAmuxChannelStatus and DMAmuxChannelStatusMask */
540 DMA_CalcDMAMUXChannelBaseAndMask(hdma);
541
542 if(hdma->DMAmuxChannel != 0U)
543 {
544 /* Resett he DMAMUX channel that corresponds to the DMA stream */
545 hdma->DMAmuxChannel->CCR = 0U;
546
547 /* Clear the DMAMUX synchro overrun flag */
549 }
550
552 {
553 /* Initialize parameters for DMAMUX request generator :
554 DMAmuxRequestGen, DMAmuxRequestGenStatus and DMAmuxRequestGenStatusMask */
555 DMA_CalcDMAMUXRequestGenBaseAndMask(hdma);
556
557 /* Reset the DMAMUX request generator register */
558 hdma->DMAmuxRequestGen->RGCR = 0U;
559
560 /* Clear the DMAMUX request generator overrun flag */
562 }
563
564 hdma->DMAmuxRequestGen = 0U;
565 hdma->DMAmuxRequestGenStatus = 0U;
567 }
568
569
570 /* Clean callbacks */
571 hdma->XferCpltCallback = NULL;
573 hdma->XferM1CpltCallback = NULL;
575 hdma->XferErrorCallback = NULL;
576 hdma->XferAbortCallback = NULL;
577
578 /* Initialize the error code */
580
581 /* Initialize the DMA state */
583
584 /* Release Lock */
585 __HAL_UNLOCK(hdma);
586
587 return HAL_OK;
588}
589
590/**
591 * @}
592 */
593
594/** @addtogroup DMA_Exported_Functions_Group2
595 *
596@verbatim
597 ===============================================================================
598 ##### IO operation functions #####
599 ===============================================================================
600 [..] This section provides functions allowing to:
601 (+) Configure the source, destination address and data length and Start DMA transfer
602 (+) Configure the source, destination address and data length and
603 Start DMA transfer with interrupt
604 (+) Register and Unregister DMA callbacks
605 (+) Abort DMA transfer
606 (+) Poll for transfer complete
607 (+) Handle DMA interrupt request
608
609@endverbatim
610 * @{
611 */
612
613/**
614 * @brief Starts the DMA Transfer.
615 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
616 * the configuration information for the specified DMA Stream.
617 * @param SrcAddress: The source memory Buffer address
618 * @param DstAddress: The destination memory Buffer address
619 * @param DataLength: The length of data to be transferred from source to destination
620 * @retval HAL status
621 */
622HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
623{
625
626 /* Check the parameters */
627 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
628
629 /* Check the DMA peripheral handle */
630 if(hdma == NULL)
631 {
632 return HAL_ERROR;
633 }
634
635 /* Process locked */
636 __HAL_LOCK(hdma);
637
638 if(HAL_DMA_STATE_READY == hdma->State)
639 {
640 /* Change DMA peripheral state */
642
643 /* Initialize the error code */
645
646 /* Disable the peripheral */
647 __HAL_DMA_DISABLE(hdma);
648
649 /* Configure the source, destination address and the data length */
650 DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
651
652 /* Enable the Peripheral */
653 __HAL_DMA_ENABLE(hdma);
654 }
655 else
656 {
657 /* Set the error code to busy */
659
660 /* Process unlocked */
661 __HAL_UNLOCK(hdma);
662
663 /* Return error status */
665 }
666 return status;
667}
668
669/**
670 * @brief Start the DMA Transfer with interrupt enabled.
671 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
672 * the configuration information for the specified DMA Stream.
673 * @param SrcAddress: The source memory Buffer address
674 * @param DstAddress: The destination memory Buffer address
675 * @param DataLength: The length of data to be transferred from source to destination
676 * @retval HAL status
677 */
678HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
679{
681
682 /* Check the parameters */
683 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
684
685 /* Check the DMA peripheral handle */
686 if(hdma == NULL)
687 {
688 return HAL_ERROR;
689 }
690
691 /* Process locked */
692 __HAL_LOCK(hdma);
693
694 if(HAL_DMA_STATE_READY == hdma->State)
695 {
696 /* Change DMA peripheral state */
698
699 /* Initialize the error code */
701
702 /* Disable the peripheral */
703 __HAL_DMA_DISABLE(hdma);
704
705 /* Configure the source, destination address and the data length */
706 DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
707
708 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
709 {
710 /* Enable Common interrupts*/
712
713 if(hdma->XferHalfCpltCallback != NULL)
714 {
715 /* Enable Half Transfer IT if corresponding Callback is set */
716 ((DMA_Stream_TypeDef *)hdma->Instance)->CR |= DMA_IT_HT;
717 }
718 }
719 else /* BDMA channel */
720 {
721 /* Enable Common interrupts */
723
724 if(hdma->XferHalfCpltCallback != NULL)
725 {
726 /*Enable Half Transfer IT if corresponding Callback is set */
728 }
729 }
730
731 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
732 {
733 /* Check if DMAMUX Synchronization is enabled */
734 if((hdma->DMAmuxChannel->CCR & DMAMUX_CxCR_SE) != 0U)
735 {
736 /* Enable DMAMUX sync overrun IT*/
738 }
739
740 if(hdma->DMAmuxRequestGen != 0U)
741 {
742 /* if using DMAMUX request generator, enable the DMAMUX request generator overrun IT*/
743 /* enable the request gen overrun IT */
745 }
746 }
747
748 /* Enable the Peripheral */
749 __HAL_DMA_ENABLE(hdma);
750 }
751 else
752 {
753 /* Set the error code to busy */
755
756 /* Process unlocked */
757 __HAL_UNLOCK(hdma);
758
759 /* Return error status */
761 }
762
763 return status;
764}
765
766/**
767 * @brief Aborts the DMA Transfer.
768 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
769 * the configuration information for the specified DMA Stream.
770 *
771 * @note After disabling a DMA Stream, a check for wait until the DMA Stream is
772 * effectively disabled is added. If a Stream is disabled
773 * while a data transfer is ongoing, the current data will be transferred
774 * and the Stream will be effectively disabled only after the transfer of
775 * this single data is finished.
776 * @retval HAL status
777 */
779{
780 /* calculate DMA base and stream number */
781 DMA_Base_Registers *regs_dma;
782 BDMA_Base_Registers *regs_bdma;
783 const __IO uint32_t *enableRegister;
784
785 uint32_t tickstart = HAL_GetTick();
786
787 /* Check the DMA peripheral handle */
788 if(hdma == NULL)
789 {
790 return HAL_ERROR;
791 }
792
793 /* Check the DMA peripheral state */
794 if(hdma->State != HAL_DMA_STATE_BUSY)
795 {
797
798 /* Process Unlocked */
799 __HAL_UNLOCK(hdma);
800
801 return HAL_ERROR;
802 }
803 else
804 {
805 /* Disable the stream/channel */
806 __HAL_DMA_DISABLE(hdma);
807
808 /* Disable all the transfer interrupts */
809 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
810 {
811 /* Disable DMA All Interrupts */
813 ((DMA_Stream_TypeDef *)hdma->Instance)->FCR &= ~(DMA_IT_FE);
814
815 enableRegister = (__IO uint32_t *)(&(((DMA_Stream_TypeDef *)hdma->Instance)->CR));
816 }
817 else /* BDMA channel */
818 {
819 /* Disable DMA All Interrupts */
821
822 enableRegister = (__IO uint32_t *)(&(((BDMA_Channel_TypeDef *)hdma->Instance)->CCR));
823 }
824
825 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
826 {
827 /* disable the DMAMUX sync overrun IT */
829 }
830
831 /* Check if the DMA Stream is effectively disabled */
832 while(((*enableRegister) & DMA_SxCR_EN) != 0U)
833 {
834 /* Check for the Timeout */
835 if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA_ABORT)
836 {
837 /* Update error code */
839
840 /* Change the DMA state */
842
843 /* Process Unlocked */
844 __HAL_UNLOCK(hdma);
845
846 return HAL_ERROR;
847 }
848 }
849
850 /* Clear all interrupt flags at correct offset within the register */
851 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
852 {
853 regs_dma = (DMA_Base_Registers *)hdma->StreamBaseAddress;
854 regs_dma->IFCR = 0x3FUL << (hdma->StreamIndex & 0x1FU);
855 }
856 else /* BDMA channel */
857 {
858 regs_bdma = (BDMA_Base_Registers *)hdma->StreamBaseAddress;
859 regs_bdma->IFCR = ((BDMA_IFCR_CGIF0) << (hdma->StreamIndex & 0x1FU));
860 }
861
862 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
863 {
864 /* Clear the DMAMUX synchro overrun flag */
866
867 if(hdma->DMAmuxRequestGen != 0U)
868 {
869 /* if using DMAMUX request generator, disable the DMAMUX request generator overrun IT */
870 /* disable the request gen overrun IT */
872
873 /* Clear the DMAMUX request generator overrun flag */
875 }
876 }
877
878 /* Change the DMA state */
880
881 /* Process Unlocked */
882 __HAL_UNLOCK(hdma);
883 }
884
885 return HAL_OK;
886}
887
888/**
889 * @brief Aborts the DMA Transfer in Interrupt mode.
890 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
891 * the configuration information for the specified DMA Stream.
892 * @retval HAL status
893 */
895{
896 BDMA_Base_Registers *regs_bdma;
897
898 /* Check the DMA peripheral handle */
899 if(hdma == NULL)
900 {
901 return HAL_ERROR;
902 }
903
904 if(hdma->State != HAL_DMA_STATE_BUSY)
905 {
907 return HAL_ERROR;
908 }
909 else
910 {
911 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
912 {
913 /* Set Abort State */
915
916 /* Disable the stream */
917 __HAL_DMA_DISABLE(hdma);
918 }
919 else /* BDMA channel */
920 {
921 /* Disable the channel */
922 __HAL_DMA_DISABLE(hdma);
923
924 /* Disable DMA All Interrupts */
926
927 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
928 {
929 /* disable the DMAMUX sync overrun IT */
931
932 /* Clear all flags */
933 regs_bdma = (BDMA_Base_Registers *)hdma->StreamBaseAddress;
934 regs_bdma->IFCR = ((BDMA_IFCR_CGIF0) << (hdma->StreamIndex & 0x1FU));
935
936 /* Clear the DMAMUX synchro overrun flag */
938
939 if(hdma->DMAmuxRequestGen != 0U)
940 {
941 /* if using DMAMUX request generator, disable the DMAMUX request generator overrun IT*/
942 /* disable the request gen overrun IT */
944
945 /* Clear the DMAMUX request generator overrun flag */
947 }
948 }
949
950 /* Change the DMA state */
952
953 /* Process Unlocked */
954 __HAL_UNLOCK(hdma);
955
956 /* Call User Abort callback */
957 if(hdma->XferAbortCallback != NULL)
958 {
959 hdma->XferAbortCallback(hdma);
960 }
961 }
962 }
963
964 return HAL_OK;
965}
966
967/**
968 * @brief Polling for transfer complete.
969 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
970 * the configuration information for the specified DMA Stream.
971 * @param CompleteLevel: Specifies the DMA level complete.
972 * @note The polling mode is kept in this version for legacy. it is recommended to use the IT model instead.
973 * This model could be used for debug purpose.
974 * @note The HAL_DMA_PollForTransfer API cannot be used in circular and double buffering mode (automatic circular mode).
975 * @param Timeout: Timeout duration.
976 * @retval HAL status
977 */
979{
981 uint32_t cpltlevel_mask;
982 uint32_t tickstart = HAL_GetTick();
983
984 /* IT status register */
985 __IO uint32_t *isr_reg;
986 /* IT clear flag register */
987 __IO uint32_t *ifcr_reg;
988
989 /* Check the DMA peripheral handle */
990 if(hdma == NULL)
991 {
992 return HAL_ERROR;
993 }
994
995 if(HAL_DMA_STATE_BUSY != hdma->State)
996 {
997 /* No transfer ongoing */
999 __HAL_UNLOCK(hdma);
1000
1001 return HAL_ERROR;
1002 }
1003
1004 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
1005 {
1006 /* Polling mode not supported in circular mode and double buffering mode */
1007 if ((((DMA_Stream_TypeDef *)hdma->Instance)->CR & DMA_SxCR_CIRC) != 0U)
1008 {
1010 return HAL_ERROR;
1011 }
1012
1013 /* Get the level transfer complete flag */
1014 if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
1015 {
1016 /* Transfer Complete flag */
1017 cpltlevel_mask = DMA_FLAG_TCIF0_4 << (hdma->StreamIndex & 0x1FU);
1018 }
1019 else
1020 {
1021 /* Half Transfer Complete flag */
1022 cpltlevel_mask = DMA_FLAG_HTIF0_4 << (hdma->StreamIndex & 0x1FU);
1023 }
1024
1025 isr_reg = &(((DMA_Base_Registers *)hdma->StreamBaseAddress)->ISR);
1026 ifcr_reg = &(((DMA_Base_Registers *)hdma->StreamBaseAddress)->IFCR);
1027 }
1028 else /* BDMA channel */
1029 {
1030 /* Polling mode not supported in circular mode */
1031 if ((((BDMA_Channel_TypeDef *)hdma->Instance)->CCR & BDMA_CCR_CIRC) != 0U)
1032 {
1034 return HAL_ERROR;
1035 }
1036
1037 /* Get the level transfer complete flag */
1038 if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
1039 {
1040 /* Transfer Complete flag */
1041 cpltlevel_mask = BDMA_FLAG_TC0 << (hdma->StreamIndex & 0x1FU);
1042 }
1043 else
1044 {
1045 /* Half Transfer Complete flag */
1046 cpltlevel_mask = BDMA_FLAG_HT0 << (hdma->StreamIndex & 0x1FU);
1047 }
1048
1049 isr_reg = &(((BDMA_Base_Registers *)hdma->StreamBaseAddress)->ISR);
1050 ifcr_reg = &(((BDMA_Base_Registers *)hdma->StreamBaseAddress)->IFCR);
1051 }
1052
1053 while(((*isr_reg) & cpltlevel_mask) == 0U)
1054 {
1055 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
1056 {
1057 if(((*isr_reg) & (DMA_FLAG_FEIF0_4 << (hdma->StreamIndex & 0x1FU))) != 0U)
1058 {
1059 /* Update error code */
1060 hdma->ErrorCode |= HAL_DMA_ERROR_FE;
1061
1062 /* Clear the FIFO error flag */
1063 (*ifcr_reg) = DMA_FLAG_FEIF0_4 << (hdma->StreamIndex & 0x1FU);
1064 }
1065
1066 if(((*isr_reg) & (DMA_FLAG_DMEIF0_4 << (hdma->StreamIndex & 0x1FU))) != 0U)
1067 {
1068 /* Update error code */
1070
1071 /* Clear the Direct Mode error flag */
1072 (*ifcr_reg) = DMA_FLAG_DMEIF0_4 << (hdma->StreamIndex & 0x1FU);
1073 }
1074
1075 if(((*isr_reg) & (DMA_FLAG_TEIF0_4 << (hdma->StreamIndex & 0x1FU))) != 0U)
1076 {
1077 /* Update error code */
1078 hdma->ErrorCode |= HAL_DMA_ERROR_TE;
1079
1080 /* Clear the transfer error flag */
1081 (*ifcr_reg) = DMA_FLAG_TEIF0_4 << (hdma->StreamIndex & 0x1FU);
1082
1083 /* Change the DMA state */
1084 hdma->State = HAL_DMA_STATE_READY;
1085
1086 /* Process Unlocked */
1087 __HAL_UNLOCK(hdma);
1088
1089 return HAL_ERROR;
1090 }
1091 }
1092 else /* BDMA channel */
1093 {
1094 if(((*isr_reg) & (BDMA_FLAG_TE0 << (hdma->StreamIndex & 0x1FU))) != 0U)
1095 {
1096 /* When a DMA transfer error occurs */
1097 /* A hardware clear of its EN bits is performed */
1098 /* Clear all flags */
1099 (*isr_reg) = ((BDMA_ISR_GIF0) << (hdma->StreamIndex & 0x1FU));
1100
1101 /* Update error code */
1103
1104 /* Change the DMA state */
1105 hdma->State = HAL_DMA_STATE_READY;
1106
1107 /* Process Unlocked */
1108 __HAL_UNLOCK(hdma);
1109
1110 return HAL_ERROR;
1111 }
1112 }
1113
1114 /* Check for the Timeout (Not applicable in circular mode)*/
1115 if(Timeout != HAL_MAX_DELAY)
1116 {
1117 if(((HAL_GetTick() - tickstart ) > Timeout)||(Timeout == 0U))
1118 {
1119 /* Update error code */
1121
1122 /* if timeout then abort the current transfer */
1123 /* No need to check return value: as in this case we will return HAL_ERROR with HAL_DMA_ERROR_TIMEOUT error code */
1124 (void) HAL_DMA_Abort(hdma);
1125 /*
1126 Note that the Abort function will
1127 - Clear the transfer error flags
1128 - Unlock
1129 - Set the State
1130 */
1131
1132 return HAL_ERROR;
1133 }
1134 }
1135
1136 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
1137 {
1138 /* Check for DMAMUX Request generator (if used) overrun status */
1139 if(hdma->DMAmuxRequestGen != 0U)
1140 {
1141 /* if using DMAMUX request generator Check for DMAMUX request generator overrun */
1142 if((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)
1143 {
1144 /* Clear the DMAMUX request generator overrun flag */
1146
1147 /* Update error code */
1149 }
1150 }
1151
1152 /* Check for DMAMUX Synchronization overrun */
1153 if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)
1154 {
1155 /* Clear the DMAMUX synchro overrun flag */
1157
1158 /* Update error code */
1160 }
1161 }
1162 }
1163
1164
1165 /* Get the level transfer complete flag */
1166 if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
1167 {
1168 /* Clear the half transfer and transfer complete flags */
1169 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
1170 {
1171 (*ifcr_reg) = (DMA_FLAG_HTIF0_4 | DMA_FLAG_TCIF0_4) << (hdma->StreamIndex & 0x1FU);
1172 }
1173 else /* BDMA channel */
1174 {
1175 (*ifcr_reg) = (BDMA_FLAG_TC0 << (hdma->StreamIndex & 0x1FU));
1176 }
1177
1178 hdma->State = HAL_DMA_STATE_READY;
1179
1180 /* Process Unlocked */
1181 __HAL_UNLOCK(hdma);
1182 }
1183 else /*CompleteLevel = HAL_DMA_HALF_TRANSFER*/
1184 {
1185 /* Clear the half transfer and transfer complete flags */
1186 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
1187 {
1188 (*ifcr_reg) = (DMA_FLAG_HTIF0_4) << (hdma->StreamIndex & 0x1FU);
1189 }
1190 else /* BDMA channel */
1191 {
1192 (*ifcr_reg) = (BDMA_FLAG_HT0 << (hdma->StreamIndex & 0x1FU));
1193 }
1194 }
1195
1196 return status;
1197}
1198
1199/**
1200 * @brief Handles DMA interrupt request.
1201 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1202 * the configuration information for the specified DMA Stream.
1203 * @retval None
1204 */
1206{
1207 uint32_t tmpisr_dma, tmpisr_bdma;
1208 uint32_t ccr_reg;
1209 __IO uint32_t count = 0U;
1210 uint32_t timeout = SystemCoreClock / 9600U;
1211
1212 /* calculate DMA base and stream number */
1213 DMA_Base_Registers *regs_dma = (DMA_Base_Registers *)hdma->StreamBaseAddress;
1214 BDMA_Base_Registers *regs_bdma = (BDMA_Base_Registers *)hdma->StreamBaseAddress;
1215
1216 tmpisr_dma = regs_dma->ISR;
1217 tmpisr_bdma = regs_bdma->ISR;
1218
1219 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
1220 {
1221 /* Transfer Error Interrupt management ***************************************/
1222 if ((tmpisr_dma & (DMA_FLAG_TEIF0_4 << (hdma->StreamIndex & 0x1FU))) != 0U)
1223 {
1224 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TE) != 0U)
1225 {
1226 /* Disable the transfer error interrupt */
1227 ((DMA_Stream_TypeDef *)hdma->Instance)->CR &= ~(DMA_IT_TE);
1228
1229 /* Clear the transfer error flag */
1230 regs_dma->IFCR = DMA_FLAG_TEIF0_4 << (hdma->StreamIndex & 0x1FU);
1231
1232 /* Update error code */
1233 hdma->ErrorCode |= HAL_DMA_ERROR_TE;
1234 }
1235 }
1236 /* FIFO Error Interrupt management ******************************************/
1237 if ((tmpisr_dma & (DMA_FLAG_FEIF0_4 << (hdma->StreamIndex & 0x1FU))) != 0U)
1238 {
1239 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_FE) != 0U)
1240 {
1241 /* Clear the FIFO error flag */
1242 regs_dma->IFCR = DMA_FLAG_FEIF0_4 << (hdma->StreamIndex & 0x1FU);
1243
1244 /* Update error code */
1245 hdma->ErrorCode |= HAL_DMA_ERROR_FE;
1246 }
1247 }
1248 /* Direct Mode Error Interrupt management ***********************************/
1249 if ((tmpisr_dma & (DMA_FLAG_DMEIF0_4 << (hdma->StreamIndex & 0x1FU))) != 0U)
1250 {
1251 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_DME) != 0U)
1252 {
1253 /* Clear the direct mode error flag */
1254 regs_dma->IFCR = DMA_FLAG_DMEIF0_4 << (hdma->StreamIndex & 0x1FU);
1255
1256 /* Update error code */
1258 }
1259 }
1260 /* Half Transfer Complete Interrupt management ******************************/
1261 if ((tmpisr_dma & (DMA_FLAG_HTIF0_4 << (hdma->StreamIndex & 0x1FU))) != 0U)
1262 {
1263 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_HT) != 0U)
1264 {
1265 /* Clear the half transfer complete flag */
1266 regs_dma->IFCR = DMA_FLAG_HTIF0_4 << (hdma->StreamIndex & 0x1FU);
1267
1268 /* Multi_Buffering mode enabled */
1269 if(((((DMA_Stream_TypeDef *)hdma->Instance)->CR) & (uint32_t)(DMA_SxCR_DBM)) != 0U)
1270 {
1271 /* Current memory buffer used is Memory 0 */
1272 if((((DMA_Stream_TypeDef *)hdma->Instance)->CR & DMA_SxCR_CT) == 0U)
1273 {
1274 if(hdma->XferHalfCpltCallback != NULL)
1275 {
1276 /* Half transfer callback */
1277 hdma->XferHalfCpltCallback(hdma);
1278 }
1279 }
1280 /* Current memory buffer used is Memory 1 */
1281 else
1282 {
1283 if(hdma->XferM1HalfCpltCallback != NULL)
1284 {
1285 /* Half transfer callback */
1286 hdma->XferM1HalfCpltCallback(hdma);
1287 }
1288 }
1289 }
1290 else
1291 {
1292 /* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
1293 if((((DMA_Stream_TypeDef *)hdma->Instance)->CR & DMA_SxCR_CIRC) == 0U)
1294 {
1295 /* Disable the half transfer interrupt */
1296 ((DMA_Stream_TypeDef *)hdma->Instance)->CR &= ~(DMA_IT_HT);
1297 }
1298
1299 if(hdma->XferHalfCpltCallback != NULL)
1300 {
1301 /* Half transfer callback */
1302 hdma->XferHalfCpltCallback(hdma);
1303 }
1304 }
1305 }
1306 }
1307 /* Transfer Complete Interrupt management ***********************************/
1308 if ((tmpisr_dma & (DMA_FLAG_TCIF0_4 << (hdma->StreamIndex & 0x1FU))) != 0U)
1309 {
1310 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TC) != 0U)
1311 {
1312 /* Clear the transfer complete flag */
1313 regs_dma->IFCR = DMA_FLAG_TCIF0_4 << (hdma->StreamIndex & 0x1FU);
1314
1315 if(HAL_DMA_STATE_ABORT == hdma->State)
1316 {
1317 /* Disable all the transfer interrupts */
1318 ((DMA_Stream_TypeDef *)hdma->Instance)->CR &= ~(DMA_IT_TC | DMA_IT_TE | DMA_IT_DME);
1319 ((DMA_Stream_TypeDef *)hdma->Instance)->FCR &= ~(DMA_IT_FE);
1320
1321 if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
1322 {
1323 ((DMA_Stream_TypeDef *)hdma->Instance)->CR &= ~(DMA_IT_HT);
1324 }
1325
1326 /* Clear all interrupt flags at correct offset within the register */
1327 regs_dma->IFCR = 0x3FUL << (hdma->StreamIndex & 0x1FU);
1328
1329 /* Change the DMA state */
1330 hdma->State = HAL_DMA_STATE_READY;
1331
1332 /* Process Unlocked */
1333 __HAL_UNLOCK(hdma);
1334
1335 if(hdma->XferAbortCallback != NULL)
1336 {
1337 hdma->XferAbortCallback(hdma);
1338 }
1339 return;
1340 }
1341
1342 if(((((DMA_Stream_TypeDef *)hdma->Instance)->CR) & (uint32_t)(DMA_SxCR_DBM)) != 0U)
1343 {
1344 /* Current memory buffer used is Memory 1 */
1345 if((((DMA_Stream_TypeDef *)hdma->Instance)->CR & DMA_SxCR_CT) != 0U)
1346 {
1347 if(hdma->XferM1CpltCallback != NULL)
1348 {
1349 /* Transfer complete Callback for memory1 */
1350 hdma->XferM1CpltCallback(hdma);
1351 }
1352 }
1353 /* Current memory buffer used is Memory 0 */
1354 else
1355 {
1356 if(hdma->XferCpltCallback != NULL)
1357 {
1358 /* Transfer complete Callback for memory0 */
1359 hdma->XferCpltCallback(hdma);
1360 }
1361 }
1362 }
1363 /* Disable the transfer complete interrupt if the DMA mode is not CIRCULAR */
1364 else
1365 {
1366 if((((DMA_Stream_TypeDef *)hdma->Instance)->CR & DMA_SxCR_CIRC) == 0U)
1367 {
1368 /* Disable the transfer complete interrupt */
1369 ((DMA_Stream_TypeDef *)hdma->Instance)->CR &= ~(DMA_IT_TC);
1370
1371 /* Change the DMA state */
1372 hdma->State = HAL_DMA_STATE_READY;
1373
1374 /* Process Unlocked */
1375 __HAL_UNLOCK(hdma);
1376 }
1377
1378 if(hdma->XferCpltCallback != NULL)
1379 {
1380 /* Transfer complete callback */
1381 hdma->XferCpltCallback(hdma);
1382 }
1383 }
1384 }
1385 }
1386
1387 /* manage error case */
1388 if(hdma->ErrorCode != HAL_DMA_ERROR_NONE)
1389 {
1390 if((hdma->ErrorCode & HAL_DMA_ERROR_TE) != 0U)
1391 {
1392 hdma->State = HAL_DMA_STATE_ABORT;
1393
1394 /* Disable the stream */
1395 __HAL_DMA_DISABLE(hdma);
1396
1397 do
1398 {
1399 if (++count > timeout)
1400 {
1401 break;
1402 }
1403 }
1404 while((((DMA_Stream_TypeDef *)hdma->Instance)->CR & DMA_SxCR_EN) != 0U);
1405
1406 if((((DMA_Stream_TypeDef *)hdma->Instance)->CR & DMA_SxCR_EN) != 0U)
1407 {
1408 /* Change the DMA state to error if DMA disable fails */
1409 hdma->State = HAL_DMA_STATE_ERROR;
1410 }
1411 else
1412 {
1413 /* Change the DMA state to Ready if DMA disable success */
1414 hdma->State = HAL_DMA_STATE_READY;
1415 }
1416
1417 /* Process Unlocked */
1418 __HAL_UNLOCK(hdma);
1419 }
1420
1421 if(hdma->XferErrorCallback != NULL)
1422 {
1423 /* Transfer error callback */
1424 hdma->XferErrorCallback(hdma);
1425 }
1426 }
1427 }
1428 else if(IS_BDMA_CHANNEL_INSTANCE(hdma->Instance) != 0U) /* BDMA instance(s) */
1429 {
1430 ccr_reg = (((BDMA_Channel_TypeDef *)hdma->Instance)->CCR);
1431
1432 /* Half Transfer Complete Interrupt management ******************************/
1433 if (((tmpisr_bdma & (BDMA_FLAG_HT0 << (hdma->StreamIndex & 0x1FU))) != 0U) && ((ccr_reg & BDMA_CCR_HTIE) != 0U))
1434 {
1435 /* Clear the half transfer complete flag */
1436 regs_bdma->IFCR = (BDMA_ISR_HTIF0 << (hdma->StreamIndex & 0x1FU));
1437
1438 /* Disable the transfer complete interrupt if the DMA mode is Double Buffering */
1439 if((ccr_reg & BDMA_CCR_DBM) != 0U)
1440 {
1441 /* Current memory buffer used is Memory 1 */
1442 if((ccr_reg & BDMA_CCR_CT) != 0U)
1443 {
1444 if(hdma->XferM1HalfCpltCallback != NULL)
1445 {
1446 /* Half transfer Callback for Memory 1 */
1447 hdma->XferM1HalfCpltCallback(hdma);
1448 }
1449 }
1450 /* Current memory buffer used is Memory 0 */
1451 else
1452 {
1453 if(hdma->XferHalfCpltCallback != NULL)
1454 {
1455 /* Half transfer Callback for Memory 0 */
1456 hdma->XferHalfCpltCallback(hdma);
1457 }
1458 }
1459 }
1460 else
1461 {
1462 if((ccr_reg & BDMA_CCR_CIRC) == 0U)
1463 {
1464 /* Disable the half transfer interrupt */
1466 }
1467
1468 /* DMA peripheral state is not updated in Half Transfer */
1469 /* but in Transfer Complete case */
1470
1471 if(hdma->XferHalfCpltCallback != NULL)
1472 {
1473 /* Half transfer callback */
1474 hdma->XferHalfCpltCallback(hdma);
1475 }
1476 }
1477 }
1478
1479 /* Transfer Complete Interrupt management ***********************************/
1480 else if (((tmpisr_bdma & (BDMA_FLAG_TC0 << (hdma->StreamIndex & 0x1FU))) != 0U) && ((ccr_reg & BDMA_CCR_TCIE) != 0U))
1481 {
1482 /* Clear the transfer complete flag */
1483 regs_bdma->IFCR = (BDMA_ISR_TCIF0) << (hdma->StreamIndex & 0x1FU);
1484
1485 /* Disable the transfer complete interrupt if the DMA mode is Double Buffering */
1486 if((ccr_reg & BDMA_CCR_DBM) != 0U)
1487 {
1488 /* Current memory buffer used is Memory 0 */
1489 if((ccr_reg & BDMA_CCR_CT) == 0U)
1490 {
1491 if(hdma->XferM1CpltCallback != NULL)
1492 {
1493 /* Transfer complete Callback for Memory 1 */
1494 hdma->XferM1CpltCallback(hdma);
1495 }
1496 }
1497 /* Current memory buffer used is Memory 1 */
1498 else
1499 {
1500 if(hdma->XferCpltCallback != NULL)
1501 {
1502 /* Transfer complete Callback for Memory 0 */
1503 hdma->XferCpltCallback(hdma);
1504 }
1505 }
1506 }
1507 else
1508 {
1509 if((ccr_reg & BDMA_CCR_CIRC) == 0U)
1510 {
1511 /* Disable the transfer complete and error interrupt, if the DMA mode is not CIRCULAR */
1513
1514 /* Change the DMA state */
1515 hdma->State = HAL_DMA_STATE_READY;
1516
1517 /* Process Unlocked */
1518 __HAL_UNLOCK(hdma);
1519 }
1520
1521 if(hdma->XferCpltCallback != NULL)
1522 {
1523 /* Transfer complete callback */
1524 hdma->XferCpltCallback(hdma);
1525 }
1526 }
1527 }
1528 /* Transfer Error Interrupt management **************************************/
1529 else if (((tmpisr_bdma & (BDMA_FLAG_TE0 << (hdma->StreamIndex & 0x1FU))) != 0U) && ((ccr_reg & BDMA_CCR_TEIE) != 0U))
1530 {
1531 /* When a DMA transfer error occurs */
1532 /* A hardware clear of its EN bits is performed */
1533 /* Disable ALL DMA IT */
1535
1536 /* Clear all flags */
1537 regs_bdma->IFCR = (BDMA_ISR_GIF0) << (hdma->StreamIndex & 0x1FU);
1538
1539 /* Update error code */
1541
1542 /* Change the DMA state */
1543 hdma->State = HAL_DMA_STATE_READY;
1544
1545 /* Process Unlocked */
1546 __HAL_UNLOCK(hdma);
1547
1548 if (hdma->XferErrorCallback != NULL)
1549 {
1550 /* Transfer error callback */
1551 hdma->XferErrorCallback(hdma);
1552 }
1553 }
1554 else
1555 {
1556 /* Nothing To Do */
1557 }
1558 }
1559 else
1560 {
1561 /* Nothing To Do */
1562 }
1563}
1564
1565/**
1566 * @brief Register callbacks
1567 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1568 * the configuration information for the specified DMA Stream.
1569 * @param CallbackID: User Callback identifier
1570 * a DMA_HandleTypeDef structure as parameter.
1571 * @param pCallback: pointer to private callback function which has pointer to
1572 * a DMA_HandleTypeDef structure as parameter.
1573 * @retval HAL status
1574 */
1576{
1577
1579
1580 /* Check the DMA peripheral handle */
1581 if(hdma == NULL)
1582 {
1583 return HAL_ERROR;
1584 }
1585
1586 /* Process locked */
1587 __HAL_LOCK(hdma);
1588
1589 if(HAL_DMA_STATE_READY == hdma->State)
1590 {
1591 switch (CallbackID)
1592 {
1594 hdma->XferCpltCallback = pCallback;
1595 break;
1596
1598 hdma->XferHalfCpltCallback = pCallback;
1599 break;
1600
1602 hdma->XferM1CpltCallback = pCallback;
1603 break;
1604
1606 hdma->XferM1HalfCpltCallback = pCallback;
1607 break;
1608
1610 hdma->XferErrorCallback = pCallback;
1611 break;
1612
1614 hdma->XferAbortCallback = pCallback;
1615 break;
1616
1617 default:
1618 status = HAL_ERROR;
1619 break;
1620 }
1621 }
1622 else
1623 {
1624 /* Return error status */
1625 status = HAL_ERROR;
1626 }
1627
1628 /* Release Lock */
1629 __HAL_UNLOCK(hdma);
1630
1631 return status;
1632}
1633
1634/**
1635 * @brief UnRegister callbacks
1636 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1637 * the configuration information for the specified DMA Stream.
1638 * @param CallbackID: User Callback identifier
1639 * a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
1640 * @retval HAL status
1641 */
1643{
1645
1646 /* Check the DMA peripheral handle */
1647 if(hdma == NULL)
1648 {
1649 return HAL_ERROR;
1650 }
1651
1652 /* Process locked */
1653 __HAL_LOCK(hdma);
1654
1655 if(HAL_DMA_STATE_READY == hdma->State)
1656 {
1657 switch (CallbackID)
1658 {
1660 hdma->XferCpltCallback = NULL;
1661 break;
1662
1664 hdma->XferHalfCpltCallback = NULL;
1665 break;
1666
1668 hdma->XferM1CpltCallback = NULL;
1669 break;
1670
1673 break;
1674
1676 hdma->XferErrorCallback = NULL;
1677 break;
1678
1680 hdma->XferAbortCallback = NULL;
1681 break;
1682
1684 hdma->XferCpltCallback = NULL;
1685 hdma->XferHalfCpltCallback = NULL;
1686 hdma->XferM1CpltCallback = NULL;
1688 hdma->XferErrorCallback = NULL;
1689 hdma->XferAbortCallback = NULL;
1690 break;
1691
1692 default:
1693 status = HAL_ERROR;
1694 break;
1695 }
1696 }
1697 else
1698 {
1699 status = HAL_ERROR;
1700 }
1701
1702 /* Release Lock */
1703 __HAL_UNLOCK(hdma);
1704
1705 return status;
1706}
1707
1708/**
1709 * @}
1710 */
1711
1712/** @addtogroup DMA_Exported_Functions_Group3
1713 *
1714@verbatim
1715 ===============================================================================
1716 ##### State and Errors functions #####
1717 ===============================================================================
1718 [..]
1719 This subsection provides functions allowing to
1720 (+) Check the DMA state
1721 (+) Get error code
1722
1723@endverbatim
1724 * @{
1725 */
1726
1727/**
1728 * @brief Returns the DMA state.
1729 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1730 * the configuration information for the specified DMA Stream.
1731 * @retval HAL state
1732 */
1734{
1735 return hdma->State;
1736}
1737
1738/**
1739 * @brief Return the DMA error code
1740 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
1741 * the configuration information for the specified DMA Stream.
1742 * @retval DMA Error Code
1743 */
1744uint32_t HAL_DMA_GetError(const DMA_HandleTypeDef *hdma)
1745{
1746 return hdma->ErrorCode;
1747}
1748
1749/**
1750 * @}
1751 */
1752
1753/**
1754 * @}
1755 */
1756
1757/** @addtogroup DMA_Private_Functions
1758 * @{
1759 */
1760
1761/**
1762 * @brief Sets the DMA Transfer parameter.
1763 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1764 * the configuration information for the specified DMA Stream.
1765 * @param SrcAddress: The source memory Buffer address
1766 * @param DstAddress: The destination memory Buffer address
1767 * @param DataLength: The length of data to be transferred from source to destination
1768 * @retval None
1769 */
1770static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
1771{
1772 /* calculate DMA base and stream number */
1773 DMA_Base_Registers *regs_dma = (DMA_Base_Registers *)hdma->StreamBaseAddress;
1774 BDMA_Base_Registers *regs_bdma = (BDMA_Base_Registers *)hdma->StreamBaseAddress;
1775
1776 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
1777 {
1778 /* Clear the DMAMUX synchro overrun flag */
1780
1781 if(hdma->DMAmuxRequestGen != 0U)
1782 {
1783 /* Clear the DMAMUX request generator overrun flag */
1785 }
1786 }
1787
1788 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
1789 {
1790 /* Clear all interrupt flags at correct offset within the register */
1791 regs_dma->IFCR = 0x3FUL << (hdma->StreamIndex & 0x1FU);
1792
1793 /* Clear DBM bit */
1794 ((DMA_Stream_TypeDef *)hdma->Instance)->CR &= (uint32_t)(~DMA_SxCR_DBM);
1795
1796 /* Configure DMA Stream data length */
1797 ((DMA_Stream_TypeDef *)hdma->Instance)->NDTR = DataLength;
1798
1799 /* Memory to Peripheral */
1800 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
1801 {
1802 /* Configure DMA Stream destination address */
1803 ((DMA_Stream_TypeDef *)hdma->Instance)->PAR = DstAddress;
1804
1805 /* Configure DMA Stream source address */
1806 ((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = SrcAddress;
1807 }
1808 /* Peripheral to Memory */
1809 else
1810 {
1811 /* Configure DMA Stream source address */
1812 ((DMA_Stream_TypeDef *)hdma->Instance)->PAR = SrcAddress;
1813
1814 /* Configure DMA Stream destination address */
1815 ((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = DstAddress;
1816 }
1817 }
1818 else if(IS_BDMA_CHANNEL_INSTANCE(hdma->Instance) != 0U) /* BDMA instance(s) */
1819 {
1820 /* Clear all flags */
1821 regs_bdma->IFCR = (BDMA_ISR_GIF0) << (hdma->StreamIndex & 0x1FU);
1822
1823 /* Configure DMA Channel data length */
1824 ((BDMA_Channel_TypeDef *)hdma->Instance)->CNDTR = DataLength;
1825
1826 /* Memory to Peripheral */
1827 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
1828 {
1829 /* Configure DMA Channel destination address */
1830 ((BDMA_Channel_TypeDef *)hdma->Instance)->CPAR = DstAddress;
1831
1832 /* Configure DMA Channel source address */
1833 ((BDMA_Channel_TypeDef *)hdma->Instance)->CM0AR = SrcAddress;
1834 }
1835 /* Peripheral to Memory*/
1836 else
1837 {
1838 /* Configure DMA Channel source address */
1839 ((BDMA_Channel_TypeDef *)hdma->Instance)->CPAR = SrcAddress;
1840
1841 /* Configure DMA Channel destination address */
1842 ((BDMA_Channel_TypeDef *)hdma->Instance)->CM0AR = DstAddress;
1843 }
1844 }
1845 else
1846 {
1847 /* Nothing To Do */
1848 }
1849}
1850
1851/**
1852 * @brief Returns the DMA Stream base address depending on stream number
1853 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1854 * the configuration information for the specified DMA Stream.
1855 * @retval Stream base address
1856 */
1857static uint32_t DMA_CalcBaseAndBitshift(DMA_HandleTypeDef *hdma)
1858{
1859 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
1860 {
1861 uint32_t stream_number = (((uint32_t)((uint32_t*)hdma->Instance) & 0xFFU) - 16U) / 24U;
1862
1863 /* lookup table for necessary bitshift of flags within status registers */
1864 static const uint8_t flagBitshiftOffset[8U] = {0U, 6U, 16U, 22U, 0U, 6U, 16U, 22U};
1865 hdma->StreamIndex = flagBitshiftOffset[stream_number & 0x7U];
1866
1867 if (stream_number > 3U)
1868 {
1869 /* return pointer to HISR and HIFCR */
1870 hdma->StreamBaseAddress = (((uint32_t)((uint32_t*)hdma->Instance) & (uint32_t)(~0x3FFU)) + 4U);
1871 }
1872 else
1873 {
1874 /* return pointer to LISR and LIFCR */
1875 hdma->StreamBaseAddress = ((uint32_t)((uint32_t*)hdma->Instance) & (uint32_t)(~0x3FFU));
1876 }
1877 }
1878 else /* BDMA instance(s) */
1879 {
1880 /* return pointer to ISR and IFCR */
1881 hdma->StreamBaseAddress = ((uint32_t)((uint32_t*)hdma->Instance) & (uint32_t)(~0xFFU));
1882 }
1883
1884 return hdma->StreamBaseAddress;
1885}
1886
1887/**
1888 * @brief Check compatibility between FIFO threshold level and size of the memory burst
1889 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1890 * the configuration information for the specified DMA Stream.
1891 * @retval HAL status
1892 */
1893static HAL_StatusTypeDef DMA_CheckFifoParam(const DMA_HandleTypeDef *hdma)
1894{
1896
1897 /* Memory Data size equal to Byte */
1899 {
1900 switch (hdma->Init.FIFOThreshold)
1901 {
1904
1906 {
1907 status = HAL_ERROR;
1908 }
1909 break;
1910
1912 if (hdma->Init.MemBurst == DMA_MBURST_INC16)
1913 {
1914 status = HAL_ERROR;
1915 }
1916 break;
1917
1919 break;
1920
1921 default:
1922 break;
1923 }
1924 }
1925
1926 /* Memory Data size equal to Half-Word */
1928 {
1929 switch (hdma->Init.FIFOThreshold)
1930 {
1933 status = HAL_ERROR;
1934 break;
1935
1938 {
1939 status = HAL_ERROR;
1940 }
1941 break;
1942
1944 if (hdma->Init.MemBurst == DMA_MBURST_INC16)
1945 {
1946 status = HAL_ERROR;
1947 }
1948 break;
1949
1950 default:
1951 break;
1952 }
1953 }
1954
1955 /* Memory Data size equal to Word */
1956 else
1957 {
1958 switch (hdma->Init.FIFOThreshold)
1959 {
1963 status = HAL_ERROR;
1964 break;
1965
1968 {
1969 status = HAL_ERROR;
1970 }
1971 break;
1972
1973 default:
1974 break;
1975 }
1976 }
1977
1978 return status;
1979}
1980
1981/**
1982 * @brief Updates the DMA handle with the DMAMUX channel and status mask depending on stream number
1983 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1984 * the configuration information for the specified DMA Stream.
1985 * @retval HAL status
1986 */
1987static void DMA_CalcDMAMUXChannelBaseAndMask(DMA_HandleTypeDef *hdma)
1988{
1989 uint32_t stream_number;
1990 uint32_t stream_baseaddress = (uint32_t)((uint32_t*)hdma->Instance);
1991
1993 {
1994 /* BDMA Channels are connected to DMAMUX2 channels */
1995 stream_number = (((uint32_t)((uint32_t*)hdma->Instance) & 0xFFU) - 8U) / 20U;
1996 hdma->DMAmuxChannel = (DMAMUX_Channel_TypeDef *)((uint32_t)(((uint32_t)DMAMUX2_Channel0) + (stream_number * 4U)));
1998 hdma->DMAmuxChannelStatusMask = 1UL << (stream_number & 0x1FU);
1999 }
2000 else
2001 {
2002 /* DMA1/DMA2 Streams are connected to DMAMUX1 channels */
2003 stream_number = (((uint32_t)((uint32_t*)hdma->Instance) & 0xFFU) - 16U) / 24U;
2004
2005 if((stream_baseaddress <= ((uint32_t)DMA2_Stream7) ) && \
2006 (stream_baseaddress >= ((uint32_t)DMA2_Stream0)))
2007 {
2008 stream_number += 8U;
2009 }
2010 hdma->DMAmuxChannel = (DMAMUX_Channel_TypeDef *)((uint32_t)(((uint32_t)DMAMUX1_Channel0) + (stream_number * 4U)));
2012 hdma->DMAmuxChannelStatusMask = 1UL << (stream_number & 0x1FU);
2013 }
2014}
2015
2016/**
2017 * @brief Updates the DMA handle with the DMAMUX request generator params
2018 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
2019 * the configuration information for the specified DMA Stream.
2020 * @retval HAL status
2021 */
2022static void DMA_CalcDMAMUXRequestGenBaseAndMask(DMA_HandleTypeDef *hdma)
2023{
2024 uint32_t request = hdma->Init.Request & DMAMUX_CxCR_DMAREQ_ID;
2025
2026 if((request >= DMA_REQUEST_GENERATOR0) && (request <= DMA_REQUEST_GENERATOR7))
2027 {
2029 {
2030 /* BDMA Channels are connected to DMAMUX2 request generator blocks */
2031 hdma->DMAmuxRequestGen = (DMAMUX_RequestGen_TypeDef *)((uint32_t)(((uint32_t)DMAMUX2_RequestGenerator0) + ((request - 1U) * 4U)));
2032
2034 }
2035 else
2036 {
2037 /* DMA1 and DMA2 Streams use DMAMUX1 request generator blocks */
2038 hdma->DMAmuxRequestGen = (DMAMUX_RequestGen_TypeDef *)((uint32_t)(((uint32_t)DMAMUX1_RequestGenerator0) + ((request - 1U) * 4U)));
2039
2041 }
2042
2043 hdma->DMAmuxRequestGenStatusMask = 1UL << (request - 1U);
2044 }
2045}
2046
2047/**
2048 * @}
2049 */
2050
2051#endif /* HAL_DMA_MODULE_ENABLED */
2052/**
2053 * @}
2054 */
2055
2056/**
2057 * @}
2058 */
2059
#define __IO
Defines 'read / write' permissions.
#define BDMA_FLAG_TE0
#define BDMA_FLAG_TC0
#define BDMA_FLAG_HT0
#define DMA_MEMORY_TO_MEMORY
Memory to memory direction.
#define DMA_MEMORY_TO_PERIPH
Memory to peripheral direction.
#define HAL_DMA_ERROR_FE
FIFO error.
#define HAL_DMA_ERROR_SYNC
DMAMUX sync overrun error.
#define HAL_DMA_ERROR_BUSY
DMA Busy error.
#define HAL_DMA_ERROR_REQGEN
DMAMUX request generator overrun error.
#define HAL_DMA_ERROR_PARAM
Parameter error.
#define HAL_DMA_ERROR_TIMEOUT
Timeout error.
#define HAL_DMA_ERROR_NOT_SUPPORTED
Not supported mode.
#define HAL_DMA_ERROR_TE
Transfer error.
#define HAL_DMA_ERROR_NONE
No error.
#define HAL_DMA_ERROR_NO_XFER
Abort requested with no Xfer ongoing.
#define HAL_DMA_ERROR_DME
Direct Mode error.
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID)
void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, HAL_DMA_LevelCompleteTypeDef CompleteLevel, uint32_t Timeout)
HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void(*pCallback)(DMA_HandleTypeDef *_hdma))
uint32_t HAL_DMA_GetError(const DMA_HandleTypeDef *hdma)
HAL_DMA_StateTypeDef HAL_DMA_GetState(const DMA_HandleTypeDef *hdma)
#define __HAL_DMA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)
Check whether the specified DMA Stream interrupt is enabled or not.
#define __HAL_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__)
Disable the specified DMA Stream interrupts.
#define __HAL_DMA_ENABLE(__HANDLE__)
Enable the specified DMA Stream.
#define __HAL_DMA_DISABLE(__HANDLE__)
Disable the specified DMA Stream.
struct __DMA_HandleTypeDef DMA_HandleTypeDef
DMA handle Structure definition.
HAL_DMA_StateTypeDef
HAL DMA State structures definition.
HAL_DMA_LevelCompleteTypeDef
HAL DMA Transfer complete level structure definition.
HAL_DMA_CallbackIDTypeDef
HAL DMA Callbacks IDs structure definition.
@ HAL_DMA_STATE_RESET
DMA not yet initialized or disabled.
@ HAL_DMA_STATE_ERROR
DMA error state.
@ HAL_DMA_STATE_READY
DMA initialized and ready for use.
@ HAL_DMA_STATE_ABORT
DMA Abort state.
@ HAL_DMA_STATE_BUSY
DMA process is ongoing.
@ HAL_DMA_FULL_TRANSFER
Full transfer.
@ HAL_DMA_XFER_M1CPLT_CB_ID
M1 Full Transfer.
@ HAL_DMA_XFER_ABORT_CB_ID
Abort.
@ HAL_DMA_XFER_ERROR_CB_ID
Error.
@ HAL_DMA_XFER_HALFCPLT_CB_ID
Half Transfer.
@ HAL_DMA_XFER_CPLT_CB_ID
Full transfer.
@ HAL_DMA_XFER_M1HALFCPLT_CB_ID
M1 Half Transfer.
@ HAL_DMA_XFER_ALL_CB_ID
All.
#define DMA_FIFOMODE_ENABLE
FIFO mode enable.
#define DMA_FIFOMODE_DISABLE
FIFO mode disable.
#define DMA_FIFO_THRESHOLD_1QUARTERFULL
FIFO threshold 1 quart full configuration.
#define DMA_FIFO_THRESHOLD_FULL
FIFO threshold full configuration.
#define DMA_FIFO_THRESHOLD_HALFFULL
FIFO threshold half full configuration.
#define DMA_FIFO_THRESHOLD_3QUARTERSFULL
FIFO threshold 3 quarts full configuration.
#define DMA_MBURST_SINGLE
#define DMA_MBURST_INC16
#define DMA_MDATAALIGN_HALFWORD
Memory data alignment: HalfWord.
#define DMA_MDATAALIGN_BYTE
Memory data alignment: Byte.
#define IS_DMA_PERIPHERAL_INC_STATE(STATE)
#define IS_DMA_BUFFER_SIZE(SIZE)
#define IS_DMA_PERIPHERAL_BURST(BURST)
#define IS_DMA_REQUEST(REQUEST)
#define IS_DMA_MEMORY_BURST(BURST)
#define IS_DMA_PRIORITY(PRIORITY)
#define IS_DMA_MEMORY_INC_STATE(STATE)
#define IS_DMA_MEMORY_DATA_SIZE(SIZE)
#define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE)
#define IS_DMA_MODE(MODE)
#define IS_DMA_FIFO_MODE_STATE(STATE)
#define IS_DMA_DIRECTION(DIRECTION)
#define IS_BDMA_REQUEST(REQUEST)
#define IS_DMA_FIFO_THRESHOLD(THRESHOLD)
#define DMA_REQUEST_MEM2MEM
memory to memory transfer
#define DMA_REQUEST_GENERATOR0
DMAMUX1 request generator 0.
#define DMA_REQUEST_GENERATOR7
DMAMUX1 request generator 7.
#define DMA_FLAG_TCIF0_4
#define DMA_FLAG_FEIF0_4
#define DMA_FLAG_HTIF0_4
#define DMA_FLAG_TEIF0_4
#define DMA_FLAG_DMEIF0_4
#define DMA_IT_TC
#define DMA_IT_DME
#define DMA_IT_FE
#define DMA_IT_HT
#define DMA_IT_TE
#define IS_BDMA_CHANNEL_DMAMUX_INSTANCE(INSTANCE)
#define IS_DMA_ALL_INSTANCE(INSTANCE)
#define IS_DMA_STREAM_INSTANCE(INSTANCE)
#define IS_DMA_DMAMUX_ALL_INSTANCE(INSTANCE)
#define MODIFY_REG(REG, CLEARMASK, SETMASK)
Definition stm32h7xx.h:219
#define IS_BDMA_CHANNEL_INSTANCE(INSTANCE)
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
#define DMA_SxCR_PL
Priority level.
#define DMAMUX_CxCR_SOIE
Synchronization overrun interrupt enable.
#define DMA_SxCR_DIR
Data transfer direction.
#define BDMA_CCR_MEM2MEM
Memory to memory mode.
#define BDMA_CCR_MINC
Memory increment mode.
#define BDMA_CCR_PL
PL[1:0] bits(Channel Priority level).
#define DMA_SxCR_PINC
Peripheral increment mode.
#define BDMA_CCR_TCIE
Transfer complete interrupt enable.
#define DMA_SxCR_TRBUFF
bufferable transfers enabled/disable
#define DMAMUX_CxCR_DMAREQ_ID
DMA request identification.
#define DMA_SxFCR_FTH
FIFO threshold selection.
#define BDMA_ISR_TCIF0
Channel 0 Transfer Complete flag.
#define DMA_SxCR_PBURST
Peripheral burst transfer configuration.
#define DMA_SxCR_DBM
Double buffer mode.
#define DMA_SxCR_MBURST
Memory burst transfer configuration.
#define BDMA_ISR_GIF0
Channel 0 Global interrupt flag.
#define BDMA_ISR_HTIF0
Channel 0 Half Transfer flag.
#define DMAMUX_RGxCR_OIE
Trigger overrun interrupt enable.
#define DMA_SxCR_MINC
Memory increment mode.
#define BDMA_IFCR_CGIF0
Channel 0 Global interrupt clearr.
#define DMA_SxFCR_DMDIS
Direct mode disable.
#define BDMA_CCR_HTIE
Half Transfer interrupt enable.
#define BDMA_CCR_MSIZE
MSIZE[1:0] bits (Memory size).
#define BDMA_CCR_DBM
Memory to memory mode.
#define BDMA_CCR_CIRC
Circular mode.
#define DMA_SxCR_EN
Stream enable / flag stream ready when read low.
#define BDMA_CCR_PINC
Peripheral increment mode.
#define BDMA_CCR_CT
Memory to memory mode.
#define DMA_SxCR_CIRC
Circular mode.
#define DMA_SxCR_CT
Current target (only in double buffer mode).
#define BDMA_CCR_PSIZE
PSIZE[1:0] bits (Peripheral size).
#define DMA_SxCR_MSIZE
Memory data size.
#define DMA_SxCR_PSIZE
#define BDMA_CCR_DIR
Data transfer direction.
#define DMAMUX_CxCR_SE
Synchronization enable.
#define DMA_SxCR_MBURST_1
0x01000000
#define BDMA_CCR_TEIE
Transfer error interrupt enable.
#define DMAMUX2_Channel0
#define DMA2_Stream0
#define DMAMUX2_RequestGenerator0
#define DMAMUX1_RequestGenStatus
#define DMAMUX2_ChannelStatus
#define DMAMUX1_Channel0
#define BDMA_Channel0
#define DMAMUX1_RequestGenerator0
#define DMAMUX2_RequestGenStatus
#define DBGMCU
#define BDMA_Channel1
#define DMAMUX1_ChannelStatus
#define DMA2_Stream7
uint32_t SystemCoreClock
System Domain1 Clock Frequency.
#define NULL
Definition usbd_def.h:44
size_type count(const key_type &key) const
Definition json.hpp:19264
This file contains all the functions prototypes for the HAL module driver.
#define assert_param(expr)
Uncomment the line below to expanse the "assert_param" macro in the HAL drivers code.
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_ERROR
@ HAL_OK
#define __HAL_UNLOCK(__HANDLE__)
#define HAL_MAX_DELAY
#define __HAL_LOCK(__HANDLE__)
__IO uint32_t CSR
DMA Channel Status Register.
__IO uint32_t CFR
DMA Channel Clear Flag Register.
__IO uint32_t CCR
DMA Multiplexer Channel x Control Register.
__IO uint32_t RGCFR
DMA Request Generator Clear Flag Register.
__IO uint32_t RGSR
DMA Request Generator Status Register.
__IO uint32_t RGCR
DMA Request Generator x Control Register.
uint32_t Direction
Specifies if the data will be transferred from memory to peripheral, from memory to memory or from pe...
uint32_t PeriphDataAlignment
Specifies the Peripheral data width.
uint32_t FIFOThreshold
Specifies the FIFO threshold level.
uint32_t PeriphBurst
Specifies the Burst transfer configuration for the peripheral transfers.
uint32_t PeriphInc
Specifies whether the Peripheral address register should be incremented or not.
uint32_t MemInc
Specifies whether the memory address register should be incremented or not.
uint32_t Request
Specifies the request selected for the specified stream.
uint32_t MemDataAlignment
Specifies the Memory data width.
uint32_t FIFOMode
Specifies if the FIFO mode or Direct mode will be used for the specified stream.
uint32_t MemBurst
Specifies the Burst transfer configuration for the memory transfers.
uint32_t Mode
Specifies the operation mode of the DMAy Streamx.
uint32_t Priority
Specifies the software priority for the DMAy Streamx.
DMA Controller.
DMAMUX_RequestGenStatus_TypeDef * DMAmuxRequestGenStatus
DMAMUX request generator Status Address.
DMAMUX_Channel_TypeDef * DMAmuxChannel
DMAMUX Channel Base Address.
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
DMA transfer Abort callback.
uint32_t DMAmuxChannelStatusMask
DMAMUX Channel Status Mask.
DMA_InitTypeDef Init
DMA communication parameters.
uint32_t StreamIndex
DMA Stream Index.
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA transfer complete callback.
__IO uint32_t ErrorCode
DMA Error code.
DMAMUX_RequestGen_TypeDef * DMAmuxRequestGen
DMAMUX request generator Base Address.
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
DMA transfer error callback.
__IO HAL_DMA_StateTypeDef State
DMA transfer state.
DMAMUX_ChannelStatus_TypeDef * DMAmuxChannelStatus
DMAMUX Channels Status Base Address.
void * Instance
Register base address.
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA Half transfer complete callback.
uint32_t StreamBaseAddress
DMA Stream Base Address.
void(* XferM1HalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA transfer Half complete Memory1 callback.
void(* XferM1CpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA transfer complete Memory1 callback.
uint32_t DMAmuxRequestGenStatusMask
DMAMUX request generator Status mask.