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.
 
 
 

639 lines
23 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_dma_ex.c
  4. * @author MCD Application Team
  5. * @version V1.2.0
  6. * @date 29-December-2017
  7. * @brief DMA Extension HAL module driver
  8. * This file provides firmware functions to manage the following
  9. * functionalities of the DMA Extension peripheral:
  10. * + Extended features functions
  11. *
  12. @verbatim
  13. ==============================================================================
  14. ##### How to use this driver #####
  15. ==============================================================================
  16. [..]
  17. The DMA Extension HAL driver can be used as follows:
  18. (+) Start a multi buffer transfer using the HAL_DMA_MultiBufferStart() function
  19. for polling mode or HAL_DMA_MultiBufferStart_IT() for interrupt mode.
  20. (+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
  21. (+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
  22. Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
  23. to respectively enable/disable the request generator.
  24. (+) To handle the DMAMUX Interrupts, the function HAL_DMAEx_MUX_IRQHandler should be called from
  25. the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler or DMAMUX2_OVR_IRQHandler .
  26. As only one interrupt line is available for all DMAMUX channels and request generators , HAL_DMA_MUX_IRQHandler should be
  27. called with, as parameter, the appropriate DMA handle as many as used DMAs in the user project
  28. (exception done if a given DMA is not using the DMAMUX SYNC block neither a request generator)
  29. -@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed.
  30. -@- When Multi (Double) Buffer mode is enabled, the transfer is circular by default.
  31. -@- In Multi (Double) buffer mode, it is possible to update the base address for
  32. the AHB memory port on the fly (DMA_SxM0AR or DMA_SxM1AR) when the stream is enabled.
  33. -@- Multi (Double) buffer mode is only possible with D2 DMAs i.e DMA1 or DMA2. not BDMA.
  34. Multi (Double) buffer mode is not possible with D3 BDMA.
  35. @endverbatim
  36. ******************************************************************************
  37. * @attention
  38. *
  39. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  40. *
  41. * Redistribution and use in source and binary forms, with or without modification,
  42. * are permitted provided that the following conditions are met:
  43. * 1. Redistributions of source code must retain the above copyright notice,
  44. * this list of conditions and the following disclaimer.
  45. * 2. Redistributions in binary form must reproduce the above copyright notice,
  46. * this list of conditions and the following disclaimer in the documentation
  47. * and/or other materials provided with the distribution.
  48. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  49. * may be used to endorse or promote products derived from this software
  50. * without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  53. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  54. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  55. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  56. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  57. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  58. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  59. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  60. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  61. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  62. *
  63. ******************************************************************************
  64. */
  65. /* Includes ------------------------------------------------------------------*/
  66. #include "stm32h7xx_hal.h"
  67. /** @addtogroup STM32H7xx_HAL_Driver
  68. * @{
  69. */
  70. /** @defgroup DMAEx DMAEx
  71. * @brief DMA Extended HAL module driver
  72. * @{
  73. */
  74. #ifdef HAL_DMA_MODULE_ENABLED
  75. /* Private types -------------------------------------------------------------*/
  76. /* Private variables ---------------------------------------------------------*/
  77. /* Private Constants ---------------------------------------------------------*/
  78. #define DMAMUX_POSITION_CxCR_SE (uint32_t)POSITION_VAL(DMAMUX_CxCR_SE) /*!< Required for left shift of the DMAMUX SYNC enable/disable */
  79. #define DMAMUX_POSITION_CxCR_EGE (uint32_t)POSITION_VAL(DMAMUX_CxCR_EGE) /*!< Required for left shift of the DMAMUX SYNC EVENT enable/disable */
  80. /* Private macros ------------------------------------------------------------*/
  81. /* Private functions ---------------------------------------------------------*/
  82. /** @addtogroup DMAEx_Private_Functions
  83. * @{
  84. */
  85. static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  86. /**
  87. * @}
  88. */
  89. /* Exported functions ---------------------------------------------------------*/
  90. /** @addtogroup DMAEx_Exported_Functions
  91. * @{
  92. */
  93. /** @addtogroup DMAEx_Exported_Functions_Group1
  94. *
  95. @verbatim
  96. ===============================================================================
  97. ##### Extended features functions #####
  98. ===============================================================================
  99. [..] This section provides functions allowing to:
  100. (+) Configure the source, destination address and data length and
  101. Start MultiBuffer DMA transfer
  102. (+) Configure the source, destination address and data length and
  103. Start MultiBuffer DMA transfer with interrupt
  104. (+) Change on the fly the memory0 or memory1 address.
  105. (+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
  106. (+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
  107. (+) Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
  108. to respectively enable/disable the request generator.
  109. (+) Handle DMAMUX interrupts using HAL_DMAEx_MUX_IRQHandler : should be called from
  110. the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler or DMAMUX2_OVR_IRQHandler
  111. @endverbatim
  112. * @{
  113. */
  114. /**
  115. * @brief Starts the multi_buffer DMA Transfer.
  116. * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
  117. * the configuration information for the specified DMA Stream.
  118. * @param SrcAddress: The source memory Buffer address
  119. * @param DstAddress: The destination memory Buffer address
  120. * @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
  121. * @param DataLength: The length of data to be transferred from source to destination
  122. * @retval HAL status
  123. */
  124. HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
  125. {
  126. HAL_StatusTypeDef status = HAL_OK;
  127. __IO uint32_t *ifcRegister_Base = NULL; /* DMA Stream Interrupt Clear register */
  128. /* Check the parameters */
  129. assert_param(IS_DMA_BUFFER_SIZE(DataLength));
  130. /* Memory-to-memory transfer not supported in double buffering mode */
  131. /* double buffering mode not supported for BDMA (D3 DMA) */
  132. if ( (IS_D2_DMA_INSTANCE(hdma) == 0U) || (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY))
  133. {
  134. hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
  135. status = HAL_ERROR;
  136. }
  137. else
  138. {
  139. /* Process Locked */
  140. __HAL_LOCK(hdma);
  141. if(HAL_DMA_STATE_READY == hdma->State)
  142. {
  143. /* Change DMA peripheral state */
  144. hdma->State = HAL_DMA_STATE_BUSY;
  145. /* Initialize the error code */
  146. hdma->ErrorCode = HAL_DMA_ERROR_NONE;
  147. /* Enable the double buffer mode */
  148. ((DMA_Stream_TypeDef *)hdma->Instance)->CR |= (uint32_t)DMA_SxCR_DBM;
  149. /* Configure DMA Stream destination address */
  150. ((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = SecondMemAddress;
  151. /* Configure the source, destination address and the data length */
  152. DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
  153. /* Calculate the interrupt clear flag register (IFCR) base address */
  154. ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 8U));
  155. /* Clear all flags */
  156. *ifcRegister_Base = 0x3FU << hdma->StreamIndex;
  157. /* Clear the DMAMUX synchro overrun flag */
  158. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  159. if(hdma->DMAmuxRequestGen != 0U)
  160. {
  161. /* Clear the DMAMUX request generator overrun flag */
  162. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  163. }
  164. /* Enable the peripheral */
  165. __HAL_DMA_ENABLE(hdma);
  166. }
  167. else
  168. {
  169. /* Set the error code to busy */
  170. hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
  171. /* Return error status */
  172. status = HAL_ERROR;
  173. }
  174. }
  175. return status;
  176. }
  177. /**
  178. * @brief Starts the multi_buffer DMA Transfer with interrupt enabled.
  179. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  180. * the configuration information for the specified DMA Stream.
  181. * @param SrcAddress: The source memory Buffer address
  182. * @param DstAddress: The destination memory Buffer address
  183. * @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
  184. * @param DataLength: The length of data to be transferred from source to destination
  185. * @retval HAL status
  186. */
  187. HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
  188. {
  189. HAL_StatusTypeDef status = HAL_OK;
  190. __IO uint32_t *ifcRegister_Base = NULL; /* DMA Stream Interrupt Clear register */
  191. /* Check the parameters */
  192. assert_param(IS_DMA_BUFFER_SIZE(DataLength));
  193. /* Memory-to-memory transfer not supported in double buffering mode */
  194. /* double buffering mode not supported for BDMA (D3 DMA) */
  195. if( (IS_D2_DMA_INSTANCE(hdma) == 0U) || (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY))
  196. {
  197. hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
  198. return HAL_ERROR;
  199. }
  200. /* Process locked */
  201. __HAL_LOCK(hdma);
  202. if(HAL_DMA_STATE_READY == hdma->State)
  203. {
  204. /* Change DMA peripheral state */
  205. hdma->State = HAL_DMA_STATE_BUSY;
  206. /* Initialize the error code */
  207. hdma->ErrorCode = HAL_DMA_ERROR_NONE;
  208. /* Enable the Double buffer mode */
  209. ((DMA_Stream_TypeDef *)hdma->Instance)->CR |= (uint32_t)DMA_SxCR_DBM;
  210. /* Configure DMA Stream destination address */
  211. ((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = SecondMemAddress;
  212. /* Configure the source, destination address and the data length */
  213. DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
  214. /* Calculate the interrupt clear flag register (IFCR) base address */
  215. ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 8U));
  216. /* Clear all flags */
  217. *ifcRegister_Base = 0x3FU << hdma->StreamIndex;
  218. /* Clear the DMAMUX synchro overrun flag */
  219. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  220. if(hdma->DMAmuxRequestGen != 0U)
  221. {
  222. /* Clear the DMAMUX request generator overrun flag */
  223. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  224. }
  225. /* Enable Common interrupts*/
  226. 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));
  227. ((DMA_Stream_TypeDef *)hdma->Instance)->FCR |= DMA_IT_FE;
  228. if(hdma->XferHalfCpltCallback != NULL)
  229. {
  230. /*Enable Half Transfer IT if corresponding Callback is set*/
  231. ((DMA_Stream_TypeDef *)hdma->Instance)->CR |= DMA_IT_HT;
  232. }
  233. /* Check if DMAMUX Synchronization is enabled*/
  234. if((hdma->DMAmuxChannel->CCR & DMAMUX_CxCR_SE) != 0)
  235. {
  236. /* Enable DMAMUX sync overrun IT*/
  237. hdma->DMAmuxChannel->CCR |= DMAMUX_CxCR_SOIE;
  238. }
  239. if(hdma->DMAmuxRequestGen != 0U)
  240. {
  241. /* if using DMAMUX request generator, enable the DMAMUX request generator overrun IT*/
  242. /* enable the request gen overrun IT*/
  243. hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_OIE;
  244. }
  245. /* Enable the peripheral */
  246. __HAL_DMA_ENABLE(hdma);
  247. }
  248. else
  249. {
  250. /* Set the error code to busy */
  251. hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
  252. /* Return error status */
  253. status = HAL_ERROR;
  254. }
  255. return status;
  256. }
  257. /**
  258. * @brief Change the memory0 or memory1 address on the fly.
  259. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  260. * the configuration information for the specified DMA Stream.
  261. * @param Address: The new address
  262. * @param memory: the memory to be changed, This parameter can be one of
  263. * the following values:
  264. * MEMORY0 /
  265. * MEMORY1
  266. * @note The MEMORY0 address can be changed only when the current transfer use
  267. * MEMORY1 and the MEMORY1 address can be changed only when the current
  268. * transfer use MEMORY0.
  269. * @retval HAL status
  270. */
  271. HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
  272. {
  273. if(memory == MEMORY0)
  274. {
  275. /* change the memory0 address */
  276. ((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = Address;
  277. }
  278. else
  279. {
  280. /* change the memory1 address */
  281. ((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = Address;
  282. }
  283. return HAL_OK;
  284. }
  285. /**
  286. * @brief Configure the DMAMUX synchronization parameters for a given DMA stream (instance).
  287. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  288. * the configuration information for the specified DMA Stream.
  289. * @param pSyncConfig : pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters
  290. * @retval HAL status
  291. */
  292. HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig)
  293. {
  294. uint32_t syncSignalID = 0;
  295. uint32_t syncPolarity = 0;
  296. /* Check the parameters */
  297. assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
  298. assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable));
  299. assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable));
  300. assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber));
  301. if(pSyncConfig->SyncEnable == ENABLE)
  302. {
  303. assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig->SyncPolarity));
  304. if(IS_D2_DMA_INSTANCE(hdma) != 0U)
  305. {
  306. assert_param(IS_D2_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
  307. }
  308. else
  309. {
  310. assert_param(IS_D3_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
  311. }
  312. syncSignalID = pSyncConfig->SyncSignalID;
  313. syncPolarity = pSyncConfig->SyncPolarity;
  314. }
  315. /*Check if the DMA state is ready */
  316. if(hdma->State == HAL_DMA_STATE_READY)
  317. {
  318. /* Process Locked */
  319. __HAL_LOCK(hdma);
  320. /* Disable the synchronization and event generation before applying a new config */
  321. CLEAR_BIT(hdma->DMAmuxChannel->CCR,(DMAMUX_CxCR_SE | DMAMUX_CxCR_EGE));
  322. /* Set the new synchronization parameters (and keep the request ID filled during the Init)*/
  323. MODIFY_REG( hdma->DMAmuxChannel->CCR, \
  324. (~DMAMUX_CxCR_DMAREQ_ID) , \
  325. (syncSignalID << POSITION_VAL(DMAMUX_CxCR_SYNC_ID)) | \
  326. ((pSyncConfig->RequestNumber - 1U) << POSITION_VAL(DMAMUX_CxCR_NBREQ)) | \
  327. syncPolarity | (pSyncConfig->SyncEnable << DMAMUX_POSITION_CxCR_SE) | \
  328. (pSyncConfig->EventEnable << DMAMUX_POSITION_CxCR_EGE));
  329. /* Process Locked */
  330. __HAL_UNLOCK(hdma);
  331. return HAL_OK;
  332. }
  333. else
  334. {
  335. /* Set the error code to busy */
  336. hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
  337. /* Return error status */
  338. return HAL_ERROR;
  339. }
  340. }
  341. /**
  342. * @brief Configure the DMAMUX request generator block used by the given DMA stream (instance).
  343. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  344. * the configuration information for the specified DMA Stream.
  345. * @param pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef :
  346. * contains the request generator parameters.
  347. *
  348. * @retval HAL status
  349. */
  350. HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)
  351. {
  352. HAL_StatusTypeDef status = HAL_OK;
  353. /* Check the parameters */
  354. assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
  355. if(IS_D2_DMA_INSTANCE(hdma) != 0U)
  356. {
  357. assert_param(IS_D2_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
  358. }
  359. else
  360. {
  361. assert_param(IS_D3_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
  362. }
  363. assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));
  364. assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));
  365. /* check if the DMA state is ready
  366. and DMA is using a DMAMUX request generator block
  367. */
  368. if(hdma->DMAmuxRequestGen == 0U)
  369. {
  370. /* Set the error code to busy */
  371. hdma->ErrorCode = HAL_DMA_ERROR_PARAM;
  372. /* error status */
  373. status = HAL_ERROR;
  374. }
  375. else if((hdma->State == HAL_DMA_STATE_READY) && ((hdma->DMAmuxRequestGen->RGCR & DMAMUX_RGxCR_GE) == 0))
  376. {
  377. /* RequestGenerator must be disable prior to the configuration i.e GE bit is 0 */
  378. /* Process Locked */
  379. __HAL_LOCK(hdma);
  380. /* Set the request generator new parameters*/
  381. hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \
  382. ((pRequestGeneratorConfig->RequestNumber - 1U) << POSITION_VAL(DMAMUX_RGxCR_NBREQ))| \
  383. pRequestGeneratorConfig->Polarity;
  384. /* Process Locked */
  385. __HAL_UNLOCK(hdma);
  386. return HAL_OK;
  387. }
  388. else
  389. {
  390. /* Set the error code to busy */
  391. hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
  392. /* error status */
  393. status = HAL_ERROR;
  394. }
  395. return status;
  396. }
  397. /**
  398. * @brief Enable the DMAMUX request generator block used by the given DMA stream (instance).
  399. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  400. * the configuration information for the specified DMA Stream.
  401. * @retval HAL status
  402. */
  403. HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
  404. {
  405. /* Check the parameters */
  406. assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
  407. /* check if the DMA state is ready
  408. and DMA is using a DMAMUX request generator block
  409. */
  410. if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0U))
  411. {
  412. /* Enable the request generator*/
  413. hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE;
  414. return HAL_OK;
  415. }
  416. else
  417. {
  418. return HAL_ERROR;
  419. }
  420. }
  421. /**
  422. * @brief Disable the DMAMUX request generator block used by the given DMA stream (instance).
  423. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  424. * the configuration information for the specified DMA Stream.
  425. * @retval HAL status
  426. */
  427. HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
  428. {
  429. /* Check the parameters */
  430. assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
  431. /* check if the DMA state is ready
  432. and DMA is using a DMAMUX request generator block
  433. */
  434. if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0U))
  435. {
  436. /* Disable the request generator*/
  437. hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE;
  438. return HAL_OK;
  439. }
  440. else
  441. {
  442. return HAL_ERROR;
  443. }
  444. }
  445. /**
  446. * @brief Handles DMAMUX interrupt request.
  447. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  448. * the configuration information for the specified DMA Stream.
  449. * @retval None
  450. */
  451. void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma)
  452. {
  453. /* Check for DMAMUX Synchronization overrun */
  454. if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)
  455. {
  456. /* Disable the synchro overrun interrupt */
  457. hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;
  458. /* Clear the DMAMUX synchro overrun flag */
  459. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  460. /* Update error code */
  461. hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;
  462. if(hdma->XferErrorCallback != NULL)
  463. {
  464. /* Transfer error callback */
  465. hdma->XferErrorCallback(hdma);
  466. }
  467. }
  468. if(hdma->DMAmuxRequestGen != 0)
  469. {
  470. /* if using a DMAMUX request generator block Check for DMAMUX request generator overrun */
  471. if((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)
  472. {
  473. /* Disable the request gen overrun interrupt */
  474. hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;
  475. /* Clear the DMAMUX request generator overrun flag */
  476. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  477. /* Update error code */
  478. hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;
  479. if(hdma->XferErrorCallback != NULL)
  480. {
  481. /* Transfer error callback */
  482. hdma->XferErrorCallback(hdma);
  483. }
  484. }
  485. }
  486. }
  487. /**
  488. * @}
  489. */
  490. /**
  491. * @}
  492. */
  493. /** @addtogroup DMAEx_Private_Functions
  494. * @{
  495. */
  496. /**
  497. * @brief Set the DMA Transfer parameter.
  498. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  499. * the configuration information for the specified DMA Stream.
  500. * @param SrcAddress: The source memory Buffer address
  501. * @param DstAddress: The destination memory Buffer address
  502. * @param DataLength: The length of data to be transferred from source to destination
  503. * @retval HAL status
  504. */
  505. static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
  506. {
  507. /* Configure DMA Stream data length */
  508. ((DMA_Stream_TypeDef *)hdma->Instance)->NDTR = DataLength;
  509. /* Peripheral to Memory */
  510. if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
  511. {
  512. /* Configure DMA Stream destination address */
  513. ((DMA_Stream_TypeDef *)hdma->Instance)->PAR = DstAddress;
  514. /* Configure DMA Stream source address */
  515. ((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = SrcAddress;
  516. }
  517. /* Memory to Peripheral */
  518. else
  519. {
  520. /* Configure DMA Stream source address */
  521. ((DMA_Stream_TypeDef *)hdma->Instance)->PAR = SrcAddress;
  522. /* Configure DMA Stream destination address */
  523. ((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = DstAddress;
  524. }
  525. }
  526. /**
  527. * @}
  528. */
  529. #endif /* HAL_DMA_MODULE_ENABLED */
  530. /**
  531. * @}
  532. */
  533. /**
  534. * @}
  535. */
  536. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/