Mercurial > public > ostc4
comparison Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_dma_ex.c @ 38:5f11787b4f42
include in ostc4 repository
author | heinrichsweikamp |
---|---|
date | Sat, 28 Apr 2018 11:52:34 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
37:ccc45c0e1ea2 | 38:5f11787b4f42 |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm32f4xx_hal_dma_ex.c | |
4 * @author MCD Application Team | |
5 * @version V1.2.0 | |
6 * @date 26-December-2014 | |
7 * @brief DMA Extension HAL module driver | |
8 * This file provides firmware functions to manage the following | |
9 * functionalities of the DMA Extension peripheral: | |
10 * + Extended features functions | |
11 * | |
12 @verbatim | |
13 ============================================================================== | |
14 ##### How to use this driver ##### | |
15 ============================================================================== | |
16 [..] | |
17 The DMA Extension HAL driver can be used as follows: | |
18 (#) Start a multi buffer transfer using the HAL_DMA_MultiBufferStart() function | |
19 for polling mode or HAL_DMA_MultiBufferStart_IT() for interrupt mode. | |
20 | |
21 -@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed. | |
22 -@- When Multi (Double) Buffer mode is enabled the, transfer is circular by default. | |
23 -@- In Multi (Double) buffer mode, it is possible to update the base address for | |
24 the AHB memory port on the fly (DMA_SxM0AR or DMA_SxM1AR) when the stream is enabled. | |
25 | |
26 @endverbatim | |
27 ****************************************************************************** | |
28 * @attention | |
29 * | |
30 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> | |
31 * | |
32 * Redistribution and use in source and binary forms, with or without modification, | |
33 * are permitted provided that the following conditions are met: | |
34 * 1. Redistributions of source code must retain the above copyright notice, | |
35 * this list of conditions and the following disclaimer. | |
36 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
37 * this list of conditions and the following disclaimer in the documentation | |
38 * and/or other materials provided with the distribution. | |
39 * 3. Neither the name of STMicroelectronics nor the names of its contributors | |
40 * may be used to endorse or promote products derived from this software | |
41 * without specific prior written permission. | |
42 * | |
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
44 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
46 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
49 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
50 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
51 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
53 * | |
54 ****************************************************************************** | |
55 */ | |
56 | |
57 /* Includes ------------------------------------------------------------------*/ | |
58 #include "stm32f4xx_hal.h" | |
59 | |
60 /** @addtogroup STM32F4xx_HAL_Driver | |
61 * @{ | |
62 */ | |
63 | |
64 /** @defgroup DMAEx DMAEx | |
65 * @brief DMA Extended HAL module driver | |
66 * @{ | |
67 */ | |
68 | |
69 #ifdef HAL_DMA_MODULE_ENABLED | |
70 | |
71 /* Private types -------------------------------------------------------------*/ | |
72 /* Private variables ---------------------------------------------------------*/ | |
73 /* Private Constants ---------------------------------------------------------*/ | |
74 /* Private macros ------------------------------------------------------------*/ | |
75 /* Private functions ---------------------------------------------------------*/ | |
76 /** @addtogroup DMAEx_Private_Functions | |
77 * @{ | |
78 */ | |
79 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); | |
80 /** | |
81 * @} | |
82 */ | |
83 | |
84 /* Exported functions ---------------------------------------------------------*/ | |
85 | |
86 /** @addtogroup DMAEx_Exported_Functions | |
87 * @{ | |
88 */ | |
89 | |
90 | |
91 /** @addtogroup DMAEx_Exported_Functions_Group1 | |
92 * | |
93 @verbatim | |
94 =============================================================================== | |
95 ##### Extended features functions ##### | |
96 =============================================================================== | |
97 [..] This section provides functions allowing to: | |
98 (+) Configure the source, destination address and data length and | |
99 Start MultiBuffer DMA transfer | |
100 (+) Configure the source, destination address and data length and | |
101 Start MultiBuffer DMA transfer with interrupt | |
102 (+) Change on the fly the memory0 or memory1 address. | |
103 | |
104 @endverbatim | |
105 * @{ | |
106 */ | |
107 | |
108 | |
109 /** | |
110 * @brief Starts the multi_buffer DMA Transfer. | |
111 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains | |
112 * the configuration information for the specified DMA Stream. | |
113 * @param SrcAddress: The source memory Buffer address | |
114 * @param DstAddress: The destination memory Buffer address | |
115 * @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer | |
116 * @param DataLength: The length of data to be transferred from source to destination | |
117 * @retval HAL status | |
118 */ | |
119 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength) | |
120 { | |
121 /* Process Locked */ | |
122 __HAL_LOCK(hdma); | |
123 | |
124 /* Current memory buffer used is Memory 0 */ | |
125 if((hdma->Instance->CR & DMA_SxCR_CT) == 0) | |
126 { | |
127 hdma->State = HAL_DMA_STATE_BUSY_MEM0; | |
128 } | |
129 /* Current memory buffer used is Memory 1 */ | |
130 else if((hdma->Instance->CR & DMA_SxCR_CT) != 0) | |
131 { | |
132 hdma->State = HAL_DMA_STATE_BUSY_MEM1; | |
133 } | |
134 | |
135 /* Check the parameters */ | |
136 assert_param(IS_DMA_BUFFER_SIZE(DataLength)); | |
137 | |
138 /* Disable the peripheral */ | |
139 __HAL_DMA_DISABLE(hdma); | |
140 | |
141 /* Enable the double buffer mode */ | |
142 hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM; | |
143 | |
144 /* Configure DMA Stream destination address */ | |
145 hdma->Instance->M1AR = SecondMemAddress; | |
146 | |
147 /* Configure the source, destination address and the data length */ | |
148 DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength); | |
149 | |
150 /* Enable the peripheral */ | |
151 __HAL_DMA_ENABLE(hdma); | |
152 | |
153 return HAL_OK; | |
154 } | |
155 | |
156 /** | |
157 * @brief Starts the multi_buffer DMA Transfer with interrupt enabled. | |
158 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |
159 * the configuration information for the specified DMA Stream. | |
160 * @param SrcAddress: The source memory Buffer address | |
161 * @param DstAddress: The destination memory Buffer address | |
162 * @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer | |
163 * @param DataLength: The length of data to be transferred from source to destination | |
164 * @retval HAL status | |
165 */ | |
166 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength) | |
167 { | |
168 /* Process Locked */ | |
169 __HAL_LOCK(hdma); | |
170 | |
171 /* Current memory buffer used is Memory 0 */ | |
172 if((hdma->Instance->CR & DMA_SxCR_CT) == 0) | |
173 { | |
174 hdma->State = HAL_DMA_STATE_BUSY_MEM0; | |
175 } | |
176 /* Current memory buffer used is Memory 1 */ | |
177 else if((hdma->Instance->CR & DMA_SxCR_CT) != 0) | |
178 { | |
179 hdma->State = HAL_DMA_STATE_BUSY_MEM1; | |
180 } | |
181 | |
182 /* Check the parameters */ | |
183 assert_param(IS_DMA_BUFFER_SIZE(DataLength)); | |
184 | |
185 /* Disable the peripheral */ | |
186 __HAL_DMA_DISABLE(hdma); | |
187 | |
188 /* Enable the Double buffer mode */ | |
189 hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM; | |
190 | |
191 /* Configure DMA Stream destination address */ | |
192 hdma->Instance->M1AR = SecondMemAddress; | |
193 | |
194 /* Configure the source, destination address and the data length */ | |
195 DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength); | |
196 | |
197 /* Enable the transfer complete interrupt */ | |
198 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TC); | |
199 | |
200 /* Enable the Half transfer interrupt */ | |
201 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_HT); | |
202 | |
203 /* Enable the transfer Error interrupt */ | |
204 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TE); | |
205 | |
206 /* Enable the fifo Error interrupt */ | |
207 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_FE); | |
208 | |
209 /* Enable the direct mode Error interrupt */ | |
210 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_DME); | |
211 | |
212 /* Enable the peripheral */ | |
213 __HAL_DMA_ENABLE(hdma); | |
214 | |
215 return HAL_OK; | |
216 } | |
217 | |
218 /** | |
219 * @brief Change the memory0 or memory1 address on the fly. | |
220 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |
221 * the configuration information for the specified DMA Stream. | |
222 * @param Address: The new address | |
223 * @param memory: the memory to be changed, This parameter can be one of | |
224 * the following values: | |
225 * MEMORY0 / | |
226 * MEMORY1 | |
227 * @note The MEMORY0 address can be changed only when the current transfer use | |
228 * MEMORY1 and the MEMORY1 address can be changed only when the current | |
229 * transfer use MEMORY0. | |
230 * @retval HAL status | |
231 */ | |
232 HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory) | |
233 { | |
234 if(memory == MEMORY0) | |
235 { | |
236 /* change the memory0 address */ | |
237 hdma->Instance->M0AR = Address; | |
238 } | |
239 else | |
240 { | |
241 /* change the memory1 address */ | |
242 hdma->Instance->M1AR = Address; | |
243 } | |
244 | |
245 return HAL_OK; | |
246 } | |
247 | |
248 /** | |
249 * @} | |
250 */ | |
251 | |
252 /** | |
253 * @} | |
254 */ | |
255 | |
256 /** @addtogroup DMAEx_Private_Functions | |
257 * @{ | |
258 */ | |
259 | |
260 /** | |
261 * @brief Set the DMA Transfer parameter. | |
262 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |
263 * the configuration information for the specified DMA Stream. | |
264 * @param SrcAddress: The source memory Buffer address | |
265 * @param DstAddress: The destination memory Buffer address | |
266 * @param DataLength: The length of data to be transferred from source to destination | |
267 * @retval HAL status | |
268 */ | |
269 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) | |
270 { | |
271 /* Configure DMA Stream data length */ | |
272 hdma->Instance->NDTR = DataLength; | |
273 | |
274 /* Peripheral to Memory */ | |
275 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH) | |
276 { | |
277 /* Configure DMA Stream destination address */ | |
278 hdma->Instance->PAR = DstAddress; | |
279 | |
280 /* Configure DMA Stream source address */ | |
281 hdma->Instance->M0AR = SrcAddress; | |
282 } | |
283 /* Memory to Peripheral */ | |
284 else | |
285 { | |
286 /* Configure DMA Stream source address */ | |
287 hdma->Instance->PAR = SrcAddress; | |
288 | |
289 /* Configure DMA Stream destination address */ | |
290 hdma->Instance->M0AR = DstAddress; | |
291 } | |
292 } | |
293 | |
294 /** | |
295 * @} | |
296 */ | |
297 | |
298 #endif /* HAL_DMA_MODULE_ENABLED */ | |
299 /** | |
300 * @} | |
301 */ | |
302 | |
303 /** | |
304 * @} | |
305 */ | |
306 | |
307 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |