stm32l4xx_hal_dma_ex.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_dma_ex.c
  4. * @author MCD Application Team
  5. * @brief DMA Extension HAL module driver
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the DMA Extension peripheral:
  8. * + Extended features functions
  9. *
  10. @verbatim
  11. ==============================================================================
  12. ##### How to use this driver #####
  13. ==============================================================================
  14. [..]
  15. The DMA Extension HAL driver can be used as follows:
  16. (+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
  17. (+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
  18. Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
  19. to respectively enable/disable the request generator.
  20. (+) To handle the DMAMUX Interrupts, the function HAL_DMAEx_MUX_IRQHandler should be called from
  21. the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler.
  22. As only one interrupt line is available for all DMAMUX channels and request generators , HAL_DMAEx_MUX_IRQHandler should be
  23. called with, as parameter, the appropriate DMA handle as many as used DMAs in the user project
  24. (exception done if a given DMA is not using the DMAMUX SYNC block neither a request generator)
  25. -@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed.
  26. -@- When Multi (Double) Buffer mode is enabled, the transfer is circular by default.
  27. -@- In Multi (Double) buffer mode, it is possible to update the base address for
  28. the AHB memory port on the fly (DMA_CM0ARx or DMA_CM1ARx) when the channel is enabled.
  29. @endverbatim
  30. ******************************************************************************
  31. * @attention
  32. *
  33. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  34. * All rights reserved.</center></h2>
  35. *
  36. * This software component is licensed by ST under BSD 3-Clause license,
  37. * the "License"; You may not use this file except in compliance with the
  38. * License. You may obtain a copy of the License at:
  39. * opensource.org/licenses/BSD-3-Clause
  40. *
  41. ******************************************************************************
  42. */
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l4xx_hal.h"
  45. #if defined(DMAMUX1)
  46. /** @addtogroup STM32L4xx_HAL_Driver
  47. * @{
  48. */
  49. /** @defgroup DMAEx DMAEx
  50. * @brief DMA Extended HAL module driver
  51. * @{
  52. */
  53. #ifdef HAL_DMA_MODULE_ENABLED
  54. /* Private typedef -----------------------------------------------------------*/
  55. /* Private define ------------------------------------------------------------*/
  56. /* Private macro -------------------------------------------------------------*/
  57. /* Private variables ---------------------------------------------------------*/
  58. /* Private Constants ---------------------------------------------------------*/
  59. /* Private function prototypes -----------------------------------------------*/
  60. /* Private functions ---------------------------------------------------------*/
  61. /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions
  62. * @{
  63. */
  64. /** @defgroup DMAEx_Exported_Functions_Group1 DMAEx Extended features functions
  65. * @brief Extended features functions
  66. *
  67. @verbatim
  68. ===============================================================================
  69. ##### Extended features functions #####
  70. ===============================================================================
  71. [..] This section provides functions allowing to:
  72. (+) Configure the DMAMUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
  73. (+) Configure the DMAMUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
  74. Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
  75. to respectively enable/disable the request generator.
  76. @endverbatim
  77. * @{
  78. */
  79. /**
  80. * @brief Configure the DMAMUX synchronization parameters for a given DMA channel (instance).
  81. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  82. * the configuration information for the specified DMA channel.
  83. * @param pSyncConfig : pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters
  84. * @retval HAL status
  85. */
  86. HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig)
  87. {
  88. /* Check the parameters */
  89. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  90. assert_param(IS_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
  91. assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig-> SyncPolarity));
  92. assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable));
  93. assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable));
  94. assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber));
  95. /*Check if the DMA state is ready */
  96. if(hdma->State == HAL_DMA_STATE_READY)
  97. {
  98. /* Process Locked */
  99. __HAL_LOCK(hdma);
  100. /* Set the new synchronization parameters (and keep the request ID filled during the Init)*/
  101. MODIFY_REG( hdma->DMAmuxChannel->CCR, \
  102. (~DMAMUX_CxCR_DMAREQ_ID) , \
  103. ((pSyncConfig->SyncSignalID) << DMAMUX_CxCR_SYNC_ID_Pos) | ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \
  104. pSyncConfig->SyncPolarity | ((uint32_t)pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \
  105. ((uint32_t)pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos));
  106. /* Process UnLocked */
  107. __HAL_UNLOCK(hdma);
  108. return HAL_OK;
  109. }
  110. else
  111. {
  112. /*DMA State not Ready*/
  113. return HAL_ERROR;
  114. }
  115. }
  116. /**
  117. * @brief Configure the DMAMUX request generator block used by the given DMA channel (instance).
  118. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  119. * the configuration information for the specified DMA channel.
  120. * @param pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef :
  121. * contains the request generator parameters.
  122. *
  123. * @retval HAL status
  124. */
  125. HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)
  126. {
  127. /* Check the parameters */
  128. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  129. assert_param(IS_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
  130. assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));
  131. assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));
  132. /* check if the DMA state is ready
  133. and DMA is using a DMAMUX request generator block
  134. */
  135. if((hdma->State == HAL_DMA_STATE_READY) && (hdma->DMAmuxRequestGen != 0U))
  136. {
  137. /* Process Locked */
  138. __HAL_LOCK(hdma);
  139. /* Set the request generator new parameters */
  140. hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \
  141. ((pRequestGeneratorConfig->RequestNumber - 1U) << DMAMUX_RGxCR_GNBREQ_Pos)| \
  142. pRequestGeneratorConfig->Polarity;
  143. /* Process UnLocked */
  144. __HAL_UNLOCK(hdma);
  145. return HAL_OK;
  146. }
  147. else
  148. {
  149. return HAL_ERROR;
  150. }
  151. }
  152. /**
  153. * @brief Enable the DMAMUX request generator block used by the given DMA channel (instance).
  154. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  155. * the configuration information for the specified DMA channel.
  156. * @retval HAL status
  157. */
  158. HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
  159. {
  160. /* Check the parameters */
  161. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  162. /* check if the DMA state is ready
  163. and DMA is using a DMAMUX request generator block
  164. */
  165. if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))
  166. {
  167. /* Enable the request generator*/
  168. hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE;
  169. return HAL_OK;
  170. }
  171. else
  172. {
  173. return HAL_ERROR;
  174. }
  175. }
  176. /**
  177. * @brief Disable the DMAMUX request generator block used by the given DMA channel (instance).
  178. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  179. * the configuration information for the specified DMA channel.
  180. * @retval HAL status
  181. */
  182. HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
  183. {
  184. /* Check the parameters */
  185. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  186. /* check if the DMA state is ready
  187. and DMA is using a DMAMUX request generator block
  188. */
  189. if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))
  190. {
  191. /* Disable the request generator*/
  192. hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE;
  193. return HAL_OK;
  194. }
  195. else
  196. {
  197. return HAL_ERROR;
  198. }
  199. }
  200. /**
  201. * @brief Handles DMAMUX interrupt request.
  202. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  203. * the configuration information for the specified DMA channel.
  204. * @retval None
  205. */
  206. void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma)
  207. {
  208. /* Check for DMAMUX Synchronization overrun */
  209. if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)
  210. {
  211. /* Disable the synchro overrun interrupt */
  212. hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;
  213. /* Clear the DMAMUX synchro overrun flag */
  214. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  215. /* Update error code */
  216. hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;
  217. if(hdma->XferErrorCallback != NULL)
  218. {
  219. /* Transfer error callback */
  220. hdma->XferErrorCallback(hdma);
  221. }
  222. }
  223. if(hdma->DMAmuxRequestGen != 0)
  224. {
  225. /* if using a DMAMUX request generator block Check for DMAMUX request generator overrun */
  226. if((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)
  227. {
  228. /* Disable the request gen overrun interrupt */
  229. hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;
  230. /* Clear the DMAMUX request generator overrun flag */
  231. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  232. /* Update error code */
  233. hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;
  234. if(hdma->XferErrorCallback != NULL)
  235. {
  236. /* Transfer error callback */
  237. hdma->XferErrorCallback(hdma);
  238. }
  239. }
  240. }
  241. }
  242. /**
  243. * @}
  244. */
  245. /**
  246. * @}
  247. */
  248. #endif /* HAL_DMA_MODULE_ENABLED */
  249. /**
  250. * @}
  251. */
  252. /**
  253. * @}
  254. */
  255. #endif /* DMAMUX1 */
  256. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/