stm32l0xx_hal_dma.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_dma.h
  4. * @author MCD Application Team
  5. * @version V1.7.0
  6. * @date 31-May-2016
  7. * @brief Header file of DMA HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 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 __STM32L0xx_HAL_DMA_H
  39. #define __STM32L0xx_HAL_DMA_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l0xx_hal_def.h"
  45. /** @addtogroup STM32L0xx_HAL_Driver
  46. * @{
  47. */
  48. /** @defgroup DMA DMA
  49. * @{
  50. */
  51. /** @defgroup DMA_Exported_Types DMA Exported Types
  52. * @{
  53. */
  54. /* Exported types ------------------------------------------------------------*/
  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. When Memory to Memory transfer is used, this is the Source Increment mode
  67. This parameter can be a value of @ref DMA_Peripheral_incremented_mode */
  68. uint32_t MemInc; /*!< Specifies whether the memory address register should be incremented or not.
  69. When Memory to Memory transfer is used, this is the Destination Increment mode
  70. This parameter can be a value of @ref DMA_Memory_incremented_mode */
  71. uint32_t PeriphDataAlignment; /*!< Specifies the Peripheral data width.
  72. When Memory to Memory transfer is used, this is the Source Alignment format
  73. This parameter can be a value of @ref DMA_Peripheral_data_size */
  74. uint32_t MemDataAlignment; /*!< Specifies the Memory data width.
  75. When Memory to Memory transfer is used, this is the Destination Alignment format
  76. This parameter can be a value of @ref DMA_Memory_data_size */
  77. uint32_t Mode; /*!< Specifies the operation mode of the DMAy Channelx (Normal or Circular).
  78. This parameter can be a value of @ref DMA_mode
  79. @note The circular buffer mode cannot be used if the memory-to-memory
  80. data transfer is configured on the selected Channel */
  81. uint32_t Priority; /*!< Specifies the software priority for the DMAy Channelx.
  82. This parameter can be a value of @ref DMA_Priority_level */
  83. } DMA_InitTypeDef;
  84. /**
  85. * @brief DMA Configuration enumeration values definition
  86. */
  87. typedef enum
  88. {
  89. DMA_MODE = 0U, /*!< Control related DMA mode Parameter in DMA_InitTypeDef */
  90. DMA_PRIORITY = 1U, /*!< Control related priority level Parameter in DMA_InitTypeDef */
  91. } DMA_ControlTypeDef;
  92. /**
  93. * @brief HAL DMA State structures definition
  94. */
  95. typedef enum
  96. {
  97. HAL_DMA_STATE_RESET = 0x00U, /*!< DMA not yet initialized or disabled */
  98. HAL_DMA_STATE_READY = 0x01U, /*!< DMA process success and ready for use */
  99. HAL_DMA_STATE_BUSY = 0x02U, /*!< DMA process is ongoing */
  100. HAL_DMA_STATE_TIMEOUT = 0x03U, /*!< DMA timeout state */
  101. HAL_DMA_STATE_ERROR = 0x04U, /*!< DMA error state */
  102. HAL_DMA_STATE_READY_HALF = 0x05U, /*!< DMA Half process success */
  103. }HAL_DMA_StateTypeDef;
  104. /**
  105. * @brief HAL DMA Error Code structure definition
  106. */
  107. typedef enum
  108. {
  109. HAL_DMA_FULL_TRANSFER = 0x00U, /*!< Full transfer */
  110. HAL_DMA_HALF_TRANSFER = 0x01U, /*!< Half Transfer */
  111. }HAL_DMA_LevelCompleteTypeDef;
  112. /**
  113. * @brief DMA handle Structure definition
  114. */
  115. typedef struct __DMA_HandleTypeDef
  116. {
  117. DMA_Channel_TypeDef *Instance; /*!< Register base address */
  118. DMA_InitTypeDef Init; /*!< DMA communication parameters */
  119. HAL_LockTypeDef Lock; /*!< DMA locking object */
  120. __IO HAL_DMA_StateTypeDef State; /*!< DMA transfer state */
  121. void *Parent; /*!< Parent object state */
  122. void (* XferCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete callback */
  123. void (* XferHalfCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA Half transfer complete callback */
  124. void (* XferErrorCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer error callback */
  125. __IO uint32_t ErrorCode; /*!< DMA Error code */
  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 Codes
  135. * @{
  136. */
  137. #define HAL_DMA_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
  138. #define HAL_DMA_ERROR_TE ((uint32_t)0x00000001U) /*!< Transfer error */
  139. #define HAL_DMA_ERROR_TIMEOUT ((uint32_t)0x00000020U) /*!< Timeout error */
  140. #if defined (STM32L011xx) || defined (STM32L021xx)
  141. #define IS_DMA_ALL_INSTANCE(INSTANCE) (((INSTANCE) == DMA1_Channel1) || \
  142. ((INSTANCE) == DMA1_Channel2) || \
  143. ((INSTANCE) == DMA1_Channel3) || \
  144. ((INSTANCE) == DMA1_Channel4) || \
  145. ((INSTANCE) == DMA1_Channel5))
  146. #else
  147. #define IS_DMA_ALL_INSTANCE(INSTANCE) (((INSTANCE) == DMA1_Channel1) || \
  148. ((INSTANCE) == DMA1_Channel2) || \
  149. ((INSTANCE) == DMA1_Channel3) || \
  150. ((INSTANCE) == DMA1_Channel4) || \
  151. ((INSTANCE) == DMA1_Channel5) || \
  152. ((INSTANCE) == DMA1_Channel6) || \
  153. ((INSTANCE) == DMA1_Channel7))
  154. #endif
  155. #define IS_DMA_ALL_CONTROLLER(CONTROLLER) (((CONTROLLER) == DMA1))
  156. /**
  157. * @}
  158. */
  159. /** @defgroup DMA_request DMA request defintiions
  160. * @{
  161. */
  162. #if defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
  163. #define DMA_REQUEST_0 ((uint32_t)0x00000000U)
  164. #define DMA_REQUEST_1 ((uint32_t)0x00000001U)
  165. #define DMA_REQUEST_2 ((uint32_t)0x00000002U)
  166. #define DMA_REQUEST_3 ((uint32_t)0x00000003U)
  167. #define DMA_REQUEST_4 ((uint32_t)0x00000004U)
  168. #define DMA_REQUEST_5 ((uint32_t)0x00000005U)
  169. #define DMA_REQUEST_6 ((uint32_t)0x00000006U)
  170. #define DMA_REQUEST_7 ((uint32_t)0x00000007U)
  171. #define DMA_REQUEST_8 ((uint32_t)0x00000008U)
  172. #define DMA_REQUEST_9 ((uint32_t)0x00000009U)
  173. #define DMA_REQUEST_10 ((uint32_t)0x0000000AU)
  174. #define DMA_REQUEST_11 ((uint32_t)0x0000000BU)
  175. #define DMA_REQUEST_12 ((uint32_t)0x0000000CU)
  176. #define DMA_REQUEST_13 ((uint32_t)0x0000000DU)
  177. #define DMA_REQUEST_14 ((uint32_t)0x0000000EU)
  178. #define DMA_REQUEST_15 ((uint32_t)0x0000000FU)
  179. #define IS_DMA_ALL_REQUEST(REQUEST) (((REQUEST) == DMA_REQUEST_0) || \
  180. ((REQUEST) == DMA_REQUEST_1) || \
  181. ((REQUEST) == DMA_REQUEST_2) || \
  182. ((REQUEST) == DMA_REQUEST_3) || \
  183. ((REQUEST) == DMA_REQUEST_4) || \
  184. ((REQUEST) == DMA_REQUEST_5) || \
  185. ((REQUEST) == DMA_REQUEST_6) || \
  186. ((REQUEST) == DMA_REQUEST_7) || \
  187. ((REQUEST) == DMA_REQUEST_8) || \
  188. ((REQUEST) == DMA_REQUEST_9) || \
  189. ((REQUEST) == DMA_REQUEST_10) || \
  190. ((REQUEST) == DMA_REQUEST_11) || \
  191. ((REQUEST) == DMA_REQUEST_12) || \
  192. ((REQUEST) == DMA_REQUEST_13) || \
  193. ((REQUEST) == DMA_REQUEST_14) || \
  194. ((REQUEST) == DMA_REQUEST_15))
  195. #else /* #if STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */
  196. #define DMA_REQUEST_0 ((uint32_t)0x00000000U)
  197. #define DMA_REQUEST_1 ((uint32_t)0x00000001U)
  198. #define DMA_REQUEST_2 ((uint32_t)0x00000002U)
  199. #define DMA_REQUEST_3 ((uint32_t)0x00000003U)
  200. #define DMA_REQUEST_4 ((uint32_t)0x00000004U)
  201. #define DMA_REQUEST_5 ((uint32_t)0x00000005U)
  202. #define DMA_REQUEST_6 ((uint32_t)0x00000006U)
  203. #define DMA_REQUEST_7 ((uint32_t)0x00000007U)
  204. #define DMA_REQUEST_8 ((uint32_t)0x00000008U)
  205. #define DMA_REQUEST_9 ((uint32_t)0x00000009U)
  206. #define DMA_REQUEST_11 ((uint32_t)0x0000000BU)
  207. #define IS_DMA_ALL_REQUEST(REQUEST) (((REQUEST) == DMA_REQUEST_0) || \
  208. ((REQUEST) == DMA_REQUEST_1) || \
  209. ((REQUEST) == DMA_REQUEST_2) || \
  210. ((REQUEST) == DMA_REQUEST_3) || \
  211. ((REQUEST) == DMA_REQUEST_4) || \
  212. ((REQUEST) == DMA_REQUEST_5) || \
  213. ((REQUEST) == DMA_REQUEST_6) || \
  214. ((REQUEST) == DMA_REQUEST_7) || \
  215. ((REQUEST) == DMA_REQUEST_8) || \
  216. ((REQUEST) == DMA_REQUEST_9) || \
  217. ((REQUEST) == DMA_REQUEST_11))
  218. #endif /* #if defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L082xx) || defined (STM32L083xx) */
  219. /**
  220. * @}
  221. */
  222. /** @defgroup DMA_Data_transfer_direction DMA Data Transfer directions
  223. * @{
  224. */
  225. #define DMA_PERIPH_TO_MEMORY ((uint32_t)0x00000000U) /*!< Peripheral to memory direction */
  226. #define DMA_MEMORY_TO_PERIPH ((uint32_t)DMA_CCR_DIR) /*!< Memory to peripheral direction */
  227. #define DMA_MEMORY_TO_MEMORY ((uint32_t)(DMA_CCR_MEM2MEM)) /*!< Memory to memory direction */
  228. #define IS_DMA_DIRECTION(DIRECTION) (((DIRECTION) == DMA_PERIPH_TO_MEMORY ) || \
  229. ((DIRECTION) == DMA_MEMORY_TO_PERIPH) || \
  230. ((DIRECTION) == DMA_MEMORY_TO_MEMORY))
  231. /**
  232. * @}
  233. */
  234. /** @defgroup DMA_Data_buffer_size DMA Data Buffer Size Check
  235. * @{
  236. */
  237. #define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1) && ((SIZE) < 0x10000))
  238. /**
  239. * @}
  240. */
  241. /** @defgroup DMA_Peripheral_incremented_mode DMA Peripheral Incremented Mode
  242. * @{
  243. */
  244. #define DMA_PINC_ENABLE ((uint32_t)DMA_CCR_PINC) /*!< Peripheral increment mode Enable */
  245. #define DMA_PINC_DISABLE ((uint32_t)0x00000000U) /*!< Peripheral increment mode Disable */
  246. #define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PINC_ENABLE) || \
  247. ((STATE) == DMA_PINC_DISABLE))
  248. /**
  249. * @}
  250. */
  251. /** @defgroup DMA_Memory_incremented_mode DMA Memory Incremented Mode
  252. * @{
  253. */
  254. #define DMA_MINC_ENABLE ((uint32_t)DMA_CCR_MINC) /*!< Memory increment mode Enable */
  255. #define DMA_MINC_DISABLE ((uint32_t)0x00000000U) /*!< Memory increment mode Disable */
  256. #define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MINC_ENABLE) || \
  257. ((STATE) == DMA_MINC_DISABLE))
  258. /**
  259. * @}
  260. */
  261. /** @defgroup DMA_Peripheral_data_size DMA Peripheral Data Size Alignment
  262. * @{
  263. */
  264. #define DMA_PDATAALIGN_BYTE ((uint32_t)0x00000000U) /*!< Peripheral data alignment : Byte */
  265. #define DMA_PDATAALIGN_HALFWORD ((uint32_t)DMA_CCR_PSIZE_0) /*!< Peripheral data alignment : HalfWord */
  266. #define DMA_PDATAALIGN_WORD ((uint32_t)DMA_CCR_PSIZE_1) /*!< Peripheral data alignment : Word */
  267. #define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PDATAALIGN_BYTE) || \
  268. ((SIZE) == DMA_PDATAALIGN_HALFWORD) || \
  269. ((SIZE) == DMA_PDATAALIGN_WORD))
  270. /**
  271. * @}
  272. */
  273. /** @defgroup DMA_Memory_data_size DMA Memory Data Size Alignment
  274. * @{
  275. */
  276. #define DMA_MDATAALIGN_BYTE ((uint32_t)0x00000000U) /*!< Memory data alignment : Byte */
  277. #define DMA_MDATAALIGN_HALFWORD ((uint32_t)DMA_CCR_MSIZE_0) /*!< Memory data alignment : HalfWord */
  278. #define DMA_MDATAALIGN_WORD ((uint32_t)DMA_CCR_MSIZE_1) /*!< Memory data alignment : Word */
  279. #define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MDATAALIGN_BYTE) || \
  280. ((SIZE) == DMA_MDATAALIGN_HALFWORD) || \
  281. ((SIZE) == DMA_MDATAALIGN_WORD ))
  282. /**
  283. * @}
  284. */
  285. /** @defgroup DMA_mode DMA Mode
  286. * @{
  287. */
  288. #define DMA_NORMAL ((uint32_t)0x00000000U) /*!< Normal Mode */
  289. #define DMA_CIRCULAR ((uint32_t)DMA_CCR_CIRC) /*!< Circular Mode */
  290. #define IS_DMA_MODE(MODE) (((MODE) == DMA_NORMAL ) || \
  291. ((MODE) == DMA_CIRCULAR))
  292. /**
  293. * @}
  294. */
  295. /** @defgroup DMA_Priority_level DMA Priority Level
  296. * @{
  297. */
  298. #define DMA_PRIORITY_LOW ((uint32_t)0x00000000U) /*!< Priority level : Low */
  299. #define DMA_PRIORITY_MEDIUM ((uint32_t)DMA_CCR_PL_0) /*!< Priority level : Medium */
  300. #define DMA_PRIORITY_HIGH ((uint32_t)DMA_CCR_PL_1) /*!< Priority level : High */
  301. #define DMA_PRIORITY_VERY_HIGH ((uint32_t)DMA_CCR_PL) /*!< Priority level : Very_High */
  302. #define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_PRIORITY_LOW ) || \
  303. ((PRIORITY) == DMA_PRIORITY_MEDIUM) || \
  304. ((PRIORITY) == DMA_PRIORITY_HIGH) || \
  305. ((PRIORITY) == DMA_PRIORITY_VERY_HIGH))
  306. /**
  307. * @}
  308. */
  309. /** @defgroup DMA_interrupt_enable_definitions DMA Interrupt Definitions
  310. * @{
  311. */
  312. #define DMA_IT_TC ((uint32_t)DMA_CCR_TCIE)
  313. #define DMA_IT_HT ((uint32_t)DMA_CCR_HTIE)
  314. #define DMA_IT_TE ((uint32_t)DMA_CCR_TEIE)
  315. /**
  316. * @}
  317. */
  318. /** @defgroup DMA_flag_definitions DMA Flag Definitions
  319. * @{
  320. */
  321. #define DMA_FLAG_GL1 ((uint32_t)0x00000001U)
  322. #define DMA_FLAG_TC1 ((uint32_t)0x00000002U)
  323. #define DMA_FLAG_HT1 ((uint32_t)0x00000004U)
  324. #define DMA_FLAG_TE1 ((uint32_t)0x00000008U)
  325. #define DMA_FLAG_GL2 ((uint32_t)0x00000010U)
  326. #define DMA_FLAG_TC2 ((uint32_t)0x00000020U)
  327. #define DMA_FLAG_HT2 ((uint32_t)0x00000040U)
  328. #define DMA_FLAG_TE2 ((uint32_t)0x00000080U)
  329. #define DMA_FLAG_GL3 ((uint32_t)0x00000100U)
  330. #define DMA_FLAG_TC3 ((uint32_t)0x00000200U)
  331. #define DMA_FLAG_HT3 ((uint32_t)0x00000400U)
  332. #define DMA_FLAG_TE3 ((uint32_t)0x00000800U)
  333. #define DMA_FLAG_GL4 ((uint32_t)0x00001000U)
  334. #define DMA_FLAG_TC4 ((uint32_t)0x00002000U)
  335. #define DMA_FLAG_HT4 ((uint32_t)0x00004000U)
  336. #define DMA_FLAG_TE4 ((uint32_t)0x00008000U)
  337. #define DMA_FLAG_GL5 ((uint32_t)0x00010000U)
  338. #define DMA_FLAG_TC5 ((uint32_t)0x00020000U)
  339. #define DMA_FLAG_HT5 ((uint32_t)0x00040000U)
  340. #define DMA_FLAG_TE5 ((uint32_t)0x00080000U)
  341. #define DMA_FLAG_GL6 ((uint32_t)0x00100000U)
  342. #define DMA_FLAG_TC6 ((uint32_t)0x00200000U)
  343. #define DMA_FLAG_HT6 ((uint32_t)0x00400000U)
  344. #define DMA_FLAG_TE6 ((uint32_t)0x00800000U)
  345. #define DMA_FLAG_GL7 ((uint32_t)0x01000000U)
  346. #define DMA_FLAG_TC7 ((uint32_t)0x02000000U)
  347. #define DMA_FLAG_HT7 ((uint32_t)0x04000000U)
  348. #define DMA_FLAG_TE7 ((uint32_t)0x08000000U)
  349. /**
  350. * @}
  351. */
  352. /**
  353. * @}
  354. */
  355. /* Exported macro ------------------------------------------------------------*/
  356. /** @defgroup DMA_Exported_Macros DMA Exported Macros
  357. * @{
  358. */
  359. /** @brief Reset DMA handle state
  360. * @param __HANDLE__: DMA handle
  361. * @retval None
  362. */
  363. #define __HAL_DMA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DMA_STATE_RESET)
  364. /**
  365. * @brief Enable the specified DMA Channel.
  366. * @param __HANDLE__: DMA handle
  367. * @retval None.
  368. */
  369. #define __HAL_DMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CCR |= DMA_CCR_EN)
  370. /**
  371. * @brief Disable the specified DMA Channel.
  372. * @param __HANDLE__: DMA handle
  373. * @retval None.
  374. */
  375. #define __HAL_DMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CCR &= ~DMA_CCR_EN)
  376. /* Interrupt & Flag management */
  377. /**
  378. * @brief Returns the current DMA Channel transfer complete flag.
  379. * @param __HANDLE__: DMA handle
  380. * @retval The specified transfer complete flag index.
  381. */
  382. #if defined (STM32L011xx) || defined (STM32L021xx)
  383. #define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__) \
  384. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TC1 :\
  385. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TC2 :\
  386. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TC3 :\
  387. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TC4 :\
  388. DMA_FLAG_TC5)
  389. #else
  390. #define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__) \
  391. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TC1 :\
  392. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TC2 :\
  393. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TC3 :\
  394. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TC4 :\
  395. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TC5 :\
  396. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TC6 :\
  397. DMA_FLAG_TC7)
  398. #endif
  399. /**
  400. * @brief Returns the current DMA Channel half transfer complete flag.
  401. * @param __HANDLE__: DMA handle
  402. * @retval The specified half transfer complete flag index.
  403. */
  404. #if defined (STM32L011xx) || defined (STM32L021xx)
  405. #define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)\
  406. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_HT1 :\
  407. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_HT2 :\
  408. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_HT3 :\
  409. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_HT4 :\
  410. DMA_FLAG_HT5)
  411. #else
  412. #define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)\
  413. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_HT1 :\
  414. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_HT2 :\
  415. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_HT3 :\
  416. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_HT4 :\
  417. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_HT5 :\
  418. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_HT6 :\
  419. DMA_FLAG_HT7)
  420. #endif
  421. /**
  422. * @brief Returns the current DMA Channel transfer error flag.
  423. * @param __HANDLE__: DMA handle
  424. * @retval The specified transfer error flag index.
  425. */
  426. #if defined (STM32L011xx) || defined (STM32L021xx)
  427. #define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)\
  428. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TE1 :\
  429. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TE2 :\
  430. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TE3 :\
  431. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TE4 :\
  432. DMA_FLAG_TE5)
  433. #else
  434. #define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)\
  435. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TE1 :\
  436. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TE2 :\
  437. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TE3 :\
  438. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TE4 :\
  439. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TE5 :\
  440. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TE6 :\
  441. DMA_FLAG_TE7)
  442. #endif
  443. /**
  444. * @brief Returns the current DMA Channel Global interrupt flag.
  445. * @param __HANDLE__: DMA handle
  446. * @retval The specified transfer error flag index.
  447. */
  448. #if defined (STM32L011xx) || defined (STM32L021xx)
  449. #define __HAL_DMA_GET_GI_FLAG_INDEX(__HANDLE__)\
  450. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_ISR_GIF1 :\
  451. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_ISR_GIF2 :\
  452. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_ISR_GIF3 :\
  453. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_ISR_GIF4 :\
  454. DMA_ISR_GIF5)
  455. #else
  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)DMA1_Channel2))? DMA_ISR_GIF2 :\
  459. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_ISR_GIF3 :\
  460. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_ISR_GIF4 :\
  461. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_ISR_GIF5 :\
  462. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_ISR_GIF6 :\
  463. DMA_ISR_GIF7)
  464. #endif
  465. /**
  466. * @brief Get the DMA Channel pending flags.
  467. * @param __HANDLE__: DMA handle
  468. * @param __FLAG__: Get the specified flag.
  469. * This parameter can be any combination of the following values:
  470. * @arg DMA_FLAG_TCIFx: Transfer complete flag
  471. * @arg DMA_FLAG_HTIFx: Half transfer complete flag
  472. * @arg DMA_FLAG_TEIFx: Transfer error flag
  473. * @arg DMA_ISR_GIFx: Global interrupt flag
  474. * Where x can be 0_4, 1_5, 2_6 or 3_7 to select the DMA Channel flag.
  475. * @retval The state of FLAG (SET or RESET).
  476. */
  477. #define __HAL_DMA_GET_FLAG(__HANDLE__, __FLAG__) (DMA1->ISR & (__FLAG__))
  478. /**
  479. * @brief Clears the DMA Channel pending flags.
  480. * @param __HANDLE__: DMA handle
  481. * @param __FLAG__: specifies the flag to clear.
  482. * This parameter can be any combination of the following values:
  483. * @arg DMA_FLAG_TCIFx: Transfer complete flag
  484. * @arg DMA_FLAG_HTIFx: Half transfer complete flag
  485. * @arg DMA_FLAG_TEIFx: Transfer error flag
  486. * @arg DMA_ISR_GIFx: Global interrupt flag
  487. * Where x can be 0_4, 1_5, 2_6 or 3_7 to select the DMA Channel flag.
  488. * @retval None
  489. */
  490. #define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) (DMA1->IFCR = (__FLAG__))
  491. /**
  492. * @brief Enables the specified DMA Channel interrupts.
  493. * @param __HANDLE__: DMA handle
  494. * @param __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled.
  495. * This parameter can be any combination of the following values:
  496. * @arg DMA_IT_TC: Transfer complete interrupt mask
  497. * @arg DMA_IT_HT: Half transfer complete interrupt mask
  498. * @arg DMA_IT_TE: Transfer error interrupt mask
  499. * @retval None
  500. */
  501. #define __HAL_DMA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CCR |= (__INTERRUPT__))
  502. /**
  503. * @brief Disables the specified DMA Channel interrupts.
  504. * @param __HANDLE__: DMA handle
  505. * @param __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled.
  506. * This parameter can be any combination of the following values:
  507. * @arg DMA_IT_TC: Transfer complete interrupt mask
  508. * @arg DMA_IT_HT: Half transfer complete interrupt mask
  509. * @arg DMA_IT_TE: Transfer error interrupt mask
  510. * @retval None
  511. */
  512. #define __HAL_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CCR &= ~(__INTERRUPT__))
  513. /**
  514. * @brief Checks whether the specified DMA Channel interrupt is enabled or not.
  515. * @param __HANDLE__: DMA handle
  516. * @param __INTERRUPT__: specifies the DMA interrupt source to check.
  517. * This parameter can be one of the following values:
  518. * @arg DMA_IT_TC: Transfer complete interrupt mask
  519. * @arg DMA_IT_HT: Half transfer complete interrupt mask
  520. * @arg DMA_IT_TE: Transfer error interrupt mask
  521. * @retval The state of DMA_IT (SET or RESET).
  522. */
  523. #define __HAL_DMA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CCR & (__INTERRUPT__)))
  524. /**
  525. * @brief Returns the number of remaining data units in the current DMAy Channelx transfer.
  526. * @param __HANDLE__: DMA handle
  527. *
  528. * @retval The number of remaining data units in the current DMA Channel transfer.
  529. */
  530. #define __HAL_DMA_GET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->CNDTR)
  531. /**
  532. * @}
  533. */
  534. /* Exported functions --------------------------------------------------------*/
  535. /** @defgroup DMA_Exported_Functions DMA Exported Functions
  536. * @{
  537. */
  538. /** @defgroup DMA_Exported_Functions_Group1 Initialization/de-initialization functions
  539. * @{
  540. */
  541. /* Initialization and de-initialization functions *****************************/
  542. HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma);
  543. HAL_StatusTypeDef HAL_DMA_DeInit (DMA_HandleTypeDef *hdma);
  544. /**
  545. * @}
  546. */
  547. /** @defgroup DMA_Exported_Functions_Group2 I/O operation functions
  548. * @{
  549. */
  550. /* IO operation functions *****************************************************/
  551. HAL_StatusTypeDef HAL_DMA_Start (DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  552. HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  553. HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma);
  554. HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout);
  555. void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma);
  556. /**
  557. * @}
  558. */
  559. /** @defgroup DMA_Exported_Functions_Group3 Peripheral State functions
  560. * @{
  561. */
  562. /* Peripheral State and Error functions ***************************************/
  563. HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma);
  564. uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma);
  565. /**
  566. * @}
  567. */
  568. /**
  569. * @}
  570. */
  571. /* Define the private group ***********************************/
  572. /**************************************************************/
  573. /** @defgroup DMA_Private DMA Private
  574. * @{
  575. */
  576. /**
  577. * @}
  578. */
  579. /**************************************************************/
  580. /**
  581. * @}
  582. */
  583. /**
  584. * @}
  585. */
  586. #ifdef __cplusplus
  587. }
  588. #endif
  589. #endif /* __STM32L0xx_HAL_DMA_H */
  590. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/