ft32f0xx_dma.c 28 KB

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