stm32f10x_dma.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_dma.c
  4. * @author MCD Application Team
  5. * @version V3.5.0
  6. * @date 11-March-2011
  7. * @brief This file provides all the DMA firmware functions.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  19. ******************************************************************************
  20. */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm32f10x_dma.h"
  23. #include "stm32f10x_rcc.h"
  24. /** @addtogroup STM32F10x_StdPeriph_Driver
  25. * @{
  26. */
  27. /** @defgroup DMA
  28. * @brief DMA driver modules
  29. * @{
  30. */
  31. /** @defgroup DMA_Private_TypesDefinitions
  32. * @{
  33. */
  34. /**
  35. * @}
  36. */
  37. /** @defgroup DMA_Private_Defines
  38. * @{
  39. */
  40. /* DMA1 Channelx interrupt pending bit masks */
  41. #define DMA1_Channel1_IT_Mask ((uint32_t)(DMA_ISR_GIF1 | DMA_ISR_TCIF1 | DMA_ISR_HTIF1 | DMA_ISR_TEIF1))
  42. #define DMA1_Channel2_IT_Mask ((uint32_t)(DMA_ISR_GIF2 | DMA_ISR_TCIF2 | DMA_ISR_HTIF2 | DMA_ISR_TEIF2))
  43. #define DMA1_Channel3_IT_Mask ((uint32_t)(DMA_ISR_GIF3 | DMA_ISR_TCIF3 | DMA_ISR_HTIF3 | DMA_ISR_TEIF3))
  44. #define DMA1_Channel4_IT_Mask ((uint32_t)(DMA_ISR_GIF4 | DMA_ISR_TCIF4 | DMA_ISR_HTIF4 | DMA_ISR_TEIF4))
  45. #define DMA1_Channel5_IT_Mask ((uint32_t)(DMA_ISR_GIF5 | DMA_ISR_TCIF5 | DMA_ISR_HTIF5 | DMA_ISR_TEIF5))
  46. #define DMA1_Channel6_IT_Mask ((uint32_t)(DMA_ISR_GIF6 | DMA_ISR_TCIF6 | DMA_ISR_HTIF6 | DMA_ISR_TEIF6))
  47. #define DMA1_Channel7_IT_Mask ((uint32_t)(DMA_ISR_GIF7 | DMA_ISR_TCIF7 | DMA_ISR_HTIF7 | DMA_ISR_TEIF7))
  48. /* DMA2 Channelx interrupt pending bit masks */
  49. #define DMA2_Channel1_IT_Mask ((uint32_t)(DMA_ISR_GIF1 | DMA_ISR_TCIF1 | DMA_ISR_HTIF1 | DMA_ISR_TEIF1))
  50. #define DMA2_Channel2_IT_Mask ((uint32_t)(DMA_ISR_GIF2 | DMA_ISR_TCIF2 | DMA_ISR_HTIF2 | DMA_ISR_TEIF2))
  51. #define DMA2_Channel3_IT_Mask ((uint32_t)(DMA_ISR_GIF3 | DMA_ISR_TCIF3 | DMA_ISR_HTIF3 | DMA_ISR_TEIF3))
  52. #define DMA2_Channel4_IT_Mask ((uint32_t)(DMA_ISR_GIF4 | DMA_ISR_TCIF4 | DMA_ISR_HTIF4 | DMA_ISR_TEIF4))
  53. #define DMA2_Channel5_IT_Mask ((uint32_t)(DMA_ISR_GIF5 | DMA_ISR_TCIF5 | DMA_ISR_HTIF5 | DMA_ISR_TEIF5))
  54. /* DMA2 FLAG mask */
  55. #define FLAG_Mask ((uint32_t)0x10000000)
  56. /* DMA registers Masks */
  57. #define CCR_CLEAR_Mask ((uint32_t)0xFFFF800F)
  58. /**
  59. * @}
  60. */
  61. /** @defgroup DMA_Private_Macros
  62. * @{
  63. */
  64. /**
  65. * @}
  66. */
  67. /** @defgroup DMA_Private_Variables
  68. * @{
  69. */
  70. /**
  71. * @}
  72. */
  73. /** @defgroup DMA_Private_FunctionPrototypes
  74. * @{
  75. */
  76. /**
  77. * @}
  78. */
  79. /** @defgroup DMA_Private_Functions
  80. * @{
  81. */
  82. /**
  83. * @brief Deinitializes the DMAy Channelx registers to their default reset
  84. * values.
  85. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  86. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  87. * @retval None
  88. */
  89. void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx)
  90. {
  91. /* Check the parameters */
  92. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  93. /* Disable the selected DMAy Channelx */
  94. DMAy_Channelx->CCR &= (uint16_t)(~DMA_CCR1_EN);
  95. /* Reset DMAy Channelx control register */
  96. DMAy_Channelx->CCR = 0;
  97. /* Reset DMAy Channelx remaining bytes register */
  98. DMAy_Channelx->CNDTR = 0;
  99. /* Reset DMAy Channelx peripheral address register */
  100. DMAy_Channelx->CPAR = 0;
  101. /* Reset DMAy Channelx memory address register */
  102. DMAy_Channelx->CMAR = 0;
  103. if (DMAy_Channelx == DMA1_Channel1)
  104. {
  105. /* Reset interrupt pending bits for DMA1 Channel1 */
  106. DMA1->IFCR |= DMA1_Channel1_IT_Mask;
  107. }
  108. else if (DMAy_Channelx == DMA1_Channel2)
  109. {
  110. /* Reset interrupt pending bits for DMA1 Channel2 */
  111. DMA1->IFCR |= DMA1_Channel2_IT_Mask;
  112. }
  113. else if (DMAy_Channelx == DMA1_Channel3)
  114. {
  115. /* Reset interrupt pending bits for DMA1 Channel3 */
  116. DMA1->IFCR |= DMA1_Channel3_IT_Mask;
  117. }
  118. else if (DMAy_Channelx == DMA1_Channel4)
  119. {
  120. /* Reset interrupt pending bits for DMA1 Channel4 */
  121. DMA1->IFCR |= DMA1_Channel4_IT_Mask;
  122. }
  123. else if (DMAy_Channelx == DMA1_Channel5)
  124. {
  125. /* Reset interrupt pending bits for DMA1 Channel5 */
  126. DMA1->IFCR |= DMA1_Channel5_IT_Mask;
  127. }
  128. else if (DMAy_Channelx == DMA1_Channel6)
  129. {
  130. /* Reset interrupt pending bits for DMA1 Channel6 */
  131. DMA1->IFCR |= DMA1_Channel6_IT_Mask;
  132. }
  133. else if (DMAy_Channelx == DMA1_Channel7)
  134. {
  135. /* Reset interrupt pending bits for DMA1 Channel7 */
  136. DMA1->IFCR |= DMA1_Channel7_IT_Mask;
  137. }
  138. else if (DMAy_Channelx == DMA2_Channel1)
  139. {
  140. /* Reset interrupt pending bits for DMA2 Channel1 */
  141. DMA2->IFCR |= DMA2_Channel1_IT_Mask;
  142. }
  143. else if (DMAy_Channelx == DMA2_Channel2)
  144. {
  145. /* Reset interrupt pending bits for DMA2 Channel2 */
  146. DMA2->IFCR |= DMA2_Channel2_IT_Mask;
  147. }
  148. else if (DMAy_Channelx == DMA2_Channel3)
  149. {
  150. /* Reset interrupt pending bits for DMA2 Channel3 */
  151. DMA2->IFCR |= DMA2_Channel3_IT_Mask;
  152. }
  153. else if (DMAy_Channelx == DMA2_Channel4)
  154. {
  155. /* Reset interrupt pending bits for DMA2 Channel4 */
  156. DMA2->IFCR |= DMA2_Channel4_IT_Mask;
  157. }
  158. else
  159. {
  160. if (DMAy_Channelx == DMA2_Channel5)
  161. {
  162. /* Reset interrupt pending bits for DMA2 Channel5 */
  163. DMA2->IFCR |= DMA2_Channel5_IT_Mask;
  164. }
  165. }
  166. }
  167. /**
  168. * @brief Initializes the DMAy Channelx according to the specified
  169. * parameters in the DMA_InitStruct.
  170. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  171. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  172. * @param DMA_InitStruct: pointer to a DMA_InitTypeDef structure that
  173. * contains the configuration information for the specified DMA Channel.
  174. * @retval None
  175. */
  176. void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct)
  177. {
  178. uint32_t tmpreg = 0;
  179. /* Check the parameters */
  180. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  181. assert_param(IS_DMA_DIR(DMA_InitStruct->DMA_DIR));
  182. assert_param(IS_DMA_BUFFER_SIZE(DMA_InitStruct->DMA_BufferSize));
  183. assert_param(IS_DMA_PERIPHERAL_INC_STATE(DMA_InitStruct->DMA_PeripheralInc));
  184. assert_param(IS_DMA_MEMORY_INC_STATE(DMA_InitStruct->DMA_MemoryInc));
  185. assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(DMA_InitStruct->DMA_PeripheralDataSize));
  186. assert_param(IS_DMA_MEMORY_DATA_SIZE(DMA_InitStruct->DMA_MemoryDataSize));
  187. assert_param(IS_DMA_MODE(DMA_InitStruct->DMA_Mode));
  188. assert_param(IS_DMA_PRIORITY(DMA_InitStruct->DMA_Priority));
  189. assert_param(IS_DMA_M2M_STATE(DMA_InitStruct->DMA_M2M));
  190. /*--------------------------- DMAy Channelx CCR Configuration -----------------*/
  191. /* Get the DMAy_Channelx CCR value */
  192. tmpreg = DMAy_Channelx->CCR;
  193. /* Clear MEM2MEM, PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */
  194. tmpreg &= CCR_CLEAR_Mask;
  195. /* Configure DMAy Channelx: data transfer, data size, priority level and mode */
  196. /* Set DIR bit according to DMA_DIR value */
  197. /* Set CIRC bit according to DMA_Mode value */
  198. /* Set PINC bit according to DMA_PeripheralInc value */
  199. /* Set MINC bit according to DMA_MemoryInc value */
  200. /* Set PSIZE bits according to DMA_PeripheralDataSize value */
  201. /* Set MSIZE bits according to DMA_MemoryDataSize value */
  202. /* Set PL bits according to DMA_Priority value */
  203. /* Set the MEM2MEM bit according to DMA_M2M value */
  204. tmpreg |= DMA_InitStruct->DMA_DIR | DMA_InitStruct->DMA_Mode |
  205. DMA_InitStruct->DMA_PeripheralInc | DMA_InitStruct->DMA_MemoryInc |
  206. DMA_InitStruct->DMA_PeripheralDataSize | DMA_InitStruct->DMA_MemoryDataSize |
  207. DMA_InitStruct->DMA_Priority | DMA_InitStruct->DMA_M2M;
  208. /* Write to DMAy Channelx CCR */
  209. DMAy_Channelx->CCR = tmpreg;
  210. /*--------------------------- DMAy Channelx CNDTR Configuration ---------------*/
  211. /* Write to DMAy Channelx CNDTR */
  212. DMAy_Channelx->CNDTR = DMA_InitStruct->DMA_BufferSize;
  213. /*--------------------------- DMAy Channelx CPAR Configuration ----------------*/
  214. /* Write to DMAy Channelx CPAR */
  215. DMAy_Channelx->CPAR = DMA_InitStruct->DMA_PeripheralBaseAddr;
  216. /*--------------------------- DMAy Channelx CMAR Configuration ----------------*/
  217. /* Write to DMAy Channelx CMAR */
  218. DMAy_Channelx->CMAR = DMA_InitStruct->DMA_MemoryBaseAddr;
  219. }
  220. /**
  221. * @brief Fills each DMA_InitStruct member with its default value.
  222. * @param DMA_InitStruct : pointer to a DMA_InitTypeDef structure which will
  223. * be initialized.
  224. * @retval None
  225. */
  226. void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct)
  227. {
  228. /*-------------- Reset DMA init structure parameters values ------------------*/
  229. /* Initialize the DMA_PeripheralBaseAddr member */
  230. DMA_InitStruct->DMA_PeripheralBaseAddr = 0;
  231. /* Initialize the DMA_MemoryBaseAddr member */
  232. DMA_InitStruct->DMA_MemoryBaseAddr = 0;
  233. /* Initialize the DMA_DIR member */
  234. DMA_InitStruct->DMA_DIR = DMA_DIR_PeripheralSRC;
  235. /* Initialize the DMA_BufferSize member */
  236. DMA_InitStruct->DMA_BufferSize = 0;
  237. /* Initialize the DMA_PeripheralInc member */
  238. DMA_InitStruct->DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  239. /* Initialize the DMA_MemoryInc member */
  240. DMA_InitStruct->DMA_MemoryInc = DMA_MemoryInc_Disable;
  241. /* Initialize the DMA_PeripheralDataSize member */
  242. DMA_InitStruct->DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  243. /* Initialize the DMA_MemoryDataSize member */
  244. DMA_InitStruct->DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  245. /* Initialize the DMA_Mode member */
  246. DMA_InitStruct->DMA_Mode = DMA_Mode_Normal;
  247. /* Initialize the DMA_Priority member */
  248. DMA_InitStruct->DMA_Priority = DMA_Priority_Low;
  249. /* Initialize the DMA_M2M member */
  250. DMA_InitStruct->DMA_M2M = DMA_M2M_Disable;
  251. }
  252. /**
  253. * @brief Enables or disables the specified DMAy Channelx.
  254. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  255. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  256. * @param NewState: new state of the DMAy Channelx.
  257. * This parameter can be: ENABLE or DISABLE.
  258. * @retval None
  259. */
  260. void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState)
  261. {
  262. /* Check the parameters */
  263. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  264. assert_param(IS_FUNCTIONAL_STATE(NewState));
  265. if (NewState != DISABLE)
  266. {
  267. /* Enable the selected DMAy Channelx */
  268. DMAy_Channelx->CCR |= DMA_CCR1_EN;
  269. }
  270. else
  271. {
  272. /* Disable the selected DMAy Channelx */
  273. DMAy_Channelx->CCR &= (uint16_t)(~DMA_CCR1_EN);
  274. }
  275. }
  276. /**
  277. * @brief Enables or disables the specified DMAy Channelx interrupts.
  278. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  279. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  280. * @param DMA_IT: specifies the DMA interrupts sources to be enabled
  281. * or disabled.
  282. * This parameter can be any combination of the following values:
  283. * @arg DMA_IT_TC: Transfer complete interrupt mask
  284. * @arg DMA_IT_HT: Half transfer interrupt mask
  285. * @arg DMA_IT_TE: Transfer error interrupt mask
  286. * @param NewState: new state of the specified DMA interrupts.
  287. * This parameter can be: ENABLE or DISABLE.
  288. * @retval None
  289. */
  290. void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState)
  291. {
  292. /* Check the parameters */
  293. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  294. assert_param(IS_DMA_CONFIG_IT(DMA_IT));
  295. assert_param(IS_FUNCTIONAL_STATE(NewState));
  296. if (NewState != DISABLE)
  297. {
  298. /* Enable the selected DMA interrupts */
  299. DMAy_Channelx->CCR |= DMA_IT;
  300. }
  301. else
  302. {
  303. /* Disable the selected DMA interrupts */
  304. DMAy_Channelx->CCR &= ~DMA_IT;
  305. }
  306. }
  307. /**
  308. * @brief Sets the number of data units in the current DMAy Channelx transfer.
  309. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  310. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  311. * @param DataNumber: The number of data units in the current DMAy Channelx
  312. * transfer.
  313. * @note This function can only be used when the DMAy_Channelx is disabled.
  314. * @retval None.
  315. */
  316. void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber)
  317. {
  318. /* Check the parameters */
  319. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  320. /*--------------------------- DMAy Channelx CNDTR Configuration ---------------*/
  321. /* Write to DMAy Channelx CNDTR */
  322. DMAy_Channelx->CNDTR = DataNumber;
  323. }
  324. /**
  325. * @brief Returns the number of remaining data units in the current
  326. * DMAy Channelx transfer.
  327. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  328. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  329. * @retval The number of remaining data units in the current DMAy Channelx
  330. * transfer.
  331. */
  332. uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx)
  333. {
  334. /* Check the parameters */
  335. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  336. /* Return the number of remaining data units for DMAy Channelx */
  337. return ((uint16_t)(DMAy_Channelx->CNDTR));
  338. }
  339. /**
  340. * @brief Checks whether the specified DMAy Channelx flag is set or not.
  341. * @param DMAy_FLAG: specifies the flag to check.
  342. * This parameter can be one of the following values:
  343. * @arg DMA1_FLAG_GL1: DMA1 Channel1 global flag.
  344. * @arg DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
  345. * @arg DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
  346. * @arg DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
  347. * @arg DMA1_FLAG_GL2: DMA1 Channel2 global flag.
  348. * @arg DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
  349. * @arg DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
  350. * @arg DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
  351. * @arg DMA1_FLAG_GL3: DMA1 Channel3 global flag.
  352. * @arg DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
  353. * @arg DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
  354. * @arg DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
  355. * @arg DMA1_FLAG_GL4: DMA1 Channel4 global flag.
  356. * @arg DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
  357. * @arg DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
  358. * @arg DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
  359. * @arg DMA1_FLAG_GL5: DMA1 Channel5 global flag.
  360. * @arg DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
  361. * @arg DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
  362. * @arg DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
  363. * @arg DMA1_FLAG_GL6: DMA1 Channel6 global flag.
  364. * @arg DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.
  365. * @arg DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.
  366. * @arg DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.
  367. * @arg DMA1_FLAG_GL7: DMA1 Channel7 global flag.
  368. * @arg DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.
  369. * @arg DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.
  370. * @arg DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.
  371. * @arg DMA2_FLAG_GL1: DMA2 Channel1 global flag.
  372. * @arg DMA2_FLAG_TC1: DMA2 Channel1 transfer complete flag.
  373. * @arg DMA2_FLAG_HT1: DMA2 Channel1 half transfer flag.
  374. * @arg DMA2_FLAG_TE1: DMA2 Channel1 transfer error flag.
  375. * @arg DMA2_FLAG_GL2: DMA2 Channel2 global flag.
  376. * @arg DMA2_FLAG_TC2: DMA2 Channel2 transfer complete flag.
  377. * @arg DMA2_FLAG_HT2: DMA2 Channel2 half transfer flag.
  378. * @arg DMA2_FLAG_TE2: DMA2 Channel2 transfer error flag.
  379. * @arg DMA2_FLAG_GL3: DMA2 Channel3 global flag.
  380. * @arg DMA2_FLAG_TC3: DMA2 Channel3 transfer complete flag.
  381. * @arg DMA2_FLAG_HT3: DMA2 Channel3 half transfer flag.
  382. * @arg DMA2_FLAG_TE3: DMA2 Channel3 transfer error flag.
  383. * @arg DMA2_FLAG_GL4: DMA2 Channel4 global flag.
  384. * @arg DMA2_FLAG_TC4: DMA2 Channel4 transfer complete flag.
  385. * @arg DMA2_FLAG_HT4: DMA2 Channel4 half transfer flag.
  386. * @arg DMA2_FLAG_TE4: DMA2 Channel4 transfer error flag.
  387. * @arg DMA2_FLAG_GL5: DMA2 Channel5 global flag.
  388. * @arg DMA2_FLAG_TC5: DMA2 Channel5 transfer complete flag.
  389. * @arg DMA2_FLAG_HT5: DMA2 Channel5 half transfer flag.
  390. * @arg DMA2_FLAG_TE5: DMA2 Channel5 transfer error flag.
  391. * @retval The new state of DMAy_FLAG (SET or RESET).
  392. */
  393. FlagStatus DMA_GetFlagStatus(uint32_t DMAy_FLAG)
  394. {
  395. FlagStatus bitstatus = RESET;
  396. uint32_t tmpreg = 0;
  397. /* Check the parameters */
  398. assert_param(IS_DMA_GET_FLAG(DMAy_FLAG));
  399. /* Calculate the used DMAy */
  400. if ((DMAy_FLAG & FLAG_Mask) != (uint32_t)RESET)
  401. {
  402. /* Get DMA2 ISR register value */
  403. tmpreg = DMA2->ISR ;
  404. }
  405. else
  406. {
  407. /* Get DMA1 ISR register value */
  408. tmpreg = DMA1->ISR ;
  409. }
  410. /* Check the status of the specified DMAy flag */
  411. if ((tmpreg & DMAy_FLAG) != (uint32_t)RESET)
  412. {
  413. /* DMAy_FLAG is set */
  414. bitstatus = SET;
  415. }
  416. else
  417. {
  418. /* DMAy_FLAG is reset */
  419. bitstatus = RESET;
  420. }
  421. /* Return the DMAy_FLAG status */
  422. return bitstatus;
  423. }
  424. /**
  425. * @brief Clears the DMAy Channelx's pending flags.
  426. * @param DMAy_FLAG: specifies the flag to clear.
  427. * This parameter can be any combination (for the same DMA) of the following values:
  428. * @arg DMA1_FLAG_GL1: DMA1 Channel1 global flag.
  429. * @arg DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
  430. * @arg DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
  431. * @arg DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
  432. * @arg DMA1_FLAG_GL2: DMA1 Channel2 global flag.
  433. * @arg DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
  434. * @arg DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
  435. * @arg DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
  436. * @arg DMA1_FLAG_GL3: DMA1 Channel3 global flag.
  437. * @arg DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
  438. * @arg DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
  439. * @arg DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
  440. * @arg DMA1_FLAG_GL4: DMA1 Channel4 global flag.
  441. * @arg DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
  442. * @arg DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
  443. * @arg DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
  444. * @arg DMA1_FLAG_GL5: DMA1 Channel5 global flag.
  445. * @arg DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
  446. * @arg DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
  447. * @arg DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
  448. * @arg DMA1_FLAG_GL6: DMA1 Channel6 global flag.
  449. * @arg DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.
  450. * @arg DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.
  451. * @arg DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.
  452. * @arg DMA1_FLAG_GL7: DMA1 Channel7 global flag.
  453. * @arg DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.
  454. * @arg DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.
  455. * @arg DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.
  456. * @arg DMA2_FLAG_GL1: DMA2 Channel1 global flag.
  457. * @arg DMA2_FLAG_TC1: DMA2 Channel1 transfer complete flag.
  458. * @arg DMA2_FLAG_HT1: DMA2 Channel1 half transfer flag.
  459. * @arg DMA2_FLAG_TE1: DMA2 Channel1 transfer error flag.
  460. * @arg DMA2_FLAG_GL2: DMA2 Channel2 global flag.
  461. * @arg DMA2_FLAG_TC2: DMA2 Channel2 transfer complete flag.
  462. * @arg DMA2_FLAG_HT2: DMA2 Channel2 half transfer flag.
  463. * @arg DMA2_FLAG_TE2: DMA2 Channel2 transfer error flag.
  464. * @arg DMA2_FLAG_GL3: DMA2 Channel3 global flag.
  465. * @arg DMA2_FLAG_TC3: DMA2 Channel3 transfer complete flag.
  466. * @arg DMA2_FLAG_HT3: DMA2 Channel3 half transfer flag.
  467. * @arg DMA2_FLAG_TE3: DMA2 Channel3 transfer error flag.
  468. * @arg DMA2_FLAG_GL4: DMA2 Channel4 global flag.
  469. * @arg DMA2_FLAG_TC4: DMA2 Channel4 transfer complete flag.
  470. * @arg DMA2_FLAG_HT4: DMA2 Channel4 half transfer flag.
  471. * @arg DMA2_FLAG_TE4: DMA2 Channel4 transfer error flag.
  472. * @arg DMA2_FLAG_GL5: DMA2 Channel5 global flag.
  473. * @arg DMA2_FLAG_TC5: DMA2 Channel5 transfer complete flag.
  474. * @arg DMA2_FLAG_HT5: DMA2 Channel5 half transfer flag.
  475. * @arg DMA2_FLAG_TE5: DMA2 Channel5 transfer error flag.
  476. * @retval None
  477. */
  478. void DMA_ClearFlag(uint32_t DMAy_FLAG)
  479. {
  480. /* Check the parameters */
  481. assert_param(IS_DMA_CLEAR_FLAG(DMAy_FLAG));
  482. /* Calculate the used DMAy */
  483. if ((DMAy_FLAG & FLAG_Mask) != (uint32_t)RESET)
  484. {
  485. /* Clear the selected DMAy flags */
  486. DMA2->IFCR = DMAy_FLAG;
  487. }
  488. else
  489. {
  490. /* Clear the selected DMAy flags */
  491. DMA1->IFCR = DMAy_FLAG;
  492. }
  493. }
  494. /**
  495. * @brief Checks whether the specified DMAy Channelx interrupt has occurred or not.
  496. * @param DMAy_IT: specifies the DMAy interrupt source to check.
  497. * This parameter can be one of the following values:
  498. * @arg DMA1_IT_GL1: DMA1 Channel1 global interrupt.
  499. * @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
  500. * @arg DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.
  501. * @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
  502. * @arg DMA1_IT_GL2: DMA1 Channel2 global interrupt.
  503. * @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
  504. * @arg DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.
  505. * @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
  506. * @arg DMA1_IT_GL3: DMA1 Channel3 global interrupt.
  507. * @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
  508. * @arg DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.
  509. * @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
  510. * @arg DMA1_IT_GL4: DMA1 Channel4 global interrupt.
  511. * @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
  512. * @arg DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.
  513. * @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
  514. * @arg DMA1_IT_GL5: DMA1 Channel5 global interrupt.
  515. * @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
  516. * @arg DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.
  517. * @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
  518. * @arg DMA1_IT_GL6: DMA1 Channel6 global interrupt.
  519. * @arg DMA1_IT_TC6: DMA1 Channel6 transfer complete interrupt.
  520. * @arg DMA1_IT_HT6: DMA1 Channel6 half transfer interrupt.
  521. * @arg DMA1_IT_TE6: DMA1 Channel6 transfer error interrupt.
  522. * @arg DMA1_IT_GL7: DMA1 Channel7 global interrupt.
  523. * @arg DMA1_IT_TC7: DMA1 Channel7 transfer complete interrupt.
  524. * @arg DMA1_IT_HT7: DMA1 Channel7 half transfer interrupt.
  525. * @arg DMA1_IT_TE7: DMA1 Channel7 transfer error interrupt.
  526. * @arg DMA2_IT_GL1: DMA2 Channel1 global interrupt.
  527. * @arg DMA2_IT_TC1: DMA2 Channel1 transfer complete interrupt.
  528. * @arg DMA2_IT_HT1: DMA2 Channel1 half transfer interrupt.
  529. * @arg DMA2_IT_TE1: DMA2 Channel1 transfer error interrupt.
  530. * @arg DMA2_IT_GL2: DMA2 Channel2 global interrupt.
  531. * @arg DMA2_IT_TC2: DMA2 Channel2 transfer complete interrupt.
  532. * @arg DMA2_IT_HT2: DMA2 Channel2 half transfer interrupt.
  533. * @arg DMA2_IT_TE2: DMA2 Channel2 transfer error interrupt.
  534. * @arg DMA2_IT_GL3: DMA2 Channel3 global interrupt.
  535. * @arg DMA2_IT_TC3: DMA2 Channel3 transfer complete interrupt.
  536. * @arg DMA2_IT_HT3: DMA2 Channel3 half transfer interrupt.
  537. * @arg DMA2_IT_TE3: DMA2 Channel3 transfer error interrupt.
  538. * @arg DMA2_IT_GL4: DMA2 Channel4 global interrupt.
  539. * @arg DMA2_IT_TC4: DMA2 Channel4 transfer complete interrupt.
  540. * @arg DMA2_IT_HT4: DMA2 Channel4 half transfer interrupt.
  541. * @arg DMA2_IT_TE4: DMA2 Channel4 transfer error interrupt.
  542. * @arg DMA2_IT_GL5: DMA2 Channel5 global interrupt.
  543. * @arg DMA2_IT_TC5: DMA2 Channel5 transfer complete interrupt.
  544. * @arg DMA2_IT_HT5: DMA2 Channel5 half transfer interrupt.
  545. * @arg DMA2_IT_TE5: DMA2 Channel5 transfer error interrupt.
  546. * @retval The new state of DMAy_IT (SET or RESET).
  547. */
  548. ITStatus DMA_GetITStatus(uint32_t DMAy_IT)
  549. {
  550. ITStatus bitstatus = RESET;
  551. uint32_t tmpreg = 0;
  552. /* Check the parameters */
  553. assert_param(IS_DMA_GET_IT(DMAy_IT));
  554. /* Calculate the used DMA */
  555. if ((DMAy_IT & FLAG_Mask) != (uint32_t)RESET)
  556. {
  557. /* Get DMA2 ISR register value */
  558. tmpreg = DMA2->ISR;
  559. }
  560. else
  561. {
  562. /* Get DMA1 ISR register value */
  563. tmpreg = DMA1->ISR;
  564. }
  565. /* Check the status of the specified DMAy interrupt */
  566. if ((tmpreg & DMAy_IT) != (uint32_t)RESET)
  567. {
  568. /* DMAy_IT is set */
  569. bitstatus = SET;
  570. }
  571. else
  572. {
  573. /* DMAy_IT is reset */
  574. bitstatus = RESET;
  575. }
  576. /* Return the DMA_IT status */
  577. return bitstatus;
  578. }
  579. /**
  580. * @brief Clears the DMAy Channelx's interrupt pending bits.
  581. * @param DMAy_IT: specifies the DMAy interrupt pending bit to clear.
  582. * This parameter can be any combination (for the same DMA) of the following values:
  583. * @arg DMA1_IT_GL1: DMA1 Channel1 global interrupt.
  584. * @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
  585. * @arg DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.
  586. * @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
  587. * @arg DMA1_IT_GL2: DMA1 Channel2 global interrupt.
  588. * @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
  589. * @arg DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.
  590. * @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
  591. * @arg DMA1_IT_GL3: DMA1 Channel3 global interrupt.
  592. * @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
  593. * @arg DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.
  594. * @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
  595. * @arg DMA1_IT_GL4: DMA1 Channel4 global interrupt.
  596. * @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
  597. * @arg DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.
  598. * @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
  599. * @arg DMA1_IT_GL5: DMA1 Channel5 global interrupt.
  600. * @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
  601. * @arg DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.
  602. * @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
  603. * @arg DMA1_IT_GL6: DMA1 Channel6 global interrupt.
  604. * @arg DMA1_IT_TC6: DMA1 Channel6 transfer complete interrupt.
  605. * @arg DMA1_IT_HT6: DMA1 Channel6 half transfer interrupt.
  606. * @arg DMA1_IT_TE6: DMA1 Channel6 transfer error interrupt.
  607. * @arg DMA1_IT_GL7: DMA1 Channel7 global interrupt.
  608. * @arg DMA1_IT_TC7: DMA1 Channel7 transfer complete interrupt.
  609. * @arg DMA1_IT_HT7: DMA1 Channel7 half transfer interrupt.
  610. * @arg DMA1_IT_TE7: DMA1 Channel7 transfer error interrupt.
  611. * @arg DMA2_IT_GL1: DMA2 Channel1 global interrupt.
  612. * @arg DMA2_IT_TC1: DMA2 Channel1 transfer complete interrupt.
  613. * @arg DMA2_IT_HT1: DMA2 Channel1 half transfer interrupt.
  614. * @arg DMA2_IT_TE1: DMA2 Channel1 transfer error interrupt.
  615. * @arg DMA2_IT_GL2: DMA2 Channel2 global interrupt.
  616. * @arg DMA2_IT_TC2: DMA2 Channel2 transfer complete interrupt.
  617. * @arg DMA2_IT_HT2: DMA2 Channel2 half transfer interrupt.
  618. * @arg DMA2_IT_TE2: DMA2 Channel2 transfer error interrupt.
  619. * @arg DMA2_IT_GL3: DMA2 Channel3 global interrupt.
  620. * @arg DMA2_IT_TC3: DMA2 Channel3 transfer complete interrupt.
  621. * @arg DMA2_IT_HT3: DMA2 Channel3 half transfer interrupt.
  622. * @arg DMA2_IT_TE3: DMA2 Channel3 transfer error interrupt.
  623. * @arg DMA2_IT_GL4: DMA2 Channel4 global interrupt.
  624. * @arg DMA2_IT_TC4: DMA2 Channel4 transfer complete interrupt.
  625. * @arg DMA2_IT_HT4: DMA2 Channel4 half transfer interrupt.
  626. * @arg DMA2_IT_TE4: DMA2 Channel4 transfer error interrupt.
  627. * @arg DMA2_IT_GL5: DMA2 Channel5 global interrupt.
  628. * @arg DMA2_IT_TC5: DMA2 Channel5 transfer complete interrupt.
  629. * @arg DMA2_IT_HT5: DMA2 Channel5 half transfer interrupt.
  630. * @arg DMA2_IT_TE5: DMA2 Channel5 transfer error interrupt.
  631. * @retval None
  632. */
  633. void DMA_ClearITPendingBit(uint32_t DMAy_IT)
  634. {
  635. /* Check the parameters */
  636. assert_param(IS_DMA_CLEAR_IT(DMAy_IT));
  637. /* Calculate the used DMAy */
  638. if ((DMAy_IT & FLAG_Mask) != (uint32_t)RESET)
  639. {
  640. /* Clear the selected DMAy interrupt pending bits */
  641. DMA2->IFCR = DMAy_IT;
  642. }
  643. else
  644. {
  645. /* Clear the selected DMAy interrupt pending bits */
  646. DMA1->IFCR = DMAy_IT;
  647. }
  648. }
  649. /**
  650. * @}
  651. */
  652. /**
  653. * @}
  654. */
  655. /**
  656. * @}
  657. */
  658. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/