You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

297 lines
10 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_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) 2019 STMicroelectronics.
  30. * All rights reserved.</center></h2>
  31. *
  32. * This software component is licensed by ST under BSD 3-Clause license,
  33. * the "License"; You may not use this file except in compliance with the
  34. * License. You may obtain a copy of the License at:
  35. * opensource.org/licenses/BSD-3-Clause
  36. *
  37. ******************************************************************************
  38. */
  39. /* Includes ------------------------------------------------------------------*/
  40. #include "stm32wbxx_hal.h"
  41. /** @addtogroup STM32WBxx_HAL_Driver
  42. * @{
  43. */
  44. /** @defgroup DMAEx DMAEx
  45. * @brief DMA Extended HAL module driver
  46. * @{
  47. */
  48. #ifdef HAL_DMA_MODULE_ENABLED
  49. /* Private typedef -----------------------------------------------------------*/
  50. /* Private define ------------------------------------------------------------*/
  51. /* Private macro -------------------------------------------------------------*/
  52. /* Private variables ---------------------------------------------------------*/
  53. /* Private Constants ---------------------------------------------------------*/
  54. /* Private function prototypes -----------------------------------------------*/
  55. /* Private functions ---------------------------------------------------------*/
  56. /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions
  57. * @{
  58. */
  59. /** @defgroup DMAEx_Exported_Functions_Group1 DMAEx Extended features functions
  60. * @brief Extended features functions
  61. *
  62. @verbatim
  63. ===============================================================================
  64. ##### Extended features functions #####
  65. ===============================================================================
  66. [..] This section provides functions allowing to:
  67. (+) Configure the DMAMUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
  68. (+) Configure the DMAMUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
  69. Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
  70. to respectively enable/disable the request generator.
  71. @endverbatim
  72. * @{
  73. */
  74. /**
  75. * @brief Configure the DMAMUX synchronization parameters for a given DMA channel (instance).
  76. * @param hdma Pointer to a DMA_HandleTypeDef structure that contains
  77. * the configuration information for the specified DMA channel.
  78. * @param pSyncConfig Pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters
  79. * @retval HAL status
  80. */
  81. HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig)
  82. {
  83. /* Check the parameters */
  84. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  85. assert_param(IS_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
  86. assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig-> SyncPolarity));
  87. assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable));
  88. assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable));
  89. assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber));
  90. /*Check if the DMA state is ready */
  91. if (hdma->State == HAL_DMA_STATE_READY)
  92. {
  93. /* Process Locked */
  94. __HAL_LOCK(hdma);
  95. /* Set the new synchronization parameters (and keep the request ID filled during the Init)*/
  96. MODIFY_REG(hdma->DMAmuxChannel->CCR, \
  97. (DMAMUX_CxCR_SYNC_ID | DMAMUX_CxCR_NBREQ | DMAMUX_CxCR_SPOL | DMAMUX_CxCR_SE | DMAMUX_CxCR_EGE), \
  98. (pSyncConfig->SyncSignalID | \
  99. ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \
  100. pSyncConfig->SyncPolarity | \
  101. ((uint32_t)pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \
  102. ((uint32_t)pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos)));
  103. /* Process UnLocked */
  104. __HAL_UNLOCK(hdma);
  105. return HAL_OK;
  106. }
  107. else
  108. {
  109. /*DMA State not Ready*/
  110. return HAL_ERROR;
  111. }
  112. }
  113. /**
  114. * @brief Configure the DMAMUX request generator block used by the given DMA channel (instance).
  115. * @param hdma Pointer to a DMA_HandleTypeDef structure that contains
  116. * the configuration information for the specified DMA channel.
  117. * @param pRequestGeneratorConfig Pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef :
  118. * contains the request generator parameters.
  119. *
  120. * @retval HAL status
  121. */
  122. HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator(DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)
  123. {
  124. /* Check the parameters */
  125. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  126. assert_param(IS_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
  127. assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));
  128. assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));
  129. /* check if the DMA state is ready
  130. and DMA is using a DMAMUX request generator block
  131. */
  132. if ((hdma->State == HAL_DMA_STATE_READY) && (hdma->DMAmuxRequestGen != 0U))
  133. {
  134. /* Process Locked */
  135. __HAL_LOCK(hdma);
  136. /* Set the request generator new parameters*/
  137. WRITE_REG(hdma->DMAmuxRequestGen->RGCR, (pRequestGeneratorConfig->SignalID | \
  138. pRequestGeneratorConfig->Polarity | \
  139. ((pRequestGeneratorConfig->RequestNumber - 1U) << DMAMUX_RGxCR_GNBREQ_Pos)));
  140. /* Process UnLocked */
  141. __HAL_UNLOCK(hdma);
  142. return HAL_OK;
  143. }
  144. else
  145. {
  146. return HAL_ERROR;
  147. }
  148. }
  149. /**
  150. * @brief Enable the DMAMUX request generator block used by the given DMA channel (instance).
  151. * @param hdma Pointer to a DMA_HandleTypeDef structure that contains
  152. * the configuration information for the specified DMA channel.
  153. * @retval HAL status
  154. */
  155. HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator(DMA_HandleTypeDef *hdma)
  156. {
  157. /* Check the parameters */
  158. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  159. /* check if the DMA state is ready
  160. and DMA is using a DMAMUX request generator block
  161. */
  162. if ((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0U))
  163. {
  164. /* Enable the request generator*/
  165. SET_BIT(hdma->DMAmuxRequestGen->RGCR, DMAMUX_RGxCR_GE);
  166. return HAL_OK;
  167. }
  168. else
  169. {
  170. return HAL_ERROR;
  171. }
  172. }
  173. /**
  174. * @brief Disable the DMAMUX request generator block used by the given DMA channel (instance).
  175. * @param hdma Pointer to a DMA_HandleTypeDef structure that contains
  176. * the configuration information for the specified DMA channel.
  177. * @retval HAL status
  178. */
  179. HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator(DMA_HandleTypeDef *hdma)
  180. {
  181. /* Check the parameters */
  182. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  183. /* check if the DMA state is ready
  184. and DMA is using a DMAMUX request generator block
  185. */
  186. if ((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))
  187. {
  188. /* Disable the request generator*/
  189. CLEAR_BIT(hdma->DMAmuxRequestGen->RGCR, DMAMUX_RGxCR_GE);
  190. return HAL_OK;
  191. }
  192. else
  193. {
  194. return HAL_ERROR;
  195. }
  196. }
  197. /**
  198. * @brief Handles DMAMUX interrupt request.
  199. * @param hdma Pointer to a DMA_HandleTypeDef structure that contains
  200. * the configuration information for the specified DMA channel.
  201. * @retval None
  202. */
  203. void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma)
  204. {
  205. /* Check for DMAMUX Synchronization overrun */
  206. if ((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)
  207. {
  208. /* Disable the synchro overrun interrupt */
  209. CLEAR_BIT(hdma->DMAmuxChannel->CCR, DMAMUX_CxCR_SOIE);
  210. /* Clear the DMAMUX synchro overrun flag */
  211. WRITE_REG(hdma->DMAmuxChannelStatus->CFR, hdma->DMAmuxChannelStatusMask);
  212. /* Update error code */
  213. hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;
  214. if (hdma->XferErrorCallback != NULL)
  215. {
  216. /* Transfer error callback */
  217. hdma->XferErrorCallback(hdma);
  218. }
  219. }
  220. if (hdma->DMAmuxRequestGen != 0U)
  221. {
  222. /* if using a DMAMUX request generator block Check for DMAMUX request generator overrun */
  223. if ((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)
  224. {
  225. /* Disable the request gen overrun interrupt */
  226. CLEAR_BIT(hdma->DMAmuxRequestGen->RGCR, DMAMUX_RGxCR_OIE);
  227. /* Clear the DMAMUX request generator overrun flag */
  228. WRITE_REG(hdma->DMAmuxRequestGenStatus->RGCFR, hdma->DMAmuxRequestGenStatusMask);
  229. /* Update error code */
  230. hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;
  231. if (hdma->XferErrorCallback != NULL)
  232. {
  233. /* Transfer error callback */
  234. hdma->XferErrorCallback(hdma);
  235. }
  236. }
  237. }
  238. }
  239. /**
  240. * @}
  241. */
  242. /**
  243. * @}
  244. */
  245. #endif /* HAL_DMA_MODULE_ENABLED */
  246. /**
  247. * @}
  248. */
  249. /**
  250. * @}
  251. */
  252. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/