]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_Keil_STM32Cube/ST_Code/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c
Make vSetupTimerInterrupt weak in the RVDS M4 MPU port to give the
[freertos] / FreeRTOS / Demo / CORTEX_MPU_STM32L4_Discovery_Keil_STM32Cube / ST_Code / Drivers / STM32L4xx_HAL_Driver / Src / stm32l4xx_hal_dma_ex.c
1 /**\r
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
9   *\r
10   @verbatim\r
11   ==============================================================================\r
12                         ##### How to use this driver #####\r
13   ==============================================================================\r
14   [..]\r
15   The DMA Extension HAL driver can be used as follows:\r
16 \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
21 \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
27 \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
32 \r
33 \r
34   @endverbatim\r
35   ******************************************************************************\r
36   * @attention\r
37   *\r
38   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.\r
39   * All rights reserved.</center></h2>\r
40   *\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
45   *\r
46   ******************************************************************************\r
47   */\r
48 \r
49 /* Includes ------------------------------------------------------------------*/\r
50 #include "stm32l4xx_hal.h"\r
51 \r
52 #if defined(DMAMUX1)\r
53 \r
54 /** @addtogroup STM32L4xx_HAL_Driver\r
55   * @{\r
56   */\r
57 \r
58 /** @defgroup DMAEx DMAEx\r
59   * @brief DMA Extended HAL module driver\r
60   * @{\r
61   */\r
62 \r
63 #ifdef HAL_DMA_MODULE_ENABLED\r
64 \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
72 \r
73 \r
74 /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions\r
75   * @{\r
76   */\r
77 \r
78 /** @defgroup DMAEx_Exported_Functions_Group1 DMAEx Extended features functions\r
79  *  @brief   Extended features functions\r
80  *\r
81 @verbatim\r
82  ===============================================================================\r
83                 #####  Extended features functions  #####\r
84  ===============================================================================\r
85     [..]  This section provides functions allowing to:\r
86 \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
91 \r
92 @endverbatim\r
93   * @{\r
94   */\r
95 \r
96 \r
97 /**\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
103   */\r
104 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig)\r
105 {\r
106   /* Check the parameters */\r
107   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));\r
108 \r
109   assert_param(IS_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));\r
110 \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
115 \r
116   /*Check if the DMA state is ready */\r
117   if(hdma->State == HAL_DMA_STATE_READY)\r
118   {\r
119     /* Process Locked */\r
120     __HAL_LOCK(hdma);\r
121 \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
128 \r
129     /* Process UnLocked */\r
130     __HAL_UNLOCK(hdma);\r
131 \r
132     return HAL_OK;\r
133   }\r
134   else\r
135   {\r
136     /*DMA State not Ready*/\r
137     return HAL_ERROR;\r
138   }\r
139 }\r
140 \r
141 /**\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
147   *\r
148   * @retval HAL status\r
149   */\r
150 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)\r
151 {\r
152   /* Check the parameters */\r
153   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));\r
154 \r
155   assert_param(IS_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));\r
156 \r
157   assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));\r
158   assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));\r
159 \r
160   /* check if the DMA state is ready\r
161      and DMA is using a DMAMUX request generator block\r
162   */\r
163   if((hdma->State == HAL_DMA_STATE_READY) && (hdma->DMAmuxRequestGen != 0U))\r
164   {\r
165     /* Process Locked */\r
166     __HAL_LOCK(hdma);\r
167 \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
174 \r
175    return HAL_OK;\r
176  }\r
177  else\r
178  {\r
179    return HAL_ERROR;\r
180  }\r
181 }\r
182 \r
183 /**\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
188   */\r
189 HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma)\r
190 {\r
191   /* Check the parameters */\r
192   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));\r
193 \r
194   /* check if the DMA state is ready\r
195      and DMA is using a DMAMUX request generator block\r
196   */\r
197   if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))\r
198   {\r
199 \r
200     /* Enable the request generator*/\r
201     hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE;\r
202 \r
203    return HAL_OK;\r
204  }\r
205  else\r
206  {\r
207    return HAL_ERROR;\r
208  }\r
209 }\r
210 \r
211 /**\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
216   */\r
217 HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator (DMA_HandleTypeDef *hdma)\r
218 {\r
219   /* Check the parameters */\r
220   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));\r
221 \r
222   /* check if the DMA state is ready\r
223      and DMA is using a DMAMUX request generator block\r
224   */\r
225   if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))\r
226   {\r
227 \r
228     /* Disable the request generator*/\r
229     hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE;\r
230 \r
231     return HAL_OK;\r
232   }\r
233   else\r
234   {\r
235     return HAL_ERROR;\r
236   }\r
237 }\r
238 \r
239 /**\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
243   * @retval None\r
244   */\r
245 void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma)\r
246 {\r
247   /* Check for DMAMUX Synchronization overrun */\r
248   if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)\r
249   {\r
250     /* Disable the synchro overrun interrupt */\r
251     hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;\r
252 \r
253     /* Clear the DMAMUX synchro overrun flag */\r
254     hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;\r
255 \r
256     /* Update error code */\r
257     hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;\r
258 \r
259     if(hdma->XferErrorCallback != NULL)\r
260     {\r
261       /* Transfer error callback */\r
262       hdma->XferErrorCallback(hdma);\r
263     }\r
264   }\r
265 \r
266   if(hdma->DMAmuxRequestGen != 0)\r
267   {\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
270     {\r
271       /* Disable the request gen overrun interrupt */\r
272       hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;\r
273 \r
274       /* Clear the DMAMUX request generator overrun flag */\r
275       hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;\r
276 \r
277       /* Update error code */\r
278       hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;\r
279 \r
280       if(hdma->XferErrorCallback != NULL)\r
281       {\r
282         /* Transfer error callback */\r
283         hdma->XferErrorCallback(hdma);\r
284       }\r
285     }\r
286   }\r
287 }\r
288 \r
289 /**\r
290   * @}\r
291   */\r
292 \r
293 /**\r
294   * @}\r
295   */\r
296 \r
297 #endif /* HAL_DMA_MODULE_ENABLED */\r
298 \r
299 /**\r
300   * @}\r
301   */\r
302 \r
303 /**\r
304   * @}\r
305   */\r
306 \r
307 #endif /* DMAMUX1 */\r
308 \r
309 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r