stm32l4xx_hal_dma_ex.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. @endverbatim
  26. ******************************************************************************
  27. * @attention
  28. *
  29. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  30. *
  31. * Redistribution and use in source and binary forms, with or without modification,
  32. * are permitted provided that the following conditions are met:
  33. * 1. Redistributions of source code must retain the above copyright notice,
  34. * this list of conditions and the following disclaimer.
  35. * 2. Redistributions in binary form must reproduce the above copyright notice,
  36. * this list of conditions and the following disclaimer in the documentation
  37. * and/or other materials provided with the distribution.
  38. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  39. * may be used to endorse or promote products derived from this software
  40. * without specific prior written permission.
  41. *
  42. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  43. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  45. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  46. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  47. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  48. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  49. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  50. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  51. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. *
  53. ******************************************************************************
  54. */
  55. /* Includes ------------------------------------------------------------------*/
  56. #include "stm32l4xx_hal.h"
  57. #if defined(DMAMUX1)
  58. /** @addtogroup STM32L4xx_HAL_Driver
  59. * @{
  60. */
  61. /** @defgroup DMAEx DMAEx
  62. * @brief DMA Extended HAL module driver
  63. * @{
  64. */
  65. #ifdef HAL_DMA_MODULE_ENABLED
  66. /* Private typedef -----------------------------------------------------------*/
  67. /* Private define ------------------------------------------------------------*/
  68. /* Private macro -------------------------------------------------------------*/
  69. /* Private variables ---------------------------------------------------------*/
  70. /* Private Constants ---------------------------------------------------------*/
  71. /* Private function prototypes -----------------------------------------------*/
  72. /* Private functions ---------------------------------------------------------*/
  73. /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions
  74. * @{
  75. */
  76. /** @defgroup DMAEx_Exported_Functions_Group1 DMAEx Extended features functions
  77. * @brief Extended features functions
  78. *
  79. @verbatim
  80. ===============================================================================
  81. ##### Extended features functions #####
  82. ===============================================================================
  83. [..] This section provides functions allowing to:
  84. (+) Configure the DMAMUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
  85. (+) Configure the DMAMUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
  86. Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
  87. to respectively enable/disable the request generator.
  88. @endverbatim
  89. * @{
  90. */
  91. /**
  92. * @brief Configure the DMAMUX synchronization parameters for a given DMA channel (instance).
  93. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  94. * the configuration information for the specified DMA channel.
  95. * @param pSyncConfig : pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters
  96. * @retval HAL status
  97. */
  98. HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig)
  99. {
  100. /* Check the parameters */
  101. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  102. assert_param(IS_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
  103. assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig-> SyncPolarity));
  104. assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable));
  105. assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable));
  106. assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber));
  107. /*Check if the DMA state is ready */
  108. if(hdma->State == HAL_DMA_STATE_READY)
  109. {
  110. /* Process Locked */
  111. __HAL_LOCK(hdma);
  112. /* Set the new synchronization parameters (and keep the request ID filled during the Init)*/
  113. MODIFY_REG( hdma->DMAmuxChannel->CCR, \
  114. (~DMAMUX_CxCR_DMAREQ_ID) , \
  115. ((pSyncConfig->SyncSignalID) << DMAMUX_CxCR_SYNC_ID_Pos) | ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \
  116. pSyncConfig->SyncPolarity | (pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \
  117. (pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos));
  118. /* Process UnLocked */
  119. __HAL_UNLOCK(hdma);
  120. return HAL_OK;
  121. }
  122. else
  123. {
  124. /*DMA State not Ready*/
  125. return HAL_ERROR;
  126. }
  127. }
  128. /**
  129. * @brief Configure the DMAMUX request generator block used by the given DMA channel (instance).
  130. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  131. * the configuration information for the specified DMA channel.
  132. * @param pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef :
  133. * contains the request generator parameters.
  134. *
  135. * @retval HAL status
  136. */
  137. HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)
  138. {
  139. /* Check the parameters */
  140. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  141. assert_param(IS_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
  142. assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));
  143. assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));
  144. /* check if the DMA state is ready
  145. and DMA is using a DMAMUX request generator block
  146. */
  147. if((hdma->State == HAL_DMA_STATE_READY) && (hdma->DMAmuxRequestGen != 0U))
  148. {
  149. /* Process Locked */
  150. __HAL_LOCK(hdma);
  151. /* Set the request generator new parameters*/
  152. hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \
  153. ((pRequestGeneratorConfig->RequestNumber - 1U) << POSITION_VAL(DMAMUX_RGxCR_GNBREQ))| \
  154. pRequestGeneratorConfig->Polarity;
  155. /* Process UnLocked */
  156. __HAL_UNLOCK(hdma);
  157. return HAL_OK;
  158. }
  159. else
  160. {
  161. return HAL_ERROR;
  162. }
  163. }
  164. /**
  165. * @brief Enable the DMAMUX request generator block used by the given DMA channel (instance).
  166. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  167. * the configuration information for the specified DMA channel.
  168. * @retval HAL status
  169. */
  170. HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
  171. {
  172. /* Check the parameters */
  173. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  174. /* check if the DMA state is ready
  175. and DMA is using a DMAMUX request generator block
  176. */
  177. if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))
  178. {
  179. /* Enable the request generator*/
  180. hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE;
  181. return HAL_OK;
  182. }
  183. else
  184. {
  185. return HAL_ERROR;
  186. }
  187. }
  188. /**
  189. * @brief Disable the DMAMUX request generator block used by the given DMA channel (instance).
  190. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  191. * the configuration information for the specified DMA channel.
  192. * @retval HAL status
  193. */
  194. HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
  195. {
  196. /* Check the parameters */
  197. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  198. /* check if the DMA state is ready
  199. and DMA is using a DMAMUX request generator block
  200. */
  201. if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))
  202. {
  203. /* Disable the request generator*/
  204. hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE;
  205. return HAL_OK;
  206. }
  207. else
  208. {
  209. return HAL_ERROR;
  210. }
  211. }
  212. /**
  213. * @brief Handles DMAMUX interrupt request.
  214. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  215. * the configuration information for the specified DMA channel.
  216. * @retval None
  217. */
  218. void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma)
  219. {
  220. /* Check for DMAMUX Synchronization overrun */
  221. if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)
  222. {
  223. /* Disable the synchro overrun interrupt */
  224. hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;
  225. /* Clear the DMAMUX synchro overrun flag */
  226. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  227. /* Update error code */
  228. hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;
  229. if(hdma->XferErrorCallback != NULL)
  230. {
  231. /* Transfer error callback */
  232. hdma->XferErrorCallback(hdma);
  233. }
  234. }
  235. if(hdma->DMAmuxRequestGen != 0)
  236. {
  237. /* if using a DMAMUX request generator block Check for DMAMUX request generator overrun */
  238. if((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)
  239. {
  240. /* Disable the request gen overrun interrupt */
  241. hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;
  242. /* Clear the DMAMUX request generator overrun flag */
  243. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  244. /* Update error code */
  245. hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;
  246. if(hdma->XferErrorCallback != NULL)
  247. {
  248. /* Transfer error callback */
  249. hdma->XferErrorCallback(hdma);
  250. }
  251. }
  252. }
  253. }
  254. /**
  255. * @}
  256. */
  257. /**
  258. * @}
  259. */
  260. #endif /* HAL_DMA_MODULE_ENABLED */
  261. /**
  262. * @}
  263. */
  264. /**
  265. * @}
  266. */
  267. #endif /* DMAMUX1 */
  268. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/