stm32l4xx_hal_dma.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_dma.h
  4. * @author MCD Application Team
  5. * @version V1.7.2
  6. * @date 16-June-2017
  7. * @brief Header file of DMA HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32L4xx_HAL_DMA_H
  39. #define __STM32L4xx_HAL_DMA_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l4xx_hal_def.h"
  45. /** @addtogroup STM32L4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup DMA
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup DMA_Exported_Types DMA Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief DMA Configuration Structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t Request; /*!< Specifies the request selected for the specified channel.
  61. This parameter can be a value of @ref DMA_request */
  62. uint32_t Direction; /*!< Specifies if the data will be transferred from memory to peripheral,
  63. from memory to memory or from peripheral to memory.
  64. This parameter can be a value of @ref DMA_Data_transfer_direction */
  65. uint32_t PeriphInc; /*!< Specifies whether the Peripheral address register should be incremented or not.
  66. This parameter can be a value of @ref DMA_Peripheral_incremented_mode */
  67. uint32_t MemInc; /*!< Specifies whether the memory address register should be incremented or not.
  68. This parameter can be a value of @ref DMA_Memory_incremented_mode */
  69. uint32_t PeriphDataAlignment; /*!< Specifies the Peripheral data width.
  70. This parameter can be a value of @ref DMA_Peripheral_data_size */
  71. uint32_t MemDataAlignment; /*!< Specifies the Memory data width.
  72. This parameter can be a value of @ref DMA_Memory_data_size */
  73. uint32_t Mode; /*!< Specifies the operation mode of the DMAy Channelx.
  74. This parameter can be a value of @ref DMA_mode
  75. @note The circular buffer mode cannot be used if the memory-to-memory
  76. data transfer is configured on the selected Channel */
  77. uint32_t Priority; /*!< Specifies the software priority for the DMAy Channelx.
  78. This parameter can be a value of @ref DMA_Priority_level */
  79. } DMA_InitTypeDef;
  80. /**
  81. * @brief HAL DMA State structures definition
  82. */
  83. typedef enum
  84. {
  85. HAL_DMA_STATE_RESET = 0x00, /*!< DMA not yet initialized or disabled */
  86. HAL_DMA_STATE_READY = 0x01, /*!< DMA initialized and ready for use */
  87. HAL_DMA_STATE_BUSY = 0x02, /*!< DMA process is ongoing */
  88. HAL_DMA_STATE_TIMEOUT = 0x03, /*!< DMA timeout state */
  89. }HAL_DMA_StateTypeDef;
  90. /**
  91. * @brief HAL DMA Error Code structure definition
  92. */
  93. typedef enum
  94. {
  95. HAL_DMA_FULL_TRANSFER = 0x00, /*!< Full transfer */
  96. HAL_DMA_HALF_TRANSFER = 0x01 /*!< Half Transfer */
  97. }HAL_DMA_LevelCompleteTypeDef;
  98. /**
  99. * @brief HAL DMA Callback ID structure definition
  100. */
  101. typedef enum
  102. {
  103. HAL_DMA_XFER_CPLT_CB_ID = 0x00, /*!< Full transfer */
  104. HAL_DMA_XFER_HALFCPLT_CB_ID = 0x01, /*!< Half transfer */
  105. HAL_DMA_XFER_ERROR_CB_ID = 0x02, /*!< Error */
  106. HAL_DMA_XFER_ABORT_CB_ID = 0x03, /*!< Abort */
  107. HAL_DMA_XFER_ALL_CB_ID = 0x04 /*!< All */
  108. }HAL_DMA_CallbackIDTypeDef;
  109. /**
  110. * @brief DMA handle Structure definition
  111. */
  112. typedef struct __DMA_HandleTypeDef
  113. {
  114. DMA_Channel_TypeDef *Instance; /*!< Register base address */
  115. DMA_InitTypeDef Init; /*!< DMA communication parameters */
  116. HAL_LockTypeDef Lock; /*!< DMA locking object */
  117. __IO HAL_DMA_StateTypeDef State; /*!< DMA transfer state */
  118. void *Parent; /*!< Parent object state */
  119. void (* XferCpltCallback)(struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete callback */
  120. void (* XferHalfCpltCallback)(struct __DMA_HandleTypeDef * hdma); /*!< DMA Half transfer complete callback */
  121. void (* XferErrorCallback)(struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer error callback */
  122. void (* XferAbortCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer abort callback */
  123. __IO uint32_t ErrorCode; /*!< DMA Error code */
  124. DMA_TypeDef *DmaBaseAddress; /*!< DMA Channel Base Address */
  125. uint32_t ChannelIndex; /*!< DMA Channel Index */
  126. }DMA_HandleTypeDef;
  127. /**
  128. * @}
  129. */
  130. /* Exported constants --------------------------------------------------------*/
  131. /** @defgroup DMA_Exported_Constants DMA Exported Constants
  132. * @{
  133. */
  134. /** @defgroup DMA_Error_Code DMA Error Code
  135. * @{
  136. */
  137. #define HAL_DMA_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */
  138. #define HAL_DMA_ERROR_TE ((uint32_t)0x00000001) /*!< Transfer error */
  139. #define HAL_DMA_ERROR_NO_XFER ((uint32_t)0x00000004) /*!< no ongoing transfer */
  140. #define HAL_DMA_ERROR_TIMEOUT ((uint32_t)0x00000020) /*!< Timeout error */
  141. #define HAL_DMA_ERROR_NOT_SUPPORTED ((uint32_t)0x00000100) /*!< Not supported mode */
  142. /**
  143. * @}
  144. */
  145. /** @defgroup DMA_request DMA request
  146. * @{
  147. */
  148. #define DMA_REQUEST_0 ((uint32_t)0x00000000)
  149. #define DMA_REQUEST_1 ((uint32_t)0x00000001)
  150. #define DMA_REQUEST_2 ((uint32_t)0x00000002)
  151. #define DMA_REQUEST_3 ((uint32_t)0x00000003)
  152. #define DMA_REQUEST_4 ((uint32_t)0x00000004)
  153. #define DMA_REQUEST_5 ((uint32_t)0x00000005)
  154. #define DMA_REQUEST_6 ((uint32_t)0x00000006)
  155. #define DMA_REQUEST_7 ((uint32_t)0x00000007)
  156. /**
  157. * @}
  158. */
  159. /** @defgroup DMA_Data_transfer_direction DMA Data transfer direction
  160. * @{
  161. */
  162. #define DMA_PERIPH_TO_MEMORY ((uint32_t)0x00000000) /*!< Peripheral to memory direction */
  163. #define DMA_MEMORY_TO_PERIPH ((uint32_t)DMA_CCR_DIR) /*!< Memory to peripheral direction */
  164. #define DMA_MEMORY_TO_MEMORY ((uint32_t)DMA_CCR_MEM2MEM) /*!< Memory to memory direction */
  165. /**
  166. * @}
  167. */
  168. /** @defgroup DMA_Peripheral_incremented_mode DMA Peripheral incremented mode
  169. * @{
  170. */
  171. #define DMA_PINC_ENABLE ((uint32_t)DMA_CCR_PINC) /*!< Peripheral increment mode Enable */
  172. #define DMA_PINC_DISABLE ((uint32_t)0x00000000) /*!< Peripheral increment mode Disable */
  173. /**
  174. * @}
  175. */
  176. /** @defgroup DMA_Memory_incremented_mode DMA Memory incremented mode
  177. * @{
  178. */
  179. #define DMA_MINC_ENABLE ((uint32_t)DMA_CCR_MINC) /*!< Memory increment mode Enable */
  180. #define DMA_MINC_DISABLE ((uint32_t)0x00000000) /*!< Memory increment mode Disable */
  181. /**
  182. * @}
  183. */
  184. /** @defgroup DMA_Peripheral_data_size DMA Peripheral data size
  185. * @{
  186. */
  187. #define DMA_PDATAALIGN_BYTE ((uint32_t)0x00000000) /*!< Peripheral data alignment : Byte */
  188. #define DMA_PDATAALIGN_HALFWORD ((uint32_t)DMA_CCR_PSIZE_0) /*!< Peripheral data alignment : HalfWord */
  189. #define DMA_PDATAALIGN_WORD ((uint32_t)DMA_CCR_PSIZE_1) /*!< Peripheral data alignment : Word */
  190. /**
  191. * @}
  192. */
  193. /** @defgroup DMA_Memory_data_size DMA Memory data size
  194. * @{
  195. */
  196. #define DMA_MDATAALIGN_BYTE ((uint32_t)0x00000000) /*!< Memory data alignment : Byte */
  197. #define DMA_MDATAALIGN_HALFWORD ((uint32_t)DMA_CCR_MSIZE_0) /*!< Memory data alignment : HalfWord */
  198. #define DMA_MDATAALIGN_WORD ((uint32_t)DMA_CCR_MSIZE_1) /*!< Memory data alignment : Word */
  199. /**
  200. * @}
  201. */
  202. /** @defgroup DMA_mode DMA mode
  203. * @{
  204. */
  205. #define DMA_NORMAL ((uint32_t)0x00000000) /*!< Normal mode */
  206. #define DMA_CIRCULAR ((uint32_t)DMA_CCR_CIRC) /*!< Circular mode */
  207. /**
  208. * @}
  209. */
  210. /** @defgroup DMA_Priority_level DMA Priority level
  211. * @{
  212. */
  213. #define DMA_PRIORITY_LOW ((uint32_t)0x00000000) /*!< Priority level : Low */
  214. #define DMA_PRIORITY_MEDIUM ((uint32_t)DMA_CCR_PL_0) /*!< Priority level : Medium */
  215. #define DMA_PRIORITY_HIGH ((uint32_t)DMA_CCR_PL_1) /*!< Priority level : High */
  216. #define DMA_PRIORITY_VERY_HIGH ((uint32_t)DMA_CCR_PL) /*!< Priority level : Very_High */
  217. /**
  218. * @}
  219. */
  220. /** @defgroup DMA_interrupt_enable_definitions DMA interrupt enable definitions
  221. * @{
  222. */
  223. #define DMA_IT_TC ((uint32_t)DMA_CCR_TCIE)
  224. #define DMA_IT_HT ((uint32_t)DMA_CCR_HTIE)
  225. #define DMA_IT_TE ((uint32_t)DMA_CCR_TEIE)
  226. /**
  227. * @}
  228. */
  229. /** @defgroup DMA_flag_definitions DMA flag definitions
  230. * @{
  231. */
  232. #define DMA_FLAG_GL1 ((uint32_t)0x00000001)
  233. #define DMA_FLAG_TC1 ((uint32_t)0x00000002)
  234. #define DMA_FLAG_HT1 ((uint32_t)0x00000004)
  235. #define DMA_FLAG_TE1 ((uint32_t)0x00000008)
  236. #define DMA_FLAG_GL2 ((uint32_t)0x00000010)
  237. #define DMA_FLAG_TC2 ((uint32_t)0x00000020)
  238. #define DMA_FLAG_HT2 ((uint32_t)0x00000040)
  239. #define DMA_FLAG_TE2 ((uint32_t)0x00000080)
  240. #define DMA_FLAG_GL3 ((uint32_t)0x00000100)
  241. #define DMA_FLAG_TC3 ((uint32_t)0x00000200)
  242. #define DMA_FLAG_HT3 ((uint32_t)0x00000400)
  243. #define DMA_FLAG_TE3 ((uint32_t)0x00000800)
  244. #define DMA_FLAG_GL4 ((uint32_t)0x00001000)
  245. #define DMA_FLAG_TC4 ((uint32_t)0x00002000)
  246. #define DMA_FLAG_HT4 ((uint32_t)0x00004000)
  247. #define DMA_FLAG_TE4 ((uint32_t)0x00008000)
  248. #define DMA_FLAG_GL5 ((uint32_t)0x00010000)
  249. #define DMA_FLAG_TC5 ((uint32_t)0x00020000)
  250. #define DMA_FLAG_HT5 ((uint32_t)0x00040000)
  251. #define DMA_FLAG_TE5 ((uint32_t)0x00080000)
  252. #define DMA_FLAG_GL6 ((uint32_t)0x00100000)
  253. #define DMA_FLAG_TC6 ((uint32_t)0x00200000)
  254. #define DMA_FLAG_HT6 ((uint32_t)0x00400000)
  255. #define DMA_FLAG_TE6 ((uint32_t)0x00800000)
  256. #define DMA_FLAG_GL7 ((uint32_t)0x01000000)
  257. #define DMA_FLAG_TC7 ((uint32_t)0x02000000)
  258. #define DMA_FLAG_HT7 ((uint32_t)0x04000000)
  259. #define DMA_FLAG_TE7 ((uint32_t)0x08000000)
  260. /**
  261. * @}
  262. */
  263. /**
  264. * @}
  265. */
  266. /* Exported macros -----------------------------------------------------------*/
  267. /** @defgroup DMA_Exported_Macros DMA Exported Macros
  268. * @{
  269. */
  270. /** @brief Reset DMA handle state.
  271. * @param __HANDLE__: DMA handle
  272. * @retval None
  273. */
  274. #define __HAL_DMA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DMA_STATE_RESET)
  275. /**
  276. * @brief Enable the specified DMA Channel.
  277. * @param __HANDLE__: DMA handle
  278. * @retval None
  279. */
  280. #define __HAL_DMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CCR |= DMA_CCR_EN)
  281. /**
  282. * @brief Disable the specified DMA Channel.
  283. * @param __HANDLE__: DMA handle
  284. * @retval None
  285. */
  286. #define __HAL_DMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CCR &= ~DMA_CCR_EN)
  287. /* Interrupt & Flag management */
  288. /**
  289. * @brief Return the current DMA Channel transfer complete flag.
  290. * @param __HANDLE__: DMA handle
  291. * @retval The specified transfer complete flag index.
  292. */
  293. #define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__) \
  294. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TC1 :\
  295. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_TC1 :\
  296. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TC2 :\
  297. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_TC2 :\
  298. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TC3 :\
  299. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_TC3 :\
  300. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TC4 :\
  301. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_TC4 :\
  302. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TC5 :\
  303. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_FLAG_TC5 :\
  304. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TC6 :\
  305. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel6))? DMA_FLAG_TC6 :\
  306. DMA_FLAG_TC7)
  307. /**
  308. * @brief Return the current DMA Channel half transfer complete flag.
  309. * @param __HANDLE__: DMA handle
  310. * @retval The specified half transfer complete flag index.
  311. */
  312. #define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)\
  313. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_HT1 :\
  314. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_HT1 :\
  315. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_HT2 :\
  316. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_HT2 :\
  317. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_HT3 :\
  318. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_HT3 :\
  319. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_HT4 :\
  320. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_HT4 :\
  321. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_HT5 :\
  322. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_FLAG_HT5 :\
  323. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_HT6 :\
  324. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel6))? DMA_FLAG_HT6 :\
  325. DMA_FLAG_HT7)
  326. /**
  327. * @brief Return the current DMA Channel transfer error flag.
  328. * @param __HANDLE__: DMA handle
  329. * @retval The specified transfer error flag index.
  330. */
  331. #define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)\
  332. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TE1 :\
  333. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_TE1 :\
  334. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TE2 :\
  335. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_TE2 :\
  336. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TE3 :\
  337. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_TE3 :\
  338. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TE4 :\
  339. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_TE4 :\
  340. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TE5 :\
  341. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_FLAG_TE5 :\
  342. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TE6 :\
  343. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel6))? DMA_FLAG_TE6 :\
  344. DMA_FLAG_TE7)
  345. /**
  346. * @brief Return the current DMA Channel Global interrupt flag.
  347. * @param __HANDLE__: DMA handle
  348. * @retval The specified transfer error flag index.
  349. */
  350. #define __HAL_DMA_GET_GI_FLAG_INDEX(__HANDLE__)\
  351. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_ISR_GIF1 :\
  352. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_ISR_GIF1 :\
  353. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_ISR_GIF2 :\
  354. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_ISR_GIF2 :\
  355. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_ISR_GIF3 :\
  356. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_ISR_GIF3 :\
  357. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_ISR_GIF4 :\
  358. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_ISR_GIF4 :\
  359. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_ISR_GIF5 :\
  360. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_ISR_GIF5 :\
  361. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_ISR_GIF6 :\
  362. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel6))? DMA_ISR_GIF6 :\
  363. DMA_ISR_GIF7)
  364. /**
  365. * @brief Get the DMA Channel pending flags.
  366. * @param __HANDLE__: DMA handle
  367. * @param __FLAG__: Get the specified flag.
  368. * This parameter can be any combination of the following values:
  369. * @arg DMA_FLAG_TCx: Transfer complete flag
  370. * @arg DMA_FLAG_HTx: Half transfer complete flag
  371. * @arg DMA_FLAG_TEx: Transfer error flag
  372. * @arg DMA_FLAG_GLx: Global interrupt flag
  373. * Where x can be from 1 to 7 to select the DMA Channel x flag.
  374. * @retval The state of FLAG (SET or RESET).
  375. */
  376. #define __HAL_DMA_GET_FLAG(__HANDLE__, __FLAG__) (((uint32_t)((__HANDLE__)->Instance) > ((uint32_t)DMA1_Channel7))? \
  377. (DMA2->ISR & (__FLAG__)) : (DMA1->ISR & (__FLAG__)))
  378. /**
  379. * @brief Clear the DMA Channel pending flags.
  380. * @param __HANDLE__: DMA handle
  381. * @param __FLAG__: specifies the flag to clear.
  382. * This parameter can be any combination of the following values:
  383. * @arg DMA_FLAG_TCx: Transfer complete flag
  384. * @arg DMA_FLAG_HTx: Half transfer complete flag
  385. * @arg DMA_FLAG_TEx: Transfer error flag
  386. * @arg DMA_FLAG_GLx: Global interrupt flag
  387. * Where x can be from 1 to 7 to select the DMA Channel x flag.
  388. * @retval None
  389. */
  390. #define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) (((uint32_t)((__HANDLE__)->Instance) > ((uint32_t)DMA1_Channel7))? \
  391. (DMA2->IFCR = (__FLAG__)) : (DMA1->IFCR = (__FLAG__)))
  392. /**
  393. * @brief Enable the specified DMA Channel interrupts.
  394. * @param __HANDLE__: DMA handle
  395. * @param __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled.
  396. * This parameter can be any combination of the following values:
  397. * @arg DMA_IT_TC: Transfer complete interrupt mask
  398. * @arg DMA_IT_HT: Half transfer complete interrupt mask
  399. * @arg DMA_IT_TE: Transfer error interrupt mask
  400. * @retval None
  401. */
  402. #define __HAL_DMA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CCR |= (__INTERRUPT__))
  403. /**
  404. * @brief Disable the specified DMA Channel interrupts.
  405. * @param __HANDLE__: DMA handle
  406. * @param __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled.
  407. * This parameter can be any combination of the following values:
  408. * @arg DMA_IT_TC: Transfer complete interrupt mask
  409. * @arg DMA_IT_HT: Half transfer complete interrupt mask
  410. * @arg DMA_IT_TE: Transfer error interrupt mask
  411. * @retval None
  412. */
  413. #define __HAL_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CCR &= ~(__INTERRUPT__))
  414. /**
  415. * @brief Check whether the specified DMA Channel interrupt is enabled or not.
  416. * @param __HANDLE__: DMA handle
  417. * @param __INTERRUPT__: specifies the DMA interrupt source to check.
  418. * This parameter can be one of the following values:
  419. * @arg DMA_IT_TC: Transfer complete interrupt mask
  420. * @arg DMA_IT_HT: Half transfer complete interrupt mask
  421. * @arg DMA_IT_TE: Transfer error interrupt mask
  422. * @retval The state of DMA_IT (SET or RESET).
  423. */
  424. #define __HAL_DMA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CCR & (__INTERRUPT__)))
  425. /**
  426. * @brief Return the number of remaining data units in the current DMA Channel transfer.
  427. * @param __HANDLE__: DMA handle
  428. * @retval The number of remaining data units in the current DMA Channel transfer.
  429. */
  430. #define __HAL_DMA_GET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->CNDTR)
  431. /**
  432. * @}
  433. */
  434. /* Exported functions --------------------------------------------------------*/
  435. /** @addtogroup DMA_Exported_Functions
  436. * @{
  437. */
  438. /** @addtogroup DMA_Exported_Functions_Group1
  439. * @{
  440. */
  441. /* Initialization and de-initialization functions *****************************/
  442. HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma);
  443. HAL_StatusTypeDef HAL_DMA_DeInit (DMA_HandleTypeDef *hdma);
  444. /**
  445. * @}
  446. */
  447. /** @addtogroup DMA_Exported_Functions_Group2
  448. * @{
  449. */
  450. /* IO operation functions *****************************************************/
  451. HAL_StatusTypeDef HAL_DMA_Start (DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  452. HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  453. HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma);
  454. HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma);
  455. HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout);
  456. void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma);
  457. HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)( DMA_HandleTypeDef * _hdma));
  458. HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID);
  459. /**
  460. * @}
  461. */
  462. /** @addtogroup DMA_Exported_Functions_Group3
  463. * @{
  464. */
  465. /* Peripheral State and Error functions ***************************************/
  466. HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma);
  467. uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma);
  468. /**
  469. * @}
  470. */
  471. /**
  472. * @}
  473. */
  474. /* Private macros ------------------------------------------------------------*/
  475. /** @defgroup DMA_Private_Macros DMA Private Macros
  476. * @{
  477. */
  478. #define IS_DMA_DIRECTION(DIRECTION) (((DIRECTION) == DMA_PERIPH_TO_MEMORY ) || \
  479. ((DIRECTION) == DMA_MEMORY_TO_PERIPH) || \
  480. ((DIRECTION) == DMA_MEMORY_TO_MEMORY))
  481. #define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1) && ((SIZE) < 0x10000))
  482. #define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PINC_ENABLE) || \
  483. ((STATE) == DMA_PINC_DISABLE))
  484. #define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MINC_ENABLE) || \
  485. ((STATE) == DMA_MINC_DISABLE))
  486. #define IS_DMA_ALL_REQUEST(REQUEST) (((REQUEST) == DMA_REQUEST_0) || \
  487. ((REQUEST) == DMA_REQUEST_1) || \
  488. ((REQUEST) == DMA_REQUEST_2) || \
  489. ((REQUEST) == DMA_REQUEST_3) || \
  490. ((REQUEST) == DMA_REQUEST_4) || \
  491. ((REQUEST) == DMA_REQUEST_5) || \
  492. ((REQUEST) == DMA_REQUEST_6) || \
  493. ((REQUEST) == DMA_REQUEST_7))
  494. #define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PDATAALIGN_BYTE) || \
  495. ((SIZE) == DMA_PDATAALIGN_HALFWORD) || \
  496. ((SIZE) == DMA_PDATAALIGN_WORD))
  497. #define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MDATAALIGN_BYTE) || \
  498. ((SIZE) == DMA_MDATAALIGN_HALFWORD) || \
  499. ((SIZE) == DMA_MDATAALIGN_WORD ))
  500. #define IS_DMA_MODE(MODE) (((MODE) == DMA_NORMAL ) || \
  501. ((MODE) == DMA_CIRCULAR))
  502. #define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_PRIORITY_LOW ) || \
  503. ((PRIORITY) == DMA_PRIORITY_MEDIUM) || \
  504. ((PRIORITY) == DMA_PRIORITY_HIGH) || \
  505. ((PRIORITY) == DMA_PRIORITY_VERY_HIGH))
  506. /**
  507. * @}
  508. */
  509. /* Private functions ---------------------------------------------------------*/
  510. /**
  511. * @}
  512. */
  513. /**
  514. * @}
  515. */
  516. #ifdef __cplusplus
  517. }
  518. #endif
  519. #endif /* __STM32L4xx_HAL_DMA_H */
  520. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/