]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_M4_AMP_STM32H745I_Discovery_IAR/ST_code/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c
Add M7/M4 AMP demo.
[freertos] / FreeRTOS / Demo / CORTEX_M7_M4_AMP_STM32H745I_Discovery_IAR / ST_code / STM32H7xx_HAL_Driver / Src / stm32h7xx_hal_dma_ex.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32h7xx_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    (+) Start a multi buffer transfer using the HAL_DMA_MultiBufferStart() function\r
17        for polling mode or HAL_DMA_MultiBufferStart_IT() for interrupt mode.\r
18 \r
19    (+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.\r
20    (+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.\r
21        Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used\r
22        to respectively enable/disable the request generator.\r
23 \r
24    (+) To handle the DMAMUX Interrupts, the function  HAL_DMAEx_MUX_IRQHandler should be called from\r
25        the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler or DMAMUX2_OVR_IRQHandler .\r
26        As only one interrupt line is available for all DMAMUX channels and request generators , HAL_DMA_MUX_IRQHandler should be\r
27        called with, as parameter, the appropriate DMA handle as many as used DMAs in the user project\r
28       (exception done if a given DMA is not using the DMAMUX SYNC block neither a request generator)\r
29 \r
30      -@-  In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed.\r
31      -@-  When Multi (Double) Buffer mode is enabled, the transfer is circular by default.\r
32      -@-  In Multi (Double) buffer mode, it is possible to update the base address for\r
33           the AHB memory port on the fly (DMA_SxM0AR or DMA_SxM1AR) when the stream is enabled.\r
34      -@-  Multi (Double) buffer mode is possible with DMA and BDMA instances.\r
35 \r
36   @endverbatim\r
37   ******************************************************************************\r
38   * @attention\r
39   *\r
40   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics.\r
41   * All rights reserved.</center></h2>\r
42   *\r
43   * This software component is licensed by ST under BSD 3-Clause license,\r
44   * the "License"; You may not use this file except in compliance with the\r
45   * License. You may obtain a copy of the License at:\r
46   *                        opensource.org/licenses/BSD-3-Clause\r
47   *\r
48   ******************************************************************************\r
49   */\r
50 \r
51 /* Includes ------------------------------------------------------------------*/\r
52 #include "stm32h7xx_hal.h"\r
53 \r
54 /** @addtogroup STM32H7xx_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 types -------------------------------------------------------------*/\r
66 /* Private variables ---------------------------------------------------------*/\r
67 /* Private Constants ---------------------------------------------------------*/\r
68 /* Private macros ------------------------------------------------------------*/\r
69 /* Private functions ---------------------------------------------------------*/\r
70 /** @addtogroup DMAEx_Private_Functions\r
71   * @{\r
72   */\r
73 \r
74 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);\r
75 \r
76 /**\r
77   * @}\r
78   */\r
79 \r
80 /* Exported functions ---------------------------------------------------------*/\r
81 \r
82 /** @addtogroup DMAEx_Exported_Functions\r
83   * @{\r
84   */\r
85 \r
86 \r
87 /** @addtogroup DMAEx_Exported_Functions_Group1\r
88   *\r
89 @verbatim\r
90  ===============================================================================\r
91                 #####  Extended features functions  #####\r
92  ===============================================================================\r
93     [..]  This section provides functions allowing to:\r
94       (+) Configure the source, destination address and data length and\r
95           Start MultiBuffer DMA transfer\r
96       (+) Configure the source, destination address and data length and\r
97           Start MultiBuffer DMA transfer with interrupt\r
98       (+) Change on the fly the memory0 or memory1 address.\r
99       (+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.\r
100       (+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.\r
101       (+) Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used\r
102           to respectively enable/disable the request generator.\r
103       (+) Handle DMAMUX interrupts using HAL_DMAEx_MUX_IRQHandler : should be called from\r
104           the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler or DMAMUX2_OVR_IRQHandler\r
105 \r
106 @endverbatim\r
107   * @{\r
108   */\r
109 \r
110 \r
111 /**\r
112   * @brief  Starts the multi_buffer DMA Transfer.\r
113   * @param  hdma      : pointer to a DMA_HandleTypeDef structure that contains\r
114   *                     the configuration information for the specified DMA Stream.\r
115   * @param  SrcAddress: The source memory Buffer address\r
116   * @param  DstAddress: The destination memory Buffer address\r
117   * @param  SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer\r
118   * @param  DataLength: The length of data to be transferred from source to destination\r
119   * @retval HAL status\r
120   */\r
121 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)\r
122 {\r
123   HAL_StatusTypeDef status = HAL_OK;\r
124   __IO uint32_t *ifcRegister_Base; /* DMA Stream Interrupt Clear register */\r
125 \r
126   /* Check the parameters */\r
127   assert_param(IS_DMA_BUFFER_SIZE(DataLength));\r
128   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));\r
129 \r
130   /* Memory-to-memory transfer not supported in double buffering mode */\r
131   if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)\r
132   {\r
133     hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;\r
134     status = HAL_ERROR;\r
135   }\r
136   else\r
137   {\r
138     /* Process Locked */\r
139     __HAL_LOCK(hdma);\r
140 \r
141     if(HAL_DMA_STATE_READY == hdma->State)\r
142     {\r
143       /* Change DMA peripheral state */\r
144       hdma->State = HAL_DMA_STATE_BUSY;\r
145 \r
146       /* Initialize the error code */\r
147       hdma->ErrorCode = HAL_DMA_ERROR_NONE;\r
148 \r
149       if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */\r
150       {\r
151         /* Enable the Double buffer mode */\r
152         ((DMA_Stream_TypeDef   *)hdma->Instance)->CR |= DMA_SxCR_DBM;\r
153 \r
154         /* Configure DMA Stream destination address */\r
155         ((DMA_Stream_TypeDef   *)hdma->Instance)->M1AR = SecondMemAddress;\r
156 \r
157         /* Calculate the interrupt clear flag register (IFCR) base address  */\r
158         ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 8U));\r
159 \r
160         /* Clear all flags */\r
161         *ifcRegister_Base = 0x3FUL << (hdma->StreamIndex & 0x1FU);\r
162       }\r
163       else /* BDMA instance(s) */\r
164       {\r
165         /* Enable the Double buffer mode */\r
166         ((BDMA_Channel_TypeDef   *)hdma->Instance)->CCR |= (BDMA_CCR_DBM | BDMA_CCR_CIRC);\r
167 \r
168         /* Configure DMA Stream destination address */\r
169         ((BDMA_Channel_TypeDef   *)hdma->Instance)->CM1AR = SecondMemAddress;\r
170 \r
171         /* Calculate the interrupt clear flag register (IFCR) base address  */\r
172         ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 4U));\r
173 \r
174         /* Clear all flags */\r
175         *ifcRegister_Base = (BDMA_ISR_GIF0) << (hdma->StreamIndex & 0x1FU);\r
176       }\r
177 \r
178       /* Configure the source, destination address and the data length */\r
179       DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);\r
180 \r
181       /* Clear the DMAMUX synchro overrun flag */\r
182       hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;\r
183 \r
184       if(hdma->DMAmuxRequestGen != 0U)\r
185       {\r
186         /* Clear the DMAMUX request generator overrun flag */\r
187         hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;\r
188       }\r
189 \r
190       /* Enable the peripheral */\r
191       __HAL_DMA_ENABLE(hdma);\r
192     }\r
193     else\r
194     {\r
195       /* Set the error code to busy */\r
196       hdma->ErrorCode = HAL_DMA_ERROR_BUSY;\r
197 \r
198       /* Return error status */\r
199       status = HAL_ERROR;\r
200     }\r
201   }\r
202   return status;\r
203 }\r
204 \r
205 /**\r
206   * @brief  Starts the multi_buffer DMA Transfer with interrupt enabled.\r
207   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains\r
208   *                     the configuration information for the specified DMA Stream.\r
209   * @param  SrcAddress: The source memory Buffer address\r
210   * @param  DstAddress: The destination memory Buffer address\r
211   * @param  SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer\r
212   * @param  DataLength: The length of data to be transferred from source to destination\r
213   * @retval HAL status\r
214   */\r
215 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)\r
216 {\r
217   HAL_StatusTypeDef status = HAL_OK;\r
218   __IO uint32_t *ifcRegister_Base; /* DMA Stream Interrupt Clear register */\r
219 \r
220   /* Check the parameters */\r
221   assert_param(IS_DMA_BUFFER_SIZE(DataLength));\r
222   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));\r
223 \r
224   /* Memory-to-memory transfer not supported in double buffering mode */\r
225   if(hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)\r
226   {\r
227     hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;\r
228     return HAL_ERROR;\r
229   }\r
230 \r
231   /* Process locked */\r
232   __HAL_LOCK(hdma);\r
233 \r
234   if(HAL_DMA_STATE_READY == hdma->State)\r
235   {\r
236     /* Change DMA peripheral state */\r
237     hdma->State = HAL_DMA_STATE_BUSY;\r
238 \r
239     /* Initialize the error code */\r
240     hdma->ErrorCode = HAL_DMA_ERROR_NONE;\r
241 \r
242     if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */\r
243     {\r
244       /* Enable the Double buffer mode */\r
245       ((DMA_Stream_TypeDef   *)hdma->Instance)->CR |= DMA_SxCR_DBM;\r
246 \r
247       /* Configure DMA Stream destination address */\r
248       ((DMA_Stream_TypeDef   *)hdma->Instance)->M1AR = SecondMemAddress;\r
249 \r
250       /* Calculate the interrupt clear flag register (IFCR) base address  */\r
251       ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 8U));\r
252 \r
253       /* Clear all flags */\r
254       *ifcRegister_Base = 0x3FUL << (hdma->StreamIndex & 0x1FU);\r
255     }\r
256     else /* BDMA instance(s) */\r
257     {\r
258       /* Enable the Double buffer mode */\r
259       ((BDMA_Channel_TypeDef   *)hdma->Instance)->CCR |= (BDMA_CCR_DBM | BDMA_CCR_CIRC);\r
260 \r
261       /* Configure DMA Stream destination address */\r
262       ((BDMA_Channel_TypeDef   *)hdma->Instance)->CM1AR = SecondMemAddress;\r
263 \r
264       /* Calculate the interrupt clear flag register (IFCR) base address  */\r
265       ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 4U));\r
266 \r
267       /* Clear all flags */\r
268       *ifcRegister_Base = (BDMA_ISR_GIF0) << (hdma->StreamIndex & 0x1FU);\r
269     }\r
270 \r
271     /* Configure the source, destination address and the data length */\r
272     DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);\r
273 \r
274     /* Clear the DMAMUX synchro overrun flag */\r
275     hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;\r
276 \r
277     if(hdma->DMAmuxRequestGen != 0U)\r
278     {\r
279       /* Clear the DMAMUX request generator overrun flag */\r
280       hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;\r
281     }\r
282 \r
283     if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */\r
284     {\r
285       /* Enable Common interrupts*/\r
286       MODIFY_REG(((DMA_Stream_TypeDef   *)hdma->Instance)->CR, (DMA_IT_TC | DMA_IT_TE | DMA_IT_DME | DMA_IT_HT), (DMA_IT_TC | DMA_IT_TE | DMA_IT_DME));\r
287       ((DMA_Stream_TypeDef   *)hdma->Instance)->FCR |= DMA_IT_FE;\r
288 \r
289       if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))\r
290       {\r
291         /*Enable Half Transfer IT if corresponding Callback is set*/\r
292         ((DMA_Stream_TypeDef   *)hdma->Instance)->CR  |= DMA_IT_HT;\r
293       }\r
294     }\r
295     else /* BDMA instance(s) */\r
296     {\r
297       /* Enable Common interrupts*/\r
298       MODIFY_REG(((BDMA_Channel_TypeDef   *)hdma->Instance)->CCR, (BDMA_CCR_TCIE | BDMA_CCR_HTIE | BDMA_CCR_TEIE), (BDMA_CCR_TCIE | BDMA_CCR_TEIE));\r
299 \r
300       if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))\r
301       {\r
302         /*Enable Half Transfer IT if corresponding Callback is set*/\r
303         ((BDMA_Channel_TypeDef   *)hdma->Instance)->CCR  |= BDMA_CCR_HTIE;\r
304       }\r
305     }\r
306 \r
307     /* Check if DMAMUX Synchronization is enabled*/\r
308     if((hdma->DMAmuxChannel->CCR & DMAMUX_CxCR_SE) != 0U)\r
309     {\r
310       /* Enable DMAMUX sync overrun IT*/\r
311       hdma->DMAmuxChannel->CCR |= DMAMUX_CxCR_SOIE;\r
312     }\r
313 \r
314     if(hdma->DMAmuxRequestGen != 0U)\r
315     {\r
316       /* if using DMAMUX request generator, enable the DMAMUX request generator overrun IT*/\r
317       /* enable the request gen overrun IT*/\r
318       hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_OIE;\r
319     }\r
320 \r
321     /* Enable the peripheral */\r
322     __HAL_DMA_ENABLE(hdma);\r
323   }\r
324   else\r
325   {\r
326     /* Set the error code to busy */\r
327     hdma->ErrorCode = HAL_DMA_ERROR_BUSY;\r
328 \r
329     /* Return error status */\r
330     status = HAL_ERROR;\r
331   }\r
332   return status;\r
333 }\r
334 \r
335 /**\r
336   * @brief  Change the memory0 or memory1 address on the fly.\r
337   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains\r
338   *                     the configuration information for the specified DMA Stream.\r
339   * @param  Address:    The new address\r
340   * @param  memory:     the memory to be changed, This parameter can be one of\r
341   *                     the following values:\r
342   *                      MEMORY0 /\r
343   *                      MEMORY1\r
344   * @note   The MEMORY0 address can be changed only when the current transfer use\r
345   *         MEMORY1 and the MEMORY1 address can be changed only when the current\r
346   *         transfer use MEMORY0.\r
347   * @retval HAL status\r
348   */\r
349 HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)\r
350 {\r
351   if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */\r
352   {\r
353     if(memory == MEMORY0)\r
354     {\r
355       /* change the memory0 address */\r
356       ((DMA_Stream_TypeDef   *)hdma->Instance)->M0AR = Address;\r
357     }\r
358     else\r
359     {\r
360       /* change the memory1 address */\r
361       ((DMA_Stream_TypeDef   *)hdma->Instance)->M1AR = Address;\r
362     }\r
363   }\r
364   else /* BDMA instance(s) */\r
365   {\r
366     if(memory == MEMORY0)\r
367     {\r
368       /* change the memory0 address */\r
369       ((BDMA_Channel_TypeDef   *)hdma->Instance)->CM0AR = Address;\r
370     }\r
371     else\r
372     {\r
373       /* change the memory1 address */\r
374       ((BDMA_Channel_TypeDef   *)hdma->Instance)->CM1AR = Address;\r
375     }\r
376   }\r
377 \r
378   return HAL_OK;\r
379 }\r
380 \r
381 /**\r
382   * @brief  Configure the DMAMUX synchronization parameters for a given DMA stream (instance).\r
383   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains\r
384   *                     the configuration information for the specified DMA Stream.\r
385   * @param  pSyncConfig : pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters\r
386   * @retval HAL status\r
387   */\r
388 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig)\r
389 {\r
390   uint32_t syncSignalID = 0;\r
391   uint32_t syncPolarity = 0;\r
392 \r
393   /* Check the parameters */\r
394   assert_param(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance));\r
395   assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable));\r
396   assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable));\r
397   assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber));\r
398 \r
399   if(pSyncConfig->SyncEnable == ENABLE)\r
400   {\r
401     assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig->SyncPolarity));\r
402 \r
403     if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */\r
404     {\r
405       assert_param(IS_DMA_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));\r
406     }\r
407     else\r
408     {\r
409       assert_param(IS_BDMA_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));\r
410     }\r
411     syncSignalID = pSyncConfig->SyncSignalID;\r
412     syncPolarity = pSyncConfig->SyncPolarity;\r
413   }\r
414 \r
415   /*Check if the DMA state is ready */\r
416   if(hdma->State == HAL_DMA_STATE_READY)\r
417   {\r
418     /* Process Locked */\r
419     __HAL_LOCK(hdma);\r
420 \r
421     /* Disable the synchronization and event generation before applying a new config */\r
422     CLEAR_BIT(hdma->DMAmuxChannel->CCR,(DMAMUX_CxCR_SE | DMAMUX_CxCR_EGE));\r
423 \r
424     /* Set the new synchronization parameters (and keep the request ID filled during the Init)*/\r
425     MODIFY_REG( hdma->DMAmuxChannel->CCR, \\r
426                (~DMAMUX_CxCR_DMAREQ_ID) , \\r
427                (syncSignalID << DMAMUX_CxCR_SYNC_ID_Pos)       | \\r
428                ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \\r
429                syncPolarity | ((uint32_t)pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos)    | \\r
430                ((uint32_t)pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos));\r
431 \r
432       /* Process Locked */\r
433     __HAL_UNLOCK(hdma);\r
434 \r
435     return HAL_OK;\r
436   }\r
437   else\r
438   {\r
439     /* Set the error code to busy */\r
440     hdma->ErrorCode = HAL_DMA_ERROR_BUSY;\r
441 \r
442     /* Return error status */\r
443     return HAL_ERROR;\r
444   }\r
445 }\r
446 \r
447 /**\r
448   * @brief  Configure the DMAMUX request generator block used by the given DMA stream (instance).\r
449   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains\r
450   *                     the configuration information for the specified DMA Stream.\r
451   * @param  pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef :\r
452   *         contains the request generator parameters.\r
453   *\r
454   * @retval HAL status\r
455   */\r
456 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)\r
457 {\r
458   HAL_StatusTypeDef status;\r
459   HAL_DMA_StateTypeDef temp_state = hdma->State;\r
460 \r
461   /* Check the parameters */\r
462   assert_param(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance));\r
463 \r
464   if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */\r
465   {\r
466     assert_param(IS_DMA_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));\r
467   }\r
468   else\r
469   {\r
470     assert_param(IS_BDMA_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));\r
471   }\r
472 \r
473 \r
474   assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));\r
475   assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));\r
476 \r
477   /* check if the DMA state is ready\r
478      and DMA is using a DMAMUX request generator block\r
479   */\r
480   if(hdma->DMAmuxRequestGen == 0U)\r
481   {\r
482     /* Set the error code to busy */\r
483     hdma->ErrorCode = HAL_DMA_ERROR_PARAM;\r
484 \r
485     /* error status */\r
486     status = HAL_ERROR;\r
487   }\r
488   else if(((hdma->DMAmuxRequestGen->RGCR & DMAMUX_RGxCR_GE) == 0U) && (temp_state == HAL_DMA_STATE_READY))\r
489   {\r
490     /* RequestGenerator must be disable prior to the configuration i.e GE bit is 0 */\r
491 \r
492     /* Process Locked */\r
493     __HAL_LOCK(hdma);\r
494 \r
495     /* Set the request generator new parameters */\r
496     hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \\r
497                                   ((pRequestGeneratorConfig->RequestNumber - 1U) << DMAMUX_RGxCR_GNBREQ_Pos)| \\r
498                                   pRequestGeneratorConfig->Polarity;\r
499     /* Process Locked */\r
500     __HAL_UNLOCK(hdma);\r
501 \r
502     return HAL_OK;\r
503   }\r
504   else\r
505   {\r
506     /* Set the error code to busy */\r
507     hdma->ErrorCode = HAL_DMA_ERROR_BUSY;\r
508 \r
509     /* error status */\r
510     status = HAL_ERROR;\r
511   }\r
512 \r
513   return status;\r
514 }\r
515 \r
516 /**\r
517   * @brief  Enable the DMAMUX request generator block used by the given DMA stream (instance).\r
518   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains\r
519   *                     the configuration information for the specified DMA Stream.\r
520   * @retval HAL status\r
521   */\r
522 HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma)\r
523 {\r
524   /* Check the parameters */\r
525   assert_param(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance));\r
526 \r
527   /* check if the DMA state is ready\r
528      and DMA is using a DMAMUX request generator block */\r
529   if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0U))\r
530   {\r
531     /* Enable the request generator*/\r
532     hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE;\r
533 \r
534    return HAL_OK;\r
535  }\r
536  else\r
537  {\r
538    return HAL_ERROR;\r
539  }\r
540 }\r
541 \r
542 /**\r
543   * @brief  Disable the DMAMUX request generator block used by the given DMA stream (instance).\r
544   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains\r
545   *                     the configuration information for the specified DMA Stream.\r
546   * @retval HAL status\r
547   */\r
548 HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator (DMA_HandleTypeDef *hdma)\r
549 {\r
550   /* Check the parameters */\r
551   assert_param(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance));\r
552 \r
553   /* check if the DMA state is ready\r
554      and DMA is using a DMAMUX request generator block */\r
555   if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0U))\r
556   {\r
557     /* Disable the request generator*/\r
558     hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE;\r
559 \r
560    return HAL_OK;\r
561  }\r
562  else\r
563  {\r
564    return HAL_ERROR;\r
565  }\r
566 }\r
567 \r
568 /**\r
569   * @brief  Handles DMAMUX interrupt request.\r
570   * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains\r
571   *               the configuration information for the specified DMA Stream.\r
572   * @retval None\r
573   */\r
574 void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma)\r
575 {\r
576   /* Check for DMAMUX Synchronization overrun */\r
577   if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)\r
578   {\r
579     /* Disable the synchro overrun interrupt */\r
580     hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;\r
581 \r
582     /* Clear the DMAMUX synchro overrun flag */\r
583     hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;\r
584 \r
585     /* Update error code */\r
586     hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;\r
587 \r
588     if(hdma->XferErrorCallback != NULL)\r
589     {\r
590       /* Transfer error callback */\r
591       hdma->XferErrorCallback(hdma);\r
592     }\r
593   }\r
594 \r
595   if(hdma->DMAmuxRequestGen != 0)\r
596   {\r
597    /* if using a DMAMUX request generator block Check for DMAMUX request generator overrun */\r
598     if((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)\r
599     {\r
600       /* Disable the request gen overrun interrupt */\r
601       hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;\r
602 \r
603       /* Clear the DMAMUX request generator overrun flag */\r
604       hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;\r
605 \r
606       /* Update error code */\r
607       hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;\r
608 \r
609       if(hdma->XferErrorCallback != NULL)\r
610       {\r
611         /* Transfer error callback */\r
612         hdma->XferErrorCallback(hdma);\r
613       }\r
614     }\r
615   }\r
616 }\r
617 \r
618 \r
619 /**\r
620   * @}\r
621   */\r
622 \r
623 /**\r
624   * @}\r
625   */\r
626 \r
627 /** @addtogroup DMAEx_Private_Functions\r
628   * @{\r
629   */\r
630 \r
631 /**\r
632   * @brief  Set the DMA Transfer parameter.\r
633   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains\r
634   *                     the configuration information for the specified DMA Stream.\r
635   * @param  SrcAddress: The source memory Buffer address\r
636   * @param  DstAddress: The destination memory Buffer address\r
637   * @param  DataLength: The length of data to be transferred from source to destination\r
638   * @retval HAL status\r
639   */\r
640 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)\r
641 {\r
642   if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */\r
643   {\r
644     /* Configure DMA Stream data length */\r
645     ((DMA_Stream_TypeDef   *)hdma->Instance)->NDTR = DataLength;\r
646 \r
647     /* Peripheral to Memory */\r
648     if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)\r
649     {\r
650       /* Configure DMA Stream destination address */\r
651       ((DMA_Stream_TypeDef   *)hdma->Instance)->PAR = DstAddress;\r
652 \r
653       /* Configure DMA Stream source address */\r
654       ((DMA_Stream_TypeDef   *)hdma->Instance)->M0AR = SrcAddress;\r
655     }\r
656     /* Memory to Peripheral */\r
657     else\r
658     {\r
659       /* Configure DMA Stream source address */\r
660       ((DMA_Stream_TypeDef   *)hdma->Instance)->PAR = SrcAddress;\r
661 \r
662       /* Configure DMA Stream destination address */\r
663       ((DMA_Stream_TypeDef   *)hdma->Instance)->M0AR = DstAddress;\r
664     }\r
665   }\r
666   else /* BDMA instance(s) */\r
667   {\r
668     /* Configure DMA Stream data length */\r
669     ((BDMA_Channel_TypeDef   *)hdma->Instance)->CNDTR = DataLength;\r
670 \r
671     /* Peripheral to Memory */\r
672     if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)\r
673     {\r
674       /* Configure DMA Stream destination address */\r
675       ((BDMA_Channel_TypeDef   *)hdma->Instance)->CPAR = DstAddress;\r
676 \r
677       /* Configure DMA Stream source address */\r
678       ((BDMA_Channel_TypeDef   *)hdma->Instance)->CM0AR = SrcAddress;\r
679     }\r
680     /* Memory to Peripheral */\r
681     else\r
682     {\r
683       /* Configure DMA Stream source address */\r
684       ((BDMA_Channel_TypeDef   *)hdma->Instance)->CPAR = SrcAddress;\r
685 \r
686       /* Configure DMA Stream destination address */\r
687       ((BDMA_Channel_TypeDef   *)hdma->Instance)->CM0AR = DstAddress;\r
688     }\r
689   }\r
690 }\r
691 \r
692 /**\r
693   * @}\r
694   */\r
695 \r
696 #endif /* HAL_DMA_MODULE_ENABLED */\r
697 /**\r
698   * @}\r
699   */\r
700 \r
701 /**\r
702   * @}\r
703   */\r
704 \r
705 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r