stm32f4xx_hal_dma.h 36 KB

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