annotate f103c8/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c @ 6:ca42336826bd default tip

working on clock sources
author cin
date Mon, 23 Jan 2017 02:40:17 +0300
parents 0c59e7a7782a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3 * @file stm32f1xx_hal_dma.c
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4 * @author MCD Application Team
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5 * @version V1.0.4
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
6 * @date 29-April-2016
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
7 * @brief DMA HAL module driver.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
8 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
9 * This file provides firmware functions to manage the following
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
10 * functionalities of the Direct Memory Access (DMA) peripheral:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
11 * + Initialization and de-initialization functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
12 * + IO operation functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
13 * + Peripheral State and errors functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
14 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
15 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
16 ##### How to use this driver #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
17 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
18 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
19 (#) Enable and configure the peripheral to be connected to the DMA Channel
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
20 (except for internal SRAM / FLASH memories: no initialization is
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
21 necessary) please refer to Reference manual for connection between peripherals
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
22 and DMA requests.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
23
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
24 (#) For a given Channel, program the required configuration through the following parameters:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
25 Transfer Direction, Source and Destination data formats,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
26 Circular or Normal mode, Channel Priority level, Source and Destination Increment mode,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
27 using HAL_DMA_Init() function.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
28
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
29 (#) Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
30 detection.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
31
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
32 (#) Use HAL_DMA_Abort() function to abort the current transfer
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
33
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
34 -@- In Memory-to-Memory transfer mode, Circular mode is not allowed.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
35 *** Polling mode IO operation ***
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
36 =================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
37 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
38 (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
39 address and destination address and the Length of data to be transferred
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
40 (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
41 case a fixed Timeout can be configured by User depending from his application.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
42
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
43 *** Interrupt mode IO operation ***
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
44 ===================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
45 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
46 (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
47 (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
48 (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
49 Source address and destination address and the Length of data to be transferred.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
50 In this case the DMA interrupt is configured
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
51 (+) Use HAL_DMAy_Channelx_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
52 (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
53 add his own function by customization of function pointer XferCpltCallback and
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
54 XferErrorCallback (i.e a member of DMA handle structure).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
55
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
56 *** DMA HAL driver macros list ***
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
57 =============================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
58 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
59 Below the list of most used macros in DMA HAL driver.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
60
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
61 (+) __HAL_DMA_ENABLE: Enable the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
62 (+) __HAL_DMA_DISABLE: Disable the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
63 (+) __HAL_DMA_GET_FLAG: Get the DMA Channel pending flags.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
64 (+) __HAL_DMA_CLEAR_FLAG: Clear the DMA Channel pending flags.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
65 (+) __HAL_DMA_ENABLE_IT: Enable the specified DMA Channel interrupts.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
66 (+) __HAL_DMA_DISABLE_IT: Disable the specified DMA Channel interrupts.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
67 (+) __HAL_DMA_GET_IT_SOURCE: Check whether the specified DMA Channel interrupt has occurred or not.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
68
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
69 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
70 (@) You can refer to the DMA HAL driver header file for more useful macros
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
71
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
72 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
73 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
74 * @attention
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
75 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
76 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
77 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
78 * Redistribution and use in source and binary forms, with or without modification,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
79 * are permitted provided that the following conditions are met:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
80 * 1. Redistributions of source code must retain the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
81 * this list of conditions and the following disclaimer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
82 * 2. Redistributions in binary form must reproduce the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
83 * this list of conditions and the following disclaimer in the documentation
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
84 * and/or other materials provided with the distribution.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
85 * 3. Neither the name of STMicroelectronics nor the names of its contributors
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
86 * may be used to endorse or promote products derived from this software
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
87 * without specific prior written permission.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
88 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
89 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
90 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
91 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
92 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
93 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
94 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
95 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
96 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
97 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
98 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
99 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
100 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
101 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
102
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
103 /* Includes ------------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
104 #include "stm32f1xx_hal.h"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
105
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
106 /** @addtogroup STM32F1xx_HAL_Driver
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
107 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
108 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
109
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
110 /** @defgroup DMA DMA
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
111 * @brief DMA HAL module driver
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
112 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
113 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
114
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
115 #ifdef HAL_DMA_MODULE_ENABLED
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
116
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
117 /* Private typedef -----------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
118 /* Private define ------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
119 /** @defgroup DMA_Private_Constants DMA Private Constants
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
120 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
121 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
122 #define HAL_TIMEOUT_DMA_ABORT ((uint32_t)1000) /* 1s */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
123 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
124 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
125 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
126
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
127 /* Private macro -------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
128 /* Private variables ---------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
129 /* Private function prototypes -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
130 /** @defgroup DMA_Private_Functions DMA Private Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
131 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
132 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
133 static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
134 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
135 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
136 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
137
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
138 /* Exported functions ---------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
139
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
140 /** @defgroup DMA_Exported_Functions DMA Exported Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
141 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
142 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
143
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
144 /** @defgroup DMA_Exported_Functions_Group1 Initialization and de-initialization functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
145 * @brief Initialization and de-initialization functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
146 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
147 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
148 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
149 ##### Initialization and de-initialization functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
150 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
151 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
152 This section provides functions allowing to initialize the DMA Channel source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
153 and destination addresses, incrementation and data sizes, transfer direction,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
154 circular/normal mode selection, memory-to-memory mode selection and Channel priority value.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
155 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
156 The HAL_DMA_Init() function follows the DMA configuration procedures as described in
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
157 reference manual.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
158
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
159 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
160 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
161 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
162
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
163 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
164 * @brief Initializes the DMA according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
165 * parameters in the DMA_InitTypeDef and create the associated handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
166 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
167 * the configuration information for the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
168 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
169 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
170 HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
171 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
172 uint32_t tmp = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
173
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
174 /* Check the DMA handle allocation */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
175 if(hdma == NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
176 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
177 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
178 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
179
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
180 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
181 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
182 assert_param(IS_DMA_DIRECTION(hdma->Init.Direction));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
183 assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
184 assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
185 assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
186 assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
187 assert_param(IS_DMA_MODE(hdma->Init.Mode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
188 assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
189
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
190 if(hdma->State == HAL_DMA_STATE_RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
191 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
192 /* Allocate lock resource and initialize it */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
193 hdma->Lock = HAL_UNLOCKED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
194 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
195
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
196 /* Change DMA peripheral state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
197 hdma->State = HAL_DMA_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
198
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
199 /* Get the CR register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
200 tmp = hdma->Instance->CCR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
201
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
202 /* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
203 tmp &= ((uint32_t)~(DMA_CCR_PL | DMA_CCR_MSIZE | DMA_CCR_PSIZE | \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
204 DMA_CCR_MINC | DMA_CCR_PINC | DMA_CCR_CIRC | \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
205 DMA_CCR_DIR));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
206
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
207 /* Prepare the DMA Channel configuration */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
208 tmp |= hdma->Init.Direction |
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
209 hdma->Init.PeriphInc | hdma->Init.MemInc |
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
210 hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
211 hdma->Init.Mode | hdma->Init.Priority;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
212
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
213 /* Write to DMA Channel CR register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
214 hdma->Instance->CCR = tmp;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
215
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
216 /* Initialise the error code */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
217 hdma->ErrorCode = HAL_DMA_ERROR_NONE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
218
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
219 /* Initialize the DMA state*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
220 hdma->State = HAL_DMA_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
221
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
222 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
223 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
224
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
225 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
226 * @brief DeInitializes the DMA peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
227 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
228 * the configuration information for the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
229 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
230 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
231 HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
232 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
233 /* Check the DMA handle allocation */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
234 if(hdma == NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
235 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
236 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
237 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
238
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
239 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
240 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
241
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
242 /* Check the DMA peripheral state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
243 if(hdma->State == HAL_DMA_STATE_BUSY)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
244 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
245 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
246 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
247
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
248 /* Disable the selected DMA Channelx */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
249 __HAL_DMA_DISABLE(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
250
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
251 /* Reset DMA Channel control register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
252 hdma->Instance->CCR = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
253
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
254 /* Reset DMA Channel Number of Data to Transfer register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
255 hdma->Instance->CNDTR = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
256
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
257 /* Reset DMA Channel peripheral address register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
258 hdma->Instance->CPAR = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
259
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
260 /* Reset DMA Channel memory address register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
261 hdma->Instance->CMAR = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
262
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
263 /* Clear all flags */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
264 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
265 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
266 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
267
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
268 /* Initialize the error code */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
269 hdma->ErrorCode = HAL_DMA_ERROR_NONE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
270
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
271 /* Initialize the DMA state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
272 hdma->State = HAL_DMA_STATE_RESET;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
273
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
274 /* Release Lock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
275 __HAL_UNLOCK(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
276
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
277 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
278 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
279
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
280 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
281 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
282 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
283
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
284 /** @defgroup DMA_Exported_Functions_Group2 Input and Output operation functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
285 * @brief I/O operation functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
286 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
287 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
288 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
289 ##### IO operation functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
290 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
291 [..] This section provides functions allowing to:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
292 (+) Configure the source, destination address and data length and Start DMA transfer
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
293 (+) Configure the source, destination address and data length and
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
294 Start DMA transfer with interrupt
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
295 (+) Abort DMA transfer
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
296 (+) Poll for transfer complete
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
297 (+) Handle DMA interrupt request
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
298
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
299 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
300 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
301 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
302
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
303 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
304 * @brief Starts the DMA Transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
305 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
306 * the configuration information for the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
307 * @param SrcAddress: The source memory Buffer address
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
308 * @param DstAddress: The destination memory Buffer address
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
309 * @param DataLength: The length of data to be transferred from source to destination
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
310 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
311 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
312 HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
313 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
314 /* Process locked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
315 __HAL_LOCK(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
316
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
317 /* Change DMA peripheral state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
318 hdma->State = HAL_DMA_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
319
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
320 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
321 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
322
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
323 /* Disable the peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
324 __HAL_DMA_DISABLE(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
325
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
326 /* Configure the source, destination address and the data length */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
327 DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
328
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
329 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
330 __HAL_DMA_ENABLE(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
331
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
332 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
333 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
334
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
335 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
336 * @brief Start the DMA Transfer with interrupt enabled.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
337 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
338 * the configuration information for the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
339 * @param SrcAddress: The source memory Buffer address
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
340 * @param DstAddress: The destination memory Buffer address
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
341 * @param DataLength: The length of data to be transferred from source to destination
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
342 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
343 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
344 HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
345 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
346 /* Process locked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
347 __HAL_LOCK(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
348
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
349 /* Change DMA peripheral state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
350 hdma->State = HAL_DMA_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
351
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
352 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
353 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
354
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
355 /* Disable the peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
356 __HAL_DMA_DISABLE(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
357
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
358 /* Configure the source, destination address and the data length */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
359 DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
360
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
361 /* Enable the transfer complete interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
362 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TC);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
363
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
364 /* Enable the Half transfer complete interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
365 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_HT);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
366
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
367 /* Enable the transfer Error interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
368 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
369
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
370 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
371 __HAL_DMA_ENABLE(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
372
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
373 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
374 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
375
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
376 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
377 * @brief Aborts the DMA Transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
378 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
379 * the configuration information for the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
380 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
381 * @note After disabling a DMA Channel, a check for wait until the DMA Channel is
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
382 * effectively disabled is added. If a Channel is disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
383 * while a data transfer is ongoing, the current data will be transferred
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
384 * and the Channel will be effectively disabled only after the transfer of
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
385 * this single data is finished.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
386 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
387 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
388 HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
389 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
390 uint32_t tickstart = 0x00;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
391
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
392 /* Disable the channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
393 __HAL_DMA_DISABLE(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
394
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
395 /* Get tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
396 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
397
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
398 /* Check if the DMA Channel is effectively disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
399 while((hdma->Instance->CCR & DMA_CCR_EN) != 0)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
400 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
401 /* Check for the Timeout */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
402 if((HAL_GetTick() - tickstart) > HAL_TIMEOUT_DMA_ABORT)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
403 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
404 /* Update error code */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
405 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
406
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
407 /* Change the DMA state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
408 hdma->State = HAL_DMA_STATE_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
409
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
410 /* Process Unlocked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
411 __HAL_UNLOCK(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
412
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
413 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
414 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
415 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
416 /* Change the DMA state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
417 hdma->State = HAL_DMA_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
418
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
419 /* Process Unlocked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
420 __HAL_UNLOCK(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
421
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
422 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
423 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
424
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
425 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
426 * @brief Polling for transfer complete.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
427 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
428 * the configuration information for the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
429 * @param CompleteLevel: Specifies the DMA level complete.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
430 * @param Timeout: Timeout duration.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
431 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
432 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
433 HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
434 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
435 uint32_t temp;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
436 uint32_t tickstart = 0x00;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
437
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
438 /* Get the level transfer complete flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
439 if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
440 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
441 /* Transfer Complete flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
442 temp = __HAL_DMA_GET_TC_FLAG_INDEX(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
443 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
444 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
445 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
446 /* Half Transfer Complete flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
447 temp = __HAL_DMA_GET_HT_FLAG_INDEX(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
448 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
449
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
450 /* Get tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
451 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
452
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
453 while(__HAL_DMA_GET_FLAG(hdma, temp) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
454 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
455 if((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
456 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
457 /* Clear the transfer error flags */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
458 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
459
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
460 /* Update error code */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
461 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
462
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
463 /* Change the DMA state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
464 hdma->State= HAL_DMA_STATE_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
465
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
466 /* Process Unlocked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
467 __HAL_UNLOCK(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
468
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
469 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
470 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
471 /* Check for the Timeout */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
472 if(Timeout != HAL_MAX_DELAY)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
473 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
474 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
475 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
476 /* Update error code */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
477 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
478
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
479 /* Change the DMA state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
480 hdma->State = HAL_DMA_STATE_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
481
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
482 /* Process Unlocked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
483 __HAL_UNLOCK(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
484
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
485 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
486 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
487 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
488 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
489
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
490 if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
491 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
492 /* Clear the transfer complete flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
493 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
494
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
495 /* The selected Channelx EN bit is cleared (DMA is disabled and
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
496 all transfers are complete) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
497 hdma->State = HAL_DMA_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
498
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
499 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
500 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
501 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
502 /* Clear the half transfer complete flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
503 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
504
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
505 /* The selected Channelx EN bit is cleared (DMA is disabled and
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
506 all transfers of half buffer are complete) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
507 hdma->State = HAL_DMA_STATE_READY_HALF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
508 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
509
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
510 /* Process unlocked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
511 __HAL_UNLOCK(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
512
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
513 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
514 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
515
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
516 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
517 * @brief Handles DMA interrupt request.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
518 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
519 * the configuration information for the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
520 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
521 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
522 void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
523 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
524 /* Transfer Error Interrupt management ***************************************/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
525 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
526 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
527 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TE) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
528 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
529 /* Disable the transfer error interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
530 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
531
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
532 /* Clear the transfer error flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
533 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
534
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
535 /* Update error code */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
536 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
537
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
538 /* Change the DMA state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
539 hdma->State = HAL_DMA_STATE_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
540
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
541 /* Process Unlocked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
542 __HAL_UNLOCK(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
543
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
544 if (hdma->XferErrorCallback != NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
545 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
546 /* Transfer error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
547 hdma->XferErrorCallback(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
548 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
549 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
550 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
551
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
552 /* Half Transfer Complete Interrupt management ******************************/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
553 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
554 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
555 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_HT) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
556 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
557 /* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
558 if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
559 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
560 /* Disable the half transfer interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
561 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
562 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
563 /* Clear the half transfer complete flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
564 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
565
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
566 /* Change DMA peripheral state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
567 hdma->State = HAL_DMA_STATE_READY_HALF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
568
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
569 if(hdma->XferHalfCpltCallback != NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
570 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
571 /* Half transfer callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
572 hdma->XferHalfCpltCallback(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
573 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
574 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
575 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
576
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
577 /* Transfer Complete Interrupt management ***********************************/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
578 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
579 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
580 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TC) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
581 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
582 if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
583 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
584 /* Disable the transfer complete interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
585 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TC);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
586 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
587 /* Clear the transfer complete flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
588 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
589
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
590 /* Update error code */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
591 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_NONE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
592
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
593 /* Change the DMA state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
594 hdma->State = HAL_DMA_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
595
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
596 /* Process Unlocked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
597 __HAL_UNLOCK(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
598
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
599 if(hdma->XferCpltCallback != NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
600 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
601 /* Transfer complete callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
602 hdma->XferCpltCallback(hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
603 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
604 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
605 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
606 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
607
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
608 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
609 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
610 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
611
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
612 /** @defgroup DMA_Exported_Functions_Group3 Peripheral State functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
613 * @brief Peripheral State functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
614 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
615 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
616 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
617 ##### State and Errors functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
618 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
619 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
620 This subsection provides functions allowing to
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
621 (+) Check the DMA state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
622 (+) Get error code
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
623
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
624 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
625 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
626 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
627
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
628 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
629 * @brief Returns the DMA state.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
630 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
631 * the configuration information for the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
632 * @retval HAL state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
633 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
634 HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
635 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
636 return hdma->State;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
637 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
638
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
639 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
640 * @brief Return the DMA error code
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
641 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
642 * the configuration information for the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
643 * @retval DMA Error Code
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
644 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
645 uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
646 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
647 return hdma->ErrorCode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
648 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
649
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
650 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
651 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
652 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
653
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
654 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
655 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
656 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
657
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
658 /** @addtogroup DMA_Private_Functions DMA Private Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
659 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
660 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
661
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
662 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
663 * @brief Sets the DMA Transfer parameter.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
664 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
665 * the configuration information for the specified DMA Channel.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
666 * @param SrcAddress: The source memory Buffer address
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
667 * @param DstAddress: The destination memory Buffer address
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
668 * @param DataLength: The length of data to be transferred from source to destination
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
669 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
670 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
671 static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
672 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
673 /* Configure DMA Channel data length */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
674 hdma->Instance->CNDTR = DataLength;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
675
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
676 /* Peripheral to Memory */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
677 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
678 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
679 /* Configure DMA Channel destination address */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
680 hdma->Instance->CPAR = DstAddress;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
681
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
682 /* Configure DMA Channel source address */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
683 hdma->Instance->CMAR = SrcAddress;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
684 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
685 /* Memory to Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
686 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
687 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
688 /* Configure DMA Channel source address */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
689 hdma->Instance->CPAR = SrcAddress;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
690
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
691 /* Configure DMA Channel destination address */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
692 hdma->Instance->CMAR = DstAddress;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
693 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
694 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
695
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
696 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
697 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
698 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
699
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
700 #endif /* HAL_DMA_MODULE_ENABLED */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
701 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
702 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
703 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
704
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
705 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
706 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
707 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
708
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
709 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/