2 ******************************************************************************
\r
3 * @file stm32f4xx_hal_dma_ex.c
\r
4 * @author MCD Application Team
\r
6 * @date 18-February-2014
\r
7 * @brief DMA Extension HAL module driver
\r
8 * This file provides firmware functions to manage the following
\r
9 * functionalities of the DMA Extension peripheral:
\r
10 * + Extended features functions
\r
13 ==============================================================================
\r
14 ##### How to use this driver #####
\r
15 ==============================================================================
\r
17 The DMA Extension HAL driver can be used as follows:
\r
18 (#) Start a multi buffer transfer using the HAL_DMA_MultiBufferStart() function
\r
19 for polling mode or HAL_DMA_MultiBufferStart_IT() for interrupt mode.
\r
21 -@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed.
\r
22 -@- When Multi (Double) Buffer mode is enabled the, transfer is circular by default.
\r
23 -@- In Multi (Double) buffer mode, it is possible to update the base address for
\r
24 the AHB memory port on-the-fly (DMA_SxM0AR or DMA_SxM1AR) when the stream is enabled.
\r
27 ******************************************************************************
\r
30 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
\r
32 * Redistribution and use in source and binary forms, with or without modification,
\r
33 * are permitted provided that the following conditions are met:
\r
34 * 1. Redistributions of source code must retain the above copyright notice,
\r
35 * this list of conditions and the following disclaimer.
\r
36 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
37 * this list of conditions and the following disclaimer in the documentation
\r
38 * and/or other materials provided with the distribution.
\r
39 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
40 * may be used to endorse or promote products derived from this software
\r
41 * without specific prior written permission.
\r
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
44 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
46 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
49 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
50 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
51 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
54 ******************************************************************************
\r
57 /* Includes ------------------------------------------------------------------*/
\r
58 #include "stm32f4xx_hal.h"
\r
60 /** @addtogroup STM32F4xx_HAL_Driver
\r
64 /** @defgroup DMAEx
\r
65 * @brief DMA Extended HAL module driver
\r
69 #ifdef HAL_DMA_MODULE_ENABLED
\r
71 /* Private typedef -----------------------------------------------------------*/
\r
72 /* Private define ------------------------------------------------------------*/
\r
73 /* Private macro -------------------------------------------------------------*/
\r
74 /* Private variables ---------------------------------------------------------*/
\r
75 /* Private function prototypes -----------------------------------------------*/
\r
76 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
\r
78 /* Private functions ---------------------------------------------------------*/
\r
80 /** @defgroup DMAEx_Private_Functions
\r
85 /** @defgroup DMAEx_Group1 Extended features functions
\r
86 * @brief Extended features functions
\r
89 ===============================================================================
\r
90 ##### Extended features functions #####
\r
91 ===============================================================================
\r
92 [..] This section provides functions allowing to:
\r
93 (+) Configure the source, destination address and data length and
\r
94 Start MultiBuffer DMA transfer
\r
95 (+) Configure the source, destination address and data length and
\r
96 Start MultiBuffer DMA transfer with interrupt
\r
97 (+) Change on the fly the memory0 or memory1 address.
\r
105 * @brief Starts the multi_buffer DMA Transfer.
\r
106 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
\r
107 * the configuration information for the specified DMA Stream.
\r
108 * @param SrcAddress: The source memory Buffer address
\r
109 * @param DstAddress: The destination memory Buffer address
\r
110 * @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
\r
111 * @param DataLength: The length of data to be transferred from source to destination
\r
112 * @retval HAL status
\r
114 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
\r
116 /* Process Locked */
\r
119 /* Current memory buffer used is Memory 0 */
\r
120 if((hdma->Instance->CR & DMA_SxCR_CT) == 0)
\r
122 hdma->State = HAL_DMA_STATE_BUSY_MEM0;
\r
124 /* Current memory buffer used is Memory 1 */
\r
125 else if((hdma->Instance->CR & DMA_SxCR_CT) != 0)
\r
127 hdma->State = HAL_DMA_STATE_BUSY_MEM1;
\r
130 /* Check the parameters */
\r
131 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
\r
133 /* Disable the peripheral */
\r
134 __HAL_DMA_DISABLE(hdma);
\r
136 /* Enable the double buffer mode */
\r
137 hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM;
\r
139 /* Configure DMA Stream destination address */
\r
140 hdma->Instance->M1AR = SecondMemAddress;
\r
142 /* Configure the source, destination address and the data length */
\r
143 DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
\r
145 /* Enable the peripheral */
\r
146 __HAL_DMA_ENABLE(hdma);
\r
152 * @brief Starts the multi_buffer DMA Transfer with interrupt enabled.
\r
153 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
154 * the configuration information for the specified DMA Stream.
\r
155 * @param SrcAddress: The source memory Buffer address
\r
156 * @param DstAddress: The destination memory Buffer address
\r
157 * @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
\r
158 * @param DataLength: The length of data to be transferred from source to destination
\r
159 * @retval HAL status
\r
161 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
\r
163 /* Process Locked */
\r
166 /* Current memory buffer used is Memory 0 */
\r
167 if((hdma->Instance->CR & DMA_SxCR_CT) == 0)
\r
169 hdma->State = HAL_DMA_STATE_BUSY_MEM0;
\r
171 /* Current memory buffer used is Memory 1 */
\r
172 else if((hdma->Instance->CR & DMA_SxCR_CT) != 0)
\r
174 hdma->State = HAL_DMA_STATE_BUSY_MEM1;
\r
177 /* Check the parameters */
\r
178 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
\r
180 /* Disable the peripheral */
\r
181 __HAL_DMA_DISABLE(hdma);
\r
183 /* Enable the Double buffer mode */
\r
184 hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM;
\r
186 /* Configure DMA Stream destination address */
\r
187 hdma->Instance->M1AR = SecondMemAddress;
\r
189 /* Configure the source, destination address and the data length */
\r
190 DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
\r
192 /* Enable the transfer complete interrupt */
\r
193 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TC);
\r
195 /* Enable the Half transfer interrupt */
\r
196 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_HT);
\r
198 /* Enable the transfer Error interrupt */
\r
199 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TE);
\r
201 /* Enable the fifo Error interrupt */
\r
202 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_FE);
\r
204 /* Enable the direct mode Error interrupt */
\r
205 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_DME);
\r
207 /* Enable the peripheral */
\r
208 __HAL_DMA_ENABLE(hdma);
\r
214 * @brief Change the memory0 or memory1 address on the fly.
\r
215 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
216 * the configuration information for the specified DMA Stream.
\r
217 * @param Address: The new address
\r
218 * @param memory: the memory to be changed, This parameter can be one of
\r
219 * the following values:
\r
222 * @note The MEMORY0 address can be changed only when the current transfer use
\r
223 * MEMORY1 and the MEMORY1 address can be changed only when the current
\r
224 * transfer use MEMORY0.
\r
225 * @retval HAL status
\r
227 HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
\r
229 if(memory == MEMORY0)
\r
231 /* change the memory0 address */
\r
232 hdma->Instance->M0AR = Address;
\r
236 /* change the memory1 address */
\r
237 hdma->Instance->M1AR = Address;
\r
248 * @brief Set the DMA Transfer parameter.
\r
249 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
250 * the configuration information for the specified DMA Stream.
\r
251 * @param SrcAddress: The source memory Buffer address
\r
252 * @param DstAddress: The destination memory Buffer address
\r
253 * @param DataLength: The length of data to be transferred from source to destination
\r
254 * @retval HAL status
\r
256 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
\r
258 /* Configure DMA Stream data length */
\r
259 hdma->Instance->NDTR = DataLength;
\r
261 /* Peripheral to Memory */
\r
262 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
\r
264 /* Configure DMA Stream destination address */
\r
265 hdma->Instance->PAR = DstAddress;
\r
267 /* Configure DMA Stream source address */
\r
268 hdma->Instance->M0AR = SrcAddress;
\r
270 /* Memory to Peripheral */
\r
273 /* Configure DMA Stream source address */
\r
274 hdma->Instance->PAR = SrcAddress;
\r
276 /* Configure DMA Stream destination address */
\r
277 hdma->Instance->M0AR = DstAddress;
\r
285 #endif /* HAL_DMA_MODULE_ENABLED */
\r
294 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r