stm32l4xx_hal_dma.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_dma.h
  4. * @author MCD Application Team
  5. * @brief Header file of DMA HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L4xx_HAL_DMA_H
  37. #define __STM32L4xx_HAL_DMA_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx_hal_def.h"
  43. /** @addtogroup STM32L4xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup DMA
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup DMA_Exported_Types DMA Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief DMA Configuration Structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t Request; /*!< Specifies the request selected for the specified channel.
  59. This parameter can be a value of @ref DMA_request */
  60. uint32_t Direction; /*!< Specifies if the data will be transferred from memory to peripheral,
  61. from memory to memory or from peripheral to memory.
  62. This parameter can be a value of @ref DMA_Data_transfer_direction */
  63. uint32_t PeriphInc; /*!< Specifies whether the Peripheral address register should be incremented or not.
  64. This parameter can be a value of @ref DMA_Peripheral_incremented_mode */
  65. uint32_t MemInc; /*!< Specifies whether the memory address register should be incremented or not.
  66. This parameter can be a value of @ref DMA_Memory_incremented_mode */
  67. uint32_t PeriphDataAlignment; /*!< Specifies the Peripheral data width.
  68. This parameter can be a value of @ref DMA_Peripheral_data_size */
  69. uint32_t MemDataAlignment; /*!< Specifies the Memory data width.
  70. This parameter can be a value of @ref DMA_Memory_data_size */
  71. uint32_t Mode; /*!< Specifies the operation mode of the DMAy Channelx.
  72. This parameter can be a value of @ref DMA_mode
  73. @note The circular buffer mode cannot be used if the memory-to-memory
  74. data transfer is configured on the selected Channel */
  75. uint32_t Priority; /*!< Specifies the software priority for the DMAy Channelx.
  76. This parameter can be a value of @ref DMA_Priority_level */
  77. } DMA_InitTypeDef;
  78. /**
  79. * @brief HAL DMA State structures definition
  80. */
  81. typedef enum
  82. {
  83. HAL_DMA_STATE_RESET = 0x00, /*!< DMA not yet initialized or disabled */
  84. HAL_DMA_STATE_READY = 0x01, /*!< DMA initialized and ready for use */
  85. HAL_DMA_STATE_BUSY = 0x02, /*!< DMA process is ongoing */
  86. HAL_DMA_STATE_TIMEOUT = 0x03, /*!< DMA timeout state */
  87. }HAL_DMA_StateTypeDef;
  88. /**
  89. * @brief HAL DMA Error Code structure definition
  90. */
  91. typedef enum
  92. {
  93. HAL_DMA_FULL_TRANSFER = 0x00, /*!< Full transfer */
  94. HAL_DMA_HALF_TRANSFER = 0x01 /*!< Half Transfer */
  95. }HAL_DMA_LevelCompleteTypeDef;
  96. /**
  97. * @brief HAL DMA Callback ID structure definition
  98. */
  99. typedef enum
  100. {
  101. HAL_DMA_XFER_CPLT_CB_ID = 0x00, /*!< Full transfer */
  102. HAL_DMA_XFER_HALFCPLT_CB_ID = 0x01, /*!< Half transfer */
  103. HAL_DMA_XFER_ERROR_CB_ID = 0x02, /*!< Error */
  104. HAL_DMA_XFER_ABORT_CB_ID = 0x03, /*!< Abort */
  105. HAL_DMA_XFER_ALL_CB_ID = 0x04 /*!< All */
  106. }HAL_DMA_CallbackIDTypeDef;
  107. /**
  108. * @brief DMA handle Structure definition
  109. */
  110. typedef struct __DMA_HandleTypeDef
  111. {
  112. DMA_Channel_TypeDef *Instance; /*!< Register base address */
  113. DMA_InitTypeDef Init; /*!< DMA communication parameters */
  114. HAL_LockTypeDef Lock; /*!< DMA locking object */
  115. __IO HAL_DMA_StateTypeDef State; /*!< DMA transfer state */
  116. void *Parent; /*!< Parent object state */
  117. void (* XferCpltCallback)(struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete callback */
  118. void (* XferHalfCpltCallback)(struct __DMA_HandleTypeDef * hdma); /*!< DMA Half transfer complete callback */
  119. void (* XferErrorCallback)(struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer error callback */
  120. void (* XferAbortCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer abort callback */
  121. __IO uint32_t ErrorCode; /*!< DMA Error code */
  122. DMA_TypeDef *DmaBaseAddress; /*!< DMA Channel Base Address */
  123. uint32_t ChannelIndex; /*!< DMA Channel Index */
  124. #if defined(DMAMUX1)
  125. DMAMUX_Channel_TypeDef *DMAmuxChannel; /*!< Register base address */
  126. DMAMUX_ChannelStatus_TypeDef *DMAmuxChannelStatus; /*!< DMAMUX Channels Status Base Address */
  127. uint32_t DMAmuxChannelStatusMask; /*!< DMAMUX Channel Status Mask */
  128. DMAMUX_RequestGen_TypeDef *DMAmuxRequestGen; /*!< DMAMUX request generator Base Address */
  129. DMAMUX_RequestGenStatus_TypeDef *DMAmuxRequestGenStatus; /*!< DMAMUX request generator Address */
  130. uint32_t DMAmuxRequestGenStatusMask; /*!< DMAMUX request generator Status mask */
  131. #endif /* DMAMUX1 */
  132. }DMA_HandleTypeDef;
  133. /**
  134. * @}
  135. */
  136. /* Exported constants --------------------------------------------------------*/
  137. /** @defgroup DMA_Exported_Constants DMA Exported Constants
  138. * @{
  139. */
  140. /** @defgroup DMA_Error_Code DMA Error Code
  141. * @{
  142. */
  143. #define HAL_DMA_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
  144. #define HAL_DMA_ERROR_TE ((uint32_t)0x00000001U) /*!< Transfer error */
  145. #define HAL_DMA_ERROR_NO_XFER ((uint32_t)0x00000004U) /*!< Abort requested with no Xfer ongoing */
  146. #define HAL_DMA_ERROR_TIMEOUT ((uint32_t)0x00000020U) /*!< Timeout error */
  147. #define HAL_DMA_ERROR_NOT_SUPPORTED ((uint32_t)0x00000100U) /*!< Not supported mode */
  148. #define HAL_DMA_ERROR_SYNC ((uint32_t)0x00000200U) /*!< DMAMUX sync overrun error */
  149. #define HAL_DMA_ERROR_REQGEN ((uint32_t)0x00000400U) /*!< DMAMUX request generator overrun error */
  150. /**
  151. * @}
  152. */
  153. /** @defgroup DMA_request DMA request
  154. * @{
  155. */
  156. #if !defined (DMAMUX1)
  157. #define DMA_REQUEST_0 ((uint32_t)0x00000000)
  158. #define DMA_REQUEST_1 ((uint32_t)0x00000001)
  159. #define DMA_REQUEST_2 ((uint32_t)0x00000002)
  160. #define DMA_REQUEST_3 ((uint32_t)0x00000003)
  161. #define DMA_REQUEST_4 ((uint32_t)0x00000004)
  162. #define DMA_REQUEST_5 ((uint32_t)0x00000005)
  163. #define DMA_REQUEST_6 ((uint32_t)0x00000006)
  164. #define DMA_REQUEST_7 ((uint32_t)0x00000007)
  165. #endif
  166. #if defined(DMAMUX1)
  167. #define DMA_REQUEST_MEM2MEM 0U /*!< memory to memory transfer */
  168. #define DMA_REQUEST_GENERATOR0 1U /*!< DMAMUX1 request generator 0 */
  169. #define DMA_REQUEST_GENERATOR1 2U /*!< DMAMUX1 request generator 1 */
  170. #define DMA_REQUEST_GENERATOR2 3U /*!< DMAMUX1 request generator 2 */
  171. #define DMA_REQUEST_GENERATOR3 4U /*!< DMAMUX1 request generator 3 */
  172. #define DMA_REQUEST_ADC1 5U /*!< DMAMUX1 ADC1 request */
  173. #define DMA_REQUEST_DAC1_CH1 6U /*!< DMAMUX1 DAC1 CH1 request */
  174. #define DMA_REQUEST_DAC1_CH2 7U /*!< DMAMUX1 DAC1 CH2 request */
  175. #define DMA_REQUEST_TIM6_UP 8U /*!< DMAMUX1 TIM6 UP request */
  176. #define DMA_REQUEST_TIM7_UP 9U /*!< DMAMUX1 TIM7 UP request */
  177. #define DMA_REQUEST_SPI1_RX 10U /*!< DMAMUX1 SPI1 RX request */
  178. #define DMA_REQUEST_SPI1_TX 11U /*!< DMAMUX1 SPI1 TX request */
  179. #define DMA_REQUEST_SPI2_RX 12U /*!< DMAMUX1 SPI2 RX request */
  180. #define DMA_REQUEST_SPI2_TX 13U /*!< DMAMUX1 SPI2 TX request */
  181. #define DMA_REQUEST_SPI3_RX 14U /*!< DMAMUX1 SPI3 RX request */
  182. #define DMA_REQUEST_SPI3_TX 15U /*!< DMAMUX1 SPI3 TX request */
  183. #define DMA_REQUEST_I2C1_RX 16U /*!< DMAMUX1 I2C1 RX request */
  184. #define DMA_REQUEST_I2C1_TX 17U /*!< DMAMUX1 I2C1 TX request */
  185. #define DMA_REQUEST_I2C2_RX 18U /*!< DMAMUX1 I2C2 RX request */
  186. #define DMA_REQUEST_I2C2_TX 19U /*!< DMAMUX1 I2C2 TX request */
  187. #define DMA_REQUEST_I2C3_RX 20U /*!< DMAMUX1 I2C3 RX request */
  188. #define DMA_REQUEST_I2C3_TX 21U /*!< DMAMUX1 I2C3 TX request */
  189. #define DMA_REQUEST_I2C4_RX 22U /*!< DMAMUX1 I2C4 RX request */
  190. #define DMA_REQUEST_I2C4_TX 23U /*!< DMAMUX1 I2C4 TX request */
  191. #define DMA_REQUEST_USART1_RX 24U /*!< DMAMUX1 USART1 RX request */
  192. #define DMA_REQUEST_USART1_TX 25U /*!< DMAMUX1 USART1 TX request */
  193. #define DMA_REQUEST_USART2_RX 26U /*!< DMAMUX1 USART2 RX request */
  194. #define DMA_REQUEST_USART2_TX 27U /*!< DMAMUX1 USART2 TX request */
  195. #define DMA_REQUEST_USART3_RX 28U /*!< DMAMUX1 USART3 RX request */
  196. #define DMA_REQUEST_USART3_TX 29U /*!< DMAMUX1 USART3 TX request */
  197. #define DMA_REQUEST_UART4_RX 30U /*!< DMAMUX1 UART4 RX request */
  198. #define DMA_REQUEST_UART4_TX 31U /*!< DMAMUX1 UART4 TX request */
  199. #define DMA_REQUEST_UART5_RX 32U /*!< DMAMUX1 UART5 RX request */
  200. #define DMA_REQUEST_UART5_TX 33U /*!< DMAMUX1 UART5 TX request */
  201. #define DMA_REQUEST_LPUART1_RX 34U /*!< DMAMUX1 LP_UART1_RX request */
  202. #define DMA_REQUEST_LPUART1_TX 35U /*!< DMAMUX1 LP_UART1_RX request */
  203. #define DMA_REQUEST_SAI1_A 36U /*!< DMAMUX1 SAI1 A request */
  204. #define DMA_REQUEST_SAI1_B 37U /*!< DMAMUX1 SAI1 B request */
  205. #define DMA_REQUEST_SAI2_A 38U /*!< DMAMUX1 SAI2 A request */
  206. #define DMA_REQUEST_SAI2_B 39U /*!< DMAMUX1 SAI2 B request */
  207. #define DMA_REQUEST_OCTOSPI1 40U /*!< DMAMUX1 OCTOSPI1 request */
  208. #define DMA_REQUEST_OCTOSPI2 41U /*!< DMAMUX1 OCTOSPI2 request */
  209. #define DMA_REQUEST_TIM1_CH1 42U /*!< DMAMUX1 TIM1 CH1 request */
  210. #define DMA_REQUEST_TIM1_CH2 43U /*!< DMAMUX1 TIM1 CH2 request */
  211. #define DMA_REQUEST_TIM1_CH3 44U /*!< DMAMUX1 TIM1 CH3 request */
  212. #define DMA_REQUEST_TIM1_CH4 45U /*!< DMAMUX1 TIM1 CH4 request */
  213. #define DMA_REQUEST_TIM1_UP 46U /*!< DMAMUX1 TIM1 UP request */
  214. #define DMA_REQUEST_TIM1_TRIG 47U /*!< DMAMUX1 TIM1 TRIG request */
  215. #define DMA_REQUEST_TIM1_COM 48U /*!< DMAMUX1 TIM1 COM request */
  216. #define DMA_REQUEST_TIM8_CH1 49U /*!< DMAMUX1 TIM8 CH1 request */
  217. #define DMA_REQUEST_TIM8_CH2 50U /*!< DMAMUX1 TIM8 CH2 request */
  218. #define DMA_REQUEST_TIM8_CH3 51U /*!< DMAMUX1 TIM8 CH3 request */
  219. #define DMA_REQUEST_TIM8_CH4 52U /*!< DMAMUX1 TIM8 CH4 request */
  220. #define DMA_REQUEST_TIM8_UP 53U /*!< DMAMUX1 TIM8 UP request */
  221. #define DMA_REQUEST_TIM8_TRIG 54U /*!< DMAMUX1 TIM8 TRIG request */
  222. #define DMA_REQUEST_TIM8_COM 55U /*!< DMAMUX1 TIM8 COM request */
  223. #define DMA_REQUEST_TIM2_CH1 56U /*!< DMAMUX1 TIM2 CH1 request */
  224. #define DMA_REQUEST_TIM2_CH2 57U /*!< DMAMUX1 TIM2 CH2 request */
  225. #define DMA_REQUEST_TIM2_CH3 58U /*!< DMAMUX1 TIM2 CH3 request */
  226. #define DMA_REQUEST_TIM2_CH4 59U /*!< DMAMUX1 TIM2 CH4 request */
  227. #define DMA_REQUEST_TIM2_UP 60U /*!< DMAMUX1 TIM2 UP request */
  228. #define DMA_REQUEST_TIM3_CH1 61U /*!< DMAMUX1 TIM3 CH1 request */
  229. #define DMA_REQUEST_TIM3_CH2 62U /*!< DMAMUX1 TIM3 CH2 request */
  230. #define DMA_REQUEST_TIM3_CH3 63U /*!< DMAMUX1 TIM3 CH3 request */
  231. #define DMA_REQUEST_TIM3_CH4 64U /*!< DMAMUX1 TIM3 CH4 request */
  232. #define DMA_REQUEST_TIM3_UP 65U /*!< DMAMUX1 TIM3 UP request */
  233. #define DMA_REQUEST_TIM3_TRIG 66U /*!< DMAMUX1 TIM3 TRIG request */
  234. #define DMA_REQUEST_TIM4_CH1 67U /*!< DMAMUX1 TIM4 CH1 request */
  235. #define DMA_REQUEST_TIM4_CH2 68U /*!< DMAMUX1 TIM4 CH2 request */
  236. #define DMA_REQUEST_TIM4_CH3 69U /*!< DMAMUX1 TIM4 CH3 request */
  237. #define DMA_REQUEST_TIM4_CH4 70U /*!< DMAMUX1 TIM4 CH4 request */
  238. #define DMA_REQUEST_TIM4_UP 71U /*!< DMAMUX1 TIM4 UP request */
  239. #define DMA_REQUEST_TIM5_CH1 72U /*!< DMAMUX1 TIM5 CH1 request */
  240. #define DMA_REQUEST_TIM5_CH2 73U /*!< DMAMUX1 TIM5 CH2 request */
  241. #define DMA_REQUEST_TIM5_CH3 74U /*!< DMAMUX1 TIM5 CH3 request */
  242. #define DMA_REQUEST_TIM5_CH4 75U /*!< DMAMUX1 TIM5 CH4 request */
  243. #define DMA_REQUEST_TIM5_UP 76U /*!< DMAMUX1 TIM5 UP request */
  244. #define DMA_REQUEST_TIM5_TRIG 77U /*!< DMAMUX1 TIM5 TRIG request */
  245. #define DMA_REQUEST_TIM15_CH1 78U /*!< DMAMUX1 TIM15 CH1 request */
  246. #define DMA_REQUEST_TIM15_UP 79U /*!< DMAMUX1 TIM15 UP request */
  247. #define DMA_REQUEST_TIM15_TRIG 80U /*!< DMAMUX1 TIM15 TRIG request */
  248. #define DMA_REQUEST_TIM15_COM 81U /*!< DMAMUX1 TIM15 COM request */
  249. #define DMA_REQUEST_TIM16_CH1 82U /*!< DMAMUX1 TIM16 CH1 request */
  250. #define DMA_REQUEST_TIM16_UP 83U /*!< DMAMUX1 TIM16 UP request */
  251. #define DMA_REQUEST_TIM17_CH1 84U /*!< DMAMUX1 TIM17 CH1 request */
  252. #define DMA_REQUEST_TIM17_UP 85U /*!< DMAMUX1 TIM17 UP request */
  253. #define DMA_REQUEST_DFSDM1_FLT0 86U /*!< DMAMUX1 DFSDM1 Filter0 request */
  254. #define DMA_REQUEST_DFSDM1_FLT1 87U /*!< DMAMUX1 DFSDM1 Filter1 request */
  255. #define DMA_REQUEST_DFSDM1_FLT2 88U /*!< DMAMUX1 DFSDM1 Filter2 request */
  256. #define DMA_REQUEST_DFSDM1_FLT3 89U /*!< DMAMUX1 DFSDM1 Filter3 request */
  257. #define DMA_REQUEST_DCMI 90U /*!< DMAMUX1 DCMI request */
  258. #define DMA_REQUEST_AES_IN 91U /*!< DMAMUX1 AES IN request */
  259. #define DMA_REQUEST_AES_OUT 92U /*!< DMAMUX1 AES OUT request */
  260. #define DMA_REQUEST_HASH_IN 93U /*!< DMAMUX1 HASH IN request */
  261. #endif /* DMAMUX1 */
  262. /**
  263. * @}
  264. */
  265. /** @defgroup DMA_Data_transfer_direction DMA Data transfer direction
  266. * @{
  267. */
  268. #define DMA_PERIPH_TO_MEMORY ((uint32_t)0x00000000) /*!< Peripheral to memory direction */
  269. #define DMA_MEMORY_TO_PERIPH ((uint32_t)DMA_CCR_DIR) /*!< Memory to peripheral direction */
  270. #define DMA_MEMORY_TO_MEMORY ((uint32_t)DMA_CCR_MEM2MEM) /*!< Memory to memory direction */
  271. /**
  272. * @}
  273. */
  274. /** @defgroup DMA_Peripheral_incremented_mode DMA Peripheral incremented mode
  275. * @{
  276. */
  277. #define DMA_PINC_ENABLE ((uint32_t)DMA_CCR_PINC) /*!< Peripheral increment mode Enable */
  278. #define DMA_PINC_DISABLE ((uint32_t)0x00000000) /*!< Peripheral increment mode Disable */
  279. /**
  280. * @}
  281. */
  282. /** @defgroup DMA_Memory_incremented_mode DMA Memory incremented mode
  283. * @{
  284. */
  285. #define DMA_MINC_ENABLE ((uint32_t)DMA_CCR_MINC) /*!< Memory increment mode Enable */
  286. #define DMA_MINC_DISABLE ((uint32_t)0x00000000) /*!< Memory increment mode Disable */
  287. /**
  288. * @}
  289. */
  290. /** @defgroup DMA_Peripheral_data_size DMA Peripheral data size
  291. * @{
  292. */
  293. #define DMA_PDATAALIGN_BYTE ((uint32_t)0x00000000) /*!< Peripheral data alignment : Byte */
  294. #define DMA_PDATAALIGN_HALFWORD ((uint32_t)DMA_CCR_PSIZE_0) /*!< Peripheral data alignment : HalfWord */
  295. #define DMA_PDATAALIGN_WORD ((uint32_t)DMA_CCR_PSIZE_1) /*!< Peripheral data alignment : Word */
  296. /**
  297. * @}
  298. */
  299. /** @defgroup DMA_Memory_data_size DMA Memory data size
  300. * @{
  301. */
  302. #define DMA_MDATAALIGN_BYTE ((uint32_t)0x00000000) /*!< Memory data alignment : Byte */
  303. #define DMA_MDATAALIGN_HALFWORD ((uint32_t)DMA_CCR_MSIZE_0) /*!< Memory data alignment : HalfWord */
  304. #define DMA_MDATAALIGN_WORD ((uint32_t)DMA_CCR_MSIZE_1) /*!< Memory data alignment : Word */
  305. /**
  306. * @}
  307. */
  308. /** @defgroup DMA_mode DMA mode
  309. * @{
  310. */
  311. #define DMA_NORMAL ((uint32_t)0x00000000) /*!< Normal mode */
  312. #define DMA_CIRCULAR ((uint32_t)DMA_CCR_CIRC) /*!< Circular mode */
  313. /**
  314. * @}
  315. */
  316. /** @defgroup DMA_Priority_level DMA Priority level
  317. * @{
  318. */
  319. #define DMA_PRIORITY_LOW ((uint32_t)0x00000000) /*!< Priority level : Low */
  320. #define DMA_PRIORITY_MEDIUM ((uint32_t)DMA_CCR_PL_0) /*!< Priority level : Medium */
  321. #define DMA_PRIORITY_HIGH ((uint32_t)DMA_CCR_PL_1) /*!< Priority level : High */
  322. #define DMA_PRIORITY_VERY_HIGH ((uint32_t)DMA_CCR_PL) /*!< Priority level : Very_High */
  323. /**
  324. * @}
  325. */
  326. /** @defgroup DMA_interrupt_enable_definitions DMA interrupt enable definitions
  327. * @{
  328. */
  329. #define DMA_IT_TC ((uint32_t)DMA_CCR_TCIE)
  330. #define DMA_IT_HT ((uint32_t)DMA_CCR_HTIE)
  331. #define DMA_IT_TE ((uint32_t)DMA_CCR_TEIE)
  332. /**
  333. * @}
  334. */
  335. /** @defgroup DMA_flag_definitions DMA flag definitions
  336. * @{
  337. */
  338. #define DMA_FLAG_GL1 ((uint32_t)0x00000001)
  339. #define DMA_FLAG_TC1 ((uint32_t)0x00000002)
  340. #define DMA_FLAG_HT1 ((uint32_t)0x00000004)
  341. #define DMA_FLAG_TE1 ((uint32_t)0x00000008)
  342. #define DMA_FLAG_GL2 ((uint32_t)0x00000010)
  343. #define DMA_FLAG_TC2 ((uint32_t)0x00000020)
  344. #define DMA_FLAG_HT2 ((uint32_t)0x00000040)
  345. #define DMA_FLAG_TE2 ((uint32_t)0x00000080)
  346. #define DMA_FLAG_GL3 ((uint32_t)0x00000100)
  347. #define DMA_FLAG_TC3 ((uint32_t)0x00000200)
  348. #define DMA_FLAG_HT3 ((uint32_t)0x00000400)
  349. #define DMA_FLAG_TE3 ((uint32_t)0x00000800)
  350. #define DMA_FLAG_GL4 ((uint32_t)0x00001000)
  351. #define DMA_FLAG_TC4 ((uint32_t)0x00002000)
  352. #define DMA_FLAG_HT4 ((uint32_t)0x00004000)
  353. #define DMA_FLAG_TE4 ((uint32_t)0x00008000)
  354. #define DMA_FLAG_GL5 ((uint32_t)0x00010000)
  355. #define DMA_FLAG_TC5 ((uint32_t)0x00020000)
  356. #define DMA_FLAG_HT5 ((uint32_t)0x00040000)
  357. #define DMA_FLAG_TE5 ((uint32_t)0x00080000)
  358. #define DMA_FLAG_GL6 ((uint32_t)0x00100000)
  359. #define DMA_FLAG_TC6 ((uint32_t)0x00200000)
  360. #define DMA_FLAG_HT6 ((uint32_t)0x00400000)
  361. #define DMA_FLAG_TE6 ((uint32_t)0x00800000)
  362. #define DMA_FLAG_GL7 ((uint32_t)0x01000000)
  363. #define DMA_FLAG_TC7 ((uint32_t)0x02000000)
  364. #define DMA_FLAG_HT7 ((uint32_t)0x04000000)
  365. #define DMA_FLAG_TE7 ((uint32_t)0x08000000)
  366. /**
  367. * @}
  368. */
  369. /**
  370. * @}
  371. */
  372. /* Exported macros -----------------------------------------------------------*/
  373. /** @defgroup DMA_Exported_Macros DMA Exported Macros
  374. * @{
  375. */
  376. /** @brief Reset DMA handle state.
  377. * @param __HANDLE__: DMA handle
  378. * @retval None
  379. */
  380. #define __HAL_DMA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DMA_STATE_RESET)
  381. /**
  382. * @brief Enable the specified DMA Channel.
  383. * @param __HANDLE__: DMA handle
  384. * @retval None
  385. */
  386. #define __HAL_DMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CCR |= DMA_CCR_EN)
  387. /**
  388. * @brief Disable the specified DMA Channel.
  389. * @param __HANDLE__: DMA handle
  390. * @retval None
  391. */
  392. #define __HAL_DMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CCR &= ~DMA_CCR_EN)
  393. /* Interrupt & Flag management */
  394. /**
  395. * @brief Return the current DMA Channel transfer complete flag.
  396. * @param __HANDLE__: DMA handle
  397. * @retval The specified transfer complete flag index.
  398. */
  399. #define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__) \
  400. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TC1 :\
  401. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_TC1 :\
  402. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TC2 :\
  403. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_TC2 :\
  404. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TC3 :\
  405. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_TC3 :\
  406. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TC4 :\
  407. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_TC4 :\
  408. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TC5 :\
  409. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_FLAG_TC5 :\
  410. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TC6 :\
  411. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel6))? DMA_FLAG_TC6 :\
  412. DMA_FLAG_TC7)
  413. /**
  414. * @brief Return the current DMA Channel half transfer complete flag.
  415. * @param __HANDLE__: DMA handle
  416. * @retval The specified half transfer complete flag index.
  417. */
  418. #define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)\
  419. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_HT1 :\
  420. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_HT1 :\
  421. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_HT2 :\
  422. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_HT2 :\
  423. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_HT3 :\
  424. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_HT3 :\
  425. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_HT4 :\
  426. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_HT4 :\
  427. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_HT5 :\
  428. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_FLAG_HT5 :\
  429. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_HT6 :\
  430. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel6))? DMA_FLAG_HT6 :\
  431. DMA_FLAG_HT7)
  432. /**
  433. * @brief Return the current DMA Channel transfer error flag.
  434. * @param __HANDLE__: DMA handle
  435. * @retval The specified transfer error flag index.
  436. */
  437. #define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)\
  438. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TE1 :\
  439. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_TE1 :\
  440. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TE2 :\
  441. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_TE2 :\
  442. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TE3 :\
  443. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_TE3 :\
  444. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TE4 :\
  445. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_TE4 :\
  446. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TE5 :\
  447. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_FLAG_TE5 :\
  448. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TE6 :\
  449. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel6))? DMA_FLAG_TE6 :\
  450. DMA_FLAG_TE7)
  451. /**
  452. * @brief Return the current DMA Channel Global interrupt flag.
  453. * @param __HANDLE__: DMA handle
  454. * @retval The specified transfer error flag index.
  455. */
  456. #define __HAL_DMA_GET_GI_FLAG_INDEX(__HANDLE__)\
  457. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_ISR_GIF1 :\
  458. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_ISR_GIF1 :\
  459. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_ISR_GIF2 :\
  460. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_ISR_GIF2 :\
  461. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_ISR_GIF3 :\
  462. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_ISR_GIF3 :\
  463. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_ISR_GIF4 :\
  464. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_ISR_GIF4 :\
  465. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_ISR_GIF5 :\
  466. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_ISR_GIF5 :\
  467. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_ISR_GIF6 :\
  468. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel6))? DMA_ISR_GIF6 :\
  469. DMA_ISR_GIF7)
  470. /**
  471. * @brief Get the DMA Channel pending flags.
  472. * @param __HANDLE__: DMA handle
  473. * @param __FLAG__: Get the specified flag.
  474. * This parameter can be any combination of the following values:
  475. * @arg DMA_FLAG_TCx: Transfer complete flag
  476. * @arg DMA_FLAG_HTx: Half transfer complete flag
  477. * @arg DMA_FLAG_TEx: Transfer error flag
  478. * @arg DMA_FLAG_GLx: Global interrupt flag
  479. * Where x can be from 1 to 7 to select the DMA Channel x flag.
  480. * @retval The state of FLAG (SET or RESET).
  481. */
  482. #define __HAL_DMA_GET_FLAG(__HANDLE__, __FLAG__) (((uint32_t)((__HANDLE__)->Instance) > ((uint32_t)DMA1_Channel7))? \
  483. (DMA2->ISR & (__FLAG__)) : (DMA1->ISR & (__FLAG__)))
  484. /**
  485. * @brief Clear the DMA Channel pending flags.
  486. * @param __HANDLE__: DMA handle
  487. * @param __FLAG__: specifies the flag to clear.
  488. * This parameter can be any combination of the following values:
  489. * @arg DMA_FLAG_TCx: Transfer complete flag
  490. * @arg DMA_FLAG_HTx: Half transfer complete flag
  491. * @arg DMA_FLAG_TEx: Transfer error flag
  492. * @arg DMA_FLAG_GLx: Global interrupt flag
  493. * Where x can be from 1 to 7 to select the DMA Channel x flag.
  494. * @retval None
  495. */
  496. #define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) (((uint32_t)((__HANDLE__)->Instance) > ((uint32_t)DMA1_Channel7))? \
  497. (DMA2->IFCR = (__FLAG__)) : (DMA1->IFCR = (__FLAG__)))
  498. /**
  499. * @brief Enable the specified DMA Channel interrupts.
  500. * @param __HANDLE__: DMA handle
  501. * @param __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled.
  502. * This parameter can be any combination of the following values:
  503. * @arg DMA_IT_TC: Transfer complete interrupt mask
  504. * @arg DMA_IT_HT: Half transfer complete interrupt mask
  505. * @arg DMA_IT_TE: Transfer error interrupt mask
  506. * @retval None
  507. */
  508. #define __HAL_DMA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CCR |= (__INTERRUPT__))
  509. /**
  510. * @brief Disable the specified DMA Channel interrupts.
  511. * @param __HANDLE__: DMA handle
  512. * @param __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled.
  513. * This parameter can be any combination of the following values:
  514. * @arg DMA_IT_TC: Transfer complete interrupt mask
  515. * @arg DMA_IT_HT: Half transfer complete interrupt mask
  516. * @arg DMA_IT_TE: Transfer error interrupt mask
  517. * @retval None
  518. */
  519. #define __HAL_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CCR &= ~(__INTERRUPT__))
  520. /**
  521. * @brief Check whether the specified DMA Channel interrupt is enabled or not.
  522. * @param __HANDLE__: DMA handle
  523. * @param __INTERRUPT__: specifies the DMA interrupt source to check.
  524. * This parameter can be one of the following values:
  525. * @arg DMA_IT_TC: Transfer complete interrupt mask
  526. * @arg DMA_IT_HT: Half transfer complete interrupt mask
  527. * @arg DMA_IT_TE: Transfer error interrupt mask
  528. * @retval The state of DMA_IT (SET or RESET).
  529. */
  530. #define __HAL_DMA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CCR & (__INTERRUPT__)))
  531. /**
  532. * @brief Return the number of remaining data units in the current DMA Channel transfer.
  533. * @param __HANDLE__: DMA handle
  534. * @retval The number of remaining data units in the current DMA Channel transfer.
  535. */
  536. #define __HAL_DMA_GET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->CNDTR)
  537. /**
  538. * @}
  539. */
  540. #if defined(DMAMUX1)
  541. /* Include DMA HAL Extension module */
  542. #include "stm32l4xx_hal_dma_ex.h"
  543. #endif /* DMAMUX1 */
  544. /* Exported functions --------------------------------------------------------*/
  545. /** @addtogroup DMA_Exported_Functions
  546. * @{
  547. */
  548. /** @addtogroup DMA_Exported_Functions_Group1
  549. * @{
  550. */
  551. /* Initialization and de-initialization functions *****************************/
  552. HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma);
  553. HAL_StatusTypeDef HAL_DMA_DeInit (DMA_HandleTypeDef *hdma);
  554. /**
  555. * @}
  556. */
  557. /** @addtogroup DMA_Exported_Functions_Group2
  558. * @{
  559. */
  560. /* IO operation functions *****************************************************/
  561. HAL_StatusTypeDef HAL_DMA_Start (DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  562. HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  563. HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma);
  564. HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma);
  565. HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, HAL_DMA_LevelCompleteTypeDef CompleteLevel, uint32_t Timeout);
  566. void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma);
  567. HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)( DMA_HandleTypeDef * _hdma));
  568. HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID);
  569. /**
  570. * @}
  571. */
  572. /** @addtogroup DMA_Exported_Functions_Group3
  573. * @{
  574. */
  575. /* Peripheral State and Error functions ***************************************/
  576. HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma);
  577. uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma);
  578. /**
  579. * @}
  580. */
  581. /**
  582. * @}
  583. */
  584. /* Private macros ------------------------------------------------------------*/
  585. /** @defgroup DMA_Private_Macros DMA Private Macros
  586. * @{
  587. */
  588. #define IS_DMA_DIRECTION(DIRECTION) (((DIRECTION) == DMA_PERIPH_TO_MEMORY ) || \
  589. ((DIRECTION) == DMA_MEMORY_TO_PERIPH) || \
  590. ((DIRECTION) == DMA_MEMORY_TO_MEMORY))
  591. #define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1) && ((SIZE) < 0x10000))
  592. #define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PINC_ENABLE) || \
  593. ((STATE) == DMA_PINC_DISABLE))
  594. #define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MINC_ENABLE) || \
  595. ((STATE) == DMA_MINC_DISABLE))
  596. #if !defined (DMAMUX1)
  597. #define IS_DMA_ALL_REQUEST(REQUEST) (((REQUEST) == DMA_REQUEST_0) || \
  598. ((REQUEST) == DMA_REQUEST_1) || \
  599. ((REQUEST) == DMA_REQUEST_2) || \
  600. ((REQUEST) == DMA_REQUEST_3) || \
  601. ((REQUEST) == DMA_REQUEST_4) || \
  602. ((REQUEST) == DMA_REQUEST_5) || \
  603. ((REQUEST) == DMA_REQUEST_6) || \
  604. ((REQUEST) == DMA_REQUEST_7))
  605. #endif
  606. #if defined(DMAMUX1)
  607. #define IS_DMA_ALL_REQUEST(REQUEST)((REQUEST) <= DMA_REQUEST_HASH_IN)
  608. #endif /* DMAMUX1 */
  609. #define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PDATAALIGN_BYTE) || \
  610. ((SIZE) == DMA_PDATAALIGN_HALFWORD) || \
  611. ((SIZE) == DMA_PDATAALIGN_WORD))
  612. #define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MDATAALIGN_BYTE) || \
  613. ((SIZE) == DMA_MDATAALIGN_HALFWORD) || \
  614. ((SIZE) == DMA_MDATAALIGN_WORD ))
  615. #define IS_DMA_MODE(MODE) (((MODE) == DMA_NORMAL ) || \
  616. ((MODE) == DMA_CIRCULAR))
  617. #define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_PRIORITY_LOW ) || \
  618. ((PRIORITY) == DMA_PRIORITY_MEDIUM) || \
  619. ((PRIORITY) == DMA_PRIORITY_HIGH) || \
  620. ((PRIORITY) == DMA_PRIORITY_VERY_HIGH))
  621. /**
  622. * @}
  623. */
  624. /* Private functions ---------------------------------------------------------*/
  625. /**
  626. * @}
  627. */
  628. /**
  629. * @}
  630. */
  631. #ifdef __cplusplus
  632. }
  633. #endif
  634. #endif /* __STM32L4xx_HAL_DMA_H */
  635. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/