Move telemetry displayport init and cms device registering
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F30x_StdPeriph_Driver / src / stm32f30x_dma.c
blob0c33b67b0ba24dc9f5f9ebd1a3d580a20a2f9e30
1 /**
2 ******************************************************************************
3 * @file stm32f30x_dma.c
4 * @author MCD Application Team
5 * @version V1.1.1
6 * @date 04-April-2014
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
13 @verbatim
15 ===============================================================================
16 ##### How to use this driver #####
17 ===============================================================================
18 [..]
19 (#) Enable The DMA controller clock using
20 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE) function for DMA1 or
21 using RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE) function for DMA2.
22 (#) Enable and configure the peripheral to be connected to the DMA channel
23 (except for internal SRAM / FLASH memories: no initialization is necessary).
24 (#) For a given Channel, program the Source and Destination addresses,
25 the transfer Direction, the Buffer Size, the Peripheral and Memory
26 Incrementation mode and Data Size, the Circular or Normal mode,
27 the channel transfer Priority and the Memory-to-Memory transfer
28 mode (if needed) using the DMA_Init() function.
29 (#) Enable the NVIC and the corresponding interrupt(s) using the function
30 DMA_ITConfig() if you need to use DMA interrupts.
31 (#) Enable the DMA channel using the DMA_Cmd() function.
32 (#) Activate the needed channel Request using PPP_DMACmd() function for
33 any PPP peripheral except internal SRAM and FLASH (ie. SPI, USART ...)
34 The function allowing this operation is provided in each PPP peripheral
35 driver (ie. SPI_DMACmd for SPI peripheral).
36 (#) Optionally, you can configure the number of data to be transferred
37 when the channel is disabled (ie. after each Transfer Complete event
38 or when a Transfer Error occurs) using the function DMA_SetCurrDataCounter().
39 And you can get the number of remaining data to be transferred using
40 the function DMA_GetCurrDataCounter() at run time (when the DMA channel is
41 enabled and running).
42 (#) To control DMA events you can use one of the following two methods:
43 (##) Check on DMA channel flags using the function DMA_GetFlagStatus().
44 (##) Use DMA interrupts through the function DMA_ITConfig() at initialization
45 phase and DMA_GetITStatus() function into interrupt routines in
46 communication phase.
47 After checking on a flag you should clear it using DMA_ClearFlag()
48 function. And after checking on an interrupt event you should
49 clear it using DMA_ClearITPendingBit() function.
51 @endverbatim
53 ******************************************************************************
54 * @attention
56 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
58 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
59 * You may not use this file except in compliance with the License.
60 * You may obtain a copy of the License at:
62 * http://www.st.com/software_license_agreement_liberty_v2
64 * Unless required by applicable law or agreed to in writing, software
65 * distributed under the License is distributed on an "AS IS" BASIS,
66 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67 * See the License for the specific language governing permissions and
68 * limitations under the License.
70 ******************************************************************************
73 /* Includes ------------------------------------------------------------------*/
74 #include "stm32f30x_dma.h"
76 /** @addtogroup STM32F30x_StdPeriph_Driver
77 * @{
80 /** @defgroup DMA
81 * @brief DMA driver modules
82 * @{
85 /* Private typedef -----------------------------------------------------------*/
86 /* Private define ------------------------------------------------------------*/
87 #define CCR_CLEAR_MASK ((uint32_t)0xFFFF800F) /* DMA Channel config registers Masks */
88 #define FLAG_Mask ((uint32_t)0x10000000) /* DMA2 FLAG mask */
91 /* DMA1 Channelx interrupt pending bit masks */
92 #define DMA1_CHANNEL1_IT_MASK ((uint32_t)(DMA_ISR_GIF1 | DMA_ISR_TCIF1 | DMA_ISR_HTIF1 | DMA_ISR_TEIF1))
93 #define DMA1_CHANNEL2_IT_MASK ((uint32_t)(DMA_ISR_GIF2 | DMA_ISR_TCIF2 | DMA_ISR_HTIF2 | DMA_ISR_TEIF2))
94 #define DMA1_CHANNEL3_IT_MASK ((uint32_t)(DMA_ISR_GIF3 | DMA_ISR_TCIF3 | DMA_ISR_HTIF3 | DMA_ISR_TEIF3))
95 #define DMA1_CHANNEL4_IT_MASK ((uint32_t)(DMA_ISR_GIF4 | DMA_ISR_TCIF4 | DMA_ISR_HTIF4 | DMA_ISR_TEIF4))
96 #define DMA1_CHANNEL5_IT_MASK ((uint32_t)(DMA_ISR_GIF5 | DMA_ISR_TCIF5 | DMA_ISR_HTIF5 | DMA_ISR_TEIF5))
97 #define DMA1_CHANNEL6_IT_MASK ((uint32_t)(DMA_ISR_GIF6 | DMA_ISR_TCIF6 | DMA_ISR_HTIF6 | DMA_ISR_TEIF6))
98 #define DMA1_CHANNEL7_IT_MASK ((uint32_t)(DMA_ISR_GIF7 | DMA_ISR_TCIF7 | DMA_ISR_HTIF7 | DMA_ISR_TEIF7))
100 /* DMA2 Channelx interrupt pending bit masks */
101 #define DMA2_CHANNEL1_IT_MASK ((uint32_t)(DMA_ISR_GIF1 | DMA_ISR_TCIF1 | DMA_ISR_HTIF1 | DMA_ISR_TEIF1))
102 #define DMA2_CHANNEL2_IT_MASK ((uint32_t)(DMA_ISR_GIF2 | DMA_ISR_TCIF2 | DMA_ISR_HTIF2 | DMA_ISR_TEIF2))
103 #define DMA2_CHANNEL3_IT_MASK ((uint32_t)(DMA_ISR_GIF3 | DMA_ISR_TCIF3 | DMA_ISR_HTIF3 | DMA_ISR_TEIF3))
104 #define DMA2_CHANNEL4_IT_MASK ((uint32_t)(DMA_ISR_GIF4 | DMA_ISR_TCIF4 | DMA_ISR_HTIF4 | DMA_ISR_TEIF4))
105 #define DMA2_CHANNEL5_IT_MASK ((uint32_t)(DMA_ISR_GIF5 | DMA_ISR_TCIF5 | DMA_ISR_HTIF5 | DMA_ISR_TEIF5))
107 /* Private macro -------------------------------------------------------------*/
108 /* Private variables ---------------------------------------------------------*/
109 /* Private function prototypes -----------------------------------------------*/
110 /* Private functions ---------------------------------------------------------*/
112 /** @defgroup DMA_Private_Functions
113 * @{
116 /** @defgroup DMA_Group1 Initialization and Configuration functions
117 * @brief Initialization and Configuration functions
119 @verbatim
120 ===============================================================================
121 ##### Initialization and Configuration functions #####
122 ===============================================================================
123 [..] This subsection provides functions allowing to initialize the DMA channel
124 source and destination addresses, incrementation and data sizes, transfer
125 direction, buffer size, circular/normal mode selection, memory-to-memory
126 mode selection and channel priority value.
127 [..] The DMA_Init() function follows the DMA configuration procedures as described
128 in reference manual (RM00316).
130 @endverbatim
131 * @{
135 * @brief Deinitializes the DMAy Channelx registers to their default reset
136 * values.
137 * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
138 * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
139 * @retval None
141 void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx)
143 /* Check the parameters */
144 assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
146 /* Disable the selected DMAy Channelx */
147 DMAy_Channelx->CCR &= (uint16_t)(~DMA_CCR_EN);
149 /* Reset DMAy Channelx control register */
150 DMAy_Channelx->CCR = 0;
152 /* Reset DMAy Channelx remaining bytes register */
153 DMAy_Channelx->CNDTR = 0;
155 /* Reset DMAy Channelx peripheral address register */
156 DMAy_Channelx->CPAR = 0;
158 /* Reset DMAy Channelx memory address register */
159 DMAy_Channelx->CMAR = 0;
161 if (DMAy_Channelx == DMA1_Channel1)
163 /* Reset interrupt pending bits for DMA1 Channel1 */
164 DMA1->IFCR |= DMA1_CHANNEL1_IT_MASK;
166 else if (DMAy_Channelx == DMA1_Channel2)
168 /* Reset interrupt pending bits for DMA1 Channel2 */
169 DMA1->IFCR |= DMA1_CHANNEL2_IT_MASK;
171 else if (DMAy_Channelx == DMA1_Channel3)
173 /* Reset interrupt pending bits for DMA1 Channel3 */
174 DMA1->IFCR |= DMA1_CHANNEL3_IT_MASK;
176 else if (DMAy_Channelx == DMA1_Channel4)
178 /* Reset interrupt pending bits for DMA1 Channel4 */
179 DMA1->IFCR |= DMA1_CHANNEL4_IT_MASK;
181 else if (DMAy_Channelx == DMA1_Channel5)
183 /* Reset interrupt pending bits for DMA1 Channel5 */
184 DMA1->IFCR |= DMA1_CHANNEL5_IT_MASK;
186 else if (DMAy_Channelx == DMA1_Channel6)
188 /* Reset interrupt pending bits for DMA1 Channel6 */
189 DMA1->IFCR |= DMA1_CHANNEL6_IT_MASK;
191 else if (DMAy_Channelx == DMA1_Channel7)
193 /* Reset interrupt pending bits for DMA1 Channel7 */
194 DMA1->IFCR |= DMA1_CHANNEL7_IT_MASK;
196 else if (DMAy_Channelx == DMA2_Channel1)
198 /* Reset interrupt pending bits for DMA2 Channel1 */
199 DMA2->IFCR |= DMA2_CHANNEL1_IT_MASK;
201 else if (DMAy_Channelx == DMA2_Channel2)
203 /* Reset interrupt pending bits for DMA2 Channel2 */
204 DMA2->IFCR |= DMA2_CHANNEL2_IT_MASK;
206 else if (DMAy_Channelx == DMA2_Channel3)
208 /* Reset interrupt pending bits for DMA2 Channel3 */
209 DMA2->IFCR |= DMA2_CHANNEL3_IT_MASK;
211 else if (DMAy_Channelx == DMA2_Channel4)
213 /* Reset interrupt pending bits for DMA2 Channel4 */
214 DMA2->IFCR |= DMA2_CHANNEL4_IT_MASK;
216 else
218 if (DMAy_Channelx == DMA2_Channel5)
220 /* Reset interrupt pending bits for DMA2 Channel5 */
221 DMA2->IFCR |= DMA2_CHANNEL5_IT_MASK;
227 * @brief Initializes the DMAy Channelx according to the specified parameters
228 * in the DMA_InitStruct.
229 * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
230 * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
231 * @param DMA_InitStruct: pointer to a DMA_InitTypeDef structure that contains
232 * the configuration information for the specified DMA Channel.
233 * @retval None
235 void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct)
237 uint32_t tmpreg = 0;
239 /* Check the parameters */
240 assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
241 assert_param(IS_DMA_DIR(DMA_InitStruct->DMA_DIR));
242 assert_param(IS_DMA_PERIPHERAL_INC_STATE(DMA_InitStruct->DMA_PeripheralInc));
243 assert_param(IS_DMA_MEMORY_INC_STATE(DMA_InitStruct->DMA_MemoryInc));
244 assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(DMA_InitStruct->DMA_PeripheralDataSize));
245 assert_param(IS_DMA_MEMORY_DATA_SIZE(DMA_InitStruct->DMA_MemoryDataSize));
246 assert_param(IS_DMA_MODE(DMA_InitStruct->DMA_Mode));
247 assert_param(IS_DMA_PRIORITY(DMA_InitStruct->DMA_Priority));
248 assert_param(IS_DMA_M2M_STATE(DMA_InitStruct->DMA_M2M));
250 /*--------------------------- DMAy Channelx CCR Configuration ----------------*/
251 /* Get the DMAy_Channelx CCR value */
252 tmpreg = DMAy_Channelx->CCR;
254 /* Clear MEM2MEM, PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */
255 tmpreg &= CCR_CLEAR_MASK;
257 /* Configure DMAy Channelx: data transfer, data size, priority level and mode */
258 /* Set DIR bit according to DMA_DIR value */
259 /* Set CIRC bit according to DMA_Mode value */
260 /* Set PINC bit according to DMA_PeripheralInc value */
261 /* Set MINC bit according to DMA_MemoryInc value */
262 /* Set PSIZE bits according to DMA_PeripheralDataSize value */
263 /* Set MSIZE bits according to DMA_MemoryDataSize value */
264 /* Set PL bits according to DMA_Priority value */
265 /* Set the MEM2MEM bit according to DMA_M2M value */
266 tmpreg |= DMA_InitStruct->DMA_DIR | DMA_InitStruct->DMA_Mode |
267 DMA_InitStruct->DMA_PeripheralInc | DMA_InitStruct->DMA_MemoryInc |
268 DMA_InitStruct->DMA_PeripheralDataSize | DMA_InitStruct->DMA_MemoryDataSize |
269 DMA_InitStruct->DMA_Priority | DMA_InitStruct->DMA_M2M;
271 /* Write to DMAy Channelx CCR */
272 DMAy_Channelx->CCR = tmpreg;
274 /*--------------------------- DMAy Channelx CNDTR Configuration --------------*/
275 /* Write to DMAy Channelx CNDTR */
276 DMAy_Channelx->CNDTR = DMA_InitStruct->DMA_BufferSize;
278 /*--------------------------- DMAy Channelx CPAR Configuration ---------------*/
279 /* Write to DMAy Channelx CPAR */
280 DMAy_Channelx->CPAR = DMA_InitStruct->DMA_PeripheralBaseAddr;
282 /*--------------------------- DMAy Channelx CMAR Configuration ---------------*/
283 /* Write to DMAy Channelx CMAR */
284 DMAy_Channelx->CMAR = DMA_InitStruct->DMA_MemoryBaseAddr;
288 * @brief Fills each DMA_InitStruct member with its default value.
289 * @param DMA_InitStruct: pointer to a DMA_InitTypeDef structure which will
290 * be initialized.
291 * @retval None
293 void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct)
295 /*-------------- Reset DMA init structure parameters values ------------------*/
296 /* Initialize the DMA_PeripheralBaseAddr member */
297 DMA_InitStruct->DMA_PeripheralBaseAddr = 0;
298 /* Initialize the DMA_MemoryBaseAddr member */
299 DMA_InitStruct->DMA_MemoryBaseAddr = 0;
300 /* Initialize the DMA_DIR member */
301 DMA_InitStruct->DMA_DIR = DMA_DIR_PeripheralSRC;
302 /* Initialize the DMA_BufferSize member */
303 DMA_InitStruct->DMA_BufferSize = 0;
304 /* Initialize the DMA_PeripheralInc member */
305 DMA_InitStruct->DMA_PeripheralInc = DMA_PeripheralInc_Disable;
306 /* Initialize the DMA_MemoryInc member */
307 DMA_InitStruct->DMA_MemoryInc = DMA_MemoryInc_Disable;
308 /* Initialize the DMA_PeripheralDataSize member */
309 DMA_InitStruct->DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
310 /* Initialize the DMA_MemoryDataSize member */
311 DMA_InitStruct->DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
312 /* Initialize the DMA_Mode member */
313 DMA_InitStruct->DMA_Mode = DMA_Mode_Normal;
314 /* Initialize the DMA_Priority member */
315 DMA_InitStruct->DMA_Priority = DMA_Priority_Low;
316 /* Initialize the DMA_M2M member */
317 DMA_InitStruct->DMA_M2M = DMA_M2M_Disable;
321 * @brief Enables or disables the specified DMAy Channelx.
322 * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
323 * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
324 * @param NewState: new state of the DMAy Channelx.
325 * This parameter can be: ENABLE or DISABLE.
326 * @retval None
328 void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState)
330 /* Check the parameters */
331 assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
332 assert_param(IS_FUNCTIONAL_STATE(NewState));
334 if (NewState != DISABLE)
336 /* Enable the selected DMAy Channelx */
337 DMAy_Channelx->CCR |= DMA_CCR_EN;
339 else
341 /* Disable the selected DMAy Channelx */
342 DMAy_Channelx->CCR &= (uint16_t)(~DMA_CCR_EN);
347 * @}
350 /** @defgroup DMA_Group2 Data Counter functions
351 * @brief Data Counter functions
353 @verbatim
354 ===============================================================================
355 ##### Data Counter functions #####
356 ===============================================================================
357 [..] This subsection provides function allowing to configure and read the buffer
358 size (number of data to be transferred).The DMA data counter can be written
359 only when the DMA channel is disabled (ie. after transfer complete event).
360 [..] The following function can be used to write the Channel data counter value:
361 (+) void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber).
362 [..]
363 (@) It is advised to use this function rather than DMA_Init() in situations
364 where only the Data buffer needs to be reloaded.
365 [..] The DMA data counter can be read to indicate the number of remaining transfers
366 for the relative DMA channel. This counter is decremented at the end of each
367 data transfer and when the transfer is complete:
368 (+) If Normal mode is selected: the counter is set to 0.
369 (+) If Circular mode is selected: the counter is reloaded with the initial
370 value(configured before enabling the DMA channel).
371 [..] The following function can be used to read the Channel data counter value:
372 (+) uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx).
374 @endverbatim
375 * @{
379 * @brief Sets the number of data units in the current DMAy Channelx transfer.
380 * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
381 * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
382 * @param DataNumber: The number of data units in the current DMAy Channelx
383 * transfer.
384 * @note This function can only be used when the DMAy_Channelx is disabled.
385 * @retval None.
387 void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber)
389 /* Check the parameters */
390 assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
392 /*--------------------------- DMAy Channelx CNDTR Configuration --------------*/
393 /* Write to DMAy Channelx CNDTR */
394 DMAy_Channelx->CNDTR = DataNumber;
398 * @brief Returns the number of remaining data units in the current
399 * DMAy Channelx transfer.
400 * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
401 * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
402 * @retval The number of remaining data units in the current DMAy Channelx
403 * transfer.
405 uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx)
407 /* Check the parameters */
408 assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
409 /* Return the number of remaining data units for DMAy Channelx */
410 return ((uint16_t)(DMAy_Channelx->CNDTR));
414 * @}
417 /** @defgroup DMA_Group3 Interrupts and flags management functions
418 * @brief Interrupts and flags management functions
420 @verbatim
421 ===============================================================================
422 ##### Interrupts and flags management functions #####
423 ===============================================================================
424 [..] This subsection provides functions allowing to configure the DMA Interrupt
425 sources and check or clear the flags or pending bits status.
426 The user should identify which mode will be used in his application to manage
427 the DMA controller events: Polling mode or Interrupt mode.
429 *** Polling Mode ***
430 ====================
431 [..] Each DMA channel can be managed through 4 event Flags (y : DMA Controller
432 number, x : DMA channel number):
433 (#) DMAy_FLAG_TCx : to indicate that a Transfer Complete event occurred.
434 (#) DMAy_FLAG_HTx : to indicate that a Half-Transfer Complete event occurred.
435 (#) DMAy_FLAG_TEx : to indicate that a Transfer Error occurred.
436 (#) DMAy_FLAG_GLx : to indicate that at least one of the events described
437 above occurred.
438 [..]
439 (@) Clearing DMAy_FLAG_GLx results in clearing all other pending flags of the
440 same channel (DMAy_FLAG_TCx, DMAy_FLAG_HTx and DMAy_FLAG_TEx).
441 [..] In this Mode it is advised to use the following functions:
442 (+) FlagStatus DMA_GetFlagStatus(uint32_t DMA_FLAG);
443 (+) void DMA_ClearFlag(uint32_t DMA_FLAG);
445 *** Interrupt Mode ***
446 ======================
447 [..] Each DMA channel can be managed through 4 Interrupts:
448 (+) Interrupt Source
449 (##) DMA_IT_TC: specifies the interrupt source for the Transfer Complete
450 event.
451 (##) DMA_IT_HT: specifies the interrupt source for the Half-transfer Complete
452 event.
453 (##) DMA_IT_TE: specifies the interrupt source for the transfer errors event.
454 (##) DMA_IT_GL: to indicate that at least one of the interrupts described
455 above occurred.
456 -@@- Clearing DMA_IT_GL interrupt results in clearing all other interrupts of
457 the same channel (DMA_IT_TCx, DMA_IT_HT and DMA_IT_TE).
458 [..] In this Mode it is advised to use the following functions:
459 (+) void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState);
460 (+) ITStatus DMA_GetITStatus(uint32_t DMA_IT);
461 (+) void DMA_ClearITPendingBit(uint32_t DMA_IT);
463 @endverbatim
464 * @{
468 * @brief Enables or disables the specified DMAy Channelx interrupts.
469 * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
470 * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
471 * @param DMA_IT: specifies the DMA interrupts sources to be enabled
472 * or disabled.
473 * This parameter can be any combination of the following values:
474 * @arg DMA_IT_TC: Transfer complete interrupt mask
475 * @arg DMA_IT_HT: Half transfer interrupt mask
476 * @arg DMA_IT_TE: Transfer error interrupt mask
477 * @param NewState: new state of the specified DMA interrupts.
478 * This parameter can be: ENABLE or DISABLE.
479 * @retval None
481 void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState)
483 /* Check the parameters */
484 assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
485 assert_param(IS_DMA_CONFIG_IT(DMA_IT));
486 assert_param(IS_FUNCTIONAL_STATE(NewState));
488 if (NewState != DISABLE)
490 /* Enable the selected DMA interrupts */
491 DMAy_Channelx->CCR |= DMA_IT;
493 else
495 /* Disable the selected DMA interrupts */
496 DMAy_Channelx->CCR &= ~DMA_IT;
501 * @brief Checks whether the specified DMAy Channelx flag is set or not.
502 * @param DMAy_FLAG: specifies the flag to check.
503 * This parameter can be one of the following values:
504 * @arg DMA1_FLAG_GL1: DMA1 Channel1 global flag.
505 * @arg DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
506 * @arg DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
507 * @arg DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
508 * @arg DMA1_FLAG_GL2: DMA1 Channel2 global flag.
509 * @arg DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
510 * @arg DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
511 * @arg DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
512 * @arg DMA1_FLAG_GL3: DMA1 Channel3 global flag.
513 * @arg DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
514 * @arg DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
515 * @arg DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
516 * @arg DMA1_FLAG_GL4: DMA1 Channel4 global flag.
517 * @arg DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
518 * @arg DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
519 * @arg DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
520 * @arg DMA1_FLAG_GL5: DMA1 Channel5 global flag.
521 * @arg DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
522 * @arg DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
523 * @arg DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
524 * @arg DMA1_FLAG_GL6: DMA1 Channel6 global flag.
525 * @arg DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.
526 * @arg DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.
527 * @arg DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.
528 * @arg DMA1_FLAG_GL7: DMA1 Channel7 global flag.
529 * @arg DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.
530 * @arg DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.
531 * @arg DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.
532 * @arg DMA2_FLAG_GL1: DMA2 Channel1 global flag.
533 * @arg DMA2_FLAG_TC1: DMA2 Channel1 transfer complete flag.
534 * @arg DMA2_FLAG_HT1: DMA2 Channel1 half transfer flag.
535 * @arg DMA2_FLAG_TE1: DMA2 Channel1 transfer error flag.
536 * @arg DMA2_FLAG_GL2: DMA2 Channel2 global flag.
537 * @arg DMA2_FLAG_TC2: DMA2 Channel2 transfer complete flag.
538 * @arg DMA2_FLAG_HT2: DMA2 Channel2 half transfer flag.
539 * @arg DMA2_FLAG_TE2: DMA2 Channel2 transfer error flag.
540 * @arg DMA2_FLAG_GL3: DMA2 Channel3 global flag.
541 * @arg DMA2_FLAG_TC3: DMA2 Channel3 transfer complete flag.
542 * @arg DMA2_FLAG_HT3: DMA2 Channel3 half transfer flag.
543 * @arg DMA2_FLAG_TE3: DMA2 Channel3 transfer error flag.
544 * @arg DMA2_FLAG_GL4: DMA2 Channel4 global flag.
545 * @arg DMA2_FLAG_TC4: DMA2 Channel4 transfer complete flag.
546 * @arg DMA2_FLAG_HT4: DMA2 Channel4 half transfer flag.
547 * @arg DMA2_FLAG_TE4: DMA2 Channel4 transfer error flag.
548 * @arg DMA2_FLAG_GL5: DMA2 Channel5 global flag.
549 * @arg DMA2_FLAG_TC5: DMA2 Channel5 transfer complete flag.
550 * @arg DMA2_FLAG_HT5: DMA2 Channel5 half transfer flag.
551 * @arg DMA2_FLAG_TE5: DMA2 Channel5 transfer error flag.
553 * @note
554 * The Global flag (DMAy_FLAG_GLx) is set whenever any of the other flags
555 * relative to the same channel is set (Transfer Complete, Half-transfer
556 * Complete or Transfer Error flags: DMAy_FLAG_TCx, DMAy_FLAG_HTx or
557 * DMAy_FLAG_TEx).
559 * @retval The new state of DMAy_FLAG (SET or RESET).
561 FlagStatus DMA_GetFlagStatus(uint32_t DMAy_FLAG)
563 FlagStatus bitstatus = RESET;
564 uint32_t tmpreg = 0;
566 /* Check the parameters */
567 assert_param(IS_DMA_GET_FLAG(DMAy_FLAG));
569 /* Calculate the used DMAy */
570 if ((DMAy_FLAG & FLAG_Mask) != (uint32_t)RESET)
572 /* Get DMA2 ISR register value */
573 tmpreg = DMA2->ISR ;
575 else
577 /* Get DMA1 ISR register value */
578 tmpreg = DMA1->ISR ;
581 /* Check the status of the specified DMAy flag */
582 if ((tmpreg & DMAy_FLAG) != (uint32_t)RESET)
584 /* DMAy_FLAG is set */
585 bitstatus = SET;
587 else
589 /* DMAy_FLAG is reset */
590 bitstatus = RESET;
593 /* Return the DMAy_FLAG status */
594 return bitstatus;
598 * @brief Clears the DMAy Channelx's pending flags.
599 * @param DMAy_FLAG: specifies the flag to clear.
600 * This parameter can be any combination (for the same DMA) of the following values:
601 * @arg DMA1_FLAG_GL1: DMA1 Channel1 global flag.
602 * @arg DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
603 * @arg DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
604 * @arg DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
605 * @arg DMA1_FLAG_GL2: DMA1 Channel2 global flag.
606 * @arg DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
607 * @arg DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
608 * @arg DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
609 * @arg DMA1_FLAG_GL3: DMA1 Channel3 global flag.
610 * @arg DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
611 * @arg DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
612 * @arg DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
613 * @arg DMA1_FLAG_GL4: DMA1 Channel4 global flag.
614 * @arg DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
615 * @arg DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
616 * @arg DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
617 * @arg DMA1_FLAG_GL5: DMA1 Channel5 global flag.
618 * @arg DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
619 * @arg DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
620 * @arg DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
621 * @arg DMA1_FLAG_GL6: DMA1 Channel6 global flag.
622 * @arg DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.
623 * @arg DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.
624 * @arg DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.
625 * @arg DMA1_FLAG_GL7: DMA1 Channel7 global flag.
626 * @arg DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.
627 * @arg DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.
628 * @arg DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.
629 * @arg DMA2_FLAG_GL1: DMA2 Channel1 global flag.
630 * @arg DMA2_FLAG_TC1: DMA2 Channel1 transfer complete flag.
631 * @arg DMA2_FLAG_HT1: DMA2 Channel1 half transfer flag.
632 * @arg DMA2_FLAG_TE1: DMA2 Channel1 transfer error flag.
633 * @arg DMA2_FLAG_GL2: DMA2 Channel2 global flag.
634 * @arg DMA2_FLAG_TC2: DMA2 Channel2 transfer complete flag.
635 * @arg DMA2_FLAG_HT2: DMA2 Channel2 half transfer flag.
636 * @arg DMA2_FLAG_TE2: DMA2 Channel2 transfer error flag.
637 * @arg DMA2_FLAG_GL3: DMA2 Channel3 global flag.
638 * @arg DMA2_FLAG_TC3: DMA2 Channel3 transfer complete flag.
639 * @arg DMA2_FLAG_HT3: DMA2 Channel3 half transfer flag.
640 * @arg DMA2_FLAG_TE3: DMA2 Channel3 transfer error flag.
641 * @arg DMA2_FLAG_GL4: DMA2 Channel4 global flag.
642 * @arg DMA2_FLAG_TC4: DMA2 Channel4 transfer complete flag.
643 * @arg DMA2_FLAG_HT4: DMA2 Channel4 half transfer flag.
644 * @arg DMA2_FLAG_TE4: DMA2 Channel4 transfer error flag.
645 * @arg DMA2_FLAG_GL5: DMA2 Channel5 global flag.
646 * @arg DMA2_FLAG_TC5: DMA2 Channel5 transfer complete flag.
647 * @arg DMA2_FLAG_HT5: DMA2 Channel5 half transfer flag.
648 * @arg DMA2_FLAG_TE5: DMA2 Channel5 transfer error flag.
650 * @note
651 * Clearing the Global flag (DMAy_FLAG_GLx) results in clearing all other flags
652 * relative to the same channel (Transfer Complete, Half-transfer Complete and
653 * Transfer Error flags: DMAy_FLAG_TCx, DMAy_FLAG_HTx and DMAy_FLAG_TEx).
655 * @retval None
657 void DMA_ClearFlag(uint32_t DMAy_FLAG)
659 /* Check the parameters */
660 assert_param(IS_DMA_CLEAR_FLAG(DMAy_FLAG));
662 /* Calculate the used DMAy */
663 if ((DMAy_FLAG & FLAG_Mask) != (uint32_t)RESET)
665 /* Clear the selected DMAy flags */
666 DMA2->IFCR = DMAy_FLAG;
668 else
670 /* Clear the selected DMAy flags */
671 DMA1->IFCR = DMAy_FLAG;
676 * @brief Checks whether the specified DMAy Channelx interrupt has occurred or not.
677 * @param DMAy_IT: specifies the DMAy interrupt source to check.
678 * This parameter can be one of the following values:
679 * @arg DMA1_IT_GL1: DMA1 Channel1 global interrupt.
680 * @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
681 * @arg DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.
682 * @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
683 * @arg DMA1_IT_GL2: DMA1 Channel2 global interrupt.
684 * @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
685 * @arg DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.
686 * @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
687 * @arg DMA1_IT_GL3: DMA1 Channel3 global interrupt.
688 * @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
689 * @arg DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.
690 * @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
691 * @arg DMA1_IT_GL4: DMA1 Channel4 global interrupt.
692 * @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
693 * @arg DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.
694 * @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
695 * @arg DMA1_IT_GL5: DMA1 Channel5 global interrupt.
696 * @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
697 * @arg DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.
698 * @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
699 * @arg DMA1_IT_GL6: DMA1 Channel6 global interrupt.
700 * @arg DMA1_IT_TC6: DMA1 Channel6 transfer complete interrupt.
701 * @arg DMA1_IT_HT6: DMA1 Channel6 half transfer interrupt.
702 * @arg DMA1_IT_TE6: DMA1 Channel6 transfer error interrupt.
703 * @arg DMA1_IT_GL7: DMA1 Channel7 global interrupt.
704 * @arg DMA1_IT_TC7: DMA1 Channel7 transfer complete interrupt.
705 * @arg DMA1_IT_HT7: DMA1 Channel7 half transfer interrupt.
706 * @arg DMA1_IT_TE7: DMA1 Channel7 transfer error interrupt.
707 * @arg DMA2_IT_GL1: DMA2 Channel1 global interrupt.
708 * @arg DMA2_IT_TC1: DMA2 Channel1 transfer complete interrupt.
709 * @arg DMA2_IT_HT1: DMA2 Channel1 half transfer interrupt.
710 * @arg DMA2_IT_TE1: DMA2 Channel1 transfer error interrupt.
711 * @arg DMA2_IT_GL2: DMA2 Channel2 global interrupt.
712 * @arg DMA2_IT_TC2: DMA2 Channel2 transfer complete interrupt.
713 * @arg DMA2_IT_HT2: DMA2 Channel2 half transfer interrupt.
714 * @arg DMA2_IT_TE2: DMA2 Channel2 transfer error interrupt.
715 * @arg DMA2_IT_GL3: DMA2 Channel3 global interrupt.
716 * @arg DMA2_IT_TC3: DMA2 Channel3 transfer complete interrupt.
717 * @arg DMA2_IT_HT3: DMA2 Channel3 half transfer interrupt.
718 * @arg DMA2_IT_TE3: DMA2 Channel3 transfer error interrupt.
719 * @arg DMA2_IT_GL4: DMA2 Channel4 global interrupt.
720 * @arg DMA2_IT_TC4: DMA2 Channel4 transfer complete interrupt.
721 * @arg DMA2_IT_HT4: DMA2 Channel4 half transfer interrupt.
722 * @arg DMA2_IT_TE4: DMA2 Channel4 transfer error interrupt.
723 * @arg DMA2_IT_GL5: DMA2 Channel5 global interrupt.
724 * @arg DMA2_IT_TC5: DMA2 Channel5 transfer complete interrupt.
725 * @arg DMA2_IT_HT5: DMA2 Channel5 half transfer interrupt.
726 * @arg DMA2_IT_TE5: DMA2 Channel5 transfer error interrupt.
728 * @note
729 * The Global interrupt (DMAy_FLAG_GLx) is set whenever any of the other
730 * interrupts relative to the same channel is set (Transfer Complete,
731 * Half-transfer Complete or Transfer Error interrupts: DMAy_IT_TCx,
732 * DMAy_IT_HTx or DMAy_IT_TEx).
734 * @retval The new state of DMAy_IT (SET or RESET).
736 ITStatus DMA_GetITStatus(uint32_t DMAy_IT)
738 ITStatus bitstatus = RESET;
739 uint32_t tmpreg = 0;
741 /* Check the parameters */
742 assert_param(IS_DMA_GET_IT(DMAy_IT));
744 /* Calculate the used DMA */
745 if ((DMAy_IT & FLAG_Mask) != (uint32_t)RESET)
747 /* Get DMA2 ISR register value */
748 tmpreg = DMA2->ISR;
750 else
752 /* Get DMA1 ISR register value */
753 tmpreg = DMA1->ISR;
756 /* Check the status of the specified DMAy interrupt */
757 if ((tmpreg & DMAy_IT) != (uint32_t)RESET)
759 /* DMAy_IT is set */
760 bitstatus = SET;
762 else
764 /* DMAy_IT is reset */
765 bitstatus = RESET;
767 /* Return the DMAy_IT status */
768 return bitstatus;
772 * @brief Clears the DMAy Channelx's interrupt pending bits.
773 * @param DMAy_IT: specifies the DMAy interrupt pending bit to clear.
774 * This parameter can be any combination (for the same DMA) of the following values:
775 * @arg DMA1_IT_GL1: DMA1 Channel1 global interrupt.
776 * @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
777 * @arg DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.
778 * @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
779 * @arg DMA1_IT_GL2: DMA1 Channel2 global interrupt.
780 * @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
781 * @arg DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.
782 * @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
783 * @arg DMA1_IT_GL3: DMA1 Channel3 global interrupt.
784 * @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
785 * @arg DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.
786 * @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
787 * @arg DMA1_IT_GL4: DMA1 Channel4 global interrupt.
788 * @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
789 * @arg DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.
790 * @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
791 * @arg DMA1_IT_GL5: DMA1 Channel5 global interrupt.
792 * @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
793 * @arg DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.
794 * @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
795 * @arg DMA1_IT_GL6: DMA1 Channel6 global interrupt.
796 * @arg DMA1_IT_TC6: DMA1 Channel6 transfer complete interrupt.
797 * @arg DMA1_IT_HT6: DMA1 Channel6 half transfer interrupt.
798 * @arg DMA1_IT_TE6: DMA1 Channel6 transfer error interrupt.
799 * @arg DMA1_IT_GL7: DMA1 Channel7 global interrupt.
800 * @arg DMA1_IT_TC7: DMA1 Channel7 transfer complete interrupt.
801 * @arg DMA1_IT_HT7: DMA1 Channel7 half transfer interrupt.
802 * @arg DMA1_IT_TE7: DMA1 Channel7 transfer error interrupt.
803 * @arg DMA2_IT_GL1: DMA2 Channel1 global interrupt.
804 * @arg DMA2_IT_TC1: DMA2 Channel1 transfer complete interrupt.
805 * @arg DMA2_IT_HT1: DMA2 Channel1 half transfer interrupt.
806 * @arg DMA2_IT_TE1: DMA2 Channel1 transfer error interrupt.
807 * @arg DMA2_IT_GL2: DMA2 Channel2 global interrupt.
808 * @arg DMA2_IT_TC2: DMA2 Channel2 transfer complete interrupt.
809 * @arg DMA2_IT_HT2: DMA2 Channel2 half transfer interrupt.
810 * @arg DMA2_IT_TE2: DMA2 Channel2 transfer error interrupt.
811 * @arg DMA2_IT_GL3: DMA2 Channel3 global interrupt.
812 * @arg DMA2_IT_TC3: DMA2 Channel3 transfer complete interrupt.
813 * @arg DMA2_IT_HT3: DMA2 Channel3 half transfer interrupt.
814 * @arg DMA2_IT_TE3: DMA2 Channel3 transfer error interrupt.
815 * @arg DMA2_IT_GL4: DMA2 Channel4 global interrupt.
816 * @arg DMA2_IT_TC4: DMA2 Channel4 transfer complete interrupt.
817 * @arg DMA2_IT_HT4: DMA2 Channel4 half transfer interrupt.
818 * @arg DMA2_IT_TE4: DMA2 Channel4 transfer error interrupt.
819 * @arg DMA2_IT_GL5: DMA2 Channel5 global interrupt.
820 * @arg DMA2_IT_TC5: DMA2 Channel5 transfer complete interrupt.
821 * @arg DMA2_IT_HT5: DMA2 Channel5 half transfer interrupt.
822 * @arg DMA2_IT_TE5: DMA2 Channel5 transfer error interrupt.
824 * @note
825 * Clearing the Global interrupt (DMAy_IT_GLx) results in clearing all other
826 * interrupts relative to the same channel (Transfer Complete, Half-transfer
827 * Complete and Transfer Error interrupts: DMAy_IT_TCx, DMAy_IT_HTx and
828 * DMAy_IT_TEx).
830 * @retval None
832 void DMA_ClearITPendingBit(uint32_t DMAy_IT)
834 /* Check the parameters */
835 assert_param(IS_DMA_CLEAR_IT(DMAy_IT));
837 /* Calculate the used DMAy */
838 if ((DMAy_IT & FLAG_Mask) != (uint32_t)RESET)
840 /* Clear the selected DMAy interrupt pending bits */
841 DMA2->IFCR = DMAy_IT;
843 else
845 /* Clear the selected DMAy interrupt pending bits */
846 DMA1->IFCR = DMAy_IT;
851 * @}
855 * @}
859 * @}
863 * @}
866 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/