Merge branch 'master' of https://github.com/texane/stlink
[fw/stlink] / example / libstm32l_discovery / src / stm32l1xx_dma.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32l1xx_dma.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0\r
6   * @date    31-December-2010\r
7   * @brief   This file provides firmware functions to manage the following \r
8   *          functionalities of the Direct Memory Access controller (DMA):           \r
9   *           - Initialization and Configuration\r
10   *           - Data Counter\r
11   *           - Interrupts and flags management\r
12   *           \r
13   *  @verbatim\r
14   *      \r
15   *          ===================================================================      \r
16   *                                 How to use this driver\r
17   *          =================================================================== \r
18   *          1. Enable The DMA controller clock using RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE)\r
19   *             function for DMA1 or using RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE)\r
20   *             function for DMA2.\r
21   *\r
22   *          2. Enable and configure the peripheral to be connected to the DMA channel\r
23   *             (except for internal SRAM / FLASH memories: no initialization is \r
24   *             necessary). \r
25   *        \r
26   *          3. For a given Channel, program the Source and Destination addresses,  \r
27   *             the transfer Direction, the Buffer Size, the Peripheral and Memory\r
28   *             Incrementation mode and Data Size, the Circular or Normal mode, \r
29   *             the channel transfer Priority and the Memory-to-Memory transfer \r
30   *             mode (if needed) using the DMA_Init() function.\r
31   *\r
32   *          4. Enable the NVIC and the corresponding interrupt(s) using the function \r
33   *             DMA_ITConfig() if you need to use DMA interrupts. \r
34   *\r
35   *          5. Enable the DMA channel using the DMA_Cmd() function. \r
36   *                \r
37   *          6. Activate the needed channel Request using PPP_DMACmd() function for\r
38   *             any PPP peripheral except internal SRAM and FLASH (ie. SPI, USART ...)\r
39   *             The function allowing this operation is provided in each PPP peripheral\r
40   *             driver (ie. SPI_DMACmd for SPI peripheral).     \r
41   *\r
42   *          7. Optionally, you can configure the number of data to be transferred\r
43   *             when the channel is disabled (ie. after each Transfer Complete event\r
44   *             or when a Transfer Error occurs) using the function DMA_SetCurrDataCounter().\r
45   *             And you can get the number of remaining data to be transferred using \r
46   *             the function DMA_GetCurrDataCounter() at run time (when the DMA channel is\r
47   *             enabled and running).  \r
48   *                   \r
49   *          8. To control DMA events you can use one of the following \r
50   *              two methods:\r
51   *               a- Check on DMA channel flags using the function DMA_GetFlagStatus().  \r
52   *               b- Use DMA interrupts through the function DMA_ITConfig() at initialization\r
53   *                  phase and DMA_GetITStatus() function into interrupt routines in\r
54   *                  communication phase.  \r
55   *              After checking on a flag you should clear it using DMA_ClearFlag()\r
56   *              function. And after checking on an interrupt event you should \r
57   *              clear it using DMA_ClearITPendingBit() function.     \r
58   *                 \r
59   *  @endverbatim\r
60   *                                  \r
61   ******************************************************************************\r
62   * @attention\r
63   *\r
64   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
65   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
66   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
67   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
68   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
69   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
70   *\r
71   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>\r
72   ******************************************************************************  \r
73   */ \r
74 \r
75 /* Includes ------------------------------------------------------------------*/\r
76 #include "stm32l1xx_dma.h"\r
77 #include "stm32l1xx_rcc.h"\r
78 \r
79 /** @addtogroup STM32L1xx_StdPeriph_Driver\r
80   * @{\r
81   */\r
82 \r
83 /** @defgroup DMA \r
84   * @brief DMA driver modules\r
85   * @{\r
86   */ \r
87 \r
88 /* Private typedef -----------------------------------------------------------*/\r
89 /* Private define ------------------------------------------------------------*/\r
90 \r
91 /* DMA1 Channelx interrupt pending bit masks */\r
92 #define DMA1_CHANNEL1_IT_MASK    ((uint32_t)(DMA_ISR_GIF1 | DMA_ISR_TCIF1 | DMA_ISR_HTIF1 | DMA_ISR_TEIF1))\r
93 #define DMA1_CHANNEL2_IT_MASK    ((uint32_t)(DMA_ISR_GIF2 | DMA_ISR_TCIF2 | DMA_ISR_HTIF2 | DMA_ISR_TEIF2))\r
94 #define DMA1_CHANNEL3_IT_MASK    ((uint32_t)(DMA_ISR_GIF3 | DMA_ISR_TCIF3 | DMA_ISR_HTIF3 | DMA_ISR_TEIF3))\r
95 #define DMA1_CHANNEL4_IT_MASK    ((uint32_t)(DMA_ISR_GIF4 | DMA_ISR_TCIF4 | DMA_ISR_HTIF4 | DMA_ISR_TEIF4))\r
96 #define DMA1_CHANNEL5_IT_MASK    ((uint32_t)(DMA_ISR_GIF5 | DMA_ISR_TCIF5 | DMA_ISR_HTIF5 | DMA_ISR_TEIF5))\r
97 #define DMA1_CHANNEL6_IT_MASK    ((uint32_t)(DMA_ISR_GIF6 | DMA_ISR_TCIF6 | DMA_ISR_HTIF6 | DMA_ISR_TEIF6))\r
98 #define DMA1_CHANNEL7_IT_MASK    ((uint32_t)(DMA_ISR_GIF7 | DMA_ISR_TCIF7 | DMA_ISR_HTIF7 | DMA_ISR_TEIF7))\r
99 \r
100 /* DMA FLAG mask */\r
101 #define FLAG_MASK                ((uint32_t)0x10000000)\r
102 \r
103 /* DMA registers Masks */\r
104 #define CCR_CLEAR_MASK           ((uint32_t)0xFFFF800F)\r
105 \r
106 /* Private macro -------------------------------------------------------------*/\r
107 /* Private variables ---------------------------------------------------------*/\r
108 /* Private function prototypes -----------------------------------------------*/\r
109 /* Private functions ---------------------------------------------------------*/\r
110 \r
111 \r
112 /** @defgroup DMA_Private_Functions\r
113   * @{\r
114   */\r
115 \r
116 /** @defgroup DMA_Group1 Initialization and Configuration functions\r
117  *  @brief   Initialization and Configuration functions\r
118  *\r
119 @verbatim   \r
120  ===============================================================================\r
121                  Initialization and Configuration functions\r
122  ===============================================================================  \r
123 \r
124   This subsection provides functions allowing to initialize the DMA channel source\r
125   and destination addresses, incrementation and data sizes, transfer direction, \r
126   buffer size, circular/normal mode selection, memory-to-memory mode selection \r
127   and channel priority value.\r
128   \r
129   The DMA_Init() function follows the DMA configuration procedures as described in\r
130   reference manual (RM0038).\r
131 \r
132 @endverbatim\r
133   * @{\r
134   */\r
135   \r
136 /**\r
137   * @brief  Deinitializes the DMAy Channelx registers to their default reset\r
138   *         values.\r
139   * @param  DMAy_Channelx: where y can be 1 to select the DMA and\r
140   *         x can be 1 to 7 for DMA1 to select the DMA Channel.\r
141   * @retval None\r
142   */\r
143 void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx)\r
144 {\r
145   /* Check the parameters */\r
146   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));\r
147 \r
148   /* Disable the selected DMAy Channelx */\r
149   DMAy_Channelx->CCR &= (uint16_t)(~DMA_CCR1_EN);\r
150 \r
151   /* Reset DMAy Channelx control register */\r
152   DMAy_Channelx->CCR  = 0;\r
153   \r
154   /* Reset DMAy Channelx remaining bytes register */\r
155   DMAy_Channelx->CNDTR = 0;\r
156   \r
157   /* Reset DMAy Channelx peripheral address register */\r
158   DMAy_Channelx->CPAR  = 0;\r
159   \r
160   /* Reset DMAy Channelx memory address register */\r
161   DMAy_Channelx->CMAR = 0;\r
162   \r
163   if (DMAy_Channelx == DMA1_Channel1)\r
164   {\r
165     /* Reset interrupt pending bits for DMA1 Channel1 */\r
166     DMA1->IFCR |= DMA1_CHANNEL1_IT_MASK;\r
167   }\r
168   else if (DMAy_Channelx == DMA1_Channel2)\r
169   {\r
170     /* Reset interrupt pending bits for DMA1 Channel2 */\r
171     DMA1->IFCR |= DMA1_CHANNEL2_IT_MASK;\r
172   }\r
173   else if (DMAy_Channelx == DMA1_Channel3)\r
174   {\r
175     /* Reset interrupt pending bits for DMA1 Channel3 */\r
176     DMA1->IFCR |= DMA1_CHANNEL3_IT_MASK;\r
177   }\r
178   else if (DMAy_Channelx == DMA1_Channel4)\r
179   {\r
180     /* Reset interrupt pending bits for DMA1 Channel4 */\r
181     DMA1->IFCR |= DMA1_CHANNEL4_IT_MASK;\r
182   }\r
183   else if (DMAy_Channelx == DMA1_Channel5)\r
184   {\r
185     /* Reset interrupt pending bits for DMA1 Channel5 */\r
186     DMA1->IFCR |= DMA1_CHANNEL5_IT_MASK;\r
187   }\r
188   else if (DMAy_Channelx == DMA1_Channel6)\r
189   {\r
190     /* Reset interrupt pending bits for DMA1 Channel6 */\r
191     DMA1->IFCR |= DMA1_CHANNEL6_IT_MASK;\r
192   }\r
193   else\r
194   {\r
195     if (DMAy_Channelx == DMA1_Channel7)\r
196     {\r
197       /* Reset interrupt pending bits for DMA1 Channel7 */\r
198       DMA1->IFCR |= DMA1_CHANNEL7_IT_MASK;    \r
199     }\r
200   }\r
201 }\r
202 \r
203 /**\r
204   * @brief  Initializes the DMAy Channelx according to the specified\r
205   *         parameters in the DMA_InitStruct.\r
206   * @param  DMAy_Channelx: where y can be 1 to select the DMA and\r
207   *         x can be 1 to 7 for DMA1 to select the DMA Channel.\r
208   * @param  DMA_InitStruct: pointer to a DMA_InitTypeDef structure that\r
209   *         contains the configuration information for the specified DMA Channel.\r
210   * @retval None\r
211   */\r
212 void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct)\r
213 {\r
214   uint32_t tmpreg = 0;\r
215 \r
216   /* Check the parameters */\r
217   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));\r
218   assert_param(IS_DMA_DIR(DMA_InitStruct->DMA_DIR));\r
219   assert_param(IS_DMA_BUFFER_SIZE(DMA_InitStruct->DMA_BufferSize));\r
220   assert_param(IS_DMA_PERIPHERAL_INC_STATE(DMA_InitStruct->DMA_PeripheralInc));\r
221   assert_param(IS_DMA_MEMORY_INC_STATE(DMA_InitStruct->DMA_MemoryInc));   \r
222   assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(DMA_InitStruct->DMA_PeripheralDataSize));\r
223   assert_param(IS_DMA_MEMORY_DATA_SIZE(DMA_InitStruct->DMA_MemoryDataSize));\r
224   assert_param(IS_DMA_MODE(DMA_InitStruct->DMA_Mode));\r
225   assert_param(IS_DMA_PRIORITY(DMA_InitStruct->DMA_Priority));\r
226   assert_param(IS_DMA_M2M_STATE(DMA_InitStruct->DMA_M2M));\r
227 \r
228 /*--------------------------- DMAy Channelx CCR Configuration -----------------*/\r
229   /* Get the DMAy_Channelx CCR value */\r
230   tmpreg = DMAy_Channelx->CCR;\r
231   /* Clear MEM2MEM, PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */\r
232   tmpreg &= CCR_CLEAR_MASK;\r
233   /* Configure DMAy Channelx: data transfer, data size, priority level and mode */\r
234   /* Set DIR bit according to DMA_DIR value */\r
235   /* Set CIRC bit according to DMA_Mode value */\r
236   /* Set PINC bit according to DMA_PeripheralInc value */\r
237   /* Set MINC bit according to DMA_MemoryInc value */\r
238   /* Set PSIZE bits according to DMA_PeripheralDataSize value */\r
239   /* Set MSIZE bits according to DMA_MemoryDataSize value */\r
240   /* Set PL bits according to DMA_Priority value */\r
241   /* Set the MEM2MEM bit according to DMA_M2M value */\r
242   tmpreg |= DMA_InitStruct->DMA_DIR | DMA_InitStruct->DMA_Mode |\r
243             DMA_InitStruct->DMA_PeripheralInc | DMA_InitStruct->DMA_MemoryInc |\r
244             DMA_InitStruct->DMA_PeripheralDataSize | DMA_InitStruct->DMA_MemoryDataSize |\r
245             DMA_InitStruct->DMA_Priority | DMA_InitStruct->DMA_M2M;\r
246 \r
247   /* Write to DMAy Channelx CCR */\r
248   DMAy_Channelx->CCR = tmpreg;\r
249 \r
250 /*--------------------------- DMAy Channelx CNDTR Configuration ---------------*/\r
251   /* Write to DMAy Channelx CNDTR */\r
252   DMAy_Channelx->CNDTR = DMA_InitStruct->DMA_BufferSize;\r
253 \r
254 /*--------------------------- DMAy Channelx CPAR Configuration ----------------*/\r
255   /* Write to DMAy Channelx CPAR */\r
256   DMAy_Channelx->CPAR = DMA_InitStruct->DMA_PeripheralBaseAddr;\r
257 \r
258 /*--------------------------- DMAy Channelx CMAR Configuration ----------------*/\r
259   /* Write to DMAy Channelx CMAR */\r
260   DMAy_Channelx->CMAR = DMA_InitStruct->DMA_MemoryBaseAddr;\r
261 }\r
262 \r
263 /**\r
264   * @brief  Fills each DMA_InitStruct member with its default value.\r
265   * @param  DMA_InitStruct: pointer to a DMA_InitTypeDef structure which will\r
266   *         be initialized.\r
267   * @retval None\r
268   */\r
269 void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct)\r
270 {\r
271 /*-------------- Reset DMA init structure parameters values ------------------*/\r
272   /* Initialize the DMA_PeripheralBaseAddr member */\r
273   DMA_InitStruct->DMA_PeripheralBaseAddr = 0;\r
274   /* Initialize the DMA_MemoryBaseAddr member */\r
275   DMA_InitStruct->DMA_MemoryBaseAddr = 0;\r
276   /* Initialize the DMA_DIR member */\r
277   DMA_InitStruct->DMA_DIR = DMA_DIR_PeripheralSRC;\r
278   /* Initialize the DMA_BufferSize member */\r
279   DMA_InitStruct->DMA_BufferSize = 0;\r
280   /* Initialize the DMA_PeripheralInc member */\r
281   DMA_InitStruct->DMA_PeripheralInc = DMA_PeripheralInc_Disable;\r
282   /* Initialize the DMA_MemoryInc member */\r
283   DMA_InitStruct->DMA_MemoryInc = DMA_MemoryInc_Disable;\r
284   /* Initialize the DMA_PeripheralDataSize member */\r
285   DMA_InitStruct->DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;\r
286   /* Initialize the DMA_MemoryDataSize member */\r
287   DMA_InitStruct->DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;\r
288   /* Initialize the DMA_Mode member */\r
289   DMA_InitStruct->DMA_Mode = DMA_Mode_Normal;\r
290   /* Initialize the DMA_Priority member */\r
291   DMA_InitStruct->DMA_Priority = DMA_Priority_Low;\r
292   /* Initialize the DMA_M2M member */\r
293   DMA_InitStruct->DMA_M2M = DMA_M2M_Disable;\r
294 }\r
295 \r
296 /**\r
297   * @brief  Enables or disables the specified DMAy Channelx.\r
298   * @param  DMAy_Channelx: where y can be 1 to select the DMA and\r
299   *         x can be 1 to 7 for DMA1 to select the DMA Channel.\r
300   * @param  NewState: new state of the DMAy Channelx. \r
301   *         This parameter can be: ENABLE or DISABLE.\r
302   * @retval None\r
303   */\r
304 void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState)\r
305 {\r
306   /* Check the parameters */\r
307   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));\r
308   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
309 \r
310   if (NewState != DISABLE)\r
311   {\r
312     /* Enable the selected DMAy Channelx */\r
313     DMAy_Channelx->CCR |= DMA_CCR1_EN;\r
314   }\r
315   else\r
316   {\r
317     /* Disable the selected DMAy Channelx */\r
318     DMAy_Channelx->CCR &= (uint16_t)(~DMA_CCR1_EN);\r
319   }\r
320 }\r
321 \r
322 /**\r
323   * @}\r
324   */\r
325 \r
326 /** @defgroup DMA_Group2 Data Counter functions\r
327  *  @brief   Data Counter functions \r
328  *\r
329 @verbatim   \r
330  ===============================================================================\r
331                            Data Counter functions\r
332  ===============================================================================  \r
333 \r
334   This subsection provides function allowing to configure and read the buffer size\r
335   (number of data to be transferred). \r
336 \r
337   The DMA data counter can be written only when the DMA channel is disabled \r
338   (ie. after transfer complete event).\r
339 \r
340   The following function can be used to write the Channel data counter value:\r
341     - void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber);\r
342 \r
343 @note It is advised to use this function rather than DMA_Init() in situations where\r
344       only the Data buffer needs to be reloaded.\r
345 \r
346   The DMA data counter can be read to indicate the number of remaining transfers for\r
347   the relative DMA channel. This counter is decremented at the end of each data \r
348   transfer and when the transfer is complete: \r
349    - If Normal mode is selected: the counter is set to 0.\r
350    - If Circular mode is selected: the counter is reloaded with the initial value\r
351      (configured before enabling the DMA channel)\r
352    \r
353   The following function can be used to read the Channel data counter value:\r
354      - uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx);\r
355 \r
356 @endverbatim\r
357   * @{\r
358   */\r
359 \r
360 /**\r
361   * @brief  Sets the number of data units in the current DMAy Channelx transfer.\r
362   * @param  DMAy_Channelx: where y can be 1 to select the DMA and\r
363   *         x can be 1 to 7 for DMA1 to select the DMA Channel.\r
364   * @param  DataNumber: The number of data units in the current DMAy Channelx\r
365   *         transfer.   \r
366   * @note   This function can only be used when the DMAy_Channelx is disabled.                 \r
367   * @retval None.\r
368   */\r
369 void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber)\r
370 {\r
371   /* Check the parameters */\r
372   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));\r
373   \r
374 /*--------------------------- DMAy Channelx CNDTR Configuration ---------------*/\r
375   /* Write to DMAy Channelx CNDTR */\r
376   DMAy_Channelx->CNDTR = DataNumber;  \r
377 }\r
378 \r
379 /**\r
380   * @brief  Returns the number of remaining data units in the current\r
381   *         DMAy Channelx transfer.\r
382   * @param  DMAy_Channelx: where y can be 1 to select the DMA and\r
383   *         x can be 1 to 7 for DMA1 to select the DMA Channel.\r
384   * @retval The number of remaining data units in the current DMAy Channelx\r
385   *         transfer.\r
386   */\r
387 uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx)\r
388 {\r
389   /* Check the parameters */\r
390   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));\r
391   /* Return the number of remaining data units for DMAy Channelx */\r
392   return ((uint16_t)(DMAy_Channelx->CNDTR));\r
393 }\r
394 \r
395 /**\r
396   * @}\r
397   */\r
398 \r
399 /** @defgroup DMA_Group3 Interrupts and flags management functions\r
400  *  @brief   Interrupts and flags management functions \r
401  *\r
402 @verbatim   \r
403  ===============================================================================\r
404                   Interrupts and flags management functions\r
405  ===============================================================================  \r
406 \r
407   This subsection provides functions allowing to configure the DMA Interrupts \r
408   sources and check or clear the flags or pending bits status.\r
409   The user should identify which mode will be used in his application to manage the\r
410   DMA controller events: Polling mode or Interrupt mode. \r
411     \r
412   Polling Mode\r
413   =============\r
414     Each DMA channel can be managed through 4 event Flags:\r
415     (y : DMA Controller number  \r
416      x : DMA channel number )\r
417        1. DMAy_FLAG_TCx : to indicate that a Transfer Complete event occurred\r
418        2. DMAy_FLAG_HTx : to indicate that a Half-Transfer Complete event occured\r
419        3. DMAy_FLAG_TEx : to indicate that a Transfer Error occured.\r
420        4. DMAy_FLAG_GLx : to indicate that at least one of the events described \r
421           above occured.             \r
422 \r
423 @note Clearing DMAy_FLAG_GLx results in clearing all other pending flags of the \r
424       same channel (DMAy_FLAG_TCx, DMAy_FLAG_HTx and DMAy_FLAG_TEx).\r
425 \r
426    In this Mode it is advised to use the following functions:\r
427       - FlagStatus DMA_GetFlagStatus(uint32_t DMA_FLAG);\r
428       - void DMA_ClearFlag(uint32_t DMA_FLAG);\r
429 \r
430   Interrupt Mode\r
431   ===============\r
432     Each DMA channel can be managed through 4 Interrupts:\r
433 \r
434     Interrupt Source\r
435     ----------------\r
436        1. DMA_IT_TC: specifies the interrupt source for the Transfer Complete event.  \r
437        2. DMA_IT_HT : specifies the interrupt source for the Half-transfer Complete event.\r
438        3. DMA_IT_TE : specifies the interrupt source for the transfer errors event.\r
439        4. DMA_IT_GL : to indicate that at least one of the interrupts described \r
440           above occurred. \r
441 \r
442 @note Clearing DMA_IT_GL interrupt results in clearing all other interrupts of the \r
443       same channel (DMA_IT_TCx, DMA_IT_HT and DMA_IT_TE).\r
444      \r
445   In this Mode it is advised to use the following functions:\r
446      - void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState);\r
447      - ITStatus DMA_GetITStatus(uint32_t DMA_IT);\r
448      - void DMA_ClearITPendingBit(uint32_t DMA_IT);\r
449 \r
450 @endverbatim\r
451   * @{\r
452   */\r
453 \r
454 /**\r
455   * @brief  Enables or disables the specified DMAy Channelx interrupts.\r
456   * @param  DMAy_Channelx: where y can be 1 to select the DMA and\r
457   *         x can be 1 to 7 for DMA1 to select the DMA Channel.\r
458   * @param  DMA_IT: specifies the DMA interrupts sources to be enabled\r
459   *         or disabled. \r
460   *   This parameter can be any combination of the following values:\r
461   *     @arg DMA_IT_TC: Transfer complete interrupt mask\r
462   *     @arg DMA_IT_HT: Half transfer interrupt mask\r
463   *     @arg DMA_IT_TE: Transfer error interrupt mask\r
464   * @param  NewState: new state of the specified DMA interrupts.\r
465   *         This parameter can be: ENABLE or DISABLE.\r
466   * @retval None\r
467   */\r
468 void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState)\r
469 {\r
470   /* Check the parameters */\r
471   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));\r
472   assert_param(IS_DMA_CONFIG_IT(DMA_IT));\r
473   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
474 \r
475   if (NewState != DISABLE)\r
476   {\r
477     /* Enable the selected DMA interrupts */\r
478     DMAy_Channelx->CCR |= DMA_IT;\r
479   }\r
480   else\r
481   {\r
482     /* Disable the selected DMA interrupts */\r
483     DMAy_Channelx->CCR &= ~DMA_IT;\r
484   }\r
485 }\r
486 \r
487 /**\r
488   * @brief  Checks whether the specified DMAy Channelx flag is set or not.\r
489   * @param  DMA_FLAG: specifies the flag to check.\r
490   *   This parameter can be one of the following values:\r
491   *     @arg DMA1_FLAG_GL1: DMA1 Channel1 global flag.\r
492   *     @arg DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.\r
493   *     @arg DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.\r
494   *     @arg DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.\r
495   *     @arg DMA1_FLAG_GL2: DMA1 Channel2 global flag.\r
496   *     @arg DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.\r
497   *     @arg DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.\r
498   *     @arg DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.\r
499   *     @arg DMA1_FLAG_GL3: DMA1 Channel3 global flag.\r
500   *     @arg DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.\r
501   *     @arg DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.\r
502   *     @arg DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.\r
503   *     @arg DMA1_FLAG_GL4: DMA1 Channel4 global flag.\r
504   *     @arg DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.\r
505   *     @arg DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.\r
506   *     @arg DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.\r
507   *     @arg DMA1_FLAG_GL5: DMA1 Channel5 global flag.\r
508   *     @arg DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.\r
509   *     @arg DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.\r
510   *     @arg DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.\r
511   *     @arg DMA1_FLAG_GL6: DMA1 Channel6 global flag.\r
512   *     @arg DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.\r
513   *     @arg DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.\r
514   *     @arg DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.\r
515   *     @arg DMA1_FLAG_GL7: DMA1 Channel7 global flag.\r
516   *     @arg DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.\r
517   *     @arg DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.\r
518   *     @arg DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.\r
519   *     \r
520   * @note\r
521   *    The Global flag (DMAy_FLAG_GLx) is set whenever any of the other flags \r
522   *    relative to the same channel is set (Transfer Complete, Half-transfer \r
523   *    Complete or Transfer Error flags: DMAy_FLAG_TCx, DMAy_FLAG_HTx or \r
524   *    DMAy_FLAG_TEx). \r
525   *      \r
526   * @retval The new state of DMA_FLAG (SET or RESET).\r
527   */\r
528 FlagStatus DMA_GetFlagStatus(uint32_t DMA_FLAG)\r
529 {\r
530   FlagStatus bitstatus = RESET;\r
531   uint32_t tmpreg = 0;\r
532 \r
533   /* Check the parameters */\r
534   assert_param(IS_DMA_GET_FLAG(DMA_FLAG));\r
535 \r
536   /* Calculate the used DMA */\r
537   if ((DMA_FLAG & FLAG_MASK) == (uint32_t)RESET)\r
538   {\r
539     /* Get DMA1 ISR register value */\r
540     tmpreg = DMA1->ISR ;\r
541   }\r
542 \r
543   /* Check the status of the specified DMA flag */\r
544   if ((tmpreg & DMA_FLAG) != (uint32_t)RESET)\r
545   {\r
546     /* DMA_FLAG is set */\r
547     bitstatus = SET;\r
548   }\r
549   else\r
550   {\r
551     /* DMA_FLAG is reset */\r
552     bitstatus = RESET;\r
553   }\r
554   \r
555   /* Return the DMA_FLAG status */\r
556   return  bitstatus;\r
557 }\r
558 \r
559 /**\r
560   * @brief  Clears the DMAy Channelx's pending flags.\r
561   * @param  DMA_FLAG: specifies the flag to clear.\r
562   *   This parameter can be any combination (for the same DMA) of the following values:\r
563   *     @arg DMA1_FLAG_GL1: DMA1 Channel1 global flag.\r
564   *     @arg DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.\r
565   *     @arg DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.\r
566   *     @arg DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.\r
567   *     @arg DMA1_FLAG_GL2: DMA1 Channel2 global flag.\r
568   *     @arg DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.\r
569   *     @arg DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.\r
570   *     @arg DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.\r
571   *     @arg DMA1_FLAG_GL3: DMA1 Channel3 global flag.\r
572   *     @arg DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.\r
573   *     @arg DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.\r
574   *     @arg DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.\r
575   *     @arg DMA1_FLAG_GL4: DMA1 Channel4 global flag.\r
576   *     @arg DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.\r
577   *     @arg DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.\r
578   *     @arg DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.\r
579   *     @arg DMA1_FLAG_GL5: DMA1 Channel5 global flag.\r
580   *     @arg DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.\r
581   *     @arg DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.\r
582   *     @arg DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.\r
583   *     @arg DMA1_FLAG_GL6: DMA1 Channel6 global flag.\r
584   *     @arg DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.\r
585   *     @arg DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.\r
586   *     @arg DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.\r
587   *     @arg DMA1_FLAG_GL7: DMA1 Channel7 global flag.\r
588   *     @arg DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.\r
589   *     @arg DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.\r
590   *     @arg DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.\r
591   *     \r
592   * @note\r
593   *    Clearing the Global flag (DMAy_FLAG_GLx) results in clearing all other flags\r
594   *    relative to the same channel (Transfer Complete, Half-transfer Complete and \r
595   *    Transfer Error flags: DMAy_FLAG_TCx, DMAy_FLAG_HTx and DMAy_FLAG_TEx).  \r
596   *      \r
597   * @retval None\r
598   */\r
599 void DMA_ClearFlag(uint32_t DMA_FLAG)\r
600 {\r
601   /* Check the parameters */\r
602   assert_param(IS_DMA_CLEAR_FLAG(DMA_FLAG));\r
603 \r
604   if ((DMA_FLAG & FLAG_MASK) == (uint32_t)RESET)\r
605   {\r
606     /* Clear the selected DMA flags */\r
607     DMA1->IFCR = DMA_FLAG;\r
608   }\r
609 }\r
610 \r
611 /**\r
612   * @brief  Checks whether the specified DMAy Channelx interrupt has occurred or not.\r
613   * @param  DMA_IT: specifies the DMA interrupt source to check. \r
614   *   This parameter can be one of the following values:\r
615   *     @arg DMA1_IT_GL1: DMA1 Channel1 global interrupt.\r
616   *     @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.\r
617   *     @arg DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.\r
618   *     @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.\r
619   *     @arg DMA1_IT_GL2: DMA1 Channel2 global interrupt.\r
620   *     @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.\r
621   *     @arg DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.\r
622   *     @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.\r
623   *     @arg DMA1_IT_GL3: DMA1 Channel3 global interrupt.\r
624   *     @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.\r
625   *     @arg DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.\r
626   *     @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.\r
627   *     @arg DMA1_IT_GL4: DMA1 Channel4 global interrupt.\r
628   *     @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.\r
629   *     @arg DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.\r
630   *     @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.\r
631   *     @arg DMA1_IT_GL5: DMA1 Channel5 global interrupt.\r
632   *     @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.\r
633   *     @arg DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.\r
634   *     @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.\r
635   *     @arg DMA1_IT_GL6: DMA1 Channel6 global interrupt.\r
636   *     @arg DMA1_IT_TC6: DMA1 Channel6 transfer complete interrupt.\r
637   *     @arg DMA1_IT_HT6: DMA1 Channel6 half transfer interrupt.\r
638   *     @arg DMA1_IT_TE6: DMA1 Channel6 transfer error interrupt.\r
639   *     @arg DMA1_IT_GL7: DMA1 Channel7 global interrupt.\r
640   *     @arg DMA1_IT_TC7: DMA1 Channel7 transfer complete interrupt.\r
641   *     @arg DMA1_IT_HT7: DMA1 Channel7 half transfer interrupt.\r
642   *     @arg DMA1_IT_TE7: DMA1 Channel7 transfer error interrupt.\r
643   *     \r
644   * @note\r
645   *    The Global interrupt (DMAy_FLAG_GLx) is set whenever any of the other \r
646   *    interrupts relative to the same channel is set (Transfer Complete, \r
647   *    Half-transfer Complete or Transfer Error interrupts: DMAy_IT_TCx, \r
648   *    DMAy_IT_HTx or DMAy_IT_TEx). \r
649   *      \r
650   * @retval The new state of DMA_IT (SET or RESET).\r
651   */\r
652 ITStatus DMA_GetITStatus(uint32_t DMA_IT)\r
653 {\r
654   ITStatus bitstatus = RESET;\r
655   uint32_t tmpreg = 0;\r
656  \r
657   /* Check the parameters */\r
658   assert_param(IS_DMA_GET_IT(DMA_IT));\r
659 \r
660   /* Calculate the used DMA */\r
661   if ((DMA_IT & FLAG_MASK) == (uint32_t)RESET)\r
662   {\r
663     /* Get DMA1 ISR register value */\r
664     tmpreg = DMA1->ISR ;\r
665   }\r
666 \r
667   /* Check the status of the specified DMA interrupt */\r
668   if ((tmpreg & DMA_IT) != (uint32_t)RESET)\r
669   {\r
670     /* DMA_IT is set */\r
671     bitstatus = SET;\r
672   }\r
673   else\r
674   {\r
675     /* DMA_IT is reset */\r
676     bitstatus = RESET;\r
677   }\r
678   /* Return the DMA_IT status */\r
679   return  bitstatus;\r
680 }\r
681 \r
682 /**\r
683   * @brief  Clears the DMAy Channelx\92s interrupt pending bits.\r
684   * @param  DMA_IT: specifies the DMA interrupt pending bit to clear.\r
685   *   This parameter can be any combination (for the same DMA) of the following values:\r
686   *     @arg DMA1_IT_GL1: DMA1 Channel1 global interrupt.\r
687   *     @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.\r
688   *     @arg DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.\r
689   *     @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.\r
690   *     @arg DMA1_IT_GL2: DMA1 Channel2 global interrupt.\r
691   *     @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.\r
692   *     @arg DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.\r
693   *     @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.\r
694   *     @arg DMA1_IT_GL3: DMA1 Channel3 global interrupt.\r
695   *     @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.\r
696   *     @arg DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.\r
697   *     @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.\r
698   *     @arg DMA1_IT_GL4: DMA1 Channel4 global interrupt.\r
699   *     @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.\r
700   *     @arg DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.\r
701   *     @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.\r
702   *     @arg DMA1_IT_GL5: DMA1 Channel5 global interrupt.\r
703   *     @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.\r
704   *     @arg DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.\r
705   *     @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.\r
706   *     @arg DMA1_IT_GL6: DMA1 Channel6 global interrupt.\r
707   *     @arg DMA1_IT_TC6: DMA1 Channel6 transfer complete interrupt.\r
708   *     @arg DMA1_IT_HT6: DMA1 Channel6 half transfer interrupt.\r
709   *     @arg DMA1_IT_TE6: DMA1 Channel6 transfer error interrupt.\r
710   *     @arg DMA1_IT_GL7: DMA1 Channel7 global interrupt.\r
711   *     @arg DMA1_IT_TC7: DMA1 Channel7 transfer complete interrupt.\r
712   *     @arg DMA1_IT_HT7: DMA1 Channel7 half transfer interrupt.\r
713   *     @arg DMA1_IT_TE7: DMA1 Channel7 transfer error interrupt.\r
714   *     \r
715   * @note\r
716   *    Clearing the Global interrupt (DMAy_IT_GLx) results in clearing all other \r
717   *    interrupts relative to the same channel (Transfer Complete, Half-transfer \r
718   *    Complete and Transfer Error interrupts: DMAy_IT_TCx, DMAy_IT_HTx and \r
719   *    DMAy_IT_TEx).  \r
720   *        \r
721   * @retval None\r
722   */\r
723 void DMA_ClearITPendingBit(uint32_t DMA_IT)\r
724 {\r
725   /* Check the parameters */\r
726   assert_param(IS_DMA_CLEAR_IT(DMA_IT));\r
727 \r
728   /* Calculate the used DMA */\r
729   if ((DMA_IT & FLAG_MASK) == (uint32_t)RESET)\r
730   {\r
731     /* Clear the selected DMA interrupt pending bits */\r
732     DMA1->IFCR = DMA_IT;\r
733   }\r
734 }\r
735 \r
736 /**\r
737   * @}\r
738   */\r
739 \r
740 /**\r
741   * @}\r
742   */\r
743 \r
744 /**\r
745   * @}\r
746   */\r
747 \r
748 /**\r
749   * @}\r
750   */\r
751 \r
752 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r