STM32L4xx_HAL_Driver  1.14.0
Initialization and de-initialization functions

Initialization and de-initialization functions. More...

Functions

HAL_StatusTypeDef HAL_DMA_Init (DMA_HandleTypeDef *hdma)
 Initialize the DMA according to the specified parameters in the DMA_InitTypeDef and initialize the associated handle. More...
 
HAL_StatusTypeDef HAL_DMA_DeInit (DMA_HandleTypeDef *hdma)
 DeInitialize the DMA peripheral. More...
 

Detailed Description

Initialization and de-initialization functions.

 ===============================================================================
             ##### Initialization and de-initialization functions  #####
 ===============================================================================
    [..]
    This section provides functions allowing to initialize the DMA Channel source
    and destination addresses, incrementation and data sizes, transfer direction,
    circular/normal mode selection, memory-to-memory mode selection and Channel priority value.
    [..]
    The HAL_DMA_Init() function follows the DMA configuration procedures as described in
    reference manual.

Function Documentation

◆ HAL_DMA_DeInit()

HAL_StatusTypeDef HAL_DMA_DeInit ( DMA_HandleTypeDef hdma)

DeInitialize the DMA peripheral.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA Channel.
Return values
HALstatus

Definition at line 294 of file stm32l4xx_hal_dma.c.

295 {
296 
297  /* Check the DMA handle allocation */
298  if (NULL == hdma )
299  {
300  return HAL_ERROR;
301  }
302 
303  /* Check the parameters */
304  assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
305 
306  /* Disable the selected DMA Channelx */
307  __HAL_DMA_DISABLE(hdma);
308 
309  /* Compute the channel index */
310  if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
311  {
312  /* DMA1 */
313  hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2U;
314  hdma->DmaBaseAddress = DMA1;
315  }
316  else
317  {
318  /* DMA2 */
319  hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2U;
320  hdma->DmaBaseAddress = DMA2;
321  }
322 
323  /* Reset DMA Channel control register */
324  hdma->Instance->CCR = 0U;
325 
326  /* Clear all flags */
327  hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << (hdma->ChannelIndex & 0x1CU));
328 
329 #if !defined (DMAMUX1)
330 
331  /* Reset DMA channel selection register */
332  if (DMA1 == hdma->DmaBaseAddress)
333  {
334  /* DMA1 */
335  DMA1_CSELR->CSELR &= ~(DMA_CSELR_C1S << (hdma->ChannelIndex & 0x1cU));
336  }
337  else
338  {
339  /* DMA2 */
340  DMA2_CSELR->CSELR &= ~(DMA_CSELR_C1S << (hdma->ChannelIndex & 0x1cU));
341  }
342 #endif /* STM32L431xx || STM32L432xx || STM32L433xx || STM32L442xx || STM32L443xx */
343  /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L442xx || STM32L486xx */
344  /* STM32L496xx || STM32L4A6xx */
345 
346 #if defined(DMAMUX1)
347 
348  /* Initialize parameters for DMAMUX channel :
349  DMAmuxChannel, DMAmuxChannelStatus and DMAmuxChannelStatusMask */
350 
352 
353  /* Reset the DMAMUX channel that corresponds to the DMA channel */
354  hdma->DMAmuxChannel->CCR = 0U;
355 
356  /* Clear the DMAMUX synchro overrun flag */
357  hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
358 
359  /* Reset Request generator parameters if any */
360  if(((hdma->Init.Request > 0U) && (hdma->Init.Request <= DMA_REQUEST_GENERATOR3)))
361  {
362  /* Initialize parameters for DMAMUX request generator :
363  DMAmuxRequestGen, DMAmuxRequestGenStatus and DMAmuxRequestGenStatusMask
364  */
366 
367  /* Reset the DMAMUX request generator register*/
368  hdma->DMAmuxRequestGen->RGCR = 0U;
369 
370  /* Clear the DMAMUX request generator overrun flag */
372  }
373 
374  hdma->DMAmuxRequestGen = 0U;
375  hdma->DMAmuxRequestGenStatus = 0U;
376  hdma->DMAmuxRequestGenStatusMask = 0U;
377 
378 #endif /* DMAMUX1 */
379 
380  /* Clean callbacks */
381  hdma->XferCpltCallback = NULL;
382  hdma->XferHalfCpltCallback = NULL;
383  hdma->XferErrorCallback = NULL;
384  hdma->XferAbortCallback = NULL;
385 
386  /* Initialise the error code */
387  hdma->ErrorCode = HAL_DMA_ERROR_NONE;
388 
389  /* Initialize the DMA state */
390  hdma->State = HAL_DMA_STATE_RESET;
391 
392  /* Release Lock */
393  __HAL_UNLOCK(hdma);
394 
395  return HAL_OK;
396 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMAMUX_RequestGenStatus_TypeDef * DMAmuxRequestGenStatus
DMAMUX_RequestGen_TypeDef * DMAmuxRequestGen
DMA_Channel_TypeDef * Instance
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
__HAL_UNLOCK(hrtc)
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA_InitTypeDef Init
DMA_TypeDef * DmaBaseAddress
__IO HAL_DMA_StateTypeDef State
DMAMUX_Channel_TypeDef * DMAmuxChannel
return HAL_OK
uint32_t DMAmuxRequestGenStatusMask
DMAMUX_ChannelStatus_TypeDef * DMAmuxChannelStatus
static void DMA_CalcDMAMUXRequestGenBaseAndMask(DMA_HandleTypeDef *hdma)
Updates the DMA handle with the DMAMUX request generator params.
static void DMA_CalcDMAMUXChannelBaseAndMask(DMA_HandleTypeDef *hdma)
Updates the DMA handle with the DMAMUX channel and status mask depending on channel number...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_DMA_Init()

