2 ******************************************************************************
3 * @file stm32f7xx_hal_dma_ex.c
4 * @author MCD Application Team
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
13 ==============================================================================
14 ##### How to use this driver #####
15 ==============================================================================
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.
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.
27 ******************************************************************************
30 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
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.
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.
54 ******************************************************************************
57 /* Includes ------------------------------------------------------------------*/
58 #include "stm32f7xx_hal.h"
60 /** @addtogroup STM32F7xx_HAL_Driver
64 /** @defgroup DMAEx DMAEx
65 * @brief DMA Extended HAL module driver
69 #ifdef HAL_DMA_MODULE_ENABLED
71 /* Private types -------------------------------------------------------------*/
72 /* Private variables ---------------------------------------------------------*/
73 /* Private Constants ---------------------------------------------------------*/
74 /* Private macros ------------------------------------------------------------*/
75 /* Private functions ---------------------------------------------------------*/
76 /** @addtogroup DMAEx_Private_Functions
80 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef
*hdma
, uint32_t SrcAddress
, uint32_t DstAddress
, uint32_t DataLength
);
86 /* Exported functions ---------------------------------------------------------*/
88 /** @addtogroup DMAEx_Exported_Functions
93 /** @addtogroup DMAEx_Exported_Functions_Group1
96 ===============================================================================
97 ##### Extended features functions #####
98 ===============================================================================
99 [..] This section provides functions allowing to:
100 (+) Configure the source, destination address and data length and
101 Start MultiBuffer DMA transfer
102 (+) Configure the source, destination address and data length and
103 Start MultiBuffer DMA transfer with interrupt
104 (+) Change on the fly the memory0 or memory1 address.
112 * @brief Starts the multi_buffer DMA Transfer.
113 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
114 * the configuration information for the specified DMA Stream.
115 * @param SrcAddress: The source memory Buffer address
116 * @param DstAddress: The destination memory Buffer address
117 * @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
118 * @param DataLength: The length of data to be transferred from source to destination
121 HAL_StatusTypeDef
HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef
*hdma
, uint32_t SrcAddress
, uint32_t DstAddress
, uint32_t SecondMemAddress
, uint32_t DataLength
)
123 HAL_StatusTypeDef status
= HAL_OK
;
125 /* Check the parameters */
126 assert_param(IS_DMA_BUFFER_SIZE(DataLength
));
128 /* Memory-to-memory transfer not supported in double buffering mode */
129 if (hdma
->Init
.Direction
== DMA_MEMORY_TO_MEMORY
)
131 hdma
->ErrorCode
= HAL_DMA_ERROR_NOT_SUPPORTED
;
139 if(HAL_DMA_STATE_READY
== hdma
->State
)
141 /* Change DMA peripheral state */
142 hdma
->State
= HAL_DMA_STATE_BUSY
;
144 /* Enable the double buffer mode */
145 hdma
->Instance
->CR
|= (uint32_t)DMA_SxCR_DBM
;
147 /* Configure DMA Stream destination address */
148 hdma
->Instance
->M1AR
= SecondMemAddress
;
150 /* Configure the source, destination address and the data length */
151 DMA_MultiBufferSetConfig(hdma
, SrcAddress
, DstAddress
, DataLength
);
153 /* Enable the peripheral */
154 __HAL_DMA_ENABLE(hdma
);
158 /* Return error status */
166 * @brief Starts the multi_buffer DMA Transfer with interrupt enabled.
167 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
168 * the configuration information for the specified DMA Stream.
169 * @param SrcAddress: The source memory Buffer address
170 * @param DstAddress: The destination memory Buffer address
171 * @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
172 * @param DataLength: The length of data to be transferred from source to destination
175 HAL_StatusTypeDef
HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef
*hdma
, uint32_t SrcAddress
, uint32_t DstAddress
, uint32_t SecondMemAddress
, uint32_t DataLength
)
177 HAL_StatusTypeDef status
= HAL_OK
;
179 /* Check the parameters */
180 assert_param(IS_DMA_BUFFER_SIZE(DataLength
));
182 /* Memory-to-memory transfer not supported in double buffering mode */
183 if (hdma
->Init
.Direction
== DMA_MEMORY_TO_MEMORY
)
185 hdma
->ErrorCode
= HAL_DMA_ERROR_NOT_SUPPORTED
;
192 if(HAL_DMA_STATE_READY
== hdma
->State
)
194 /* Change DMA peripheral state */
195 hdma
->State
= HAL_DMA_STATE_BUSY
;
197 /* Initialize the error code */
198 hdma
->ErrorCode
= HAL_DMA_ERROR_NONE
;
200 /* Enable the Double buffer mode */
201 hdma
->Instance
->CR
|= (uint32_t)DMA_SxCR_DBM
;
203 /* Configure DMA Stream destination address */
204 hdma
->Instance
->M1AR
= SecondMemAddress
;
206 /* Configure the source, destination address and the data length */
207 DMA_MultiBufferSetConfig(hdma
, SrcAddress
, DstAddress
, DataLength
);
209 /* Clear all flags */
210 __HAL_DMA_CLEAR_FLAG (hdma
, __HAL_DMA_GET_TC_FLAG_INDEX(hdma
));
211 __HAL_DMA_CLEAR_FLAG (hdma
, __HAL_DMA_GET_HT_FLAG_INDEX(hdma
));
212 __HAL_DMA_CLEAR_FLAG (hdma
, __HAL_DMA_GET_TE_FLAG_INDEX(hdma
));
213 __HAL_DMA_CLEAR_FLAG (hdma
, __HAL_DMA_GET_DME_FLAG_INDEX(hdma
));
214 __HAL_DMA_CLEAR_FLAG (hdma
, __HAL_DMA_GET_FE_FLAG_INDEX(hdma
));
216 /* Enable Common interrupts*/
217 hdma
->Instance
->CR
|= DMA_IT_TC
| DMA_IT_TE
| DMA_IT_DME
;
218 hdma
->Instance
->FCR
|= DMA_IT_FE
;
220 if((hdma
->XferHalfCpltCallback
!= NULL
) || (hdma
->XferM1HalfCpltCallback
!= NULL
))
222 hdma
->Instance
->CR
|= DMA_IT_HT
;
225 /* Enable the peripheral */
226 __HAL_DMA_ENABLE(hdma
);
230 /* Process unlocked */
233 /* Return error status */
240 * @brief Change the memory0 or memory1 address on the fly.
241 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
242 * the configuration information for the specified DMA Stream.
243 * @param Address: The new address
244 * @param memory: the memory to be changed, This parameter can be one of
245 * the following values:
248 * @note The MEMORY0 address can be changed only when the current transfer use
249 * MEMORY1 and the MEMORY1 address can be changed only when the current
250 * transfer use MEMORY0.
253 HAL_StatusTypeDef
HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef
*hdma
, uint32_t Address
, HAL_DMA_MemoryTypeDef memory
)
255 if(memory
== MEMORY0
)
257 /* change the memory0 address */
258 hdma
->Instance
->M0AR
= Address
;
262 /* change the memory1 address */
263 hdma
->Instance
->M1AR
= Address
;
277 /** @addtogroup DMAEx_Private_Functions
282 * @brief Set the DMA Transfer parameter.
283 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
284 * the configuration information for the specified DMA Stream.
285 * @param SrcAddress: The source memory Buffer address
286 * @param DstAddress: The destination memory Buffer address
287 * @param DataLength: The length of data to be transferred from source to destination
290 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef
*hdma
, uint32_t SrcAddress
, uint32_t DstAddress
, uint32_t DataLength
)
292 /* Configure DMA Stream data length */
293 hdma
->Instance
->NDTR
= DataLength
;
295 /* Peripheral to Memory */
296 if((hdma
->Init
.Direction
) == DMA_MEMORY_TO_PERIPH
)
298 /* Configure DMA Stream destination address */
299 hdma
->Instance
->PAR
= DstAddress
;
301 /* Configure DMA Stream source address */
302 hdma
->Instance
->M0AR
= SrcAddress
;
304 /* Memory to Peripheral */
307 /* Configure DMA Stream source address */
308 hdma
->Instance
->PAR
= SrcAddress
;
310 /* Configure DMA Stream destination address */
311 hdma
->Instance
->M0AR
= DstAddress
;
319 #endif /* HAL_DMA_MODULE_ENABLED */
328 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/