STM32F4xx HAL Documentation
Hardware Abstraction Layer for STM32F4 familiy
Loading...
Searching...
No Matches
stm32f4xx_hal_dma_ex.c
Go to the documentation of this file.
1
38/* Includes ------------------------------------------------------------------*/
39#include "stm32f4xx_hal.h"
40
50#ifdef HAL_DMA_MODULE_ENABLED
51
52/* Private types -------------------------------------------------------------*/
53/* Private variables ---------------------------------------------------------*/
54/* Private Constants ---------------------------------------------------------*/
55/* Private macros ------------------------------------------------------------*/
56/* Private functions ---------------------------------------------------------*/
60static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
65/* Exported functions ---------------------------------------------------------*/
66
100HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
101{
102 HAL_StatusTypeDef status = HAL_OK;
103
104 /* Check the parameters */
105 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
106
107 /* Memory-to-memory transfer not supported in double buffering mode */
109 {
111 status = HAL_ERROR;
112 }
113 else
114 {
115 /* Process Locked */
116 __HAL_LOCK(hdma);
117
118 if(HAL_DMA_STATE_READY == hdma->State)
119 {
120 /* Change DMA peripheral state */
121 hdma->State = HAL_DMA_STATE_BUSY;
122
123 /* Enable the double buffer mode */
124 hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM;
125
126 /* Configure DMA Stream destination address */
127 hdma->Instance->M1AR = SecondMemAddress;
128
129 /* Configure the source, destination address and the data length */
130 DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
131
132 /* Enable the peripheral */
133 __HAL_DMA_ENABLE(hdma);
134 }
135 else
136 {
137 /* Return error status */
138 status = HAL_BUSY;
139 }
140 }
141 return status;
142}
143
154HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
155{
156 HAL_StatusTypeDef status = HAL_OK;
157
158 /* Check the parameters */
159 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
160
161 /* Memory-to-memory transfer not supported in double buffering mode */
163 {
165 return HAL_ERROR;
166 }
167
168 /* Check callback functions */
169 if ((NULL == hdma->XferCpltCallback) || (NULL == hdma->XferM1CpltCallback) || (NULL == hdma->XferErrorCallback))
170 {
172 return HAL_ERROR;
173 }
174
175 /* Process locked */
176 __HAL_LOCK(hdma);
177
178 if(HAL_DMA_STATE_READY == hdma->State)
179 {
180 /* Change DMA peripheral state */
182
183 /* Initialize the error code */
185
186 /* Enable the Double buffer mode */
187 hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM;
188
189 /* Configure DMA Stream destination address */
190 hdma->Instance->M1AR = SecondMemAddress;
191
192 /* Configure the source, destination address and the data length */
193 DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
194
195 /* Clear all flags */
201
202 /* Enable Common interrupts*/
203 hdma->Instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME;
204 hdma->Instance->FCR |= DMA_IT_FE;
205
206 if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
207 {
208 hdma->Instance->CR |= DMA_IT_HT;
209 }
210
211 /* Enable the peripheral */
212 __HAL_DMA_ENABLE(hdma);
213 }
214 else
215 {
216 /* Process unlocked */
217 __HAL_UNLOCK(hdma);
218
219 /* Return error status */
220 status = HAL_BUSY;
221 }
222 return status;
223}
224
240{
241 if(memory == MEMORY0)
242 {
243 /* change the memory0 address */
244 hdma->Instance->M0AR = Address;
245 }
246 else
247 {
248 /* change the memory1 address */
249 hdma->Instance->M1AR = Address;
250 }
251
252 return HAL_OK;
253}
254
276static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
277{
278 /* Configure DMA Stream data length */
279 hdma->Instance->NDTR = DataLength;
280
281 /* Peripheral to Memory */
282 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
283 {
284 /* Configure DMA Stream destination address */
285 hdma->Instance->PAR = DstAddress;
286
287 /* Configure DMA Stream source address */
288 hdma->Instance->M0AR = SrcAddress;
289 }
290 /* Memory to Peripheral */
291 else
292 {
293 /* Configure DMA Stream source address */
294 hdma->Instance->PAR = SrcAddress;
295
296 /* Configure DMA Stream destination address */
297 hdma->Instance->M0AR = DstAddress;
298 }
299}
300
305#endif /* HAL_DMA_MODULE_ENABLED */
HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
Change the memory0 or memory1 address on the fly.
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
Starts the multi_buffer DMA Transfer.
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
Starts the multi_buffer DMA Transfer with interrupt enabled.
HAL_DMA_MemoryTypeDef
HAL DMA Memory definition
static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Set the DMA Transfer parameter.
#define DMA_MEMORY_TO_MEMORY
#define DMA_MEMORY_TO_PERIPH
#define HAL_DMA_ERROR_PARAM
#define HAL_DMA_ERROR_NOT_SUPPORTED
#define HAL_DMA_ERROR_NONE
@ HAL_DMA_STATE_READY
@ HAL_DMA_STATE_BUSY
#define IS_DMA_BUFFER_SIZE(SIZE)
#define DMA_IT_TC
#define DMA_IT_DME
#define DMA_IT_FE
#define DMA_IT_HT
#define DMA_IT_TE
#define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)
Return the current DMA Stream half transfer complete flag.
#define __HAL_DMA_GET_DME_FLAG_INDEX(__HANDLE__)
Return the current DMA Stream direct mode error flag.
#define __HAL_DMA_GET_FE_FLAG_INDEX(__HANDLE__)
Return the current DMA Stream FIFO error flag.
#define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)
Return the current DMA Stream transfer error flag.
#define __HAL_DMA_ENABLE(__HANDLE__)
Enable the specified DMA Stream.
#define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the DMA Stream pending flags.
#define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__)
Return the current DMA Stream transfer complete flag.
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL Status structures definition
@ HAL_ERROR
@ HAL_OK
@ HAL_BUSY
#define __HAL_UNLOCK(__HANDLE__)
#define __HAL_LOCK(__HANDLE__)
DMA handle Structure definition.
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
__IO HAL_DMA_StateTypeDef State
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA_Stream_TypeDef * Instance
void(* XferM1HalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferM1CpltCallback)(struct __DMA_HandleTypeDef *hdma)