stm32f7xx_hal_dma.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_dma.h
  4. * @author MCD Application Team
  5. * @brief Header file of DMA HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file in
  13. * the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef __STM32F7xx_HAL_DMA_H
  20. #define __STM32F7xx_HAL_DMA_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f7xx_hal_def.h"
  26. /** @addtogroup STM32F7xx_HAL_Driver
  27. * @{
  28. */
  29. /** @addtogroup DMA
  30. * @{
  31. */
  32. /* Exported types ------------------------------------------------------------*/
  33. /** @defgroup DMA_Exported_Types DMA Exported Types
  34. * @brief DMA Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief DMA Configuration Structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t Channel; /*!< Specifies the channel used for the specified stream.
  43. This parameter can be a value of @ref DMAEx_Channel_selection */
  44. uint32_t Direction; /*!< Specifies if the data will be transferred from memory to peripheral,
  45. from memory to memory or from peripheral to memory.
  46. This parameter can be a value of @ref DMA_Data_transfer_direction */
  47. uint32_t PeriphInc; /*!< Specifies whether the Peripheral address register should be incremented or not.
  48. This parameter can be a value of @ref DMA_Peripheral_incremented_mode */
  49. uint32_t MemInc; /*!< Specifies whether the memory address register should be incremented or not.
  50. This parameter can be a value of @ref DMA_Memory_incremented_mode */
  51. uint32_t PeriphDataAlignment; /*!< Specifies the Peripheral data width.
  52. This parameter can be a value of @ref DMA_Peripheral_data_size */
  53. uint32_t MemDataAlignment; /*!< Specifies the Memory data width.
  54. This parameter can be a value of @ref DMA_Memory_data_size */
  55. uint32_t Mode; /*!< Specifies the operation mode of the DMAy Streamx.
  56. This parameter can be a value of @ref DMA_mode
  57. @note The circular buffer mode cannot be used if the memory-to-memory
  58. data transfer is configured on the selected Stream */
  59. uint32_t Priority; /*!< Specifies the software priority for the DMAy Streamx.
  60. This parameter can be a value of @ref DMA_Priority_level */
  61. uint32_t FIFOMode; /*!< Specifies if the FIFO mode or Direct mode will be used for the specified stream.
  62. This parameter can be a value of @ref DMA_FIFO_direct_mode
  63. @note The Direct mode (FIFO mode disabled) cannot be used if the
  64. memory-to-memory data transfer is configured on the selected stream */
  65. uint32_t FIFOThreshold; /*!< Specifies the FIFO threshold level.
  66. This parameter can be a value of @ref DMA_FIFO_threshold_level */
  67. uint32_t MemBurst; /*!< Specifies the Burst transfer configuration for the memory transfers.
  68. It specifies the amount of data to be transferred in a single non interruptible
  69. transaction.
  70. This parameter can be a value of @ref DMA_Memory_burst
  71. @note The burst mode is possible only if the address Increment mode is enabled. */
  72. uint32_t PeriphBurst; /*!< Specifies the Burst transfer configuration for the peripheral transfers.
  73. It specifies the amount of data to be transferred in a single non interruptible
  74. transaction.
  75. This parameter can be a value of @ref DMA_Peripheral_burst
  76. @note The burst mode is possible only if the address Increment mode is enabled. */
  77. }DMA_InitTypeDef;
  78. /**
  79. * @brief HAL DMA State structures definition
  80. */
  81. typedef enum
  82. {
  83. HAL_DMA_STATE_RESET = 0x00U, /*!< DMA not yet initialized or disabled */
  84. HAL_DMA_STATE_READY = 0x01U, /*!< DMA initialized and ready for use */
  85. HAL_DMA_STATE_BUSY = 0x02U, /*!< DMA process is ongoing */
  86. HAL_DMA_STATE_TIMEOUT = 0x03U, /*!< DMA timeout state */
  87. HAL_DMA_STATE_ERROR = 0x04U, /*!< DMA error state */
  88. HAL_DMA_STATE_ABORT = 0x05U, /*!< DMA Abort state */
  89. }HAL_DMA_StateTypeDef;
  90. /**
  91. * @brief HAL DMA Error Code structure definition
  92. */
  93. typedef enum
  94. {
  95. HAL_DMA_FULL_TRANSFER = 0x00U, /*!< Full transfer */
  96. HAL_DMA_HALF_TRANSFER = 0x01U, /*!< Half Transfer */
  97. }HAL_DMA_LevelCompleteTypeDef;
  98. /**
  99. * @brief HAL DMA Error Code structure definition
  100. */
  101. typedef enum
  102. {
  103. HAL_DMA_XFER_CPLT_CB_ID = 0x00U, /*!< Full transfer */
  104. HAL_DMA_XFER_HALFCPLT_CB_ID = 0x01U, /*!< Half Transfer */
  105. HAL_DMA_XFER_M1CPLT_CB_ID = 0x02U, /*!< M1 Full Transfer */
  106. HAL_DMA_XFER_M1HALFCPLT_CB_ID = 0x03U, /*!< M1 Half Transfer */
  107. HAL_DMA_XFER_ERROR_CB_ID = 0x04U, /*!< Error */
  108. HAL_DMA_XFER_ABORT_CB_ID = 0x05U, /*!< Abort */
  109. HAL_DMA_XFER_ALL_CB_ID = 0x06U /*!< All */
  110. }HAL_DMA_CallbackIDTypeDef;
  111. /**
  112. * @brief DMA handle Structure definition
  113. */
  114. typedef struct __DMA_HandleTypeDef
  115. {
  116. DMA_Stream_TypeDef *Instance; /*!< Register base address */
  117. DMA_InitTypeDef Init; /*!< DMA communication parameters */
  118. HAL_LockTypeDef Lock; /*!< DMA locking object */
  119. __IO HAL_DMA_StateTypeDef State; /*!< DMA transfer state */
  120. void *Parent; /*!< Parent object state */
  121. void (* XferCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete callback */
  122. void (* XferHalfCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA Half transfer complete callback */
  123. void (* XferM1CpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete Memory1 callback */
  124. void (* XferM1HalfCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer Half complete Memory1 callback */
  125. void (* XferErrorCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer error callback */
  126. void (* XferAbortCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer Abort callback */
  127. __IO uint32_t ErrorCode; /*!< DMA Error code */
  128. uint32_t StreamBaseAddress; /*!< DMA Stream Base Address */
  129. uint32_t StreamIndex; /*!< DMA Stream Index */
  130. }DMA_HandleTypeDef;
  131. /**
  132. * @}
  133. */
  134. /* Exported constants --------------------------------------------------------*/
  135. /** @defgroup DMA_Exported_Constants DMA Exported Constants
  136. * @brief DMA Exported constants
  137. * @{
  138. */
  139. /** @defgroup DMA_Error_Code DMA Error Code
  140. * @brief DMA Error Code
  141. * @{
  142. */
  143. #define HAL_DMA_ERROR_NONE 0x00000000U /*!< No error */
  144. #define HAL_DMA_ERROR_TE 0x00000001U /*!< Transfer error */
  145. #define HAL_DMA_ERROR_FE 0x00000002U /*!< FIFO error */
  146. #define HAL_DMA_ERROR_DME 0x00000004U /*!< Direct Mode error */
  147. #define HAL_DMA_ERROR_TIMEOUT 0x00000020U /*!< Timeout error */
  148. #define HAL_DMA_ERROR_PARAM 0x00000040U /*!< Parameter error */
  149. #define HAL_DMA_ERROR_NO_XFER 0x00000080U /*!< Abort requested with no Xfer ongoing */
  150. #define HAL_DMA_ERROR_NOT_SUPPORTED 0x00000100U /*!< Not supported mode */
  151. /**
  152. * @}
  153. */
  154. /** @defgroup DMA_Data_transfer_direction DMA Data transfer direction
  155. * @brief DMA data transfer direction
  156. * @{
  157. */
  158. #define DMA_PERIPH_TO_MEMORY 0x00000000U /*!< Peripheral to memory direction */
  159. #define DMA_MEMORY_TO_PERIPH DMA_SxCR_DIR_0 /*!< Memory to peripheral direction */
  160. #define DMA_MEMORY_TO_MEMORY DMA_SxCR_DIR_1 /*!< Memory to memory direction */
  161. /**
  162. * @}
  163. */
  164. /** @defgroup DMA_Peripheral_incremented_mode DMA Peripheral incremented mode
  165. * @brief DMA peripheral incremented mode
  166. * @{
  167. */
  168. #define DMA_PINC_ENABLE DMA_SxCR_PINC /*!< Peripheral increment mode enable */
  169. #define DMA_PINC_DISABLE 0x00000000U /*!< Peripheral increment mode disable */
  170. /**
  171. * @}
  172. */
  173. /** @defgroup DMA_Memory_incremented_mode DMA Memory incremented mode
  174. * @brief DMA memory incremented mode
  175. * @{
  176. */
  177. #define DMA_MINC_ENABLE DMA_SxCR_MINC /*!< Memory increment mode enable */
  178. #define DMA_MINC_DISABLE 0x00000000U /*!< Memory increment mode disable */
  179. /**
  180. * @}
  181. */
  182. /** @defgroup DMA_Peripheral_data_size DMA Peripheral data size
  183. * @brief DMA peripheral data size
  184. * @{
  185. */
  186. #define DMA_PDATAALIGN_BYTE 0x00000000U /*!< Peripheral data alignment: Byte */
  187. #define DMA_PDATAALIGN_HALFWORD DMA_SxCR_PSIZE_0 /*!< Peripheral data alignment: HalfWord */
  188. #define DMA_PDATAALIGN_WORD DMA_SxCR_PSIZE_1 /*!< Peripheral data alignment: Word */
  189. /**
  190. * @}
  191. */
  192. /** @defgroup DMA_Memory_data_size DMA Memory data size
  193. * @brief DMA memory data size
  194. * @{
  195. */
  196. #define DMA_MDATAALIGN_BYTE 0x00000000U /*!< Memory data alignment: Byte */
  197. #define DMA_MDATAALIGN_HALFWORD DMA_SxCR_MSIZE_0 /*!< Memory data alignment: HalfWord */
  198. #define DMA_MDATAALIGN_WORD DMA_SxCR_MSIZE_1 /*!< Memory data alignment: Word */
  199. /**
  200. * @}
  201. */
  202. /** @defgroup DMA_mode DMA mode
  203. * @brief DMA mode
  204. * @{
  205. */
  206. #define DMA_NORMAL 0x00000000U /*!< Normal mode */
  207. #define DMA_CIRCULAR DMA_SxCR_CIRC /*!< Circular mode */
  208. #define DMA_PFCTRL DMA_SxCR_PFCTRL /*!< Peripheral flow control mode */
  209. /**
  210. * @}
  211. */
  212. /** @defgroup DMA_Priority_level DMA Priority level
  213. * @brief DMA priority levels
  214. * @{
  215. */
  216. #define DMA_PRIORITY_LOW 0x00000000U /*!< Priority level: Low */
  217. #define DMA_PRIORITY_MEDIUM DMA_SxCR_PL_0 /*!< Priority level: Medium */
  218. #define DMA_PRIORITY_HIGH DMA_SxCR_PL_1 /*!< Priority level: High */
  219. #define DMA_PRIORITY_VERY_HIGH DMA_SxCR_PL /*!< Priority level: Very High */
  220. /**
  221. * @}
  222. */
  223. /** @defgroup DMA_FIFO_direct_mode DMA FIFO direct mode
  224. * @brief DMA FIFO direct mode
  225. * @{
  226. */
  227. #define DMA_FIFOMODE_DISABLE 0x00000000U /*!< FIFO mode disable */
  228. #define DMA_FIFOMODE_ENABLE DMA_SxFCR_DMDIS /*!< FIFO mode enable */
  229. /**
  230. * @}
  231. */
  232. /** @defgroup DMA_FIFO_threshold_level DMA FIFO threshold level
  233. * @brief DMA FIFO level
  234. * @{
  235. */
  236. #define DMA_FIFO_THRESHOLD_1QUARTERFULL 0x00000000U /*!< FIFO threshold 1 quart full configuration */
  237. #define DMA_FIFO_THRESHOLD_HALFFULL DMA_SxFCR_FTH_0 /*!< FIFO threshold half full configuration */
  238. #define DMA_FIFO_THRESHOLD_3QUARTERSFULL DMA_SxFCR_FTH_1 /*!< FIFO threshold 3 quarts full configuration */
  239. #define DMA_FIFO_THRESHOLD_FULL DMA_SxFCR_FTH /*!< FIFO threshold full configuration */
  240. /**
  241. * @}
  242. */
  243. /** @defgroup DMA_Memory_burst DMA Memory burst
  244. * @brief DMA memory burst
  245. * @{
  246. */
  247. #define DMA_MBURST_SINGLE 0x00000000U
  248. #define DMA_MBURST_INC4 DMA_SxCR_MBURST_0
  249. #define DMA_MBURST_INC8 DMA_SxCR_MBURST_1
  250. #define DMA_MBURST_INC16 DMA_SxCR_MBURST
  251. /**
  252. * @}
  253. */
  254. /** @defgroup DMA_Peripheral_burst DMA Peripheral burst
  255. * @brief DMA peripheral burst
  256. * @{
  257. */
  258. #define DMA_PBURST_SINGLE 0x00000000U
  259. #define DMA_PBURST_INC4 DMA_SxCR_PBURST_0
  260. #define DMA_PBURST_INC8 DMA_SxCR_PBURST_1
  261. #define DMA_PBURST_INC16 DMA_SxCR_PBURST
  262. /**
  263. * @}
  264. */
  265. /** @defgroup DMA_interrupt_enable_definitions DMA interrupt enable definitions
  266. * @brief DMA interrupts definition
  267. * @{
  268. */
  269. #define DMA_IT_TC DMA_SxCR_TCIE
  270. #define DMA_IT_HT DMA_SxCR_HTIE
  271. #define DMA_IT_TE DMA_SxCR_TEIE
  272. #define DMA_IT_DME DMA_SxCR_DMEIE
  273. #define DMA_IT_FE 0x00000080U
  274. /**
  275. * @}
  276. */
  277. /** @defgroup DMA_flag_definitions DMA flag definitions
  278. * @brief DMA flag definitions
  279. * @{
  280. */
  281. #define DMA_FLAG_FEIF0_4 0x00000001U
  282. #define DMA_FLAG_DMEIF0_4 0x00000004U
  283. #define DMA_FLAG_TEIF0_4 0x00000008U
  284. #define DMA_FLAG_HTIF0_4 0x00000010U
  285. #define DMA_FLAG_TCIF0_4 0x00000020U
  286. #define DMA_FLAG_FEIF1_5 0x00000040U
  287. #define DMA_FLAG_DMEIF1_5 0x00000100U
  288. #define DMA_FLAG_TEIF1_5 0x00000200U
  289. #define DMA_FLAG_HTIF1_5 0x00000400U
  290. #define DMA_FLAG_TCIF1_5 0x00000800U
  291. #define DMA_FLAG_FEIF2_6 0x00010000U
  292. #define DMA_FLAG_DMEIF2_6 0x00040000U
  293. #define DMA_FLAG_TEIF2_6 0x00080000U
  294. #define DMA_FLAG_HTIF2_6 0x00100000U
  295. #define DMA_FLAG_TCIF2_6 0x00200000U
  296. #define DMA_FLAG_FEIF3_7 0x00400000U
  297. #define DMA_FLAG_DMEIF3_7 0x01000000U
  298. #define DMA_FLAG_TEIF3_7 0x02000000U
  299. #define DMA_FLAG_HTIF3_7 0x04000000U
  300. #define DMA_FLAG_TCIF3_7 0x08000000U
  301. /**
  302. * @}
  303. */
  304. /**
  305. * @}
  306. */
  307. /* Exported macro ------------------------------------------------------------*/
  308. /** @brief Reset DMA handle state
  309. * @param __HANDLE__ specifies the DMA handle.
  310. * @retval None
  311. */
  312. #define __HAL_DMA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DMA_STATE_RESET)
  313. /**
  314. * @brief Return the current DMA Stream FIFO filled level.
  315. * @param __HANDLE__ DMA handle
  316. * @retval The FIFO filling state.
  317. * - DMA_FIFOStatus_Less1QuarterFull: when FIFO is less than 1 quarter-full
  318. * and not empty.
  319. * - DMA_FIFOStatus_1QuarterFull: if more than 1 quarter-full.
  320. * - DMA_FIFOStatus_HalfFull: if more than 1 half-full.
  321. * - DMA_FIFOStatus_3QuartersFull: if more than 3 quarters-full.
  322. * - DMA_FIFOStatus_Empty: when FIFO is empty
  323. * - DMA_FIFOStatus_Full: when FIFO is full
  324. */
  325. #define __HAL_DMA_GET_FS(__HANDLE__) (((__HANDLE__)->Instance->FCR & (DMA_SxFCR_FS)))
  326. /**
  327. * @brief Enable the specified DMA Stream.
  328. * @param __HANDLE__ DMA handle
  329. * @retval None
  330. */
  331. #define __HAL_DMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= DMA_SxCR_EN)
  332. /**
  333. * @brief Disable the specified DMA Stream.
  334. * @param __HANDLE__ DMA handle
  335. * @retval None
  336. */
  337. #define __HAL_DMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~DMA_SxCR_EN)
  338. /* Interrupt & Flag management */
  339. /**
  340. * @brief Return the current DMA Stream transfer complete flag.
  341. * @param __HANDLE__ DMA handle
  342. * @retval The specified transfer complete flag index.
  343. */
  344. #define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__) \
  345. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream0))? DMA_FLAG_TCIF0_4 :\
  346. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream0))? DMA_FLAG_TCIF0_4 :\
  347. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream4))? DMA_FLAG_TCIF0_4 :\
  348. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream4))? DMA_FLAG_TCIF0_4 :\
  349. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream1))? DMA_FLAG_TCIF1_5 :\
  350. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream1))? DMA_FLAG_TCIF1_5 :\
  351. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream5))? DMA_FLAG_TCIF1_5 :\
  352. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream5))? DMA_FLAG_TCIF1_5 :\
  353. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream2))? DMA_FLAG_TCIF2_6 :\
  354. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream2))? DMA_FLAG_TCIF2_6 :\
  355. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream6))? DMA_FLAG_TCIF2_6 :\
  356. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream6))? DMA_FLAG_TCIF2_6 :\
  357. DMA_FLAG_TCIF3_7)
  358. /**
  359. * @brief Return the current DMA Stream half transfer complete flag.
  360. * @param __HANDLE__ DMA handle
  361. * @retval The specified half transfer complete flag index.
  362. */
  363. #define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)\
  364. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream0))? DMA_FLAG_HTIF0_4 :\
  365. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream0))? DMA_FLAG_HTIF0_4 :\
  366. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream4))? DMA_FLAG_HTIF0_4 :\
  367. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream4))? DMA_FLAG_HTIF0_4 :\
  368. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream1))? DMA_FLAG_HTIF1_5 :\
  369. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream1))? DMA_FLAG_HTIF1_5 :\
  370. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream5))? DMA_FLAG_HTIF1_5 :\
  371. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream5))? DMA_FLAG_HTIF1_5 :\
  372. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream2))? DMA_FLAG_HTIF2_6 :\
  373. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream2))? DMA_FLAG_HTIF2_6 :\
  374. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream6))? DMA_FLAG_HTIF2_6 :\
  375. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream6))? DMA_FLAG_HTIF2_6 :\
  376. DMA_FLAG_HTIF3_7)
  377. /**
  378. * @brief Return the current DMA Stream transfer error flag.
  379. * @param __HANDLE__ DMA handle
  380. * @retval The specified transfer error flag index.
  381. */
  382. #define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)\
  383. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream0))? DMA_FLAG_TEIF0_4 :\
  384. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream0))? DMA_FLAG_TEIF0_4 :\
  385. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream4))? DMA_FLAG_TEIF0_4 :\
  386. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream4))? DMA_FLAG_TEIF0_4 :\
  387. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream1))? DMA_FLAG_TEIF1_5 :\
  388. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream1))? DMA_FLAG_TEIF1_5 :\
  389. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream5))? DMA_FLAG_TEIF1_5 :\
  390. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream5))? DMA_FLAG_TEIF1_5 :\
  391. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream2))? DMA_FLAG_TEIF2_6 :\
  392. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream2))? DMA_FLAG_TEIF2_6 :\
  393. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream6))? DMA_FLAG_TEIF2_6 :\
  394. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream6))? DMA_FLAG_TEIF2_6 :\
  395. DMA_FLAG_TEIF3_7)
  396. /**
  397. * @brief Return the current DMA Stream FIFO error flag.
  398. * @param __HANDLE__ DMA handle
  399. * @retval The specified FIFO error flag index.
  400. */
  401. #define __HAL_DMA_GET_FE_FLAG_INDEX(__HANDLE__)\
  402. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream0))? DMA_FLAG_FEIF0_4 :\
  403. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream0))? DMA_FLAG_FEIF0_4 :\
  404. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream4))? DMA_FLAG_FEIF0_4 :\
  405. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream4))? DMA_FLAG_FEIF0_4 :\
  406. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream1))? DMA_FLAG_FEIF1_5 :\
  407. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream1))? DMA_FLAG_FEIF1_5 :\
  408. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream5))? DMA_FLAG_FEIF1_5 :\
  409. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream5))? DMA_FLAG_FEIF1_5 :\
  410. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream2))? DMA_FLAG_FEIF2_6 :\
  411. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream2))? DMA_FLAG_FEIF2_6 :\
  412. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream6))? DMA_FLAG_FEIF2_6 :\
  413. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream6))? DMA_FLAG_FEIF2_6 :\
  414. DMA_FLAG_FEIF3_7)
  415. /**
  416. * @brief Return the current DMA Stream direct mode error flag.
  417. * @param __HANDLE__ DMA handle
  418. * @retval The specified direct mode error flag index.
  419. */
  420. #define __HAL_DMA_GET_DME_FLAG_INDEX(__HANDLE__)\
  421. (((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream0))? DMA_FLAG_DMEIF0_4 :\
  422. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream0))? DMA_FLAG_DMEIF0_4 :\
  423. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream4))? DMA_FLAG_DMEIF0_4 :\
  424. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream4))? DMA_FLAG_DMEIF0_4 :\
  425. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream1))? DMA_FLAG_DMEIF1_5 :\
  426. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream1))? DMA_FLAG_DMEIF1_5 :\
  427. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream5))? DMA_FLAG_DMEIF1_5 :\
  428. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream5))? DMA_FLAG_DMEIF1_5 :\
  429. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream2))? DMA_FLAG_DMEIF2_6 :\
  430. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream2))? DMA_FLAG_DMEIF2_6 :\
  431. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream6))? DMA_FLAG_DMEIF2_6 :\
  432. ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream6))? DMA_FLAG_DMEIF2_6 :\
  433. DMA_FLAG_DMEIF3_7)
  434. /**
  435. * @brief Get the DMA Stream pending flags.
  436. * @param __HANDLE__ DMA handle
  437. * @param __FLAG__ Get the specified flag.
  438. * This parameter can be any combination of the following values:
  439. * @arg DMA_FLAG_TCIFx: Transfer complete flag.
  440. * @arg DMA_FLAG_HTIFx: Half transfer complete flag.
  441. * @arg DMA_FLAG_TEIFx: Transfer error flag.
  442. * @arg DMA_FLAG_DMEIFx: Direct mode error flag.
  443. * @arg DMA_FLAG_FEIFx: FIFO error flag.
  444. * Where x can be 0_4, 1_5, 2_6 or 3_7 to select the DMA Stream flag.
  445. * @retval The state of FLAG (SET or RESET).
  446. */
  447. #define __HAL_DMA_GET_FLAG(__HANDLE__, __FLAG__)\
  448. (((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA2_Stream3)? (DMA2->HISR & (__FLAG__)) :\
  449. ((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA1_Stream7)? (DMA2->LISR & (__FLAG__)) :\
  450. ((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA1_Stream3)? (DMA1->HISR & (__FLAG__)) : (DMA1->LISR & (__FLAG__)))
  451. /**
  452. * @brief Clear the DMA Stream pending flags.
  453. * @param __HANDLE__ DMA handle
  454. * @param __FLAG__ specifies the flag to clear.
  455. * This parameter can be any combination of the following values:
  456. * @arg DMA_FLAG_TCIFx: Transfer complete flag.
  457. * @arg DMA_FLAG_HTIFx: Half transfer complete flag.
  458. * @arg DMA_FLAG_TEIFx: Transfer error flag.
  459. * @arg DMA_FLAG_DMEIFx: Direct mode error flag.
  460. * @arg DMA_FLAG_FEIFx: FIFO error flag.
  461. * Where x can be 0_4, 1_5, 2_6 or 3_7 to select the DMA Stream flag.
  462. * @retval None
  463. */
  464. #define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) \
  465. (((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA2_Stream3)? (DMA2->HIFCR = (__FLAG__)) :\
  466. ((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA1_Stream7)? (DMA2->LIFCR = (__FLAG__)) :\
  467. ((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA1_Stream3)? (DMA1->HIFCR = (__FLAG__)) : (DMA1->LIFCR = (__FLAG__)))
  468. /**
  469. * @brief Enable the specified DMA Stream interrupts.
  470. * @param __HANDLE__ DMA handle
  471. * @param __INTERRUPT__ specifies the DMA interrupt sources to be enabled or disabled.
  472. * This parameter can be one of the following values:
  473. * @arg DMA_IT_TC: Transfer complete interrupt mask.
  474. * @arg DMA_IT_HT: Half transfer complete interrupt mask.
  475. * @arg DMA_IT_TE: Transfer error interrupt mask.
  476. * @arg DMA_IT_FE: FIFO error interrupt mask.
  477. * @arg DMA_IT_DME: Direct mode error interrupt.
  478. * @retval None
  479. */
  480. #define __HAL_DMA_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__INTERRUPT__) != DMA_IT_FE)? \
  481. ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) : ((__HANDLE__)->Instance->FCR |= (__INTERRUPT__)))
  482. /**
  483. * @brief Disable the specified DMA Stream interrupts.
  484. * @param __HANDLE__ DMA handle
  485. * @param __INTERRUPT__ specifies the DMA interrupt sources to be enabled or disabled.
  486. * This parameter can be one of the following values:
  487. * @arg DMA_IT_TC: Transfer complete interrupt mask.
  488. * @arg DMA_IT_HT: Half transfer complete interrupt mask.
  489. * @arg DMA_IT_TE: Transfer error interrupt mask.
  490. * @arg DMA_IT_FE: FIFO error interrupt mask.
  491. * @arg DMA_IT_DME: Direct mode error interrupt.
  492. * @retval None
  493. */
  494. #define __HAL_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__INTERRUPT__) != DMA_IT_FE)? \
  495. ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) : ((__HANDLE__)->Instance->FCR &= ~(__INTERRUPT__)))
  496. /**
  497. * @brief Check whether the specified DMA Stream interrupt is enabled or not.
  498. * @param __HANDLE__ DMA handle
  499. * @param __INTERRUPT__ specifies the DMA interrupt source to check.
  500. * This parameter can be one of the following values:
  501. * @arg DMA_IT_TC: Transfer complete interrupt mask.
  502. * @arg DMA_IT_HT: Half transfer complete interrupt mask.
  503. * @arg DMA_IT_TE: Transfer error interrupt mask.
  504. * @arg DMA_IT_FE: FIFO error interrupt mask.
  505. * @arg DMA_IT_DME: Direct mode error interrupt.
  506. * @retval The state of DMA_IT.
  507. */
  508. #define __HAL_DMA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__INTERRUPT__) != DMA_IT_FE)? \
  509. ((__HANDLE__)->Instance->CR & (__INTERRUPT__)) : \
  510. ((__HANDLE__)->Instance->FCR & (__INTERRUPT__)))
  511. /**
  512. * @brief Writes the number of data units to be transferred on the DMA Stream.
  513. * @param __HANDLE__ DMA handle
  514. * @param __COUNTER__ Number of data units to be transferred (from 0 to 65535)
  515. * Number of data items depends only on the Peripheral data format.
  516. *
  517. * @note If Peripheral data format is Bytes: number of data units is equal
  518. * to total number of bytes to be transferred.
  519. *
  520. * @note If Peripheral data format is Half-Word: number of data units is
  521. * equal to total number of bytes to be transferred / 2.
  522. *
  523. * @note If Peripheral data format is Word: number of data units is equal
  524. * to total number of bytes to be transferred / 4.
  525. *
  526. * @retval The number of remaining data units in the current DMAy Streamx transfer.
  527. */
  528. #define __HAL_DMA_SET_COUNTER(__HANDLE__, __COUNTER__) ((__HANDLE__)->Instance->NDTR = (uint16_t)(__COUNTER__))
  529. /**
  530. * @brief Returns the number of remaining data units in the current DMAy Streamx transfer.
  531. * @param __HANDLE__ DMA handle
  532. *
  533. * @retval The number of remaining data units in the current DMA Stream transfer.
  534. */
  535. #define __HAL_DMA_GET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->NDTR)
  536. /* Include DMA HAL Extension module */
  537. #include "stm32f7xx_hal_dma_ex.h"
  538. /* Exported functions --------------------------------------------------------*/
  539. /** @defgroup DMA_Exported_Functions DMA Exported Functions
  540. * @brief DMA Exported functions
  541. * @{
  542. */
  543. /** @defgroup DMA_Exported_Functions_Group1 Initialization and de-initialization functions
  544. * @brief Initialization and de-initialization functions
  545. * @{
  546. */
  547. HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma);
  548. HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma);
  549. /**
  550. * @}
  551. */
  552. /** @defgroup DMA_Exported_Functions_Group2 I/O operation functions
  553. * @brief I/O operation functions
  554. * @{
  555. */
  556. HAL_StatusTypeDef HAL_DMA_Start (DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  557. HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  558. HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma);
  559. HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma);
  560. HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, HAL_DMA_LevelCompleteTypeDef CompleteLevel, uint32_t Timeout);
  561. void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma);
  562. HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)(DMA_HandleTypeDef *_hdma));
  563. HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID);
  564. /**
  565. * @}
  566. */
  567. /** @defgroup DMA_Exported_Functions_Group3 Peripheral State functions
  568. * @brief Peripheral State functions
  569. * @{
  570. */
  571. HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma);
  572. uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma);
  573. /**
  574. * @}
  575. */
  576. /**
  577. * @}
  578. */
  579. /* Private Constants -------------------------------------------------------------*/
  580. /** @defgroup DMA_Private_Constants DMA Private Constants
  581. * @brief DMA private defines and constants
  582. * @{
  583. */
  584. /**
  585. * @}
  586. */
  587. /* Private macros ------------------------------------------------------------*/
  588. /** @defgroup DMA_Private_Macros DMA Private Macros
  589. * @brief DMA private macros
  590. * @{
  591. */
  592. #define IS_DMA_DIRECTION(DIRECTION) (((DIRECTION) == DMA_PERIPH_TO_MEMORY ) || \
  593. ((DIRECTION) == DMA_MEMORY_TO_PERIPH) || \
  594. ((DIRECTION) == DMA_MEMORY_TO_MEMORY))
  595. #define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x01U) && ((SIZE) < 0x10000U))
  596. #define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PINC_ENABLE) || \
  597. ((STATE) == DMA_PINC_DISABLE))
  598. #define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MINC_ENABLE) || \
  599. ((STATE) == DMA_MINC_DISABLE))
  600. #define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PDATAALIGN_BYTE) || \
  601. ((SIZE) == DMA_PDATAALIGN_HALFWORD) || \
  602. ((SIZE) == DMA_PDATAALIGN_WORD))
  603. #define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MDATAALIGN_BYTE) || \
  604. ((SIZE) == DMA_MDATAALIGN_HALFWORD) || \
  605. ((SIZE) == DMA_MDATAALIGN_WORD ))
  606. #define IS_DMA_MODE(MODE) (((MODE) == DMA_NORMAL ) || \
  607. ((MODE) == DMA_CIRCULAR) || \
  608. ((MODE) == DMA_PFCTRL))
  609. #define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_PRIORITY_LOW ) || \
  610. ((PRIORITY) == DMA_PRIORITY_MEDIUM) || \
  611. ((PRIORITY) == DMA_PRIORITY_HIGH) || \
  612. ((PRIORITY) == DMA_PRIORITY_VERY_HIGH))
  613. #define IS_DMA_FIFO_MODE_STATE(STATE) (((STATE) == DMA_FIFOMODE_DISABLE ) || \
  614. ((STATE) == DMA_FIFOMODE_ENABLE))
  615. #define IS_DMA_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == DMA_FIFO_THRESHOLD_1QUARTERFULL ) || \
  616. ((THRESHOLD) == DMA_FIFO_THRESHOLD_HALFFULL) || \
  617. ((THRESHOLD) == DMA_FIFO_THRESHOLD_3QUARTERSFULL) || \
  618. ((THRESHOLD) == DMA_FIFO_THRESHOLD_FULL))
  619. #define IS_DMA_MEMORY_BURST(BURST) (((BURST) == DMA_MBURST_SINGLE) || \
  620. ((BURST) == DMA_MBURST_INC4) || \
  621. ((BURST) == DMA_MBURST_INC8) || \
  622. ((BURST) == DMA_MBURST_INC16))
  623. #define IS_DMA_PERIPHERAL_BURST(BURST) (((BURST) == DMA_PBURST_SINGLE) || \
  624. ((BURST) == DMA_PBURST_INC4) || \
  625. ((BURST) == DMA_PBURST_INC8) || \
  626. ((BURST) == DMA_PBURST_INC16))
  627. /**
  628. * @}
  629. */
  630. /* Private functions ---------------------------------------------------------*/
  631. /** @defgroup DMA_Private_Functions DMA Private Functions
  632. * @brief DMA private functions
  633. * @{
  634. */
  635. /**
  636. * @}
  637. */
  638. /**
  639. * @}
  640. */
  641. /**
  642. * @}
  643. */
  644. #ifdef __cplusplus
  645. }
  646. #endif
  647. #endif /* __STM32F7xx_HAL_DMA_H */