2 ******************************************************************************
\r
3 * @file stm32l4xx_hal_dma_ex.c
\r
4 * @author MCD Application Team
\r
5 * @brief DMA Extension HAL module driver
\r
6 * This file provides firmware functions to manage the following
\r
7 * functionalities of the DMA Extension peripheral:
\r
8 * + Extended features functions
\r
11 ==============================================================================
\r
12 ##### How to use this driver #####
\r
13 ==============================================================================
\r
15 The DMA Extension HAL driver can be used as follows:
\r
17 (+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
\r
18 (+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
\r
19 Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
\r
20 to respectively enable/disable the request generator.
\r
22 (+) To handle the DMAMUX Interrupts, the function HAL_DMAEx_MUX_IRQHandler should be called from
\r
23 the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler.
\r
24 As only one interrupt line is available for all DMAMUX channels and request generators , HAL_DMAEx_MUX_IRQHandler should be
\r
25 called with, as parameter, the appropriate DMA handle as many as used DMAs in the user project
\r
26 (exception done if a given DMA is not using the DMAMUX SYNC block neither a request generator)
\r
28 -@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed.
\r
29 -@- When Multi (Double) Buffer mode is enabled, the transfer is circular by default.
\r
30 -@- In Multi (Double) buffer mode, it is possible to update the base address for
\r
31 the AHB memory port on the fly (DMA_CM0ARx or DMA_CM1ARx) when the channel is enabled.
\r
35 ******************************************************************************
\r
38 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
39 * All rights reserved.</center></h2>
\r
41 * This software component is licensed by ST under BSD 3-Clause license,
\r
42 * the "License"; You may not use this file except in compliance with the
\r
43 * License. You may obtain a copy of the License at:
\r
44 * opensource.org/licenses/BSD-3-Clause
\r
46 ******************************************************************************
\r
49 /* Includes ------------------------------------------------------------------*/
\r
50 #include "stm32l4xx_hal.h"
\r
52 #if defined(DMAMUX1)
\r
54 /** @addtogroup STM32L4xx_HAL_Driver
\r
58 /** @defgroup DMAEx DMAEx
\r
59 * @brief DMA Extended HAL module driver
\r
63 #ifdef HAL_DMA_MODULE_ENABLED
\r
65 /* Private typedef -----------------------------------------------------------*/
\r
66 /* Private define ------------------------------------------------------------*/
\r
67 /* Private macro -------------------------------------------------------------*/
\r
68 /* Private variables ---------------------------------------------------------*/
\r
69 /* Private Constants ---------------------------------------------------------*/
\r
70 /* Private function prototypes -----------------------------------------------*/
\r
71 /* Private functions ---------------------------------------------------------*/
\r
74 /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions
\r
78 /** @defgroup DMAEx_Exported_Functions_Group1 DMAEx Extended features functions
\r
79 * @brief Extended features functions
\r
82 ===============================================================================
\r
83 ##### Extended features functions #####
\r
84 ===============================================================================
\r
85 [..] This section provides functions allowing to:
\r
87 (+) Configure the DMAMUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
\r
88 (+) Configure the DMAMUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
\r
89 Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
\r
90 to respectively enable/disable the request generator.
\r
98 * @brief Configure the DMAMUX synchronization parameters for a given DMA channel (instance).
\r
99 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
\r
100 * the configuration information for the specified DMA channel.
\r
101 * @param pSyncConfig : pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters
\r
102 * @retval HAL status
\r
104 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig)
\r
106 /* Check the parameters */
\r
107 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
\r
109 assert_param(IS_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
\r
111 assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig-> SyncPolarity));
\r
112 assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable));
\r
113 assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable));
\r
114 assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber));
\r
116 /*Check if the DMA state is ready */
\r
117 if(hdma->State == HAL_DMA_STATE_READY)
\r
119 /* Process Locked */
\r
122 /* Set the new synchronization parameters (and keep the request ID filled during the Init)*/
\r
123 MODIFY_REG( hdma->DMAmuxChannel->CCR, \
\r
124 (~DMAMUX_CxCR_DMAREQ_ID) , \
\r
125 ((pSyncConfig->SyncSignalID) << DMAMUX_CxCR_SYNC_ID_Pos) | ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \
\r
126 pSyncConfig->SyncPolarity | ((uint32_t)pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \
\r
127 ((uint32_t)pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos));
\r
129 /* Process UnLocked */
\r
130 __HAL_UNLOCK(hdma);
\r
136 /*DMA State not Ready*/
\r
142 * @brief Configure the DMAMUX request generator block used by the given DMA channel (instance).
\r
143 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
\r
144 * the configuration information for the specified DMA channel.
\r
145 * @param pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef :
\r
146 * contains the request generator parameters.
\r
148 * @retval HAL status
\r
150 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)
\r
152 /* Check the parameters */
\r
153 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
\r
155 assert_param(IS_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
\r
157 assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));
\r
158 assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));
\r
160 /* check if the DMA state is ready
\r
161 and DMA is using a DMAMUX request generator block
\r
163 if((hdma->State == HAL_DMA_STATE_READY) && (hdma->DMAmuxRequestGen != 0U))
\r
165 /* Process Locked */
\r
168 /* Set the request generator new parameters */
\r
169 hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \
\r
170 ((pRequestGeneratorConfig->RequestNumber - 1U) << DMAMUX_RGxCR_GNBREQ_Pos)| \
\r
171 pRequestGeneratorConfig->Polarity;
\r
172 /* Process UnLocked */
\r
173 __HAL_UNLOCK(hdma);
\r
184 * @brief Enable the DMAMUX request generator block used by the given DMA channel (instance).
\r
185 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
\r
186 * the configuration information for the specified DMA channel.
\r
187 * @retval HAL status
\r
189 HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
\r
191 /* Check the parameters */
\r
192 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
\r
194 /* check if the DMA state is ready
\r
195 and DMA is using a DMAMUX request generator block
\r
197 if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))
\r
200 /* Enable the request generator*/
\r
201 hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE;
\r
212 * @brief Disable the DMAMUX request generator block used by the given DMA channel (instance).
\r
213 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
\r
214 * the configuration information for the specified DMA channel.
\r
215 * @retval HAL status
\r
217 HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
\r
219 /* Check the parameters */
\r
220 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
\r
222 /* check if the DMA state is ready
\r
223 and DMA is using a DMAMUX request generator block
\r
225 if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))
\r
228 /* Disable the request generator*/
\r
229 hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE;
\r
240 * @brief Handles DMAMUX interrupt request.
\r
241 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
\r
242 * the configuration information for the specified DMA channel.
\r
245 void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma)
\r
247 /* Check for DMAMUX Synchronization overrun */
\r
248 if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)
\r
250 /* Disable the synchro overrun interrupt */
\r
251 hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;
\r
253 /* Clear the DMAMUX synchro overrun flag */
\r
254 hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
\r
256 /* Update error code */
\r
257 hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;
\r
259 if(hdma->XferErrorCallback != NULL)
\r
261 /* Transfer error callback */
\r
262 hdma->XferErrorCallback(hdma);
\r
266 if(hdma->DMAmuxRequestGen != 0)
\r
268 /* if using a DMAMUX request generator block Check for DMAMUX request generator overrun */
\r
269 if((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)
\r
271 /* Disable the request gen overrun interrupt */
\r
272 hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;
\r
274 /* Clear the DMAMUX request generator overrun flag */
\r
275 hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
\r
277 /* Update error code */
\r
278 hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;
\r
280 if(hdma->XferErrorCallback != NULL)
\r
282 /* Transfer error callback */
\r
283 hdma->XferErrorCallback(hdma);
\r
297 #endif /* HAL_DMA_MODULE_ENABLED */
\r
307 #endif /* DMAMUX1 */
\r
309 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r