stm32f0xx_dma.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_dma.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 23-March-2012
  7. * @brief This file contains all the functions prototypes for the DMA firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM32F0XX_DMA_H
  30. #define __STM32F0XX_DMA_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f0xx.h"
  36. /** @addtogroup STM32F0xx_StdPeriph_Driver
  37. * @{
  38. */
  39. /** @addtogroup DMA
  40. * @{
  41. */
  42. /* Exported types ------------------------------------------------------------*/
  43. /**
  44. * @brief DMA Init structures definition
  45. */
  46. typedef struct
  47. {
  48. uint32_t DMA_PeripheralBaseAddr; /*!< Specifies the peripheral base address for DMAy Channelx. */
  49. uint32_t DMA_MemoryBaseAddr; /*!< Specifies the memory base address for DMAy Channelx. */
  50. uint32_t DMA_DIR; /*!< Specifies if the peripheral is the source or destination.
  51. This parameter can be a value of @ref DMA_data_transfer_direction */
  52. uint32_t DMA_BufferSize; /*!< Specifies the buffer size, in data unit, of the specified Channel.
  53. The data unit is equal to the configuration set in DMA_PeripheralDataSize
  54. or DMA_MemoryDataSize members depending in the transfer direction */
  55. uint32_t DMA_PeripheralInc; /*!< Specifies whether the Peripheral address register is incremented or not.
  56. This parameter can be a value of @ref DMA_peripheral_incremented_mode */
  57. uint32_t DMA_MemoryInc; /*!< Specifies whether the memory address register is incremented or not.
  58. This parameter can be a value of @ref DMA_memory_incremented_mode */
  59. uint32_t DMA_PeripheralDataSize; /*!< Specifies the Peripheral data width.
  60. This parameter can be a value of @ref DMA_peripheral_data_size */
  61. uint32_t DMA_MemoryDataSize; /*!< Specifies the Memory data width.
  62. This parameter can be a value of @ref DMA_memory_data_size */
  63. uint32_t DMA_Mode; /*!< Specifies the operation mode of the DMAy Channelx.
  64. This parameter can be a value of @ref DMA_circular_normal_mode
  65. @note: The circular buffer mode cannot be used if the memory-to-memory
  66. data transfer is configured on the selected Channel */
  67. uint32_t DMA_Priority; /*!< Specifies the software priority for the DMAy Channelx.
  68. This parameter can be a value of @ref DMA_priority_level */
  69. uint32_t DMA_M2M; /*!< Specifies if the DMAy Channelx will be used in memory-to-memory transfer.
  70. This parameter can be a value of @ref DMA_memory_to_memory */
  71. }DMA_InitTypeDef;
  72. /* Exported constants --------------------------------------------------------*/
  73. /** @defgroup DMA_Exported_Constants
  74. * @{
  75. */
  76. #define IS_DMA_ALL_PERIPH(PERIPH) (((PERIPH) == DMA1_Channel1) || \
  77. ((PERIPH) == DMA1_Channel2) || \
  78. ((PERIPH) == DMA1_Channel3) || \
  79. ((PERIPH) == DMA1_Channel4) || \
  80. ((PERIPH) == DMA1_Channel5))
  81. /** @defgroup DMA_data_transfer_direction
  82. * @{
  83. */
  84. #define DMA_DIR_PeripheralSRC ((uint32_t)0x00000000)
  85. #define DMA_DIR_PeripheralDST DMA_CCR_DIR
  86. #define IS_DMA_DIR(DIR) (((DIR) == DMA_DIR_PeripheralSRC) || \
  87. ((DIR) == DMA_DIR_PeripheralDST))
  88. /**
  89. * @}
  90. */
  91. /** @defgroup DMA_peripheral_incremented_mode
  92. * @{
  93. */
  94. #define DMA_PeripheralInc_Disable ((uint32_t)0x00000000)
  95. #define DMA_PeripheralInc_Enable DMA_CCR_PINC
  96. #define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PeripheralInc_Disable) || \
  97. ((STATE) == DMA_PeripheralInc_Enable))
  98. /**
  99. * @}
  100. */
  101. /** @defgroup DMA_memory_incremented_mode
  102. * @{
  103. */
  104. #define DMA_MemoryInc_Disable ((uint32_t)0x00000000)
  105. #define DMA_MemoryInc_Enable DMA_CCR_MINC
  106. #define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MemoryInc_Disable) || \
  107. ((STATE) == DMA_MemoryInc_Enable))
  108. /**
  109. * @}
  110. */
  111. /** @defgroup DMA_peripheral_data_size
  112. * @{
  113. */
  114. #define DMA_PeripheralDataSize_Byte ((uint32_t)0x00000000)
  115. #define DMA_PeripheralDataSize_HalfWord DMA_CCR_PSIZE_0
  116. #define DMA_PeripheralDataSize_Word DMA_CCR_PSIZE_1
  117. #define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PeripheralDataSize_Byte) || \
  118. ((SIZE) == DMA_PeripheralDataSize_HalfWord) || \
  119. ((SIZE) == DMA_PeripheralDataSize_Word))
  120. /**
  121. * @}
  122. */
  123. /** @defgroup DMA_memory_data_size
  124. * @{
  125. */
  126. #define DMA_MemoryDataSize_Byte ((uint32_t)0x00000000)
  127. #define DMA_MemoryDataSize_HalfWord DMA_CCR_MSIZE_0
  128. #define DMA_MemoryDataSize_Word DMA_CCR_MSIZE_1
  129. #define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MemoryDataSize_Byte) || \
  130. ((SIZE) == DMA_MemoryDataSize_HalfWord) || \
  131. ((SIZE) == DMA_MemoryDataSize_Word))
  132. /**
  133. * @}
  134. */
  135. /** @defgroup DMA_circular_normal_mode
  136. * @{
  137. */
  138. #define DMA_Mode_Normal ((uint32_t)0x00000000)
  139. #define DMA_Mode_Circular DMA_CCR_CIRC
  140. #define IS_DMA_MODE(MODE) (((MODE) == DMA_Mode_Normal) || ((MODE) == DMA_Mode_Circular))
  141. /**
  142. * @}
  143. */
  144. /** @defgroup DMA_priority_level
  145. * @{
  146. */
  147. #define DMA_Priority_VeryHigh DMA_CCR_PL
  148. #define DMA_Priority_High DMA_CCR_PL_1
  149. #define DMA_Priority_Medium DMA_CCR_PL_0
  150. #define DMA_Priority_Low ((uint32_t)0x00000000)
  151. #define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_Priority_VeryHigh) || \
  152. ((PRIORITY) == DMA_Priority_High) || \
  153. ((PRIORITY) == DMA_Priority_Medium) || \
  154. ((PRIORITY) == DMA_Priority_Low))
  155. /**
  156. * @}
  157. */
  158. /** @defgroup DMA_memory_to_memory
  159. * @{
  160. */
  161. #define DMA_M2M_Disable ((uint32_t)0x00000000)
  162. #define DMA_M2M_Enable DMA_CCR_MEM2MEM
  163. #define IS_DMA_M2M_STATE(STATE) (((STATE) == DMA_M2M_Disable) || ((STATE) == DMA_M2M_Enable))
  164. /**
  165. * @}
  166. */
  167. /** @defgroup DMA_interrupts_definition
  168. * @{
  169. */
  170. #define DMA_IT_TC DMA_CCR_TCIE
  171. #define DMA_IT_HT DMA_CCR_HTIE
  172. #define DMA_IT_TE DMA_CCR_TEIE
  173. #define IS_DMA_CONFIG_IT(IT) ((((IT) & 0xFFFFFFF1) == 0x00) && ((IT) != 0x00))
  174. #define DMA1_IT_GL1 DMA_ISR_GIF1
  175. #define DMA1_IT_TC1 DMA_ISR_TCIF1
  176. #define DMA1_IT_HT1 DMA_ISR_HTIF1
  177. #define DMA1_IT_TE1 DMA_ISR_TEIF1
  178. #define DMA1_IT_GL2 DMA_ISR_GIF2
  179. #define DMA1_IT_TC2 DMA_ISR_TCIF2
  180. #define DMA1_IT_HT2 DMA_ISR_HTIF2
  181. #define DMA1_IT_TE2 DMA_ISR_TEIF2
  182. #define DMA1_IT_GL3 DMA_ISR_GIF3
  183. #define DMA1_IT_TC3 DMA_ISR_TCIF3
  184. #define DMA1_IT_HT3 DMA_ISR_HTIF3
  185. #define DMA1_IT_TE3 DMA_ISR_TEIF3
  186. #define DMA1_IT_GL4 DMA_ISR_GIF4
  187. #define DMA1_IT_TC4 DMA_ISR_TCIF4
  188. #define DMA1_IT_HT4 DMA_ISR_HTIF4
  189. #define DMA1_IT_TE4 DMA_ISR_TEIF4
  190. #define DMA1_IT_GL5 DMA_ISR_GIF5
  191. #define DMA1_IT_TC5 DMA_ISR_TCIF5
  192. #define DMA1_IT_HT5 DMA_ISR_HTIF5
  193. #define DMA1_IT_TE5 DMA_ISR_TEIF5
  194. #define IS_DMA_CLEAR_IT(IT) ((((IT) & 0xFFF00000) == 0x00) && ((IT) != 0x00))
  195. #define IS_DMA_GET_IT(IT) (((IT) == DMA1_IT_GL1) || ((IT) == DMA1_IT_TC1) || \
  196. ((IT) == DMA1_IT_HT1) || ((IT) == DMA1_IT_TE1) || \
  197. ((IT) == DMA1_IT_GL2) || ((IT) == DMA1_IT_TC2) || \
  198. ((IT) == DMA1_IT_HT2) || ((IT) == DMA1_IT_TE2) || \
  199. ((IT) == DMA1_IT_GL3) || ((IT) == DMA1_IT_TC3) || \
  200. ((IT) == DMA1_IT_HT3) || ((IT) == DMA1_IT_TE3) || \
  201. ((IT) == DMA1_IT_GL4) || ((IT) == DMA1_IT_TC4) || \
  202. ((IT) == DMA1_IT_HT4) || ((IT) == DMA1_IT_TE4) || \
  203. ((IT) == DMA1_IT_GL5) || ((IT) == DMA1_IT_TC5) || \
  204. ((IT) == DMA1_IT_HT5) || ((IT) == DMA1_IT_TE5))
  205. /**
  206. * @}
  207. */
  208. /** @defgroup DMA_flags_definition
  209. * @{
  210. */
  211. #define DMA1_FLAG_GL1 DMA_ISR_GIF1
  212. #define DMA1_FLAG_TC1 DMA_ISR_TCIF1
  213. #define DMA1_FLAG_HT1 DMA_ISR_HTIF1
  214. #define DMA1_FLAG_TE1 DMA_ISR_TEIF1
  215. #define DMA1_FLAG_GL2 DMA_ISR_GIF2
  216. #define DMA1_FLAG_TC2 DMA_ISR_TCIF2
  217. #define DMA1_FLAG_HT2 DMA_ISR_HTIF2
  218. #define DMA1_FLAG_TE2 DMA_ISR_TEIF2
  219. #define DMA1_FLAG_GL3 DMA_ISR_GIF3
  220. #define DMA1_FLAG_TC3 DMA_ISR_TCIF3
  221. #define DMA1_FLAG_HT3 DMA_ISR_HTIF3
  222. #define DMA1_FLAG_TE3 DMA_ISR_TEIF3
  223. #define DMA1_FLAG_GL4 DMA_ISR_GIF4
  224. #define DMA1_FLAG_TC4 DMA_ISR_TCIF4
  225. #define DMA1_FLAG_HT4 DMA_ISR_HTIF4
  226. #define DMA1_FLAG_TE4 DMA_ISR_TEIF4
  227. #define DMA1_FLAG_GL5 DMA_ISR_GIF5
  228. #define DMA1_FLAG_TC5 DMA_ISR_TCIF5
  229. #define DMA1_FLAG_HT5 DMA_ISR_HTIF5
  230. #define DMA1_FLAG_TE5 DMA_ISR_TEIF5
  231. #define IS_DMA_CLEAR_FLAG(FLAG) ((((FLAG) & 0xFFF00000) == 0x00) && ((FLAG) != 0x00))
  232. #define IS_DMA_GET_FLAG(FLAG) (((FLAG) == DMA1_FLAG_GL1) || ((FLAG) == DMA1_FLAG_TC1) || \
  233. ((FLAG) == DMA1_FLAG_HT1) || ((FLAG) == DMA1_FLAG_TE1) || \
  234. ((FLAG) == DMA1_FLAG_GL2) || ((FLAG) == DMA1_FLAG_TC2) || \
  235. ((FLAG) == DMA1_FLAG_HT2) || ((FLAG) == DMA1_FLAG_TE2) || \
  236. ((FLAG) == DMA1_FLAG_GL3) || ((FLAG) == DMA1_FLAG_TC3) || \
  237. ((FLAG) == DMA1_FLAG_HT3) || ((FLAG) == DMA1_FLAG_TE3) || \
  238. ((FLAG) == DMA1_FLAG_GL4) || ((FLAG) == DMA1_FLAG_TC4) || \
  239. ((FLAG) == DMA1_FLAG_HT4) || ((FLAG) == DMA1_FLAG_TE4) || \
  240. ((FLAG) == DMA1_FLAG_GL5) || ((FLAG) == DMA1_FLAG_TC5) || \
  241. ((FLAG) == DMA1_FLAG_HT5) || ((FLAG) == DMA1_FLAG_TE5))
  242. /**
  243. * @}
  244. */
  245. /** @defgroup DMA_Buffer_Size
  246. * @{
  247. */
  248. #define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1) && ((SIZE) < 0x10000))
  249. /**
  250. * @}
  251. */
  252. /**
  253. * @}
  254. */
  255. /* Exported macro ------------------------------------------------------------*/
  256. /* Exported functions ------------------------------------------------------- */
  257. /* Function used to set the DMA configuration to the default reset state ******/
  258. void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx);
  259. /* Initialization and Configuration functions *********************************/
  260. void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct);
  261. void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct);
  262. void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState);
  263. /* Data Counter functions******************************************************/
  264. void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber);
  265. uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx);
  266. /* Interrupts and flags management functions **********************************/
  267. void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState);
  268. FlagStatus DMA_GetFlagStatus(uint32_t DMA_FLAG);
  269. void DMA_ClearFlag(uint32_t DMA_FLAG);
  270. ITStatus DMA_GetITStatus(uint32_t DMA_IT);
  271. void DMA_ClearITPendingBit(uint32_t DMA_IT);
  272. #ifdef __cplusplus
  273. }
  274. #endif
  275. #endif /*__STM32F0XX_DMA_H */
  276. /**
  277. * @}
  278. */
  279. /**
  280. * @}
  281. */
  282. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/