Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
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.
 
 
 
 
 
 

653 lines
28 KiB

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