stm32f10x_dma.c 27 KB

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