stm32l4xx_hal_dma.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_dma.c
  4. * @author MCD Application Team
  5. * @brief DMA HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Direct Memory Access (DMA) peripheral:
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral State and errors functions
  11. *
  12. ******************************************************************************
  13. * @attention
  14. *
  15. * Copyright (c) 2017 STMicroelectronics.
  16. * All rights reserved.
  17. *
  18. * This software is licensed under terms that can be found in the LICENSE file
  19. * in the root directory of this software component.
  20. * If no LICENSE file comes with this software, it is provided AS-IS.
  21. *
  22. ******************************************************************************
  23. @verbatim
  24. ==============================================================================
  25. ##### How to use this driver #####
  26. ==============================================================================
  27. [..]
  28. (#) Enable and configure the peripheral to be connected to the DMA Channel
  29. (except for internal SRAM / FLASH memories: no initialization is
  30. necessary). Please refer to the Reference manual for connection between peripherals
  31. and DMA requests.
  32. (#) For a given Channel, program the required configuration through the following parameters:
  33. Channel request, Transfer Direction, Source and Destination data formats,
  34. Circular or Normal mode, Channel Priority level, Source and Destination Increment mode
  35. using HAL_DMA_Init() function.
  36. Prior to HAL_DMA_Init the peripheral clock shall be enabled for both DMA & DMAMUX
  37. thanks to:
  38. (##) DMA1 or DMA2: __HAL_RCC_DMA1_CLK_ENABLE() or __HAL_RCC_DMA2_CLK_ENABLE() ;
  39. (##) DMAMUX1: __HAL_RCC_DMAMUX1_CLK_ENABLE();
  40. (#) Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error
  41. detection.
  42. (#) Use HAL_DMA_Abort() function to abort the current transfer
  43. -@- In Memory-to-Memory transfer mode, Circular mode is not allowed.
  44. *** Polling mode IO operation ***
  45. =================================
  46. [..]
  47. (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source
  48. address and destination address and the Length of data to be transferred
  49. (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this
  50. case a fixed Timeout can be configured by User depending from his application.
  51. *** Interrupt mode IO operation ***
  52. ===================================
  53. [..]
  54. (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority()
  55. (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ()
  56. (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of
  57. Source address and destination address and the Length of data to be transferred.
  58. In this case the DMA interrupt is configured
  59. (+) Use HAL_DMA_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine
  60. (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can
  61. add his own function to register callbacks with HAL_DMA_RegisterCallback().
  62. *** DMA HAL driver macros list ***
  63. =============================================
  64. [..]
  65. Below the list of macros in DMA HAL driver.
  66. (+) __HAL_DMA_ENABLE: Enable the specified DMA Channel.
  67. (+) __HAL_DMA_DISABLE: Disable the specified DMA Channel.
  68. (+) __HAL_DMA_GET_FLAG: Get the DMA Channel pending flags.
  69. (+) __HAL_DMA_CLEAR_FLAG: Clear the DMA Channel pending flags.
  70. (+) __HAL_DMA_ENABLE_IT: Enable the specified DMA Channel interrupts.
  71. (+) __HAL_DMA_DISABLE_IT: Disable the specified DMA Channel interrupts.
  72. (+) __HAL_DMA_GET_IT_SOURCE: Check whether the specified DMA Channel interrupt is enabled or not.
  73. [..]
  74. (@) You can refer to the DMA HAL driver header file for more useful macros
  75. @endverbatim
  76. ******************************************************************************
  77. */
  78. /* Includes ------------------------------------------------------------------*/
  79. #include "stm32l4xx_hal.h"
  80. /** @addtogroup STM32L4xx_HAL_Driver
  81. * @{
  82. */
  83. /** @defgroup DMA DMA
  84. * @brief DMA HAL module driver
  85. * @{
  86. */
  87. #ifdef HAL_DMA_MODULE_ENABLED
  88. /* Private typedef -----------------------------------------------------------*/
  89. /* Private define ------------------------------------------------------------*/
  90. /* Private macro -------------------------------------------------------------*/
  91. /* Private variables ---------------------------------------------------------*/
  92. /* Private function prototypes -----------------------------------------------*/
  93. /** @defgroup DMA_Private_Functions DMA Private Functions
  94. * @{
  95. */
  96. static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  97. #if defined(DMAMUX1)
  98. static void DMA_CalcDMAMUXChannelBaseAndMask(DMA_HandleTypeDef *hdma);
  99. static void DMA_CalcDMAMUXRequestGenBaseAndMask(DMA_HandleTypeDef *hdma);
  100. #endif /* DMAMUX1 */
  101. /**
  102. * @}
  103. */
  104. /* Exported functions ---------------------------------------------------------*/
  105. /** @defgroup DMA_Exported_Functions DMA Exported Functions
  106. * @{
  107. */
  108. /** @defgroup DMA_Exported_Functions_Group1 Initialization and de-initialization functions
  109. * @brief Initialization and de-initialization functions
  110. *
  111. @verbatim
  112. ===============================================================================
  113. ##### Initialization and de-initialization functions #####
  114. ===============================================================================
  115. [..]
  116. This section provides functions allowing to initialize the DMA Channel source
  117. and destination addresses, incrementation and data sizes, transfer direction,
  118. circular/normal mode selection, memory-to-memory mode selection and Channel priority value.
  119. [..]
  120. The HAL_DMA_Init() function follows the DMA configuration procedures as described in
  121. reference manual.
  122. @endverbatim
  123. * @{
  124. */
  125. /**
  126. * @brief Initialize the DMA according to the specified
  127. * parameters in the DMA_InitTypeDef and initialize the associated handle.
  128. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  129. * the configuration information for the specified DMA Channel.
  130. * @retval HAL status
  131. */
  132. HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
  133. {
  134. uint32_t tmp;
  135. /* Check the DMA handle allocation */
  136. if (hdma == NULL)
  137. {
  138. return HAL_ERROR;
  139. }
  140. /* Check the parameters */
  141. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  142. assert_param(IS_DMA_DIRECTION(hdma->Init.Direction));
  143. assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc));
  144. assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc));
  145. assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment));
  146. assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment));
  147. assert_param(IS_DMA_MODE(hdma->Init.Mode));
  148. assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
  149. assert_param(IS_DMA_ALL_REQUEST(hdma->Init.Request));
  150. /* Compute the channel index */
  151. if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
  152. {
  153. /* DMA1 */
  154. hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2U;
  155. hdma->DmaBaseAddress = DMA1;
  156. }
  157. else
  158. {
  159. /* DMA2 */
  160. hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2U;
  161. hdma->DmaBaseAddress = DMA2;
  162. }
  163. /* Change DMA peripheral state */
  164. hdma->State = HAL_DMA_STATE_BUSY;
  165. /* Get the CR register value */
  166. tmp = hdma->Instance->CCR;
  167. /* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR and MEM2MEM bits */
  168. tmp &= ((uint32_t)~(DMA_CCR_PL | DMA_CCR_MSIZE | DMA_CCR_PSIZE |
  169. DMA_CCR_MINC | DMA_CCR_PINC | DMA_CCR_CIRC |
  170. DMA_CCR_DIR | DMA_CCR_MEM2MEM));
  171. /* Prepare the DMA Channel configuration */
  172. tmp |= hdma->Init.Direction |
  173. hdma->Init.PeriphInc | hdma->Init.MemInc |
  174. hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
  175. hdma->Init.Mode | hdma->Init.Priority;
  176. /* Write to DMA Channel CR register */
  177. hdma->Instance->CCR = tmp;
  178. #if defined(DMAMUX1)
  179. /* Initialize parameters for DMAMUX channel :
  180. DMAmuxChannel, DMAmuxChannelStatus and DMAmuxChannelStatusMask
  181. */
  182. DMA_CalcDMAMUXChannelBaseAndMask(hdma);
  183. if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
  184. {
  185. /* if memory to memory force the request to 0*/
  186. hdma->Init.Request = DMA_REQUEST_MEM2MEM;
  187. }
  188. /* Set peripheral request to DMAMUX channel */
  189. hdma->DMAmuxChannel->CCR = (hdma->Init.Request & DMAMUX_CxCR_DMAREQ_ID);
  190. /* Clear the DMAMUX synchro overrun flag */
  191. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  192. if (((hdma->Init.Request > 0U) && (hdma->Init.Request <= DMA_REQUEST_GENERATOR3)))
  193. {
  194. /* Initialize parameters for DMAMUX request generator :
  195. DMAmuxRequestGen, DMAmuxRequestGenStatus and DMAmuxRequestGenStatusMask
  196. */
  197. DMA_CalcDMAMUXRequestGenBaseAndMask(hdma);
  198. /* Reset the DMAMUX request generator register*/
  199. hdma->DMAmuxRequestGen->RGCR = 0U;
  200. /* Clear the DMAMUX request generator overrun flag */
  201. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  202. }
  203. else
  204. {
  205. hdma->DMAmuxRequestGen = 0U;
  206. hdma->DMAmuxRequestGenStatus = 0U;
  207. hdma->DMAmuxRequestGenStatusMask = 0U;
  208. }
  209. #endif /* DMAMUX1 */
  210. #if !defined (DMAMUX1)
  211. /* Set request selection */
  212. if (hdma->Init.Direction != DMA_MEMORY_TO_MEMORY)
  213. {
  214. /* Write to DMA channel selection register */
  215. if (DMA1 == hdma->DmaBaseAddress)
  216. {
  217. /* Reset request selection for DMA1 Channelx */
  218. DMA1_CSELR->CSELR &= ~(DMA_CSELR_C1S << (hdma->ChannelIndex & 0x1cU));
  219. /* Configure request selection for DMA1 Channelx */
  220. DMA1_CSELR->CSELR |= (uint32_t)(hdma->Init.Request << (hdma->ChannelIndex & 0x1cU));
  221. }
  222. else /* DMA2 */
  223. {
  224. /* Reset request selection for DMA2 Channelx */
  225. DMA2_CSELR->CSELR &= ~(DMA_CSELR_C1S << (hdma->ChannelIndex & 0x1cU));
  226. /* Configure request selection for DMA2 Channelx */
  227. DMA2_CSELR->CSELR |= (uint32_t)(hdma->Init.Request << (hdma->ChannelIndex & 0x1cU));
  228. }
  229. }
  230. #endif /* STM32L431xx || STM32L432xx || STM32L433xx || STM32L442xx || STM32L443xx */
  231. /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L442xx || STM32L486xx */
  232. /* STM32L496xx || STM32L4A6xx */
  233. /* Initialise the error code */
  234. hdma->ErrorCode = HAL_DMA_ERROR_NONE;
  235. /* Initialize the DMA state*/
  236. hdma->State = HAL_DMA_STATE_READY;
  237. /* Allocate lock resource and initialize it */
  238. hdma->Lock = HAL_UNLOCKED;
  239. return HAL_OK;
  240. }
  241. /**
  242. * @brief DeInitialize the DMA peripheral.
  243. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  244. * the configuration information for the specified DMA Channel.
  245. * @retval HAL status
  246. */
  247. HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
  248. {
  249. /* Check the DMA handle allocation */
  250. if (NULL == hdma)
  251. {
  252. return HAL_ERROR;
  253. }
  254. /* Check the parameters */
  255. assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
  256. /* Disable the selected DMA Channelx */
  257. __HAL_DMA_DISABLE(hdma);
  258. /* Compute the channel index */
  259. if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
  260. {
  261. /* DMA1 */
  262. hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2U;
  263. hdma->DmaBaseAddress = DMA1;
  264. }
  265. else
  266. {
  267. /* DMA2 */
  268. hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2U;
  269. hdma->DmaBaseAddress = DMA2;
  270. }
  271. /* Reset DMA Channel control register */
  272. hdma->Instance->CCR = 0U;
  273. /* Clear all flags */
  274. hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << (hdma->ChannelIndex & 0x1CU));
  275. #if !defined (DMAMUX1)
  276. /* Reset DMA channel selection register */
  277. if (DMA1 == hdma->DmaBaseAddress)
  278. {
  279. /* DMA1 */
  280. DMA1_CSELR->CSELR &= ~(DMA_CSELR_C1S << (hdma->ChannelIndex & 0x1cU));
  281. }
  282. else
  283. {
  284. /* DMA2 */
  285. DMA2_CSELR->CSELR &= ~(DMA_CSELR_C1S << (hdma->ChannelIndex & 0x1cU));
  286. }
  287. #endif /* STM32L431xx || STM32L432xx || STM32L433xx || STM32L442xx || STM32L443xx */
  288. /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L442xx || STM32L486xx */
  289. /* STM32L496xx || STM32L4A6xx */
  290. #if defined(DMAMUX1)
  291. /* Initialize parameters for DMAMUX channel :
  292. DMAmuxChannel, DMAmuxChannelStatus and DMAmuxChannelStatusMask */
  293. DMA_CalcDMAMUXChannelBaseAndMask(hdma);
  294. /* Reset the DMAMUX channel that corresponds to the DMA channel */
  295. hdma->DMAmuxChannel->CCR = 0U;
  296. /* Clear the DMAMUX synchro overrun flag */
  297. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  298. /* Reset Request generator parameters if any */
  299. if (((hdma->Init.Request > 0U) && (hdma->Init.Request <= DMA_REQUEST_GENERATOR3)))
  300. {
  301. /* Initialize parameters for DMAMUX request generator :
  302. DMAmuxRequestGen, DMAmuxRequestGenStatus and DMAmuxRequestGenStatusMask
  303. */
  304. DMA_CalcDMAMUXRequestGenBaseAndMask(hdma);
  305. /* Reset the DMAMUX request generator register*/
  306. hdma->DMAmuxRequestGen->RGCR = 0U;
  307. /* Clear the DMAMUX request generator overrun flag */
  308. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  309. }
  310. hdma->DMAmuxRequestGen = 0U;
  311. hdma->DMAmuxRequestGenStatus = 0U;
  312. hdma->DMAmuxRequestGenStatusMask = 0U;
  313. #endif /* DMAMUX1 */
  314. /* Clean callbacks */
  315. hdma->XferCpltCallback = NULL;
  316. hdma->XferHalfCpltCallback = NULL;
  317. hdma->XferErrorCallback = NULL;
  318. hdma->XferAbortCallback = NULL;
  319. /* Initialise the error code */
  320. hdma->ErrorCode = HAL_DMA_ERROR_NONE;
  321. /* Initialize the DMA state */
  322. hdma->State = HAL_DMA_STATE_RESET;
  323. /* Release Lock */
  324. __HAL_UNLOCK(hdma);
  325. return HAL_OK;
  326. }
  327. /**
  328. * @}
  329. */
  330. /** @defgroup DMA_Exported_Functions_Group2 Input and Output operation functions
  331. * @brief Input and Output operation functions
  332. *
  333. @verbatim
  334. ===============================================================================
  335. ##### IO operation functions #####
  336. ===============================================================================
  337. [..] This section provides functions allowing to:
  338. (+) Configure the source, destination address and data length and Start DMA transfer
  339. (+) Configure the source, destination address and data length and
  340. Start DMA transfer with interrupt
  341. (+) Abort DMA transfer
  342. (+) Poll for transfer complete
  343. (+) Handle DMA interrupt request
  344. @endverbatim
  345. * @{
  346. */
  347. /**
  348. * @brief Start the DMA Transfer.
  349. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  350. * the configuration information for the specified DMA Channel.
  351. * @param SrcAddress The source memory Buffer address
  352. * @param DstAddress The destination memory Buffer address
  353. * @param DataLength The length of data to be transferred from source to destination
  354. * @retval HAL status
  355. */
  356. HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
  357. {
  358. HAL_StatusTypeDef status = HAL_OK;
  359. /* Check the parameters */
  360. assert_param(IS_DMA_BUFFER_SIZE(DataLength));
  361. /* Process locked */
  362. __HAL_LOCK(hdma);
  363. if (HAL_DMA_STATE_READY == hdma->State)
  364. {
  365. /* Change DMA peripheral state */
  366. hdma->State = HAL_DMA_STATE_BUSY;
  367. hdma->ErrorCode = HAL_DMA_ERROR_NONE;
  368. /* Disable the peripheral */
  369. __HAL_DMA_DISABLE(hdma);
  370. /* Configure the source, destination address and the data length & clear flags*/
  371. DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
  372. /* Enable the Peripheral */
  373. __HAL_DMA_ENABLE(hdma);
  374. }
  375. else
  376. {
  377. /* Process Unlocked */
  378. __HAL_UNLOCK(hdma);
  379. status = HAL_BUSY;
  380. }
  381. return status;
  382. }
  383. /**
  384. * @brief Start the DMA Transfer with interrupt enabled.
  385. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  386. * the configuration information for the specified DMA Channel.
  387. * @param SrcAddress The source memory Buffer address
  388. * @param DstAddress The destination memory Buffer address
  389. * @param DataLength The length of data to be transferred from source to destination
  390. * @retval HAL status
  391. */
  392. HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
  393. {
  394. HAL_StatusTypeDef status = HAL_OK;
  395. /* Check the parameters */
  396. assert_param(IS_DMA_BUFFER_SIZE(DataLength));
  397. /* Process locked */
  398. __HAL_LOCK(hdma);
  399. if (HAL_DMA_STATE_READY == hdma->State)
  400. {
  401. /* Change DMA peripheral state */
  402. hdma->State = HAL_DMA_STATE_BUSY;
  403. hdma->ErrorCode = HAL_DMA_ERROR_NONE;
  404. /* Disable the peripheral */
  405. __HAL_DMA_DISABLE(hdma);
  406. /* Configure the source, destination address and the data length & clear flags*/
  407. DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
  408. /* Enable the transfer complete interrupt */
  409. /* Enable the transfer Error interrupt */
  410. if (NULL != hdma->XferHalfCpltCallback)
  411. {
  412. /* Enable the Half transfer complete interrupt as well */
  413. __HAL_DMA_ENABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
  414. }
  415. else
  416. {
  417. __HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
  418. __HAL_DMA_ENABLE_IT(hdma, (DMA_IT_TC | DMA_IT_TE));
  419. }
  420. #ifdef DMAMUX1
  421. /* Check if DMAMUX Synchronization is enabled*/
  422. if ((hdma->DMAmuxChannel->CCR & DMAMUX_CxCR_SE) != 0U)
  423. {
  424. /* Enable DMAMUX sync overrun IT*/
  425. hdma->DMAmuxChannel->CCR |= DMAMUX_CxCR_SOIE;
  426. }
  427. if (hdma->DMAmuxRequestGen != 0U)
  428. {
  429. /* if using DMAMUX request generator, enable the DMAMUX request generator overrun IT*/
  430. /* enable the request gen overrun IT*/
  431. hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_OIE;
  432. }
  433. #endif /* DMAMUX1 */
  434. /* Enable the Peripheral */
  435. __HAL_DMA_ENABLE(hdma);
  436. }
  437. else
  438. {
  439. /* Process Unlocked */
  440. __HAL_UNLOCK(hdma);
  441. /* Remain BUSY */
  442. status = HAL_BUSY;
  443. }
  444. return status;
  445. }
  446. /**
  447. * @brief Abort the DMA Transfer.
  448. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  449. * the configuration information for the specified DMA Channel.
  450. * @retval HAL status
  451. */
  452. HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
  453. {
  454. HAL_StatusTypeDef status = HAL_OK;
  455. /* Check the DMA peripheral state */
  456. if (hdma->State != HAL_DMA_STATE_BUSY)
  457. {
  458. hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
  459. /* Process Unlocked */
  460. __HAL_UNLOCK(hdma);
  461. return HAL_ERROR;
  462. }
  463. else
  464. {
  465. /* Disable DMA IT */
  466. __HAL_DMA_DISABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
  467. #if defined(DMAMUX1)
  468. /* disable the DMAMUX sync overrun IT*/
  469. hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;
  470. #endif /* DMAMUX1 */
  471. /* Disable the channel */
  472. __HAL_DMA_DISABLE(hdma);
  473. /* Clear all flags */
  474. hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << (hdma->ChannelIndex & 0x1CU));
  475. #if defined(DMAMUX1)
  476. /* Clear the DMAMUX synchro overrun flag */
  477. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  478. if (hdma->DMAmuxRequestGen != 0U)
  479. {
  480. /* if using DMAMUX request generator, disable the DMAMUX request generator overrun IT*/
  481. /* disable the request gen overrun IT*/
  482. hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;
  483. /* Clear the DMAMUX request generator overrun flag */
  484. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  485. }
  486. #endif /* DMAMUX1 */
  487. /* Change the DMA state */
  488. hdma->State = HAL_DMA_STATE_READY;
  489. /* Process Unlocked */
  490. __HAL_UNLOCK(hdma);
  491. return status;
  492. }
  493. }
  494. /**
  495. * @brief Aborts the DMA Transfer in Interrupt mode.
  496. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  497. * the configuration information for the specified DMA Channel.
  498. * @retval HAL status
  499. */
  500. HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
  501. {
  502. HAL_StatusTypeDef status = HAL_OK;
  503. if (HAL_DMA_STATE_BUSY != hdma->State)
  504. {
  505. /* no transfer ongoing */
  506. hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
  507. status = HAL_ERROR;
  508. }
  509. else
  510. {
  511. /* Disable DMA IT */
  512. __HAL_DMA_DISABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
  513. /* Disable the channel */
  514. __HAL_DMA_DISABLE(hdma);
  515. #if defined(DMAMUX1)
  516. /* disable the DMAMUX sync overrun IT*/
  517. hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;
  518. /* Clear all flags */
  519. hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << (hdma->ChannelIndex & 0x1CU));
  520. /* Clear the DMAMUX synchro overrun flag */
  521. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  522. if (hdma->DMAmuxRequestGen != 0U)
  523. {
  524. /* if using DMAMUX request generator, disable the DMAMUX request generator overrun IT*/
  525. /* disable the request gen overrun IT*/
  526. hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;
  527. /* Clear the DMAMUX request generator overrun flag */
  528. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  529. }
  530. #else
  531. /* Clear all flags */
  532. hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << (hdma->ChannelIndex & 0x1CU));
  533. #endif /* DMAMUX1 */
  534. /* Change the DMA state */
  535. hdma->State = HAL_DMA_STATE_READY;
  536. /* Process Unlocked */
  537. __HAL_UNLOCK(hdma);
  538. /* Call User Abort callback */
  539. if (hdma->XferAbortCallback != NULL)
  540. {
  541. hdma->XferAbortCallback(hdma);
  542. }
  543. }
  544. return status;
  545. }
  546. /**
  547. * @brief Polling for transfer complete.
  548. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  549. * the configuration information for the specified DMA Channel.
  550. * @param CompleteLevel Specifies the DMA level complete.
  551. * @param Timeout Timeout duration.
  552. * @retval HAL status
  553. */
  554. HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, HAL_DMA_LevelCompleteTypeDef CompleteLevel, uint32_t Timeout)
  555. {
  556. uint32_t temp;
  557. uint32_t tickstart;
  558. if (HAL_DMA_STATE_BUSY != hdma->State)
  559. {
  560. /* no transfer ongoing */
  561. hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
  562. __HAL_UNLOCK(hdma);
  563. return HAL_ERROR;
  564. }
  565. /* Polling mode not supported in circular mode */
  566. if ((hdma->Instance->CCR & DMA_CCR_CIRC) != 0U)
  567. {
  568. hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
  569. return HAL_ERROR;
  570. }
  571. /* Get the level transfer complete flag */
  572. if (HAL_DMA_FULL_TRANSFER == CompleteLevel)
  573. {
  574. /* Transfer Complete flag */
  575. temp = DMA_FLAG_TC1 << (hdma->ChannelIndex & 0x1CU);
  576. }
  577. else
  578. {
  579. /* Half Transfer Complete flag */
  580. temp = DMA_FLAG_HT1 << (hdma->ChannelIndex & 0x1CU);
  581. }
  582. /* Get tick */
  583. tickstart = HAL_GetTick();
  584. while ((hdma->DmaBaseAddress->ISR & temp) == 0U)
  585. {
  586. if ((hdma->DmaBaseAddress->ISR & (DMA_FLAG_TE1 << (hdma->ChannelIndex & 0x1CU))) != 0U)
  587. {
  588. /* When a DMA transfer error occurs */
  589. /* A hardware clear of its EN bits is performed */
  590. /* Clear all flags */
  591. hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << (hdma->ChannelIndex & 0x1CU));
  592. /* Update error code */
  593. hdma->ErrorCode = HAL_DMA_ERROR_TE;
  594. /* Change the DMA state */
  595. hdma->State = HAL_DMA_STATE_READY;
  596. /* Process Unlocked */
  597. __HAL_UNLOCK(hdma);
  598. return HAL_ERROR;
  599. }
  600. /* Check for the Timeout */
  601. if (Timeout != HAL_MAX_DELAY)
  602. {
  603. if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
  604. {
  605. /* Update error code */
  606. hdma->ErrorCode = HAL_DMA_ERROR_TIMEOUT;
  607. /* Change the DMA state */
  608. hdma->State = HAL_DMA_STATE_READY;
  609. /* Process Unlocked */
  610. __HAL_UNLOCK(hdma);
  611. return HAL_ERROR;
  612. }
  613. }
  614. }
  615. #if defined(DMAMUX1)
  616. /*Check for DMAMUX Request generator (if used) overrun status */
  617. if (hdma->DMAmuxRequestGen != 0U)
  618. {
  619. /* if using DMAMUX request generator Check for DMAMUX request generator overrun */
  620. if ((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)
  621. {
  622. /* Disable the request gen overrun interrupt */
  623. hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_OIE;
  624. /* Clear the DMAMUX request generator overrun flag */
  625. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  626. /* Update error code */
  627. hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;
  628. }
  629. }
  630. /* Check for DMAMUX Synchronization overrun */
  631. if ((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)
  632. {
  633. /* Clear the DMAMUX synchro overrun flag */
  634. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  635. /* Update error code */
  636. hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;
  637. }
  638. #endif /* DMAMUX1 */
  639. if (HAL_DMA_FULL_TRANSFER == CompleteLevel)
  640. {
  641. /* Clear the transfer complete flag */
  642. hdma->DmaBaseAddress->IFCR = (DMA_FLAG_TC1 << (hdma->ChannelIndex & 0x1CU));
  643. /* Process unlocked */
  644. __HAL_UNLOCK(hdma);
  645. /* The selected Channelx EN bit is cleared (DMA is disabled and
  646. all transfers are complete) */
  647. hdma->State = HAL_DMA_STATE_READY;
  648. }
  649. else
  650. {
  651. /* Clear the half transfer complete flag */
  652. hdma->DmaBaseAddress->IFCR = (DMA_FLAG_HT1 << (hdma->ChannelIndex & 0x1CU));
  653. }
  654. return HAL_OK;
  655. }
  656. /**
  657. * @brief Handle DMA interrupt request.
  658. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  659. * the configuration information for the specified DMA Channel.
  660. * @retval None
  661. */
  662. void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
  663. {
  664. uint32_t flag_it = hdma->DmaBaseAddress->ISR;
  665. uint32_t source_it = hdma->Instance->CCR;
  666. /* Half Transfer Complete Interrupt management ******************************/
  667. if (((flag_it & (DMA_FLAG_HT1 << (hdma->ChannelIndex & 0x1CU))) != 0U) && ((source_it & DMA_IT_HT) != 0U))
  668. {
  669. /* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
  670. if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
  671. {
  672. /* Disable the half transfer interrupt */
  673. __HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
  674. }
  675. /* Clear the half transfer complete flag */
  676. hdma->DmaBaseAddress->IFCR = DMA_ISR_HTIF1 << (hdma->ChannelIndex & 0x1CU);
  677. /* DMA peripheral state is not updated in Half Transfer */
  678. /* but in Transfer Complete case */
  679. if (hdma->XferHalfCpltCallback != NULL)
  680. {
  681. /* Half transfer callback */
  682. hdma->XferHalfCpltCallback(hdma);
  683. }
  684. }
  685. /* Transfer Complete Interrupt management ***********************************/
  686. else if (((flag_it & (DMA_FLAG_TC1 << (hdma->ChannelIndex & 0x1CU))) != 0U) && ((source_it & DMA_IT_TC) != 0U))
  687. {
  688. if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
  689. {
  690. /* Disable the transfer complete interrupt if the DMA mode is not CIRCULAR */
  691. /* Disable the transfer complete and error interrupt */
  692. /* if the DMA mode is not CIRCULAR */
  693. __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE | DMA_IT_TC);
  694. /* Change the DMA state */
  695. hdma->State = HAL_DMA_STATE_READY;
  696. }
  697. /* Clear the transfer complete flag */
  698. hdma->DmaBaseAddress->IFCR = (DMA_ISR_TCIF1 << (hdma->ChannelIndex & 0x1CU));
  699. /* Process Unlocked */
  700. __HAL_UNLOCK(hdma);
  701. if (hdma->XferCpltCallback != NULL)
  702. {
  703. /* Transfer complete callback */
  704. hdma->XferCpltCallback(hdma);
  705. }
  706. }
  707. /* Transfer Error Interrupt management **************************************/
  708. else if (((flag_it & (DMA_FLAG_TE1 << (hdma->ChannelIndex & 0x1CU))) != 0U) && ((source_it & DMA_IT_TE) != 0U))
  709. {
  710. /* When a DMA transfer error occurs */
  711. /* A hardware clear of its EN bits is performed */
  712. /* Disable ALL DMA IT */
  713. __HAL_DMA_DISABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
  714. /* Clear all flags */
  715. hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << (hdma->ChannelIndex & 0x1CU));
  716. /* Update error code */
  717. hdma->ErrorCode = HAL_DMA_ERROR_TE;
  718. /* Change the DMA state */
  719. hdma->State = HAL_DMA_STATE_READY;
  720. /* Process Unlocked */
  721. __HAL_UNLOCK(hdma);
  722. if (hdma->XferErrorCallback != NULL)
  723. {
  724. /* Transfer error callback */
  725. hdma->XferErrorCallback(hdma);
  726. }
  727. }
  728. else
  729. {
  730. /* Nothing To Do */
  731. }
  732. return;
  733. }
  734. /**
  735. * @brief Register callbacks
  736. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  737. * the configuration information for the specified DMA Channel.
  738. * @param CallbackID User Callback identifier
  739. * a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
  740. * @param pCallback pointer to private callback function which has pointer to
  741. * a DMA_HandleTypeDef structure as parameter.
  742. * @retval HAL status
  743. */
  744. HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)(DMA_HandleTypeDef *_hdma))
  745. {
  746. HAL_StatusTypeDef status = HAL_OK;
  747. /* Process locked */
  748. __HAL_LOCK(hdma);
  749. if (HAL_DMA_STATE_READY == hdma->State)
  750. {
  751. switch (CallbackID)
  752. {
  753. case HAL_DMA_XFER_CPLT_CB_ID:
  754. hdma->XferCpltCallback = pCallback;
  755. break;
  756. case HAL_DMA_XFER_HALFCPLT_CB_ID:
  757. hdma->XferHalfCpltCallback = pCallback;
  758. break;
  759. case HAL_DMA_XFER_ERROR_CB_ID:
  760. hdma->XferErrorCallback = pCallback;
  761. break;
  762. case HAL_DMA_XFER_ABORT_CB_ID:
  763. hdma->XferAbortCallback = pCallback;
  764. break;
  765. default:
  766. status = HAL_ERROR;
  767. break;
  768. }
  769. }
  770. else
  771. {
  772. status = HAL_ERROR;
  773. }
  774. /* Release Lock */
  775. __HAL_UNLOCK(hdma);
  776. return status;
  777. }
  778. /**
  779. * @brief UnRegister callbacks
  780. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  781. * the configuration information for the specified DMA Channel.
  782. * @param CallbackID User Callback identifier
  783. * a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
  784. * @retval HAL status
  785. */
  786. HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID)
  787. {
  788. HAL_StatusTypeDef status = HAL_OK;
  789. /* Process locked */
  790. __HAL_LOCK(hdma);
  791. if (HAL_DMA_STATE_READY == hdma->State)
  792. {
  793. switch (CallbackID)
  794. {
  795. case HAL_DMA_XFER_CPLT_CB_ID:
  796. hdma->XferCpltCallback = NULL;
  797. break;
  798. case HAL_DMA_XFER_HALFCPLT_CB_ID:
  799. hdma->XferHalfCpltCallback = NULL;
  800. break;
  801. case HAL_DMA_XFER_ERROR_CB_ID:
  802. hdma->XferErrorCallback = NULL;
  803. break;
  804. case HAL_DMA_XFER_ABORT_CB_ID:
  805. hdma->XferAbortCallback = NULL;
  806. break;
  807. case HAL_DMA_XFER_ALL_CB_ID:
  808. hdma->XferCpltCallback = NULL;
  809. hdma->XferHalfCpltCallback = NULL;
  810. hdma->XferErrorCallback = NULL;
  811. hdma->XferAbortCallback = NULL;
  812. break;
  813. default:
  814. status = HAL_ERROR;
  815. break;
  816. }
  817. }
  818. else
  819. {
  820. status = HAL_ERROR;
  821. }
  822. /* Release Lock */
  823. __HAL_UNLOCK(hdma);
  824. return status;
  825. }
  826. /**
  827. * @}
  828. */
  829. /** @defgroup DMA_Exported_Functions_Group3 Peripheral State and Errors functions
  830. * @brief Peripheral State and Errors functions
  831. *
  832. @verbatim
  833. ===============================================================================
  834. ##### Peripheral State and Errors functions #####
  835. ===============================================================================
  836. [..]
  837. This subsection provides functions allowing to
  838. (+) Check the DMA state
  839. (+) Get error code
  840. @endverbatim
  841. * @{
  842. */
  843. /**
  844. * @brief Return the DMA handle state.
  845. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  846. * the configuration information for the specified DMA Channel.
  847. * @retval HAL state
  848. */
  849. HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
  850. {
  851. /* Return DMA handle state */
  852. return hdma->State;
  853. }
  854. /**
  855. * @brief Return the DMA error code.
  856. * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
  857. * the configuration information for the specified DMA Channel.
  858. * @retval DMA Error Code
  859. */
  860. uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
  861. {
  862. return hdma->ErrorCode;
  863. }
  864. /**
  865. * @}
  866. */
  867. /**
  868. * @}
  869. */
  870. /** @addtogroup DMA_Private_Functions
  871. * @{
  872. */
  873. /**
  874. * @brief Sets the DMA Transfer parameter.
  875. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  876. * the configuration information for the specified DMA Channel.
  877. * @param SrcAddress The source memory Buffer address
  878. * @param DstAddress The destination memory Buffer address
  879. * @param DataLength The length of data to be transferred from source to destination
  880. * @retval HAL status
  881. */
  882. static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
  883. {
  884. #if defined(DMAMUX1)
  885. /* Clear the DMAMUX synchro overrun flag */
  886. hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
  887. if (hdma->DMAmuxRequestGen != 0U)
  888. {
  889. /* Clear the DMAMUX request generator overrun flag */
  890. hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
  891. }
  892. #endif
  893. /* Clear all flags */
  894. hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << (hdma->ChannelIndex & 0x1CU));
  895. /* Configure DMA Channel data length */
  896. hdma->Instance->CNDTR = DataLength;
  897. /* Memory to Peripheral */
  898. if ((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
  899. {
  900. /* Configure DMA Channel destination address */
  901. hdma->Instance->CPAR = DstAddress;
  902. /* Configure DMA Channel source address */
  903. hdma->Instance->CMAR = SrcAddress;
  904. }
  905. /* Peripheral to Memory */
  906. else
  907. {
  908. /* Configure DMA Channel source address */
  909. hdma->Instance->CPAR = SrcAddress;
  910. /* Configure DMA Channel destination address */
  911. hdma->Instance->CMAR = DstAddress;
  912. }
  913. }
  914. #if defined(DMAMUX1)
  915. /**
  916. * @brief Updates the DMA handle with the DMAMUX channel and status mask depending on channel number
  917. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  918. * the configuration information for the specified DMA Channel.
  919. * @retval None
  920. */
  921. static void DMA_CalcDMAMUXChannelBaseAndMask(DMA_HandleTypeDef *hdma)
  922. {
  923. uint32_t channel_number;
  924. /* check if instance is not outside the DMA channel range */
  925. if ((uint32_t)hdma->Instance < (uint32_t)DMA2_Channel1)
  926. {
  927. /* DMA1 */
  928. hdma->DMAmuxChannel = (DMAMUX1_Channel0 + (hdma->ChannelIndex >> 2U));
  929. }
  930. else
  931. {
  932. /* DMA2 */
  933. hdma->DMAmuxChannel = (DMAMUX1_Channel7 + (hdma->ChannelIndex >> 2U));
  934. }
  935. channel_number = (((uint32_t)hdma->Instance & 0xFFU) - 8U) / 20U;
  936. hdma->DMAmuxChannelStatus = DMAMUX1_ChannelStatus;
  937. hdma->DMAmuxChannelStatusMask = 1UL << (channel_number & 0x1FU);
  938. }
  939. /**
  940. * @brief Updates the DMA handle with the DMAMUX request generator params
  941. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  942. * the configuration information for the specified DMA Channel.
  943. * @retval None
  944. */
  945. static void DMA_CalcDMAMUXRequestGenBaseAndMask(DMA_HandleTypeDef *hdma)
  946. {
  947. uint32_t request = hdma->Init.Request & DMAMUX_CxCR_DMAREQ_ID;
  948. /* DMA Channels are connected to DMAMUX1 request generator blocks*/
  949. hdma->DMAmuxRequestGen = (DMAMUX_RequestGen_TypeDef *)((uint32_t)(((uint32_t)DMAMUX1_RequestGenerator0) + ((request - 1U) * 4U)));
  950. hdma->DMAmuxRequestGenStatus = DMAMUX1_RequestGenStatus;
  951. /* here "Request" is either DMA_REQUEST_GENERATOR0 to DMA_REQUEST_GENERATOR3, i.e. <= 4*/
  952. hdma->DMAmuxRequestGenStatusMask = 1UL << ((request - 1U) & 0x3U);
  953. }
  954. #endif /* DMAMUX1 */
  955. /**
  956. * @}
  957. */
  958. /**
  959. * @}
  960. */
  961. #endif /* HAL_DMA_MODULE_ENABLED */
  962. /**
  963. * @}
  964. */
  965. /**
  966. * @}
  967. */