You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

698 lines
33 KiB

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