HAL_StatusTypeDef HAL_DMA_Init ( DMA_HandleTypeDef hdma)

Initialize the DMA according to the specified parameters in the DMA_InitTypeDef and initialize the associated handle.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA Channel.
Return values
HALstatus

Definition at line 153 of file stm32l4xx_hal_dma.c.

154 {
155  uint32_t tmp;
156 
157  /* Check the DMA handle allocation */
158  if(hdma == NULL)
159  {
160  return HAL_ERROR;
161  }
162 
163  /* Check the parameters */
164  assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
165  assert_param(IS_DMA_DIRECTION(hdma->Init.Direction));
166  assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc));
167  assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc));
168  assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment));
169  assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment));
170  assert_param(IS_DMA_MODE(hdma->Init.Mode));
171  assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
172 
173  assert_param(IS_DMA_ALL_REQUEST(hdma->Init.Request));
174 
175  /* Compute the channel index */
176  if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
177  {
178  /* DMA1 */
179  hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2U;
180  hdma->DmaBaseAddress = DMA1;
181  }
182  else
183  {
184  /* DMA2 */
185  hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2U;
186  hdma->DmaBaseAddress = DMA2;
187  }
188 
189  /* Change DMA peripheral state */
190  hdma->State = HAL_DMA_STATE_BUSY;
191 
192  /* Get the CR register value */
193  tmp = hdma->Instance->CCR;
194 
195  /* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR and MEM2MEM bits */
196  tmp &= ((uint32_t)~(DMA_CCR_PL | DMA_CCR_MSIZE | DMA_CCR_PSIZE |
197  DMA_CCR_MINC | DMA_CCR_PINC | DMA_CCR_CIRC |
198  DMA_CCR_DIR | DMA_CCR_MEM2MEM));
199 
200  /* Prepare the DMA Channel configuration */
201  tmp |= hdma->Init.Direction |
202  hdma->Init.PeriphInc | hdma->Init.MemInc |
203  hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
204  hdma->Init.Mode | hdma->Init.Priority;
205 
206  /* Write to DMA Channel CR register */
207  hdma->Instance->CCR = tmp;
208 
209 #if defined(DMAMUX1)
210  /* Initialize parameters for DMAMUX channel :
211  DMAmuxChannel, DMAmuxChannelStatus and DMAmuxChannelStatusMask
212  */
214 
215  if(hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
216  {
217  /* if memory to memory force the request to 0*/
218  hdma->Init.Request = DMA_REQUEST_MEM2MEM;
219  }
220 
221  /* Set peripheral request to DMAMUX channel */
222  hdma->DMAmuxChannel->CCR = (hdma->Init.Request & DMAMUX_CxCR_DMAREQ_ID);
223 
224  /* Clear the DMAMUX synchro overrun flag */
225  hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
226 
227  if(((hdma->Init.Request > 0U) && (hdma->Init.Request <= DMA_REQUEST_GENERATOR3)))
228  {
229  /* Initialize parameters for DMAMUX request generator :
230  DMAmuxRequestGen, DMAmuxRequestGenStatus and DMAmuxRequestGenStatusMask
231  */
233 
234  /* Reset the DMAMUX request generator register*/
235  hdma->DMAmuxRequestGen->RGCR = 0U;
236 
237  /* Clear the DMAMUX request generator overrun flag */
239  }
240  else
241  {
242  hdma->DMAmuxRequestGen = 0U;
243  hdma->DMAmuxRequestGenStatus = 0U;
244  hdma->DMAmuxRequestGenStatusMask = 0U;
245  }
246 #endif /* DMAMUX1 */
247 
248 #if !defined (DMAMUX1)
249 
250  /* Set request selection */
251  if(hdma->Init.Direction != DMA_MEMORY_TO_MEMORY)
252  {
253  /* Write to DMA channel selection register */
254  if (DMA1 == hdma->DmaBaseAddress)
255  {
256  /* Reset request selection for DMA1 Channelx */
257  DMA1_CSELR->CSELR &= ~(DMA_CSELR_C1S << (hdma->ChannelIndex & 0x1cU));
258 
259  /* Configure request selection for DMA1 Channelx */
260  DMA1_CSELR->CSELR |= (uint32_t) (hdma->Init.Request << (hdma->ChannelIndex & 0x1cU));
261  }
262  else /* DMA2 */
263  {
264  /* Reset request selection for DMA2 Channelx */
265  DMA2_CSELR->CSELR &= ~(DMA_CSELR_C1S << (hdma->ChannelIndex & 0x1cU));
266 
267  /* Configure request selection for DMA2 Channelx */
268  DMA2_CSELR->CSELR |= (uint32_t) (hdma->Init.Request << (hdma->ChannelIndex & 0x1cU));
269  }
270  }
271 
272 #endif /* STM32L431xx || STM32L432xx || STM32L433xx || STM32L442xx || STM32L443xx */
273  /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L442xx || STM32L486xx */
274  /* STM32L496xx || STM32L4A6xx */
275 
276  /* Initialise the error code */
277  hdma->ErrorCode = HAL_DMA_ERROR_NONE;
278 
279  /* Initialize the DMA state*/
280  hdma->State = HAL_DMA_STATE_READY;
281 
282  /* Allocate lock resource and initialize it */
283  hdma->Lock = HAL_UNLOCKED;
284 
285  return HAL_OK;
286 }
DMAMUX_RequestGenStatus_TypeDef * DMAmuxRequestGenStatus
DMAMUX_RequestGen_TypeDef * DMAmuxRequestGen
DMA_Channel_TypeDef * Instance
DMA_InitTypeDef Init
DMA_TypeDef * DmaBaseAddress
HAL_LockTypeDef Lock
__IO HAL_DMA_StateTypeDef State
DMAMUX_Channel_TypeDef * DMAmuxChannel
return HAL_OK
uint32_t DMAmuxRequestGenStatusMask
DMAMUX_ChannelStatus_TypeDef * DMAmuxChannelStatus
static void DMA_CalcDMAMUXRequestGenBaseAndMask(DMA_HandleTypeDef *hdma)
Updates the DMA handle with the DMAMUX request generator params.
static void DMA_CalcDMAMUXChannelBaseAndMask(DMA_HandleTypeDef *hdma)
Updates the DMA handle with the DMAMUX channel and status mask depending on channel number...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))