stm32l1xx_hal_dma.h 30 KB

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