stm32f0xx_dma.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_dma.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 23-March-2012
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the Direct Memory Access controller (DMA):
  9. * + Initialization and Configuration
  10. * + Data Counter
  11. * + Interrupts and flags management
  12. *
  13. * @verbatim
  14. ==============================================================================
  15. ##### How to use this driver #####
  16. ==============================================================================
  17. [..]
  18. (#) Enable The DMA controller clock using
  19. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE) function for DMA1.
  20. (#) Enable and configure the peripheral to be connected to the DMA channel
  21. (except for internal SRAM / FLASH memories: no initialization is necessary).
  22. (#) For a given Channel, program the Source and Destination addresses,
  23. the transfer Direction, the Buffer Size, the Peripheral and Memory
  24. Incrementation mode and Data Size, the Circular or Normal mode,
  25. the channel transfer Priority and the Memory-to-Memory transfer
  26. mode (if needed) using the DMA_Init() function.
  27. (#) Enable the NVIC and the corresponding interrupt(s) using the function
  28. DMA_ITConfig() if you need to use DMA interrupts.
  29. (#) Enable the DMA channel using the DMA_Cmd() function.
  30. (#) Activate the needed channel Request using PPP_DMACmd() function for
  31. any PPP peripheral except internal SRAM and FLASH (ie. SPI, USART ...)
  32. The function allowing this operation is provided in each PPP peripheral
  33. driver (ie. SPI_DMACmd for SPI peripheral).
  34. (#) Optionally, you can configure the number of data to be transferred
  35. when the channel is disabled (ie. after each Transfer Complete event
  36. or when a Transfer Error occurs) using the function DMA_SetCurrDataCounter().
  37. And you can get the number of remaining data to be transferred using
  38. the function DMA_GetCurrDataCounter() at run time (when the DMA channel is
  39. enabled and running).
  40. (#) To control DMA events you can use one of the following two methods:
  41. (##) Check on DMA channel flags using the function DMA_GetFlagStatus().
  42. (##) Use DMA interrupts through the function DMA_ITConfig() at initialization
  43. phase and DMA_GetITStatus() function into interrupt routines in
  44. communication phase.
  45. After checking on a flag you should clear it using DMA_ClearFlag()
  46. function. And after checking on an interrupt event you should
  47. clear it using DMA_ClearITPendingBit() function.
  48. @endverbatim
  49. *
  50. ******************************************************************************
  51. * @attention
  52. *
  53. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  54. *
  55. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  56. * You may not use this file except in compliance with the License.
  57. * You may obtain a copy of the License at:
  58. *
  59. * http://www.st.com/software_license_agreement_liberty_v2
  60. *
  61. * Unless required by applicable law or agreed to in writing, software
  62. * distributed under the License is distributed on an "AS IS" BASIS,
  63. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  64. * See the License for the specific language governing permissions and
  65. * limitations under the License.
  66. *
  67. ******************************************************************************
  68. */
  69. /* Includes ------------------------------------------------------------------*/
  70. #include "stm32f0xx_dma.h"
  71. /** @addtogroup STM32F0xx_StdPeriph_Driver
  72. * @{
  73. */
  74. /** @defgroup DMA
  75. * @brief DMA driver modules
  76. * @{
  77. */
  78. /* Private typedef -----------------------------------------------------------*/
  79. /* Private define ------------------------------------------------------------*/
  80. #define CCR_CLEAR_MASK ((uint32_t)0xFFFF800F) /* DMA Channel config registers Masks */
  81. /* DMA1 Channelx interrupt pending bit masks */
  82. #define DMA1_CHANNEL1_IT_MASK ((uint32_t)(DMA_ISR_GIF1 | DMA_ISR_TCIF1 | DMA_ISR_HTIF1 | DMA_ISR_TEIF1))
  83. #define DMA1_CHANNEL2_IT_MASK ((uint32_t)(DMA_ISR_GIF2 | DMA_ISR_TCIF2 | DMA_ISR_HTIF2 | DMA_ISR_TEIF2))
  84. #define DMA1_CHANNEL3_IT_MASK ((uint32_t)(DMA_ISR_GIF3 | DMA_ISR_TCIF3 | DMA_ISR_HTIF3 | DMA_ISR_TEIF3))
  85. #define DMA1_CHANNEL4_IT_MASK ((uint32_t)(DMA_ISR_GIF4 | DMA_ISR_TCIF4 | DMA_ISR_HTIF4 | DMA_ISR_TEIF4))
  86. #define DMA1_CHANNEL5_IT_MASK ((uint32_t)(DMA_ISR_GIF5 | DMA_ISR_TCIF5 | DMA_ISR_HTIF5 | DMA_ISR_TEIF5))
  87. /* Private macro -------------------------------------------------------------*/
  88. /* Private variables ---------------------------------------------------------*/
  89. /* Private function prototypes -----------------------------------------------*/
  90. /* Private functions ---------------------------------------------------------*/
  91. /** @defgroup DMA_Private_Functions
  92. * @{
  93. */
  94. /** @defgroup DMA_Group1 Initialization and Configuration functions
  95. * @brief Initialization and Configuration functions
  96. *
  97. @verbatim
  98. ===============================================================================
  99. ##### Initialization and Configuration functions #####
  100. ===============================================================================
  101. [..] This subsection provides functions allowing to initialize the DMA channel
  102. source and destination addresses, incrementation and data sizes, transfer
  103. direction, buffer size, circular/normal mode selection, memory-to-memory
  104. mode selection and channel priority value.
  105. [..] The DMA_Init() function follows the DMA configuration procedures as described
  106. in reference manual (RM0091).
  107. @endverbatim
  108. * @{
  109. */
  110. /**
  111. * @brief Deinitializes the DMAy Channelx registers to their default reset
  112. * values.
  113. * @param DMAy_Channelx: where y can be 1 to select the DMA and
  114. * x can be 1 to 5 for DMA1 to select the DMA Channel.
  115. * @retval None
  116. */
  117. void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx)
  118. {
  119. /* Check the parameters */
  120. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  121. /* Disable the selected DMAy Channelx */
  122. DMAy_Channelx->CCR &= (uint16_t)(~DMA_CCR_EN);
  123. /* Reset DMAy Channelx control register */
  124. DMAy_Channelx->CCR = 0;
  125. /* Reset DMAy Channelx remaining bytes register */
  126. DMAy_Channelx->CNDTR = 0;
  127. /* Reset DMAy Channelx peripheral address register */
  128. DMAy_Channelx->CPAR = 0;
  129. /* Reset DMAy Channelx memory address register */
  130. DMAy_Channelx->CMAR = 0;
  131. if (DMAy_Channelx == DMA1_Channel1)
  132. {
  133. /* Reset interrupt pending bits for DMA1 Channel1 */
  134. DMA1->IFCR |= DMA1_CHANNEL1_IT_MASK;
  135. }
  136. else if (DMAy_Channelx == DMA1_Channel2)
  137. {
  138. /* Reset interrupt pending bits for DMA1 Channel2 */
  139. DMA1->IFCR |= DMA1_CHANNEL2_IT_MASK;
  140. }
  141. else if (DMAy_Channelx == DMA1_Channel3)
  142. {
  143. /* Reset interrupt pending bits for DMA1 Channel3 */
  144. DMA1->IFCR |= DMA1_CHANNEL3_IT_MASK;
  145. }
  146. else if (DMAy_Channelx == DMA1_Channel4)
  147. {
  148. /* Reset interrupt pending bits for DMA1 Channel4 */
  149. DMA1->IFCR |= DMA1_CHANNEL4_IT_MASK;
  150. }
  151. else
  152. {
  153. if (DMAy_Channelx == DMA1_Channel5)
  154. {
  155. /* Reset interrupt pending bits for DMA1 Channel5 */
  156. DMA1->IFCR |= DMA1_CHANNEL5_IT_MASK;
  157. }
  158. }
  159. }
  160. /**
  161. * @brief Initializes the DMAy Channelx according to the specified parameters
  162. * in the DMA_InitStruct.
  163. * @param DMAy_Channelx: where y can be 1 to select the DMA and x can be 1 to 5
  164. * for DMA1 to select the DMA Channel.
  165. * @param DMA_InitStruct: pointer to a DMA_InitTypeDef structure that contains
  166. * the configuration information for the specified DMA Channel.
  167. * @retval None
  168. */
  169. void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct)
  170. {
  171. uint32_t tmpreg = 0;
  172. /* Check the parameters */
  173. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  174. assert_param(IS_DMA_DIR(DMA_InitStruct->DMA_DIR));
  175. assert_param(IS_DMA_BUFFER_SIZE(DMA_InitStruct->DMA_BufferSize));
  176. assert_param(IS_DMA_PERIPHERAL_INC_STATE(DMA_InitStruct->DMA_PeripheralInc));
  177. assert_param(IS_DMA_MEMORY_INC_STATE(DMA_InitStruct->DMA_MemoryInc));
  178. assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(DMA_InitStruct->DMA_PeripheralDataSize));
  179. assert_param(IS_DMA_MEMORY_DATA_SIZE(DMA_InitStruct->DMA_MemoryDataSize));
  180. assert_param(IS_DMA_MODE(DMA_InitStruct->DMA_Mode));
  181. assert_param(IS_DMA_PRIORITY(DMA_InitStruct->DMA_Priority));
  182. assert_param(IS_DMA_M2M_STATE(DMA_InitStruct->DMA_M2M));
  183. /*--------------------------- DMAy Channelx CCR Configuration ----------------*/
  184. /* Get the DMAy_Channelx CCR value */
  185. tmpreg = DMAy_Channelx->CCR;
  186. /* Clear MEM2MEM, PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */
  187. tmpreg &= CCR_CLEAR_MASK;
  188. /* Configure DMAy Channelx: data transfer, data size, priority level and mode */
  189. /* Set DIR bit according to DMA_DIR value */
  190. /* Set CIRC bit according to DMA_Mode value */
  191. /* Set PINC bit according to DMA_PeripheralInc value */
  192. /* Set MINC bit according to DMA_MemoryInc value */
  193. /* Set PSIZE bits according to DMA_PeripheralDataSize value */
  194. /* Set MSIZE bits according to DMA_MemoryDataSize value */
  195. /* Set PL bits according to DMA_Priority value */
  196. /* Set the MEM2MEM bit according to DMA_M2M value */
  197. tmpreg |= DMA_InitStruct->DMA_DIR | DMA_InitStruct->DMA_Mode |
  198. DMA_InitStruct->DMA_PeripheralInc | DMA_InitStruct->DMA_MemoryInc |
  199. DMA_InitStruct->DMA_PeripheralDataSize | DMA_InitStruct->DMA_MemoryDataSize |
  200. DMA_InitStruct->DMA_Priority | DMA_InitStruct->DMA_M2M;
  201. /* Write to DMAy Channelx CCR */
  202. DMAy_Channelx->CCR = tmpreg;
  203. /*--------------------------- DMAy Channelx CNDTR Configuration --------------*/
  204. /* Write to DMAy Channelx CNDTR */
  205. DMAy_Channelx->CNDTR = DMA_InitStruct->DMA_BufferSize;
  206. /*--------------------------- DMAy Channelx CPAR Configuration ---------------*/
  207. /* Write to DMAy Channelx CPAR */
  208. DMAy_Channelx->CPAR = DMA_InitStruct->DMA_PeripheralBaseAddr;
  209. /*--------------------------- DMAy Channelx CMAR Configuration ---------------*/
  210. /* Write to DMAy Channelx CMAR */
  211. DMAy_Channelx->CMAR = DMA_InitStruct->DMA_MemoryBaseAddr;
  212. }
  213. /**
  214. * @brief Fills each DMA_InitStruct member with its default value.
  215. * @param DMA_InitStruct: pointer to a DMA_InitTypeDef structure which will
  216. * be initialized.
  217. * @retval None
  218. */
  219. void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct)
  220. {
  221. /*-------------- Reset DMA init structure parameters values ------------------*/
  222. /* Initialize the DMA_PeripheralBaseAddr member */
  223. DMA_InitStruct->DMA_PeripheralBaseAddr = 0;
  224. /* Initialize the DMA_MemoryBaseAddr member */
  225. DMA_InitStruct->DMA_MemoryBaseAddr = 0;
  226. /* Initialize the DMA_DIR member */
  227. DMA_InitStruct->DMA_DIR = DMA_DIR_PeripheralSRC;
  228. /* Initialize the DMA_BufferSize member */
  229. DMA_InitStruct->DMA_BufferSize = 0;
  230. /* Initialize the DMA_PeripheralInc member */
  231. DMA_InitStruct->DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  232. /* Initialize the DMA_MemoryInc member */
  233. DMA_InitStruct->DMA_MemoryInc = DMA_MemoryInc_Disable;
  234. /* Initialize the DMA_PeripheralDataSize member */
  235. DMA_InitStruct->DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  236. /* Initialize the DMA_MemoryDataSize member */
  237. DMA_InitStruct->DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  238. /* Initialize the DMA_Mode member */
  239. DMA_InitStruct->DMA_Mode = DMA_Mode_Normal;
  240. /* Initialize the DMA_Priority member */
  241. DMA_InitStruct->DMA_Priority = DMA_Priority_Low;
  242. /* Initialize the DMA_M2M member */
  243. DMA_InitStruct->DMA_M2M = DMA_M2M_Disable;
  244. }
  245. /**
  246. * @brief Enables or disables the specified DMAy Channelx.
  247. * @param DMAy_Channelx: where y can be 1 to select the DMA and
  248. * x can be 1 to 5 for DMA1 to select the DMA Channel.
  249. * @param NewState: new state of the DMAy Channelx.
  250. * This parameter can be: ENABLE or DISABLE.
  251. * @retval None
  252. */
  253. void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState)
  254. {
  255. /* Check the parameters */
  256. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  257. assert_param(IS_FUNCTIONAL_STATE(NewState));
  258. if (NewState != DISABLE)
  259. {
  260. /* Enable the selected DMAy Channelx */
  261. DMAy_Channelx->CCR |= DMA_CCR_EN;
  262. }
  263. else
  264. {
  265. /* Disable the selected DMAy Channelx */
  266. DMAy_Channelx->CCR &= (uint16_t)(~DMA_CCR_EN);
  267. }
  268. }
  269. /**
  270. * @}
  271. */
  272. /** @defgroup DMA_Group2 Data Counter functions
  273. * @brief Data Counter functions
  274. *
  275. @verbatim
  276. ===============================================================================
  277. ##### Data Counter functions #####
  278. ===============================================================================
  279. [..] This subsection provides function allowing to configure and read the buffer
  280. size (number of data to be transferred).The DMA data counter can be written
  281. only when the DMA channel is disabled (ie. after transfer complete event).
  282. [..] The following function can be used to write the Channel data counter value:
  283. (+) void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t
  284. DataNumber).
  285. -@- It is advised to use this function rather than DMA_Init() in situations
  286. where only the Data buffer needs to be reloaded.
  287. [..] The DMA data counter can be read to indicate the number of remaining transfers
  288. for the relative DMA channel. This counter is decremented at the end of each
  289. data transfer and when the transfer is complete:
  290. (+) If Normal mode is selected: the counter is set to 0.
  291. (+) If Circular mode is selected: the counter is reloaded with the initial
  292. value(configured before enabling the DMA channel).
  293. [..] The following function can be used to read the Channel data counter value:
  294. (+) uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx).
  295. @endverbatim
  296. * @{
  297. */
  298. /**
  299. * @brief Sets the number of data units in the current DMAy Channelx transfer.
  300. * @param DMAy_Channelx: where y can be 1 to select the DMA and x can be
  301. * 1 to 5 for DMA1 to select the DMA Channel.
  302. * @param DataNumber: The number of data units in the current DMAy Channelx
  303. * transfer.
  304. * @note This function can only be used when the DMAy_Channelx is disabled.
  305. * @retval None.
  306. */
  307. void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber)
  308. {
  309. /* Check the parameters */
  310. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  311. /*--------------------------- DMAy Channelx CNDTR Configuration --------------*/
  312. /* Write to DMAy Channelx CNDTR */
  313. DMAy_Channelx->CNDTR = DataNumber;
  314. }
  315. /**
  316. * @brief Returns the number of remaining data units in the current
  317. * DMAy Channelx transfer.
  318. * @param DMAy_Channelx: where y can be 1 to select the DMA and
  319. * x can be 1 to 5 for DMA1 to select the DMA Channel.
  320. * @retval The number of remaining data units in the current DMAy Channelx
  321. * transfer.
  322. */
  323. uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx)
  324. {
  325. /* Check the parameters */
  326. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  327. /* Return the number of remaining data units for DMAy Channelx */
  328. return ((uint16_t)(DMAy_Channelx->CNDTR));
  329. }
  330. /**
  331. * @}
  332. */
  333. /** @defgroup DMA_Group3 Interrupts and flags management functions
  334. * @brief Interrupts and flags management functions
  335. *
  336. @verbatim
  337. ===============================================================================
  338. ##### Interrupts and flags management functions #####
  339. ===============================================================================
  340. [..] This subsection provides functions allowing to configure the DMA Interrupts
  341. sources and check or clear the flags or pending bits status.
  342. The user should identify which mode will be used in his application to manage
  343. the DMA controller events: Polling mode or Interrupt mode.
  344. *** Polling Mode ***
  345. ====================
  346. [..] Each DMA channel can be managed through 4 event Flags:(y : DMA Controller
  347. number x : DMA channel number ).
  348. (#) DMAy_FLAG_TCx : to indicate that a Transfer Complete event occurred.
  349. (#) DMAy_FLAG_HTx : to indicate that a Half-Transfer Complete event occurred.
  350. (#) DMAy_FLAG_TEx : to indicate that a Transfer Error occurred.
  351. (#) DMAy_FLAG_GLx : to indicate that at least one of the events described
  352. above occurred.
  353. -@- Clearing DMAy_FLAG_GLx results in clearing all other pending flags of the
  354. same channel (DMAy_FLAG_TCx, DMAy_FLAG_HTx and DMAy_FLAG_TEx).
  355. [..]In this Mode it is advised to use the following functions:
  356. (+) FlagStatus DMA_GetFlagStatus(uint32_t DMA_FLAG);
  357. (+) void DMA_ClearFlag(uint32_t DMA_FLAG);
  358. *** Interrupt Mode ***
  359. ======================
  360. [..] Each DMA channel can be managed through 4 Interrupts:
  361. (+) Interrupt Source
  362. (##) DMA_IT_TC: specifies the interrupt source for the Transfer Complete
  363. event.
  364. (##) DMA_IT_HT : specifies the interrupt source for the Half-transfer Complete
  365. event.
  366. (##) DMA_IT_TE : specifies the interrupt source for the transfer errors event.
  367. (##) DMA_IT_GL : to indicate that at least one of the interrupts described
  368. above occurred.
  369. -@@- Clearing DMA_IT_GL interrupt results in clearing all other interrupts of
  370. the same channel (DMA_IT_TCx, DMA_IT_HT and DMA_IT_TE).
  371. [..]In this Mode it is advised to use the following functions:
  372. (+) void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT,
  373. FunctionalState NewState);
  374. (+) ITStatus DMA_GetITStatus(uint32_t DMA_IT);
  375. (+) void DMA_ClearITPendingBit(uint32_t DMA_IT);
  376. @endverbatim
  377. * @{
  378. */
  379. /**
  380. * @brief Enables or disables the specified DMAy Channelx interrupts.
  381. * @param DMAy_Channelx: where y can be 1 to select the DMA and
  382. * x can be 1 to 5 for DMA1 to select the DMA Channel.
  383. * @param DMA_IT: specifies the DMA interrupts sources to be enabled
  384. * or disabled.
  385. * This parameter can be any combination of the following values:
  386. * @arg DMA_IT_TC: Transfer complete interrupt mask
  387. * @arg DMA_IT_HT: Half transfer interrupt mask
  388. * @arg DMA_IT_TE: Transfer error interrupt mask
  389. * @param NewState: new state of the specified DMA interrupts.
  390. * This parameter can be: ENABLE or DISABLE.
  391. * @retval None
  392. */
  393. void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState)
  394. {
  395. /* Check the parameters */
  396. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  397. assert_param(IS_DMA_CONFIG_IT(DMA_IT));
  398. assert_param(IS_FUNCTIONAL_STATE(NewState));
  399. if (NewState != DISABLE)
  400. {
  401. /* Enable the selected DMA interrupts */
  402. DMAy_Channelx->CCR |= DMA_IT;
  403. }
  404. else
  405. {
  406. /* Disable the selected DMA interrupts */
  407. DMAy_Channelx->CCR &= ~DMA_IT;
  408. }
  409. }
  410. /**
  411. * @brief Checks whether the specified DMAy Channelx flag is set or not.
  412. * @param DMA_FLAG: specifies the flag to check.
  413. * This parameter can be one of the following values:
  414. * @arg DMA1_FLAG_GL1: DMA1 Channel1 global flag.
  415. * @arg DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
  416. * @arg DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
  417. * @arg DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
  418. * @arg DMA1_FLAG_GL2: DMA1 Channel2 global flag.
  419. * @arg DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
  420. * @arg DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
  421. * @arg DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
  422. * @arg DMA1_FLAG_GL3: DMA1 Channel3 global flag.
  423. * @arg DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
  424. * @arg DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
  425. * @arg DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
  426. * @arg DMA1_FLAG_GL4: DMA1 Channel4 global flag.
  427. * @arg DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
  428. * @arg DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
  429. * @arg DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
  430. * @arg DMA1_FLAG_GL5: DMA1 Channel5 global flag.
  431. * @arg DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
  432. * @arg DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
  433. * @arg DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
  434. *
  435. * @note
  436. * The Global flag (DMAy_FLAG_GLx) is set whenever any of the other flags
  437. * relative to the same channel is set (Transfer Complete, Half-transfer
  438. * Complete or Transfer Error flags: DMAy_FLAG_TCx, DMAy_FLAG_HTx or
  439. * DMAy_FLAG_TEx).
  440. *
  441. * @retval The new state of DMA_FLAG (SET or RESET).
  442. */
  443. FlagStatus DMA_GetFlagStatus(uint32_t DMA_FLAG)
  444. {
  445. FlagStatus bitstatus = RESET;
  446. /* Check the parameters */
  447. assert_param(IS_DMA_GET_FLAG(DMA_FLAG));
  448. /* Check the status of the specified DMA flag */
  449. if ((DMA1->ISR & DMA_FLAG) != (uint32_t)RESET)
  450. {
  451. /* DMA_FLAG is set */
  452. bitstatus = SET;
  453. }
  454. else
  455. {
  456. /* DMA_FLAG is reset */
  457. bitstatus = RESET;
  458. }
  459. /* Return the DMA_FLAG status */
  460. return bitstatus;
  461. }
  462. /**
  463. * @brief Clears the DMAy Channelx's pending flags.
  464. * @param DMA_FLAG: specifies the flag to clear.
  465. * This parameter can be any combination (for the same DMA) of the following values:
  466. * @arg DMA1_FLAG_GL1: DMA1 Channel1 global flag.
  467. * @arg DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
  468. * @arg DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
  469. * @arg DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
  470. * @arg DMA1_FLAG_GL2: DMA1 Channel2 global flag.
  471. * @arg DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
  472. * @arg DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
  473. * @arg DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
  474. * @arg DMA1_FLAG_GL3: DMA1 Channel3 global flag.
  475. * @arg DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
  476. * @arg DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
  477. * @arg DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
  478. * @arg DMA1_FLAG_GL4: DMA1 Channel4 global flag.
  479. * @arg DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
  480. * @arg DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
  481. * @arg DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
  482. * @arg DMA1_FLAG_GL5: DMA1 Channel5 global flag.
  483. * @arg DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
  484. * @arg DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
  485. * @arg DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
  486. *
  487. * @note
  488. * Clearing the Global flag (DMAy_FLAG_GLx) results in clearing all other flags
  489. * relative to the same channel (Transfer Complete, Half-transfer Complete and
  490. * Transfer Error flags: DMAy_FLAG_TCx, DMAy_FLAG_HTx and DMAy_FLAG_TEx).
  491. *
  492. * @retval None
  493. */
  494. void DMA_ClearFlag(uint32_t DMA_FLAG)
  495. {
  496. /* Check the parameters */
  497. assert_param(IS_DMA_CLEAR_FLAG(DMA_FLAG));
  498. /* Clear the selected DMA flags */
  499. DMA1->IFCR = DMA_FLAG;
  500. }
  501. /**
  502. * @brief Checks whether the specified DMAy Channelx interrupt has occurred or not.
  503. * @param DMA_IT: specifies the DMA interrupt source to check.
  504. * This parameter can be one of the following values:
  505. * @arg DMA1_IT_GL1: DMA1 Channel1 global interrupt.
  506. * @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
  507. * @arg DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.
  508. * @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
  509. * @arg DMA1_IT_GL2: DMA1 Channel2 global interrupt.
  510. * @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
  511. * @arg DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.
  512. * @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
  513. * @arg DMA1_IT_GL3: DMA1 Channel3 global interrupt.
  514. * @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
  515. * @arg DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.
  516. * @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
  517. * @arg DMA1_IT_GL4: DMA1 Channel4 global interrupt.
  518. * @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
  519. * @arg DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.
  520. * @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
  521. * @arg DMA1_IT_GL5: DMA1 Channel5 global interrupt.
  522. * @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
  523. * @arg DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.
  524. * @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
  525. *
  526. * @note
  527. * The Global interrupt (DMAy_FLAG_GLx) is set whenever any of the other
  528. * interrupts relative to the same channel is set (Transfer Complete,
  529. * Half-transfer Complete or Transfer Error interrupts: DMAy_IT_TCx,
  530. * DMAy_IT_HTx or DMAy_IT_TEx).
  531. *
  532. * @retval The new state of DMA_IT (SET or RESET).
  533. */
  534. ITStatus DMA_GetITStatus(uint32_t DMA_IT)
  535. {
  536. ITStatus bitstatus = RESET;
  537. /* Check the parameters */
  538. assert_param(IS_DMA_GET_IT(DMA_IT));
  539. /* Check the status of the specified DMA interrupt */
  540. if ((DMA1->ISR & DMA_IT) != (uint32_t)RESET)
  541. {
  542. /* DMA_IT is set */
  543. bitstatus = SET;
  544. }
  545. else
  546. {
  547. /* DMA_IT is reset */
  548. bitstatus = RESET;
  549. }
  550. /* Return the DMA_IT status */
  551. return bitstatus;
  552. }
  553. /**
  554. * @brief Clears the DMAy Channelx's interrupt pending bits.
  555. * @param DMA_IT: specifies the DMA interrupt pending bit to clear.
  556. * This parameter can be any combination (for the same DMA) of the following values:
  557. * @arg DMA1_IT_GL1: DMA1 Channel1 global interrupt.
  558. * @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
  559. * @arg DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.
  560. * @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
  561. * @arg DMA1_IT_GL2: DMA1 Channel2 global interrupt.
  562. * @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
  563. * @arg DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.
  564. * @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
  565. * @arg DMA1_IT_GL3: DMA1 Channel3 global interrupt.
  566. * @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
  567. * @arg DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.
  568. * @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
  569. * @arg DMA1_IT_GL4: DMA1 Channel4 global interrupt.
  570. * @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
  571. * @arg DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.
  572. * @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
  573. * @arg DMA1_IT_GL5: DMA1 Channel5 global interrupt.
  574. * @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
  575. * @arg DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.
  576. * @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
  577. *
  578. * @note
  579. * Clearing the Global interrupt (DMAy_IT_GLx) results in clearing all other
  580. * interrupts relative to the same channel (Transfer Complete, Half-transfer
  581. * Complete and Transfer Error interrupts: DMAy_IT_TCx, DMAy_IT_HTx and
  582. * DMAy_IT_TEx).
  583. *
  584. * @retval None
  585. */
  586. void DMA_ClearITPendingBit(uint32_t DMA_IT)
  587. {
  588. /* Check the parameters */
  589. assert_param(IS_DMA_CLEAR_IT(DMA_IT));
  590. /* Clear the selected DMA interrupt pending bits */
  591. DMA1->IFCR = DMA_IT;
  592. }
  593. /**
  594. * @}
  595. */
  596. /**
  597. * @}
  598. */
  599. /**
  600. * @}
  601. */
  602. /**
  603. * @}
  604. */
  605. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/