HAL_dma.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /**
  2. ******************************************************************************
  3. * @file HAL_dma.h
  4. * @author AE Team
  5. * @version V1.1.0
  6. * @date 28/08/2019
  7. * @brief This file contains all the functions prototypes for the DMA firmware
  8. * library.
  9. ******************************************************************************
  10. * @copy
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, MindMotion SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2019 MindMotion</center></h2>
  20. */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __HAL_DMA_H
  23. #define __HAL_DMA_H
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "HAL_device.h"
  26. /** @addtogroup StdPeriph_Driver
  27. * @{
  28. */
  29. /** @addtogroup DMA
  30. * @{
  31. */
  32. /** @defgroup DMA_Exported_Types
  33. * @{
  34. */
  35. /**
  36. * @brief DMA Init structure definition
  37. */
  38. typedef struct
  39. {
  40. uint32_t DMA_PeripheralBaseAddr;
  41. uint32_t DMA_MemoryBaseAddr;
  42. uint32_t DMA_DIR;
  43. uint32_t DMA_BufferSize;
  44. uint32_t DMA_PeripheralInc;
  45. uint32_t DMA_MemoryInc;
  46. uint32_t DMA_PeripheralDataSize;
  47. uint32_t DMA_MemoryDataSize;
  48. uint32_t DMA_Mode;
  49. uint32_t DMA_Priority;
  50. uint32_t DMA_M2M;
  51. } DMA_InitTypeDef;
  52. /**
  53. * @}
  54. */
  55. /** @defgroup DMA_Exported_Constants
  56. * @{
  57. */
  58. #define IS_DMA_ALL_PERIPH(PERIPH) (((*(uint32_t*)&(PERIPH)) == DMA1_Channel1_BASE) || \
  59. ((*(uint32_t*)&(PERIPH)) == DMA1_Channel2_BASE) || \
  60. ((*(uint32_t*)&(PERIPH)) == DMA1_Channel3_BASE) || \
  61. ((*(uint32_t*)&(PERIPH)) == DMA1_Channel4_BASE) || \
  62. ((*(uint32_t*)&(PERIPH)) == DMA1_Channel5_BASE) || \
  63. ((*(uint32_t*)&(PERIPH)) == DMA1_Channel6_BASE) || \
  64. ((*(uint32_t*)&(PERIPH)) == DMA1_Channel7_BASE))
  65. /** @defgroup DMA_data_transfer_direction
  66. * @{
  67. */
  68. #define DMA_DIR_PeripheralDST ((uint32_t)0x00000010) //mtop
  69. #define DMA_DIR_PeripheralSRC ((uint32_t)0x00000000) //ptom
  70. #define IS_DMA_DIR(DIR) (((DIR) == DMA_DIR_PeripheralDST) || \
  71. ((DIR) == DMA_DIR_PeripheralSRC))
  72. /**
  73. * @}
  74. */
  75. /** @defgroup DMA_peripheral_incremented_mode
  76. * @{
  77. */
  78. #define DMA_PeripheralInc_Enable ((uint32_t)0x00000040)
  79. #define DMA_PeripheralInc_Disable ((uint32_t)0x00000000)
  80. #define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PeripheralInc_Enable) || \
  81. ((STATE) == DMA_PeripheralInc_Disable))
  82. /**
  83. * @}
  84. */
  85. /** @defgroup DMA_memory_incremented_mode
  86. * @{
  87. */
  88. #define DMA_MemoryInc_Enable ((uint32_t)0x00000080)
  89. #define DMA_MemoryInc_Disable ((uint32_t)0x00000000)
  90. #define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MemoryInc_Enable) || \
  91. ((STATE) == DMA_MemoryInc_Disable))
  92. /**
  93. * @}
  94. */
  95. /** @defgroup DMA_peripheral_data_size
  96. * @{
  97. */
  98. #define DMA_PeripheralDataSize_Byte ((uint32_t)0x00000000)
  99. #define DMA_PeripheralDataSize_HalfWord ((uint32_t)0x00000100)
  100. #define DMA_PeripheralDataSize_Word ((uint32_t)0x00000200)
  101. #define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PeripheralDataSize_Byte) || \
  102. ((SIZE) == DMA_PeripheralDataSize_HalfWord) || \
  103. ((SIZE) == DMA_PeripheralDataSize_Word))
  104. /**
  105. * @}
  106. */
  107. /** @defgroup DMA_memory_data_size
  108. * @{
  109. */
  110. #define DMA_MemoryDataSize_Byte ((uint32_t)0x00000000)
  111. #define DMA_MemoryDataSize_HalfWord ((uint32_t)0x00000400)
  112. #define DMA_MemoryDataSize_Word ((uint32_t)0x00000800)
  113. #define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MemoryDataSize_Byte) || \
  114. ((SIZE) == DMA_MemoryDataSize_HalfWord) || \
  115. ((SIZE) == DMA_MemoryDataSize_Word))
  116. /**
  117. * @}
  118. */
  119. /** @defgroup DMA_circular_normal_mode
  120. * @{
  121. */
  122. #define DMA_Mode_Circular ((uint32_t)0x00000020)
  123. #define DMA_Mode_Normal ((uint32_t)0x00000000)
  124. #define IS_DMA_MODE(MODE) (((MODE) == DMA_Mode_Circular) || ((MODE) == DMA_Mode_Normal))
  125. /**
  126. * @}
  127. */
  128. /** @defgroup DMA_priority_level
  129. * @{
  130. */
  131. #define DMA_Priority_VeryHigh ((uint32_t)0x00003000)
  132. #define DMA_Priority_High ((uint32_t)0x00002000)
  133. #define DMA_Priority_Medium ((uint32_t)0x00001000)
  134. #define DMA_Priority_Low ((uint32_t)0x00000000)
  135. #define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_Priority_VeryHigh) || \
  136. ((PRIORITY) == DMA_Priority_High) || \
  137. ((PRIORITY) == DMA_Priority_Medium) || \
  138. ((PRIORITY) == DMA_Priority_Low))
  139. /**
  140. * @}
  141. */
  142. /** @defgroup DMA_memory_to_memory
  143. * @{
  144. */
  145. #define DMA_M2M_Enable ((uint32_t)0x00004000)
  146. #define DMA_M2M_Disable ((uint32_t)0x00000000)
  147. #define IS_DMA_M2M_STATE(STATE) (((STATE) == DMA_M2M_Enable) || ((STATE) == DMA_M2M_Disable))
  148. /**
  149. * @}
  150. */
  151. /** @defgroup DMA_interrupts_definition
  152. * @{
  153. */
  154. #define DMA_IT_TC ((uint32_t)0x00000002)
  155. #define DMA_IT_HT ((uint32_t)0x00000004)
  156. #define DMA_IT_TE ((uint32_t)0x00000008)
  157. #define IS_DMA_CONFIG_IT(IT) ((((IT) & 0xFFFFFFF1) == 0x00) && ((IT) != 0x00))
  158. /**
  159. * @brief For DMA1
  160. */
  161. #define DMA1_IT_GL1 ((uint32_t)0x00000001)
  162. #define DMA1_IT_TC1 ((uint32_t)0x00000002)
  163. #define DMA1_IT_HT1 ((uint32_t)0x00000004)
  164. #define DMA1_IT_TE1 ((uint32_t)0x00000008)
  165. #define DMA1_IT_GL2 ((uint32_t)0x00000010)
  166. #define DMA1_IT_TC2 ((uint32_t)0x00000020)
  167. #define DMA1_IT_HT2 ((uint32_t)0x00000040)
  168. #define DMA1_IT_TE2 ((uint32_t)0x00000080)
  169. #define DMA1_IT_GL3 ((uint32_t)0x00000100)
  170. #define DMA1_IT_TC3 ((uint32_t)0x00000200)
  171. #define DMA1_IT_HT3 ((uint32_t)0x00000400)
  172. #define DMA1_IT_TE3 ((uint32_t)0x00000800)
  173. #define DMA1_IT_GL4 ((uint32_t)0x00001000)
  174. #define DMA1_IT_TC4 ((uint32_t)0x00002000)
  175. #define DMA1_IT_HT4 ((uint32_t)0x00004000)
  176. #define DMA1_IT_TE4 ((uint32_t)0x00008000)
  177. #define DMA1_IT_GL5 ((uint32_t)0x00010000)
  178. #define DMA1_IT_TC5 ((uint32_t)0x00020000)
  179. #define DMA1_IT_HT5 ((uint32_t)0x00040000)
  180. #define DMA1_IT_TE5 ((uint32_t)0x00080000)
  181. #define DMA1_IT_GL6 ((uint32_t)0x00100000)
  182. #define DMA1_IT_TC6 ((uint32_t)0x00200000)
  183. #define DMA1_IT_HT6 ((uint32_t)0x00400000)
  184. #define DMA1_IT_TE6 ((uint32_t)0x00800000)
  185. #define DMA1_IT_GL7 ((uint32_t)0x01000000)
  186. #define DMA1_IT_TC7 ((uint32_t)0x02000000)
  187. #define DMA1_IT_HT7 ((uint32_t)0x04000000)
  188. #define DMA1_IT_TE7 ((uint32_t)0x08000000)
  189. #define IS_DMA_CLEAR_IT(IT) (((((IT) & 0xF0000000) == 0x00) || (((IT) & 0xEFF00000) == 0x00)) && ((IT) != 0x00))
  190. #define IS_DMA_GET_IT(IT) (((IT) == DMA1_IT_GL1) || ((IT) == DMA1_IT_TC1) || \
  191. ((IT) == DMA1_IT_HT1) || ((IT) == DMA1_IT_TE1) || \
  192. ((IT) == DMA1_IT_GL2) || ((IT) == DMA1_IT_TC2) || \
  193. ((IT) == DMA1_IT_HT2) || ((IT) == DMA1_IT_TE2) || \
  194. ((IT) == DMA1_IT_GL3) || ((IT) == DMA1_IT_TC3) || \
  195. ((IT) == DMA1_IT_HT3) || ((IT) == DMA1_IT_TE3) || \
  196. ((IT) == DMA1_IT_GL4) || ((IT) == DMA1_IT_TC4) || \
  197. ((IT) == DMA1_IT_HT4) || ((IT) == DMA1_IT_TE4) || \
  198. ((IT) == DMA1_IT_GL5) || ((IT) == DMA1_IT_TC5) || \
  199. ((IT) == DMA1_IT_HT5) || ((IT) == DMA1_IT_TE5) || \
  200. ((IT) == DMA1_IT_GL6) || ((IT) == DMA1_IT_TC6) || \
  201. ((IT) == DMA1_IT_HT6) || ((IT) == DMA1_IT_TE6) || \
  202. ((IT) == DMA1_IT_GL7) || ((IT) == DMA1_IT_TC7) || \
  203. ((IT) == DMA1_IT_HT7) || ((IT) == DMA1_IT_TE7) || \
  204. /**
  205. * @}
  206. */
  207. /** @defgroup DMA_flags_definition
  208. * @{
  209. */
  210. /**
  211. * @brief For DMA1
  212. */
  213. #define DMA1_FLAG_GL1 ((uint32_t)0x00000001)
  214. #define DMA1_FLAG_TC1 ((uint32_t)0x00000002)
  215. #define DMA1_FLAG_HT1 ((uint32_t)0x00000004)
  216. #define DMA1_FLAG_TE1 ((uint32_t)0x00000008)
  217. #define DMA1_FLAG_GL2 ((uint32_t)0x00000010)
  218. #define DMA1_FLAG_TC2 ((uint32_t)0x00000020)
  219. #define DMA1_FLAG_HT2 ((uint32_t)0x00000040)
  220. #define DMA1_FLAG_TE2 ((uint32_t)0x00000080)
  221. #define DMA1_FLAG_GL3 ((uint32_t)0x00000100)
  222. #define DMA1_FLAG_TC3 ((uint32_t)0x00000200)
  223. #define DMA1_FLAG_HT3 ((uint32_t)0x00000400)
  224. #define DMA1_FLAG_TE3 ((uint32_t)0x00000800)
  225. #define DMA1_FLAG_GL4 ((uint32_t)0x00001000)
  226. #define DMA1_FLAG_TC4 ((uint32_t)0x00002000)
  227. #define DMA1_FLAG_HT4 ((uint32_t)0x00004000)
  228. #define DMA1_FLAG_TE4 ((uint32_t)0x00008000)
  229. #define DMA1_FLAG_GL5 ((uint32_t)0x00010000)
  230. #define DMA1_FLAG_TC5 ((uint32_t)0x00020000)
  231. #define DMA1_FLAG_HT5 ((uint32_t)0x00040000)
  232. #define DMA1_FLAG_TE5 ((uint32_t)0x00080000)
  233. #define DMA1_FLAG_GL6 ((uint32_t)0x00100000)
  234. #define DMA1_FLAG_TC6 ((uint32_t)0x00200000)
  235. #define DMA1_FLAG_HT6 ((uint32_t)0x00400000)
  236. #define DMA1_FLAG_TE6 ((uint32_t)0x00800000)
  237. #define DMA1_FLAG_GL7 ((uint32_t)0x01000000)
  238. #define DMA1_FLAG_TC7 ((uint32_t)0x02000000)
  239. #define DMA1_FLAG_HT7 ((uint32_t)0x04000000)
  240. #define DMA1_FLAG_TE7 ((uint32_t)0x08000000)
  241. #define IS_DMA_CLEAR_FLAG(FLAG) (((((FLAG) & 0xF0000000) == 0x00) || (((FLAG) & 0xEFF00000) == 0x00)) && ((FLAG) != 0x00))
  242. #define IS_DMA_GET_FLAG(FLAG) (((FLAG) == DMA1_FLAG_GL1) || ((FLAG) == DMA1_FLAG_TC1) || \
  243. ((FLAG) == DMA1_FLAG_HT1) || ((FLAG) == DMA1_FLAG_TE1) || \
  244. ((FLAG) == DMA1_FLAG_GL2) || ((FLAG) == DMA1_FLAG_TC2) || \
  245. ((FLAG) == DMA1_FLAG_HT2) || ((FLAG) == DMA1_FLAG_TE2) || \
  246. ((FLAG) == DMA1_FLAG_GL3) || ((FLAG) == DMA1_FLAG_TC3) || \
  247. ((FLAG) == DMA1_FLAG_HT3) || ((FLAG) == DMA1_FLAG_TE3) || \
  248. ((FLAG) == DMA1_FLAG_GL4) || ((FLAG) == DMA1_FLAG_TC4) || \
  249. ((FLAG) == DMA1_FLAG_HT4) || ((FLAG) == DMA1_FLAG_TE4) || \
  250. ((FLAG) == DMA1_FLAG_GL5) || ((FLAG) == DMA1_FLAG_TC5) || \
  251. ((FLAG) == DMA1_FLAG_HT5) || ((FLAG) == DMA1_FLAG_TE5) || \
  252. ((FLAG) == DMA1_FLAG_GL6) || ((FLAG) == DMA1_FLAG_TC6) || \
  253. ((FLAG) == DMA1_FLAG_HT6) || ((FLAG) == DMA1_FLAG_TE6) || \
  254. ((FLAG) == DMA1_FLAG_GL7) || ((FLAG) == DMA1_FLAG_TC7) || \
  255. ((FLAG) == DMA1_FLAG_HT7) || ((FLAG) == DMA1_FLAG_TE7))
  256. /**
  257. * @}
  258. */
  259. /** @defgroup DMA_Buffer_Size
  260. * @{
  261. */
  262. #define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1) && ((SIZE) < 0x10000))
  263. /**
  264. * @}
  265. */
  266. /**
  267. * @}
  268. */
  269. /** @defgroup DMA_Exported_Macros
  270. * @{
  271. */
  272. /**
  273. * @}
  274. */
  275. /** @defgroup DMA_Exported_Functions
  276. * @{
  277. */
  278. void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx);
  279. void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct);
  280. void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct);
  281. void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState);
  282. void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState);
  283. uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx);
  284. FlagStatus DMA_GetFlagStatus(uint32_t DMA_FLAG);
  285. void DMA_ClearFlag(uint32_t DMA_FLAG);
  286. ITStatus DMA_GetITStatus(uint32_t DMA_IT);
  287. void DMA_ClearITPendingBit(uint32_t DMA_IT);
  288. #endif /*__HAL_DMA_H */
  289. /**
  290. * @}
  291. */
  292. /**
  293. * @}
  294. */
  295. /**
  296. * @}
  297. */
  298. /*------------------ (C) COPYRIGHT 2019 MindMotion ------------------*/