1 /**
2   ******************************************************************************
3   * @file    stm32u5xx_ll_dma.c
4   * @author  MCD Application Team
5   * @brief   DMA LL module driver.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2021 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17  @verbatim
18   ==============================================================================
19                         ##### LL DMA driver acronyms #####
20   ==============================================================================
21   [..]  Acronyms table :
22                    =========================================
23                    || Acronym ||                          ||
24                    =========================================
25                    || SRC     ||  Source                  ||
26                    || DEST    ||  Destination             ||
27                    || ADDR    ||  Address                 ||
28                    || ADDRS   ||  Addresses               ||
29                    || INC     ||  Increment / Incremented ||
30                    || DEC     ||  Decrement / Decremented ||
31                    || BLK     ||  Block                   ||
32                    || RPT     ||  Repeat / Repeated       ||
33                    || TRIG    ||  Trigger                 ||
34                    =========================================
35  @endverbatim
36   ******************************************************************************
37   */
38 
39 #if defined (USE_FULL_LL_DRIVER)
40 
41 /* Includes ------------------------------------------------------------------*/
42 #include "stm32u5xx_ll_dma.h"
43 #include "stm32u5xx_ll_bus.h"
44 #ifdef  USE_FULL_ASSERT
45 #include "stm32_assert.h"
46 #else
47 #define assert_param(expr) ((void)0U)
48 #endif /* USE_FULL_ASSERT */
49 
50 /** @addtogroup STM32U5xx_LL_Driver
51   * @{
52   */
53 
54 #if (defined (GPDMA1) || defined (LPDMA1))
55 
56 /** @addtogroup DMA_LL
57   * @{
58   */
59 
60 /* Private types -------------------------------------------------------------*/
61 /* Private variables ---------------------------------------------------------*/
62 /* Private constants ---------------------------------------------------------*/
63 /* Private macros ------------------------------------------------------------*/
64 
65 /** @addtogroup DMA_LL_Private_Macros
66   * @{
67   */
68 #define IS_LL_DMA_ALL_CHANNEL_INSTANCE(INSTANCE, Channel) ((((INSTANCE) == GPDMA1)                && \
69                                                             (((Channel)  == LL_DMA_CHANNEL_0)     || \
70                                                              ((Channel)  == LL_DMA_CHANNEL_1)     || \
71                                                              ((Channel)  == LL_DMA_CHANNEL_2)     || \
72                                                              ((Channel)  == LL_DMA_CHANNEL_3)     || \
73                                                              ((Channel)  == LL_DMA_CHANNEL_4)     || \
74                                                              ((Channel)  == LL_DMA_CHANNEL_5)     || \
75                                                              ((Channel)  == LL_DMA_CHANNEL_6)     || \
76                                                              ((Channel)  == LL_DMA_CHANNEL_7)     || \
77                                                              ((Channel)  == LL_DMA_CHANNEL_8)     || \
78                                                              ((Channel)  == LL_DMA_CHANNEL_9)     || \
79                                                              ((Channel)  == LL_DMA_CHANNEL_10)    || \
80                                                              ((Channel)  == LL_DMA_CHANNEL_11)    || \
81                                                              ((Channel)  == LL_DMA_CHANNEL_12)    || \
82                                                              ((Channel)  == LL_DMA_CHANNEL_13)    || \
83                                                              ((Channel)  == LL_DMA_CHANNEL_14)    || \
84                                                              ((Channel)  == LL_DMA_CHANNEL_15)    || \
85                                                              ((Channel)  == LL_DMA_CHANNEL_ALL))) || \
86                                                            (((INSTANCE) == LPDMA1)                && \
87                                                             (((Channel)  == LL_DMA_CHANNEL_0)     || \
88                                                              ((Channel)  == LL_DMA_CHANNEL_1)     || \
89                                                              ((Channel)  == LL_DMA_CHANNEL_2)     || \
90                                                              ((Channel)  == LL_DMA_CHANNEL_3)     || \
91                                                              ((Channel)  == LL_DMA_CHANNEL_ALL))))
92 
93 #define IS_LL_GPDMA_CHANNEL_INSTANCE(INSTANCE, Channel)   (((INSTANCE) == GPDMA1)                && \
94                                                            (((Channel)  == LL_DMA_CHANNEL_0)     || \
95                                                             ((Channel)  == LL_DMA_CHANNEL_1)     || \
96                                                             ((Channel)  == LL_DMA_CHANNEL_2)     || \
97                                                             ((Channel)  == LL_DMA_CHANNEL_3)     || \
98                                                             ((Channel)  == LL_DMA_CHANNEL_4)     || \
99                                                             ((Channel)  == LL_DMA_CHANNEL_5)     || \
100                                                             ((Channel)  == LL_DMA_CHANNEL_6)     || \
101                                                             ((Channel)  == LL_DMA_CHANNEL_7)     || \
102                                                             ((Channel)  == LL_DMA_CHANNEL_8)     || \
103                                                             ((Channel)  == LL_DMA_CHANNEL_9)     || \
104                                                             ((Channel)  == LL_DMA_CHANNEL_10)    || \
105                                                             ((Channel)  == LL_DMA_CHANNEL_11)    || \
106                                                             ((Channel)  == LL_DMA_CHANNEL_12)    || \
107                                                             ((Channel)  == LL_DMA_CHANNEL_13)    || \
108                                                             ((Channel)  == LL_DMA_CHANNEL_14)    || \
109                                                             ((Channel)  == LL_DMA_CHANNEL_15)))
110 
111 #define IS_LL_DMA_2D_CHANNEL_INSTANCE(INSTANCE, Channel)  (((INSTANCE) == GPDMA1)                && \
112                                                            (((Channel)  == LL_DMA_CHANNEL_12)    || \
113                                                             ((Channel)  == LL_DMA_CHANNEL_13)    || \
114                                                             ((Channel)  == LL_DMA_CHANNEL_14)    || \
115                                                             ((Channel)  == LL_DMA_CHANNEL_15)))
116 
117 #define IS_LL_DMA_DIRECTION(__VALUE__)                    (((__VALUE__) == LL_DMA_DIRECTION_MEMORY_TO_MEMORY) || \
118                                                            ((__VALUE__) == LL_DMA_DIRECTION_PERIPH_TO_MEMORY) || \
119                                                            ((__VALUE__) == LL_DMA_DIRECTION_MEMORY_TO_PERIPH))
120 
121 #define IS_LL_DMA_DATA_ALIGNMENT(__VALUE__)               (((__VALUE__) == LL_DMA_DATA_ALIGN_ZEROPADD)    || \
122                                                            ((__VALUE__) == LL_DMA_DATA_ALIGN_SIGNEXTPADD) || \
123                                                            ((__VALUE__) == LL_DMA_DATA_PACK_UNPACK))
124 
125 #define IS_LL_DMA_BURST_LENGTH(__VALUE__)                 (((__VALUE__) > 0U) && ((__VALUE__) <= 64U))
126 
127 #define IS_LL_DMA_SRC_DATA_WIDTH(__VALUE__)               (((__VALUE__) == LL_DMA_SRC_DATAWIDTH_BYTE)     || \
128                                                            ((__VALUE__) == LL_DMA_SRC_DATAWIDTH_HALFWORD) || \
129                                                            ((__VALUE__) == LL_DMA_SRC_DATAWIDTH_WORD))
130 
131 #define IS_LL_DMA_DEST_DATA_WIDTH(__VALUE__)              (((__VALUE__) == LL_DMA_DEST_DATAWIDTH_BYTE)     || \
132                                                            ((__VALUE__) == LL_DMA_DEST_DATAWIDTH_HALFWORD) || \
133                                                            ((__VALUE__) == LL_DMA_DEST_DATAWIDTH_WORD))
134 
135 #define IS_LL_DMA_SRC_INCREMENT_MODE(__VALUE__)           (((__VALUE__) == LL_DMA_SRC_FIXED) || \
136                                                            ((__VALUE__) == LL_DMA_SRC_INCREMENT))
137 
138 #define IS_LL_DMA_DEST_INCREMENT_MODE(__VALUE__)          (((__VALUE__) == LL_DMA_DEST_FIXED) || \
139                                                            ((__VALUE__) == LL_DMA_DEST_INCREMENT))
140 
141 #define IS_LL_DMA_PRIORITY(__VALUE__)                     (((__VALUE__) == LL_DMA_LOW_PRIORITY_LOW_WEIGHT)  || \
142                                                            ((__VALUE__) == LL_DMA_LOW_PRIORITY_MID_WEIGHT)  || \
143                                                            ((__VALUE__) == LL_DMA_LOW_PRIORITY_HIGH_WEIGHT) || \
144                                                            ((__VALUE__) == LL_DMA_HIGH_PRIORITY))
145 
146 #define IS_LL_DMA_BLK_DATALENGTH(__VALUE__)                ((__VALUE__) <= 0xFFFFU)
147 
148 #define IS_LL_DMA_BLK_REPEATCOUNT(__VALUE__)               ((__VALUE__) <= 0x0EFFU)
149 
150 #define IS_LL_DMA_TRIGGER_MODE(__VALUE__)                 (((__VALUE__) == LL_DMA_TRIGM_BLK_TRANSFER)      || \
151                                                            ((__VALUE__) == LL_DMA_TRIGM_RPT_BLK_TRANSFER)  || \
152                                                            ((__VALUE__) == LL_DMA_TRIGM_LLI_LINK_TRANSFER) || \
153                                                            ((__VALUE__) == LL_DMA_TRIGM_SINGLBURST_TRANSFER ))
154 
155 #define IS_LL_DMA_TRIGGER_POLARITY(__VALUE__)             (((__VALUE__) == LL_DMA_TRIG_POLARITY_MASKED) || \
156                                                            ((__VALUE__) == LL_DMA_TRIG_POLARITY_RISING) || \
157                                                            ((__VALUE__) == LL_DMA_TRIG_POLARITY_FALLING))
158 
159 #define IS_LL_DMA_BLKHW_REQUEST(__VALUE__)                (((__VALUE__) == LL_DMA_HWREQUEST_SINGLEBURST) || \
160                                                            ((__VALUE__) == LL_DMA_HWREQUEST_BLK))
161 
162 #if defined (LL_GPDMA1_TRIGGER_JPEG_OFT)
163 #define IS_LL_DMA_TRIGGER_SELECTION(__VALUE__)             ((__VALUE__) <= LL_GPDMA1_TRIGGER_JPEG_OFT)
164 #else
165 #define IS_LL_DMA_TRIGGER_SELECTION(__VALUE__)             ((__VALUE__) <= LL_GPDMA1_TRIGGER_ADC1_AWD1)
166 #endif /* LL_GPDMA1_TRIGGER_JPEG_OFT */
167 
168 #if defined (LL_GPDMA1_REQUEST_JPEG_TX)
169 #define IS_LL_DMA_REQUEST_SELECTION(__VALUE__)             ((__VALUE__) <= LL_GPDMA1_REQUEST_JPEG_TX)
170 #elif defined (LL_GPDMA1_REQUEST_ADC2)
171 #define IS_LL_DMA_REQUEST_SELECTION(__VALUE__)             ((__VALUE__) <= LL_GPDMA1_REQUEST_ADC2)
172 #else
173 #define IS_LL_DMA_REQUEST_SELECTION(__VALUE__)             ((__VALUE__) <= LL_GPDMA1_REQUEST_LPTIM3_UE)
174 #endif /* LL_GPDMA1_REQUEST_JPEG_TX */
175 
176 #define IS_LL_DMA_TRANSFER_EVENT_MODE(__VALUE__)          (((__VALUE__) == LL_DMA_TCEM_BLK_TRANSFER)         || \
177                                                            ((__VALUE__) == LL_DMA_TCEM_RPT_BLK_TRANSFER)     || \
178                                                            ((__VALUE__) == LL_DMA_TCEM_EACH_LLITEM_TRANSFER) || \
179                                                            ((__VALUE__) == LL_DMA_TCEM_LAST_LLITEM_TRANSFER))
180 
181 #define IS_LL_DMA_DEST_HALFWORD_EXCHANGE(__VALUE__)       (((__VALUE__) == LL_DMA_DEST_HALFWORD_PRESERVE) || \
182                                                            ((__VALUE__) == LL_DMA_DEST_HALFWORD_EXCHANGE))
183 
184 #define IS_LL_DMA_DEST_BYTE_EXCHANGE(__VALUE__)           (((__VALUE__) == LL_DMA_DEST_BYTE_PRESERVE) || \
185                                                            ((__VALUE__) == LL_DMA_DEST_BYTE_EXCHANGE))
186 
187 #define IS_LL_DMA_SRC_BYTE_EXCHANGE(__VALUE__)            (((__VALUE__) == LL_DMA_SRC_BYTE_PRESERVE) || \
188                                                            ((__VALUE__) == LL_DMA_SRC_BYTE_EXCHANGE))
189 
190 #define IS_LL_DMA_LINK_ALLOCATED_PORT(__VALUE__)          (((__VALUE__) == LL_DMA_LINK_ALLOCATED_PORT0) || \
191                                                            ((__VALUE__) == LL_DMA_LINK_ALLOCATED_PORT1))
192 
193 #define IS_LL_DMA_SRC_ALLOCATED_PORT(__VALUE__)           (((__VALUE__) == LL_DMA_SRC_ALLOCATED_PORT0) || \
194                                                            ((__VALUE__) == LL_DMA_SRC_ALLOCATED_PORT1))
195 
196 #define IS_LL_DMA_DEST_ALLOCATED_PORT(__VALUE__)          (((__VALUE__) == LL_DMA_DEST_ALLOCATED_PORT0) || \
197                                                            ((__VALUE__) == LL_DMA_DEST_ALLOCATED_PORT1))
198 
199 #define IS_LL_DMA_LINK_STEP_MODE(__VALUE__)               (((__VALUE__) == LL_DMA_LSM_FULL_EXECUTION) || \
200                                                            ((__VALUE__) == LL_DMA_LSM_1LINK_EXECUTION))
201 
202 #define IS_LL_DMA_BURST_SRC_ADDR_UPDATE(__VALUE__)        (((__VALUE__) == LL_DMA_BURST_SRC_ADDR_INCREMENT) || \
203                                                            ((__VALUE__) == LL_DMA_BURST_SRC_ADDR_DECREMENT))
204 
205 #define IS_LL_DMA_BURST_DEST_ADDR_UPDATE(__VALUE__)       (((__VALUE__) == LL_DMA_BURST_DEST_ADDR_INCREMENT) || \
206                                                            ((__VALUE__) == LL_DMA_BURST_DEST_ADDR_DECREMENT))
207 
208 #define IS_LL_DMA_BURST_ADDR_UPDATE_VALUE(__VALUE__)       ((__VALUE__) <= 0x1FFFU)
209 
210 #define IS_LL_DMA_BLKRPT_SRC_ADDR_UPDATE(__VALUE__)       (((__VALUE__) == LL_DMA_BLKRPT_SRC_ADDR_INCREMENT) || \
211                                                            ((__VALUE__) == LL_DMA_BLKRPT_SRC_ADDR_DECREMENT))
212 
213 #define IS_LL_DMA_BLKRPT_DEST_ADDR_UPDATE(__VALUE__)      (((__VALUE__) == LL_DMA_BLKRPT_DEST_ADDR_INCREMENT) || \
214                                                            ((__VALUE__) == LL_DMA_BLKRPT_DEST_ADDR_DECREMENT))
215 
216 #define IS_LL_DMA_BLKRPT_ADDR_UPDATE_VALUE(__VALUE__)      ((__VALUE__) <= 0xFFFFU)
217 
218 #define IS_LL_DMA_LINK_BASEADDR(__VALUE__)                (((__VALUE__) & 0xFFFFU) == 0U)
219 
220 #define IS_LL_DMA_LINK_ADDR_OFFSET(__VALUE__)             (((__VALUE__) & 0x03U) == 0U)
221 
222 #define IS_LL_DMA_LINK_UPDATE_REGISTERS(__VALUE__)       ((((__VALUE__) & 0x01FE0000U) == 0U) && ((__VALUE__) != 0U))
223 
224 #define IS_LL_DMA_LINK_NODETYPE(__VALUE__)                (((__VALUE__) == LL_DMA_GPDMA_2D_NODE)     || \
225                                                            ((__VALUE__) == LL_DMA_GPDMA_LINEAR_NODE) || \
226                                                            ((__VALUE__) == LL_DMA_LPDMA_LINEAR_NODE))
227 
228 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
229 #define IS_LL_DMA_CHANNEL_SRC_SEC(__VALUE__)              (((__VALUE__) == LL_DMA_CHANNEL_SRC_NSEC) || \
230                                                            ((__VALUE__) == LL_DMA_CHANNEL_SRC_SEC))
231 
232 #define IS_LL_DMA_CHANNEL_DEST_SEC(__VALUE__)             (((__VALUE__) == LL_DMA_CHANNEL_DEST_NSEC) || \
233                                                            ((__VALUE__) == LL_DMA_CHANNEL_DEST_SEC))
234 #endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
235 /**
236   * @}
237   */
238 
239 /* Private function prototypes -----------------------------------------------*/
240 /* Exported functions --------------------------------------------------------*/
241 
242 /** @addtogroup DMA_LL_Exported_Functions
243   * @{
244   */
245 
246 /** @addtogroup DMA_LL_EF_Init
247   * @{
248   */
249 
250 /**
251   * @brief De-initialize the DMA registers to their default reset values.
252   * @note  This API is used for all available DMA channels.
253   * @note  To convert DMAx_Channely Instance to DMAx Instance and Channely, use
254   *        helper macros :
255   *        @arg @ref LL_DMA_GET_INSTANCE
256   *        @arg @ref LL_DMA_GET_CHANNEL
257   * @param  DMAx DMAx Instance
258   * @param  Channel This parameter can be one of the following values:
259   *         @arg @ref LL_DMA_CHANNEL_0
260   *         @arg @ref LL_DMA_CHANNEL_1
261   *         @arg @ref LL_DMA_CHANNEL_2
262   *         @arg @ref LL_DMA_CHANNEL_3
263   *         @arg @ref LL_DMA_CHANNEL_4
264   *         @arg @ref LL_DMA_CHANNEL_5
265   *         @arg @ref LL_DMA_CHANNEL_6
266   *         @arg @ref LL_DMA_CHANNEL_7
267   *         @arg @ref LL_DMA_CHANNEL_8
268   *         @arg @ref LL_DMA_CHANNEL_9
269   *         @arg @ref LL_DMA_CHANNEL_10
270   *         @arg @ref LL_DMA_CHANNEL_11
271   *         @arg @ref LL_DMA_CHANNEL_12
272   *         @arg @ref LL_DMA_CHANNEL_13
273   *         @arg @ref LL_DMA_CHANNEL_14
274   *         @arg @ref LL_DMA_CHANNEL_15
275   * @retval An ErrorStatus enumeration value:
276   *          - SUCCESS : DMA registers are de-initialized.
277   *          - ERROR   : DMA registers are not de-initialized.
278   */
LL_DMA_DeInit(DMA_TypeDef * DMAx,uint32_t Channel)279 uint32_t LL_DMA_DeInit(DMA_TypeDef *DMAx, uint32_t Channel)
280 {
281   DMA_Channel_TypeDef *tmp;
282   ErrorStatus status = SUCCESS;
283 
284   /* Check the DMA Instance DMAx and Channel parameters */
285   assert_param(IS_LL_DMA_ALL_CHANNEL_INSTANCE(DMAx, Channel));
286 
287   if (Channel == LL_DMA_CHANNEL_ALL)
288   {
289     if (DMAx == GPDMA1)
290     {
291       /* Force reset of DMA clock */
292       LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPDMA1);
293 
294       /* Release reset of DMA clock */
295       LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPDMA1);
296     }
297     else
298     {
299       /* Force reset of DMA clock */
300       LL_AHB3_GRP1_ForceReset(LL_AHB3_GRP1_PERIPH_LPDMA1);
301 
302       /* Release reset of DMA clock */
303       LL_AHB3_GRP1_ReleaseReset(LL_AHB3_GRP1_PERIPH_LPDMA1);
304     }
305   }
306   else
307   {
308     /* Get the DMA Channel Instance */
309     tmp = (DMA_Channel_TypeDef *)(LL_DMA_GET_CHANNEL_INSTANCE(DMAx, Channel));
310 
311     /* Suspend DMA channel */
312     LL_DMA_SuspendChannel(DMAx, Channel);
313 
314     /* Disable the selected Channel */
315     LL_DMA_ResetChannel(DMAx, Channel);
316 
317     /* Reset DMAx_Channely control register */
318     LL_DMA_WriteReg(tmp, CLBAR, 0U);
319 
320     /* Reset DMAx_Channely control register */
321     LL_DMA_WriteReg(tmp, CCR, 0U);
322 
323     /* Reset DMAx_Channely Configuration register */
324     LL_DMA_WriteReg(tmp, CTR1, 0U);
325 
326     /* Reset DMAx_Channely transfer register 2 */
327     LL_DMA_WriteReg(tmp, CTR2, 0U);
328 
329     /* Reset DMAx_Channely block number of data register */
330     LL_DMA_WriteReg(tmp, CBR1, 0U);
331 
332     /* Reset DMAx_Channely source address register */
333     LL_DMA_WriteReg(tmp, CSAR, 0U);
334 
335     /* Reset DMAx_Channely destination address register */
336     LL_DMA_WriteReg(tmp, CDAR, 0U);
337 
338     /* Check DMA channel */
339     if (IS_LL_DMA_2D_CHANNEL_INSTANCE(DMAx, Channel) != 0U)
340     {
341       /* Reset DMAx_Channely transfer register 3 */
342       LL_DMA_WriteReg(tmp, CTR3, 0U);
343 
344       /* Reset DMAx_Channely Block register 2 */
345       LL_DMA_WriteReg(tmp, CBR2, 0U);
346     }
347 
348     /* Reset DMAx_Channely Linked list address register */
349     LL_DMA_WriteReg(tmp, CLLR, 0U);
350 
351     /* Reset DMAx_Channely pending flags */
352     LL_DMA_WriteReg(tmp, CFCR, 0x00003F00U);
353 
354     /* Reset DMAx_Channely attribute */
355     LL_DMA_DisableChannelPrivilege(DMAx, Channel);
356 
357 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
358     LL_DMA_DisableChannelSecure(DMAx, Channel);
359 #endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
360   }
361 
362   return (uint32_t)status;
363 }
364 
365 /**
366   * @brief Initialize the DMA registers according to the specified parameters
367   *        in DMA_InitStruct.
368   * @note  This API is used for all available DMA channels.
369   * @note  A software request transfer can be done once programming the direction
370   *        field in memory to memory value.
371   * @note  To convert DMAx_Channely Instance to DMAx Instance and Channely, use
372   *        helper macros :
373   *        @arg @ref LL_DMA_GET_INSTANCE
374   *        @arg @ref LL_DMA_GET_CHANNEL
375   * @param  DMAx DMAx Instance
376   * @param  Channel This parameter can be one of the following values:
377   *         @arg @ref LL_DMA_CHANNEL_0
378   *         @arg @ref LL_DMA_CHANNEL_1
379   *         @arg @ref LL_DMA_CHANNEL_2
380   *         @arg @ref LL_DMA_CHANNEL_3
381   *         @arg @ref LL_DMA_CHANNEL_4
382   *         @arg @ref LL_DMA_CHANNEL_5
383   *         @arg @ref LL_DMA_CHANNEL_6
384   *         @arg @ref LL_DMA_CHANNEL_7
385   *         @arg @ref LL_DMA_CHANNEL_8
386   *         @arg @ref LL_DMA_CHANNEL_9
387   *         @arg @ref LL_DMA_CHANNEL_10
388   *         @arg @ref LL_DMA_CHANNEL_11
389   *         @arg @ref LL_DMA_CHANNEL_12
390   *         @arg @ref LL_DMA_CHANNEL_13
391   *         @arg @ref LL_DMA_CHANNEL_14
392   *         @arg @ref LL_DMA_CHANNEL_15
393   * @param  DMA_InitStruct pointer to a @ref LL_DMA_InitTypeDef structure.
394   * @retval An ErrorStatus enumeration value:
395   *          - SUCCESS : DMA registers are initialized.
396   *          - ERROR   : Not applicable.
397   */
LL_DMA_Init(DMA_TypeDef * DMAx,uint32_t Channel,LL_DMA_InitTypeDef * DMA_InitStruct)398 uint32_t LL_DMA_Init(DMA_TypeDef *DMAx, uint32_t Channel, LL_DMA_InitTypeDef *DMA_InitStruct)
399 {
400   /* Check the DMA Instance DMAx and Channel parameters*/
401   assert_param(IS_LL_DMA_ALL_CHANNEL_INSTANCE(DMAx, Channel));
402 
403   /* Check the DMA parameters from DMA_InitStruct */
404   assert_param(IS_LL_DMA_DIRECTION(DMA_InitStruct->Direction));
405 
406   /* Check direction */
407   if (DMA_InitStruct->Direction != LL_DMA_DIRECTION_MEMORY_TO_MEMORY)
408   {
409     assert_param(IS_LL_DMA_REQUEST_SELECTION(DMA_InitStruct->Request));
410   }
411 
412   assert_param(IS_LL_DMA_DATA_ALIGNMENT(DMA_InitStruct->DataAlignment));
413   assert_param(IS_LL_DMA_SRC_DATA_WIDTH(DMA_InitStruct->SrcDataWidth));
414   assert_param(IS_LL_DMA_DEST_DATA_WIDTH(DMA_InitStruct->DestDataWidth));
415   assert_param(IS_LL_DMA_SRC_INCREMENT_MODE(DMA_InitStruct->SrcIncMode));
416   assert_param(IS_LL_DMA_DEST_INCREMENT_MODE(DMA_InitStruct->DestIncMode));
417   assert_param(IS_LL_DMA_PRIORITY(DMA_InitStruct->Priority));
418   assert_param(IS_LL_DMA_BLK_DATALENGTH(DMA_InitStruct->BlkDataLength));
419   assert_param(IS_LL_DMA_TRIGGER_POLARITY(DMA_InitStruct->TriggerPolarity));
420   assert_param(IS_LL_DMA_BLKHW_REQUEST(DMA_InitStruct->BlkHWRequest));
421   assert_param(IS_LL_DMA_TRANSFER_EVENT_MODE(DMA_InitStruct->TransferEventMode));
422   assert_param(IS_LL_DMA_LINK_STEP_MODE(DMA_InitStruct->LinkStepMode));
423   assert_param(IS_LL_DMA_LINK_BASEADDR(DMA_InitStruct->LinkedListBaseAddr));
424   assert_param(IS_LL_DMA_LINK_ADDR_OFFSET(DMA_InitStruct->LinkedListAddrOffset));
425 
426   /* Check DMA instance */
427   if (IS_LL_GPDMA_CHANNEL_INSTANCE(DMAx, Channel) != 0U)
428   {
429     assert_param(IS_LL_DMA_BURST_LENGTH(DMA_InitStruct->SrcBurstLength));
430     assert_param(IS_LL_DMA_BURST_LENGTH(DMA_InitStruct->DestBurstLength));
431     assert_param(IS_LL_DMA_DEST_HALFWORD_EXCHANGE(DMA_InitStruct->DestHWordExchange));
432     assert_param(IS_LL_DMA_DEST_BYTE_EXCHANGE(DMA_InitStruct->DestByteExchange));
433     assert_param(IS_LL_DMA_SRC_BYTE_EXCHANGE(DMA_InitStruct->SrcByteExchange));
434     assert_param(IS_LL_DMA_LINK_ALLOCATED_PORT(DMA_InitStruct->LinkAllocatedPort));
435     assert_param(IS_LL_DMA_SRC_ALLOCATED_PORT(DMA_InitStruct->SrcAllocatedPort));
436     assert_param(IS_LL_DMA_DEST_ALLOCATED_PORT(DMA_InitStruct->DestAllocatedPort));
437   }
438 
439   /* Check trigger polarity */
440   if (DMA_InitStruct->TriggerPolarity != LL_DMA_TRIG_POLARITY_MASKED)
441   {
442     assert_param(IS_LL_DMA_TRIGGER_MODE(DMA_InitStruct->TriggerMode));
443     assert_param(IS_LL_DMA_TRIGGER_SELECTION(DMA_InitStruct->TriggerSelection));
444   }
445 
446   /* Check DMA channel */
447   if (IS_LL_DMA_2D_CHANNEL_INSTANCE(DMAx, Channel) != 0U)
448   {
449     assert_param(IS_LL_DMA_BLK_REPEATCOUNT(DMA_InitStruct->BlkRptCount));
450     assert_param(IS_LL_DMA_BURST_SRC_ADDR_UPDATE(DMA_InitStruct->SrcAddrUpdateMode));
451     assert_param(IS_LL_DMA_BURST_DEST_ADDR_UPDATE(DMA_InitStruct->DestAddrUpdateMode));
452     assert_param(IS_LL_DMA_BURST_ADDR_UPDATE_VALUE(DMA_InitStruct->SrcAddrOffset));
453     assert_param(IS_LL_DMA_BURST_ADDR_UPDATE_VALUE(DMA_InitStruct->DestAddrOffset));
454     assert_param(IS_LL_DMA_BLKRPT_SRC_ADDR_UPDATE(DMA_InitStruct->BlkRptSrcAddrUpdateMode));
455     assert_param(IS_LL_DMA_BLKRPT_DEST_ADDR_UPDATE(DMA_InitStruct->BlkRptDestAddrUpdateMode));
456     assert_param(IS_LL_DMA_BLKRPT_ADDR_UPDATE_VALUE(DMA_InitStruct->BlkRptSrcAddrOffset));
457     assert_param(IS_LL_DMA_BLKRPT_ADDR_UPDATE_VALUE(DMA_InitStruct->BlkRptDestAddrOffset));
458   }
459 
460   /*-------------------------- DMAx CLBAR Configuration ------------------------
461    * Configure the Transfer linked list address with parameter :
462    * - LinkedListBaseAdd:                              DMA_CLBAR_LBA[31:16] bits
463    */
464   LL_DMA_SetLinkedListBaseAddr(DMAx, Channel, DMA_InitStruct->LinkedListBaseAddr);
465 
466   /*-------------------------- DMAx CCR Configuration --------------------------
467    * Configure the control parameter :
468    * - LinkAllocatedPort:                              DMA_CCR_LAP bit
469    *   LinkAllocatedPort field is not supported by LPDMA channels.
470    * - LinkStepMode:                                   DMA_CCR_LSM bit
471    * - Priority:                                       DMA_CCR_PRIO [23:22] bits
472    */
473   LL_DMA_ConfigControl(DMAx, Channel, DMA_InitStruct->Priority | \
474                        DMA_InitStruct->LinkAllocatedPort       | \
475                        DMA_InitStruct->LinkStepMode);
476 
477   /*-------------------------- DMAx CTR1 Configuration -------------------------
478    * Configure the Data transfer  parameter :
479    * - DestAllocatedPort:                         DMA_CTR1_DAP bit
480    *   DestAllocatedPort field is not supported by LPDMA channels.
481    * - DestHWordExchange:                         DMA_CTR1_DHX bit
482    *   DestHWordExchange field is not supported by LPDMA channels.
483    * - DestByteExchange:                          DMA_CTR1_DBX bit
484    *   DestByteExchange field is not supported by LPDMA channels.
485    * - DestIncMode:                               DMA_CTR1_DINC bit
486    * - DestDataWidth:                             DMA_CTR1_DDW_LOG2 [17:16] bits
487    * - SrcAllocatedPort:                          DMA_CTR1_SAP bit
488    *   SrcAllocatedPort field is not supported by LPDMA channels.
489    * - SrcByteExchange:                           DMA_CTR1_SBX bit
490    *   SrcByteExchange field is not supported by LPDMA channels.
491    * - DataAlignment:                             DMA_CTR1_PAM [12:11] bits
492    *   DataAlignment field is reduced to one bit by LPDMA channels.
493    * - SrcIncMode:                                DMA_CTR1_SINC bit
494    * - SrcDataWidth:                              DMA_CTR1_SDW_LOG2 [1:0] bits
495    * - SrcBurstLength:                            DMA_CTR1_SBL_1 [9:4] bits
496    *   SrcBurstLength field is not supported by LPDMA channels.
497    * - DestBurstLength:                           DMA_CTR1_DBL_1 [25:20] bits
498    *   DestBurstLength field is not supported by LPDMA channels.
499    */
500   LL_DMA_ConfigTransfer(DMAx, Channel, DMA_InitStruct->DestAllocatedPort | \
501                         DMA_InitStruct->DestHWordExchange                | \
502                         DMA_InitStruct->DestByteExchange                 | \
503                         DMA_InitStruct->DestIncMode                      | \
504                         DMA_InitStruct->DestDataWidth                    | \
505                         DMA_InitStruct->SrcAllocatedPort                 | \
506                         DMA_InitStruct->SrcByteExchange                  | \
507                         DMA_InitStruct->DataAlignment                    | \
508                         DMA_InitStruct->SrcIncMode                       | \
509                         DMA_InitStruct->SrcDataWidth);
510   /* Check DMA instance */
511   if (IS_LL_GPDMA_CHANNEL_INSTANCE(DMAx, Channel) != 0U)
512   {
513     LL_DMA_ConfigBurstLength(DMAx, Channel,  DMA_InitStruct->SrcBurstLength,
514                              DMA_InitStruct->DestBurstLength);
515   }
516 
517   /*-------------------------- DMAx CTR2 Configuration -------------------------
518    * Configure the channel transfer parameter :
519    * - TransferEventMode:                          DMA_CTR2_TCEM [31:30] bits
520    * - TriggerPolarity:                            DMA_CTR2_TRIGPOL [25:24] bits
521    * - TriggerMode:                                DMA_CTR2_TRIGM  [15:14] bits
522    * - BlkHWRequest:                               DMA_CTR2_BREQ bit
523    * - Direction:                                  DMA_CTR2_DREQ bit
524    * - Direction:                                  DMA_CTR2_SWREQ bit
525    *   Direction field is reduced to one bit for LPDMA channels (SWREQ).
526    * - TriggerSelection:                           DMA_CTR2_TRIGSEL [21:16] bits
527    *   TriggerSelection field is reduced to 5 bits for LPDMA channels.
528    * - Request:                                    DMA_CTR2_REQSEL [6:0] bits
529    *   Request field is reduced to 5 bits for LPDMA channels.
530    */
531   LL_DMA_ConfigChannelTransfer(DMAx, Channel, DMA_InitStruct->TransferEventMode | \
532                                DMA_InitStruct->TriggerPolarity                  | \
533                                DMA_InitStruct->BlkHWRequest                     | \
534                                DMA_InitStruct->Direction);
535 
536   /* Check direction */
537   if (DMA_InitStruct->Direction != LL_DMA_DIRECTION_MEMORY_TO_MEMORY)
538   {
539     LL_DMA_SetPeriphRequest(DMAx, Channel, DMA_InitStruct->Request);
540   }
541 
542   /* Check trigger polarity */
543   if (DMA_InitStruct->TriggerPolarity != LL_DMA_TRIG_POLARITY_MASKED)
544   {
545     LL_DMA_SetHWTrigger(DMAx, Channel, DMA_InitStruct->TriggerSelection);
546     LL_DMA_SetTriggerMode(DMAx, Channel, DMA_InitStruct->TriggerMode);
547   }
548 
549   /*-------------------------- DMAx CBR1 Configuration -------------------------
550    * Configure the Transfer Block counters and update mode with parameter :
551    * - BlkDataLength:                                   DMA_CBR1_BNDT[15:0] bits
552    * - BlkRptCount:                                     DMA_CBR1_BRC[26:16] bits
553    *   BlkRptCount field is supported only by 2D addressing channels.
554    * - BlkRptSrcAddrUpdateMode:                                DMA_CBR1_BRSDEC bit
555    *   BlkRptSrcAddrUpdateMode field is supported only by 2D addressing channels.
556    * - BlkRptDestAddrUpdateMode:                               DMA_CBR1_BRDDEC bit
557    *   BlkRptDestAddrUpdateMode field is supported only by 2D addressing channels.
558    * - SrcAddrUpdateMode:                                      DMA_CBR1_SDEC bit
559    *   SrcAddrUpdateMode field is supported only by 2D addressing channels.
560    * - DestAddrUpdateMode:                                     DMA_CBR1_DDEC bit
561    *   DestAddrUpdateMode field is supported only by 2D addressing channels.
562    */
563   LL_DMA_SetBlkDataLength(DMAx, Channel, DMA_InitStruct->BlkDataLength);
564 
565   /* Check DMA channel */
566   if (IS_LL_DMA_2D_CHANNEL_INSTANCE(DMAx, Channel) != 0U)
567   {
568     LL_DMA_SetBlkRptCount(DMAx, Channel, DMA_InitStruct->BlkRptCount);
569     LL_DMA_ConfigBlkRptAddrUpdate(DMAx, Channel, DMA_InitStruct->BlkRptSrcAddrUpdateMode  | \
570                                   DMA_InitStruct->BlkRptDestAddrUpdateMode                | \
571                                   DMA_InitStruct->SrcAddrUpdateMode                       | \
572                                   DMA_InitStruct->DestAddrUpdateMode);
573   }
574 
575   /*-------------------------- DMAx CSAR and CDAR Configuration ----------------
576    * Configure the Transfer source address with parameter :
577    * - SrcAddress:                                        DMA_CSAR_SA[31:0] bits
578    * - DestAddress:                                       DMA_CDAR_DA[31:0] bits
579    */
580   LL_DMA_ConfigAddresses(DMAx, Channel, DMA_InitStruct->SrcAddress, DMA_InitStruct->DestAddress);
581 
582   /* Check DMA channel */
583   if (IS_LL_DMA_2D_CHANNEL_INSTANCE(DMAx, Channel) != 0U)
584   {
585     /*------------------------ DMAx CTR3 Configuration -------------------------
586      * Configure the Transfer Block counters and update mode with parameter :
587      * - SrcAddrOffset:                                 DMA_CTR3_SAO[28:16] bits
588      *   SrcAddrOffset field is supported only by 2D addressing channels.
589      * - DestAddrOffset:                                DMA_CTR3_DAO[12:0] bits
590      *   DestAddrOffset field is supported only by 2D addressing channels.
591      */
592     LL_DMA_ConfigAddrUpdateValue(DMAx, Channel, DMA_InitStruct->SrcAddrOffset, DMA_InitStruct->DestAddrOffset);
593 
594     /*------------------------ DMAx CBR2 Configuration -----------------------
595      * Configure the Transfer Block counters and update mode with parameter :
596      * - BlkRptSrcAddrOffset:                         DMA_CBR2_BRSAO[15:0] bits
597      *   BlkRptSrcAddrOffset field is supported only by 2D addressing channels.
598      * - BlkRptDestAddrOffset:                        DMA_CBR2_BRDAO[31:16] bits
599      *   BlkRptDestAddrOffset field is supported only by 2D addressing channels.
600      */
601     LL_DMA_ConfigBlkRptAddrUpdateValue(DMAx, Channel, DMA_InitStruct->BlkRptSrcAddrOffset,
602                                        DMA_InitStruct->BlkRptDestAddrOffset);
603   }
604 
605   /*-------------------------- DMAx CLLR Configuration -------------------------
606    * Configure the Transfer linked list address with parameter :
607    * - DestAddrOffset:                                    DMA_CLLR_LA[15:2] bits
608    */
609   LL_DMA_SetLinkedListAddrOffset(DMAx, Channel, DMA_InitStruct->LinkedListAddrOffset);
610 
611   return (uint32_t)SUCCESS;
612 }
613 
614 /**
615   * @brief  Set each @ref LL_DMA_InitTypeDef field to default value.
616   * @param  DMA_InitStruct Pointer to a @ref LL_DMA_InitTypeDef structure.
617   * @retval None.
618   */
LL_DMA_StructInit(LL_DMA_InitTypeDef * DMA_InitStruct)619 void LL_DMA_StructInit(LL_DMA_InitTypeDef *DMA_InitStruct)
620 {
621   /* Set DMA_InitStruct fields to default values */
622   DMA_InitStruct->SrcAddress               = 0x00000000U;
623   DMA_InitStruct->DestAddress              = 0x00000000U;
624   DMA_InitStruct->Direction                = LL_DMA_DIRECTION_MEMORY_TO_MEMORY;
625   DMA_InitStruct->BlkHWRequest             = LL_DMA_HWREQUEST_SINGLEBURST;
626   DMA_InitStruct->DataAlignment            = LL_DMA_DATA_ALIGN_ZEROPADD;
627   DMA_InitStruct->SrcBurstLength           = 1U;
628   DMA_InitStruct->DestBurstLength          = 1U;
629   DMA_InitStruct->SrcDataWidth             = LL_DMA_SRC_DATAWIDTH_BYTE;
630   DMA_InitStruct->DestDataWidth            = LL_DMA_DEST_DATAWIDTH_BYTE;
631   DMA_InitStruct->SrcIncMode               = LL_DMA_SRC_FIXED;
632   DMA_InitStruct->DestIncMode              = LL_DMA_DEST_FIXED;
633   DMA_InitStruct->Priority                 = LL_DMA_LOW_PRIORITY_LOW_WEIGHT;
634   DMA_InitStruct->BlkDataLength            = 0x00000000U;
635   DMA_InitStruct->BlkRptCount              = 0x00000000U;
636   DMA_InitStruct->TriggerMode              = LL_DMA_TRIGM_BLK_TRANSFER;
637   DMA_InitStruct->TriggerPolarity          = LL_DMA_TRIG_POLARITY_MASKED;
638   DMA_InitStruct->TriggerSelection         = 0x00000000U;
639   DMA_InitStruct->Request                  = 0x00000000U;
640   DMA_InitStruct->TransferEventMode        = LL_DMA_TCEM_BLK_TRANSFER;
641   DMA_InitStruct->DestHWordExchange        = LL_DMA_DEST_HALFWORD_PRESERVE;
642   DMA_InitStruct->DestByteExchange         = LL_DMA_DEST_BYTE_PRESERVE;
643   DMA_InitStruct->SrcByteExchange          = LL_DMA_SRC_BYTE_PRESERVE;
644   DMA_InitStruct->SrcAllocatedPort         = LL_DMA_SRC_ALLOCATED_PORT0;
645   DMA_InitStruct->DestAllocatedPort        = LL_DMA_DEST_ALLOCATED_PORT0;
646   DMA_InitStruct->LinkAllocatedPort        = LL_DMA_LINK_ALLOCATED_PORT0;
647   DMA_InitStruct->LinkStepMode             = LL_DMA_LSM_FULL_EXECUTION;
648   DMA_InitStruct->SrcAddrUpdateMode        = LL_DMA_BURST_SRC_ADDR_INCREMENT;
649   DMA_InitStruct->DestAddrUpdateMode       = LL_DMA_BURST_DEST_ADDR_INCREMENT;
650   DMA_InitStruct->SrcAddrOffset            = 0x00000000U;
651   DMA_InitStruct->DestAddrOffset           = 0x00000000U;
652   DMA_InitStruct->BlkRptSrcAddrUpdateMode  = LL_DMA_BLKRPT_SRC_ADDR_INCREMENT;
653   DMA_InitStruct->BlkRptDestAddrUpdateMode = LL_DMA_BLKRPT_DEST_ADDR_INCREMENT;
654   DMA_InitStruct->BlkRptSrcAddrOffset      = 0x00000000U;
655   DMA_InitStruct->BlkRptDestAddrOffset     = 0x00000000U;
656   DMA_InitStruct->LinkedListBaseAddr       = 0x00000000U;
657   DMA_InitStruct->LinkedListAddrOffset     = 0x00000000U;
658 }
659 
660 /**
661   * @brief  Set each @ref LL_DMA_InitLinkedListTypeDef field to default value.
662   * @param  DMA_InitLinkedListStruct Pointer to
663   *         a @ref LL_DMA_InitLinkedListTypeDef structure.
664   * @retval None.
665   */
LL_DMA_ListStructInit(LL_DMA_InitLinkedListTypeDef * DMA_InitLinkedListStruct)666 void LL_DMA_ListStructInit(LL_DMA_InitLinkedListTypeDef *DMA_InitLinkedListStruct)
667 {
668   /* Set LL_DMA_InitLinkedListTypeDef fields to default values */
669   DMA_InitLinkedListStruct->Priority          = LL_DMA_LOW_PRIORITY_LOW_WEIGHT;
670   DMA_InitLinkedListStruct->LinkStepMode      = LL_DMA_LSM_FULL_EXECUTION;
671   DMA_InitLinkedListStruct->TransferEventMode = LL_DMA_TCEM_LAST_LLITEM_TRANSFER;
672   DMA_InitLinkedListStruct->LinkAllocatedPort = LL_DMA_LINK_ALLOCATED_PORT0;
673 }
674 
675 /**
676   * @brief De-initialize the DMA linked list.
677   * @note  This API is used for all available DMA channels.
678   * @note  To convert DMAx_Channely Instance to DMAx Instance and Channely, use
679   *        helper macros :
680   *        @arg @ref LL_DMA_GET_INSTANCE
681   *        @arg @ref LL_DMA_GET_CHANNEL
682   * @param  DMAx DMAx Instance
683   * @param  Channel This parameter can be one of the following values:
684   *         @arg @ref LL_DMA_CHANNEL_0
685   *         @arg @ref LL_DMA_CHANNEL_1
686   *         @arg @ref LL_DMA_CHANNEL_2
687   *         @arg @ref LL_DMA_CHANNEL_3
688   *         @arg @ref LL_DMA_CHANNEL_4
689   *         @arg @ref LL_DMA_CHANNEL_5
690   *         @arg @ref LL_DMA_CHANNEL_6
691   *         @arg @ref LL_DMA_CHANNEL_7
692   *         @arg @ref LL_DMA_CHANNEL_8
693   *         @arg @ref LL_DMA_CHANNEL_9
694   *         @arg @ref LL_DMA_CHANNEL_10
695   *         @arg @ref LL_DMA_CHANNEL_11
696   *         @arg @ref LL_DMA_CHANNEL_12
697   *         @arg @ref LL_DMA_CHANNEL_13
698   *         @arg @ref LL_DMA_CHANNEL_14
699   *         @arg @ref LL_DMA_CHANNEL_15
700   * @retval An ErrorStatus enumeration value:
701   *          - SUCCESS : DMA registers are de-initialized.
702   *          - ERROR   : DMA registers are not de-initialized.
703   */
LL_DMA_List_DeInit(DMA_TypeDef * DMAx,uint32_t Channel)704 uint32_t LL_DMA_List_DeInit(DMA_TypeDef *DMAx, uint32_t Channel)
705 {
706   return LL_DMA_DeInit(DMAx, Channel);
707 }
708 
709 /**
710   * @brief Initialize the DMA linked list according to the specified parameters
711   *        in LL_DMA_InitLinkedListTypeDef.
712   * @note  This API is used for all available DMA channels.
713   * @note  To convert DMAx_Channely Instance to DMAx Instance and Channely, use
714   *        helper macros :
715   *        @arg @ref LL_DMA_GET_INSTANCE
716   *        @arg @ref LL_DMA_GET_CHANNEL
717   * @param  DMAx DMAx Instance
718   * @param  Channel This parameter can be one of the following values:
719   *         @arg @ref LL_DMA_CHANNEL_0
720   *         @arg @ref LL_DMA_CHANNEL_1
721   *         @arg @ref LL_DMA_CHANNEL_2
722   *         @arg @ref LL_DMA_CHANNEL_3
723   *         @arg @ref LL_DMA_CHANNEL_4
724   *         @arg @ref LL_DMA_CHANNEL_5
725   *         @arg @ref LL_DMA_CHANNEL_6
726   *         @arg @ref LL_DMA_CHANNEL_7
727   *         @arg @ref LL_DMA_CHANNEL_8
728   *         @arg @ref LL_DMA_CHANNEL_9
729   *         @arg @ref LL_DMA_CHANNEL_10
730   *         @arg @ref LL_DMA_CHANNEL_11
731   *         @arg @ref LL_DMA_CHANNEL_12
732   *         @arg @ref LL_DMA_CHANNEL_13
733   *         @arg @ref LL_DMA_CHANNEL_14
734   *         @arg @ref LL_DMA_CHANNEL_15
735   * @param  DMA_InitLinkedListStruct pointer to
736   *         a @ref LL_DMA_InitLinkedListTypeDef structure.
737   * @retval An ErrorStatus enumeration value:
738   *          - SUCCESS : DMA registers are initialized.
739   *          - ERROR   : Not applicable.
740   */
LL_DMA_List_Init(DMA_TypeDef * DMAx,uint32_t Channel,LL_DMA_InitLinkedListTypeDef * DMA_InitLinkedListStruct)741 uint32_t LL_DMA_List_Init(DMA_TypeDef *DMAx, uint32_t Channel, LL_DMA_InitLinkedListTypeDef *DMA_InitLinkedListStruct)
742 {
743   /* Check the DMA Instance DMAx and Channel parameters*/
744   assert_param(IS_LL_DMA_ALL_CHANNEL_INSTANCE(DMAx, Channel));
745 
746   /* Check the DMA parameters from DMA_InitLinkedListStruct */
747   assert_param(IS_LL_DMA_PRIORITY(DMA_InitLinkedListStruct->Priority));
748   assert_param(IS_LL_DMA_LINK_STEP_MODE(DMA_InitLinkedListStruct->LinkStepMode));
749   assert_param(IS_LL_DMA_TRANSFER_EVENT_MODE(DMA_InitLinkedListStruct->TransferEventMode));
750   /* Check DMA instance */
751   if (IS_LL_GPDMA_CHANNEL_INSTANCE(DMAx, Channel) != 0U)
752   {
753     assert_param(IS_LL_DMA_LINK_ALLOCATED_PORT(DMA_InitLinkedListStruct->LinkAllocatedPort));
754   }
755 
756   /*-------------------------- DMAx CCR Configuration --------------------------
757    * Configure the control parameter :
758    * - LinkAllocatedPort:                              DMA_CCR_LAP bit
759    *   LinkAllocatedPort field is supported only by GPDMA channels.
760    * - LinkStepMode:                                   DMA_CCR_LSM bit
761    * - Priority:                                       DMA_CCR_PRIO [23:22] bits
762    */
763   LL_DMA_ConfigControl(DMAx, Channel, DMA_InitLinkedListStruct->Priority | \
764                        DMA_InitLinkedListStruct->LinkAllocatedPort       | \
765                        DMA_InitLinkedListStruct->LinkStepMode);
766 
767   /*-------------------------- DMAx CTR2 Configuration -------------------------
768    * Configure the channel transfer parameter :
769    * - TransferEventMode:                          DMA_CTR2_TCEM [31:30] bits
770    */
771   LL_DMA_SetTransferEventMode(DMAx, Channel, DMA_InitLinkedListStruct->TransferEventMode);
772 
773   return (uint32_t)SUCCESS;
774 }
775 
776 /**
777   * @brief  Set each @ref LL_DMA_InitNodeTypeDef field to default value.
778   * @param  DMA_InitNodeStruct Pointer to a @ref LL_DMA_InitNodeTypeDef
779   *         structure.
780   * @retval None.
781   */
LL_DMA_NodeStructInit(LL_DMA_InitNodeTypeDef * DMA_InitNodeStruct)782 void LL_DMA_NodeStructInit(LL_DMA_InitNodeTypeDef *DMA_InitNodeStruct)
783 {
784   /* Set DMA_InitNodeStruct fields to default values */
785 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
786   DMA_InitNodeStruct->DestSecure               = LL_DMA_CHANNEL_DEST_NSEC;
787 #endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
788   DMA_InitNodeStruct->DestAllocatedPort        = LL_DMA_DEST_ALLOCATED_PORT0;
789   DMA_InitNodeStruct->DestHWordExchange        = LL_DMA_DEST_HALFWORD_PRESERVE;
790   DMA_InitNodeStruct->DestByteExchange         = LL_DMA_DEST_BYTE_PRESERVE;
791   DMA_InitNodeStruct->DestBurstLength          = 1U;
792   DMA_InitNodeStruct->DestIncMode              = LL_DMA_DEST_FIXED;
793   DMA_InitNodeStruct->DestDataWidth            = LL_DMA_DEST_DATAWIDTH_BYTE;
794 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
795   DMA_InitNodeStruct->SrcSecure                = LL_DMA_CHANNEL_SRC_NSEC;
796 #endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
797   DMA_InitNodeStruct->SrcAllocatedPort         = LL_DMA_SRC_ALLOCATED_PORT0;
798   DMA_InitNodeStruct->SrcByteExchange          = LL_DMA_SRC_BYTE_PRESERVE;
799   DMA_InitNodeStruct->DataAlignment            = LL_DMA_DATA_ALIGN_ZEROPADD;
800   DMA_InitNodeStruct->SrcBurstLength           = 1U;
801   DMA_InitNodeStruct->SrcIncMode               = LL_DMA_SRC_FIXED;
802   DMA_InitNodeStruct->SrcDataWidth             = LL_DMA_SRC_DATAWIDTH_BYTE;
803   DMA_InitNodeStruct->TransferEventMode        = LL_DMA_TCEM_BLK_TRANSFER;
804   DMA_InitNodeStruct->TriggerPolarity          = LL_DMA_TRIG_POLARITY_MASKED;
805   DMA_InitNodeStruct->TriggerSelection         = 0x00000000U;
806   DMA_InitNodeStruct->TriggerMode              = LL_DMA_TRIGM_BLK_TRANSFER;
807   DMA_InitNodeStruct->BlkHWRequest             = LL_DMA_HWREQUEST_SINGLEBURST;
808   DMA_InitNodeStruct->Direction                = LL_DMA_DIRECTION_MEMORY_TO_MEMORY;
809   DMA_InitNodeStruct->Request                  = 0x00000000U;
810   DMA_InitNodeStruct->BlkRptDestAddrUpdateMode = LL_DMA_BLKRPT_DEST_ADDR_INCREMENT;
811   DMA_InitNodeStruct->BlkRptSrcAddrUpdateMode  = LL_DMA_BLKRPT_SRC_ADDR_INCREMENT;
812   DMA_InitNodeStruct->DestAddrUpdateMode       = LL_DMA_BURST_DEST_ADDR_INCREMENT;
813   DMA_InitNodeStruct->SrcAddrUpdateMode        = LL_DMA_BURST_SRC_ADDR_INCREMENT;
814   DMA_InitNodeStruct->BlkRptCount              = 0x00000000U;
815   DMA_InitNodeStruct->BlkDataLength            = 0x00000000U;
816   DMA_InitNodeStruct->SrcAddress               = 0x00000000U;
817   DMA_InitNodeStruct->DestAddress              = 0x00000000U;
818   DMA_InitNodeStruct->DestAddrOffset           = 0x00000000U;
819   DMA_InitNodeStruct->SrcAddrOffset            = 0x00000000U;
820   DMA_InitNodeStruct->BlkRptDestAddrOffset     = 0x00000000U;
821   DMA_InitNodeStruct->BlkRptSrcAddrOffset      = 0x00000000U;
822   DMA_InitNodeStruct->UpdateRegisters          = (LL_DMA_UPDATE_CTR1 | LL_DMA_UPDATE_CTR2 | \
823                                                   LL_DMA_UPDATE_CBR1 | LL_DMA_UPDATE_CSAR | \
824                                                   LL_DMA_UPDATE_CDAR | LL_DMA_UPDATE_CTR3 | \
825                                                   LL_DMA_UPDATE_CBR2 | LL_DMA_UPDATE_CLLR);
826   DMA_InitNodeStruct->NodeType                 = LL_DMA_GPDMA_LINEAR_NODE;
827 }
828 
829 /**
830   * @brief  Initializes DMA linked list node according to the specified
831   *         parameters in the DMA_InitNodeStruct.
832   * @param  DMA_InitNodeStruct Pointer to a LL_DMA_InitNodeTypeDef structure
833   *         that contains linked list node
834   *         registers configurations.
835   * @param  pNode Pointer to linked list node to fill according to
836   *         LL_DMA_LinkNodeTypeDef parameters.
837   * @retval None
838   */
LL_DMA_CreateLinkNode(LL_DMA_InitNodeTypeDef * DMA_InitNodeStruct,LL_DMA_LinkNodeTypeDef * pNode)839 uint32_t LL_DMA_CreateLinkNode(LL_DMA_InitNodeTypeDef *DMA_InitNodeStruct, LL_DMA_LinkNodeTypeDef *pNode)
840 {
841   uint32_t reg_counter = 0U;
842 
843   /* Check the DMA Node type */
844   assert_param(IS_LL_DMA_LINK_NODETYPE(DMA_InitNodeStruct->NodeType));
845 
846   /* Check the DMA parameters from DMA_InitNodeStruct */
847   assert_param(IS_LL_DMA_DIRECTION(DMA_InitNodeStruct->Direction));
848 
849   /* Check direction */
850   if (DMA_InitNodeStruct->Direction != LL_DMA_DIRECTION_MEMORY_TO_MEMORY)
851   {
852     assert_param(IS_LL_DMA_REQUEST_SELECTION(DMA_InitNodeStruct->Request));
853   }
854 
855   assert_param(IS_LL_DMA_DATA_ALIGNMENT(DMA_InitNodeStruct->DataAlignment));
856   assert_param(IS_LL_DMA_SRC_DATA_WIDTH(DMA_InitNodeStruct->SrcDataWidth));
857   assert_param(IS_LL_DMA_DEST_DATA_WIDTH(DMA_InitNodeStruct->DestDataWidth));
858   assert_param(IS_LL_DMA_SRC_INCREMENT_MODE(DMA_InitNodeStruct->SrcIncMode));
859   assert_param(IS_LL_DMA_DEST_INCREMENT_MODE(DMA_InitNodeStruct->DestIncMode));
860   assert_param(IS_LL_DMA_BLK_DATALENGTH(DMA_InitNodeStruct->BlkDataLength));
861   assert_param(IS_LL_DMA_TRIGGER_POLARITY(DMA_InitNodeStruct->TriggerPolarity));
862   assert_param(IS_LL_DMA_BLKHW_REQUEST(DMA_InitNodeStruct->BlkHWRequest));
863   assert_param(IS_LL_DMA_TRANSFER_EVENT_MODE(DMA_InitNodeStruct->TransferEventMode));
864   assert_param(IS_LL_DMA_LINK_UPDATE_REGISTERS(DMA_InitNodeStruct->UpdateRegisters));
865 
866 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
867   assert_param(IS_LL_DMA_CHANNEL_SRC_SEC(DMA_InitNodeStruct->SrcSecure));
868   assert_param(IS_LL_DMA_CHANNEL_DEST_SEC(DMA_InitNodeStruct->DestSecure));
869 #endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
870 
871   /* Check trigger polarity */
872   if (DMA_InitNodeStruct->TriggerPolarity != LL_DMA_TRIG_POLARITY_MASKED)
873   {
874     assert_param(IS_LL_DMA_TRIGGER_MODE(DMA_InitNodeStruct->TriggerMode));
875     assert_param(IS_LL_DMA_TRIGGER_SELECTION(DMA_InitNodeStruct->TriggerSelection));
876   }
877 
878   /* Check node type */
879   if (DMA_InitNodeStruct->NodeType == LL_DMA_GPDMA_LINEAR_NODE)
880   {
881     assert_param(IS_LL_DMA_BURST_LENGTH(DMA_InitNodeStruct->SrcBurstLength));
882     assert_param(IS_LL_DMA_BURST_LENGTH(DMA_InitNodeStruct->DestBurstLength));
883     assert_param(IS_LL_DMA_DEST_HALFWORD_EXCHANGE(DMA_InitNodeStruct->DestHWordExchange));
884     assert_param(IS_LL_DMA_DEST_BYTE_EXCHANGE(DMA_InitNodeStruct->DestByteExchange));
885     assert_param(IS_LL_DMA_SRC_BYTE_EXCHANGE(DMA_InitNodeStruct->SrcByteExchange));
886     assert_param(IS_LL_DMA_SRC_ALLOCATED_PORT(DMA_InitNodeStruct->SrcAllocatedPort));
887     assert_param(IS_LL_DMA_DEST_ALLOCATED_PORT(DMA_InitNodeStruct->DestAllocatedPort));
888   }
889 
890   /* Check DMA channel */
891   if (DMA_InitNodeStruct->NodeType == LL_DMA_GPDMA_2D_NODE)
892   {
893     assert_param(IS_LL_DMA_BLK_REPEATCOUNT(DMA_InitNodeStruct->BlkRptCount));
894     assert_param(IS_LL_DMA_BURST_SRC_ADDR_UPDATE(DMA_InitNodeStruct->SrcAddrUpdateMode));
895     assert_param(IS_LL_DMA_BURST_DEST_ADDR_UPDATE(DMA_InitNodeStruct->DestAddrUpdateMode));
896     assert_param(IS_LL_DMA_BURST_ADDR_UPDATE_VALUE(DMA_InitNodeStruct->SrcAddrOffset));
897     assert_param(IS_LL_DMA_BURST_ADDR_UPDATE_VALUE(DMA_InitNodeStruct->DestAddrOffset));
898     assert_param(IS_LL_DMA_BLKRPT_SRC_ADDR_UPDATE(DMA_InitNodeStruct->BlkRptSrcAddrUpdateMode));
899     assert_param(IS_LL_DMA_BLKRPT_DEST_ADDR_UPDATE(DMA_InitNodeStruct->BlkRptDestAddrUpdateMode));
900     assert_param(IS_LL_DMA_BLKRPT_ADDR_UPDATE_VALUE(DMA_InitNodeStruct->BlkRptSrcAddrOffset));
901     assert_param(IS_LL_DMA_BLKRPT_ADDR_UPDATE_VALUE(DMA_InitNodeStruct->BlkRptDestAddrOffset));
902   }
903 
904   /* Check if CTR1 register update is enabled */
905   if ((DMA_InitNodeStruct->UpdateRegisters & LL_DMA_UPDATE_CTR1) == LL_DMA_UPDATE_CTR1)
906   {
907     /*-------------------------- DMAx CTR1 Configuration -----------------------
908     * Configure the Data transfer  parameter :
909     * - DestAllocatedPort:                        DMA_CTR1_DAP bit
910     *   DestAllocatedPort field is not supported by LPDMA channels.
911     * - DestHWordExchange:                        DMA_CTR1_DHX bit
912     *   DestHWordExchange field is not supported by LPDMA channels.
913     * - DestByteExchange:                         DMA_CTR1_DBX bit
914     *   DestByteExchange field is not supported by LPDMA channels.
915     * - DestIncMode:                              DMA_CTR1_DINC bit
916     * - DestDataWidth:                            DMA_CTR1_DDW_LOG2 [17:16] bits
917     * - SrcAllocatedPort:                         DMA_CTR1_SAP bit
918     *   SrcAllocatedPort field is not supported by LPDMA channels.
919     * - SrcByteExchange:                          DMA_CTR1_SBX bit
920     *   SrcByteExchange field is not supported by LPDMA channels.
921     * - DataAlignment:                            DMA_CTR1_PAM [12:11] bits
922     *   DataAlignment field is reduced to one bit for LPDMA channels.
923     * - SrcIncMode:                               DMA_CTR1_SINC bit
924     * - SrcDataWidth:                             DMA_CTR1_SDW_LOG2 [1:0] bits
925     * - SrcBurstLength:                           DMA_CTR1_SBL_1 [9:4] bits
926     *   SrcBurstLength field is not supported by LPDMA channels.
927     * - DestBurstLength:                          DMA_CTR1_DBL_1 [25:20] bits
928     *   DestBurstLength field is not supported by LPDMA channels.
929     */
930 
931     pNode->LinkRegisters[reg_counter] = (DMA_InitNodeStruct->DestIncMode   | \
932                                          DMA_InitNodeStruct->DestDataWidth | \
933                                          DMA_InitNodeStruct->DataAlignment | \
934                                          DMA_InitNodeStruct->SrcIncMode    | \
935                                          DMA_InitNodeStruct->SrcDataWidth);
936 
937 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
938     pNode->LinkRegisters[reg_counter] |= (DMA_InitNodeStruct->DestSecure | \
939                                           DMA_InitNodeStruct->SrcSecure);
940 #endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
941 
942     /* Update CTR1 register fields for not LPDMA channels */
943     if (DMA_InitNodeStruct->NodeType != LL_DMA_LPDMA_LINEAR_NODE)
944     {
945       pNode->LinkRegisters[reg_counter] |= (DMA_InitNodeStruct->DestAllocatedPort                              | \
946                                             DMA_InitNodeStruct->DestHWordExchange                              | \
947                                             DMA_InitNodeStruct->DestByteExchange                               | \
948                                             ((DMA_InitNodeStruct->DestBurstLength - 1U) << DMA_CTR1_DBL_1_Pos) | \
949                                             DMA_InitNodeStruct->SrcAllocatedPort                               | \
950                                             DMA_InitNodeStruct->SrcByteExchange                                | \
951                                             ((DMA_InitNodeStruct->SrcBurstLength - 1U) << DMA_CTR1_SBL_1_Pos));
952     }
953 
954     /* Increment counter for the next register */
955     reg_counter++;
956   }
957 
958 
959   /* Check if CTR2 register update is enabled */
960   if ((DMA_InitNodeStruct->UpdateRegisters & LL_DMA_UPDATE_CTR2) == LL_DMA_UPDATE_CTR2)
961   {
962     /*-------------------------- DMAx CTR2 Configuration -----------------------
963      * Configure the channel transfer parameter :
964      * - TransferEventMode:                        DMA_CTR2_TCEM [31:30] bits
965      * - TriggerPolarity:                          DMA_CTR2_TRIGPOL [25:24] bits
966      * - TriggerMode:                              DMA_CTR2_TRIGM  [15:14] bits
967      * - BlkHWRequest:                             DMA_CTR2_BREQ bit
968      * - Direction:                                DMA_CTR2_DREQ bit
969      * - Direction:                                DMA_CTR2_SWREQ bit
970      *   Direction field is reduced to one bit for LPDMA channels (SWREQ).
971      * - TriggerSelection:                         DMA_CTR2_TRIGSEL [21:16] bits
972      *   DataAlignment field is reduced to 5 bits for LPDMA channels.
973      * - Request:                                  DMA_CTR2_REQSEL [6:0] bits
974      *   DataAlignment field is reduced to 5 bits for LPDMA channels.
975      */
976     pNode->LinkRegisters[reg_counter] = (DMA_InitNodeStruct->TransferEventMode | \
977                                          DMA_InitNodeStruct->TriggerPolarity   | \
978                                          DMA_InitNodeStruct->BlkHWRequest      | \
979                                          DMA_InitNodeStruct->Direction);
980 
981     /* Check direction */
982     if (DMA_InitNodeStruct->Direction != LL_DMA_DIRECTION_MEMORY_TO_MEMORY)
983     {
984       pNode->LinkRegisters[reg_counter] |= DMA_InitNodeStruct->Request & DMA_CTR2_REQSEL;
985     }
986 
987     /* Check trigger polarity */
988     if (DMA_InitNodeStruct->TriggerPolarity != LL_DMA_TRIG_POLARITY_MASKED)
989     {
990       pNode->LinkRegisters[reg_counter] |= (((DMA_InitNodeStruct->TriggerSelection << DMA_CTR2_TRIGSEL_Pos) & \
991                                              DMA_CTR2_TRIGSEL) | DMA_InitNodeStruct->TriggerMode);
992     }
993 
994     /* Update CTR2 register fields for LPDMA */
995     if (DMA_InitNodeStruct->NodeType == LL_DMA_LPDMA_LINEAR_NODE)
996     {
997       pNode->LinkRegisters[reg_counter] &= (~(1UL << 21U) & ~(3UL << 5U));
998     }
999 
1000     /* Increment counter for the next register */
1001     reg_counter++;
1002   }
1003 
1004   /* Check if CBR1 register update is enabled */
1005   if ((DMA_InitNodeStruct->UpdateRegisters & LL_DMA_UPDATE_CBR1) == LL_DMA_UPDATE_CBR1)
1006   {
1007     /*-------------------------- DMAx CBR1 Configuration -----------------------
1008      * Configure the Transfer Block counters and update mode with parameter :
1009      * - BlkDataLength:                                 DMA_CBR1_BNDT[15:0] bits
1010      * - BlkRptCount:                                   DMA_CBR1_BRC[26:16] bits
1011      *   BlkRptCount field is supported only by 2D addressing channels.
1012      * - BlkRptSrcAddrUpdateMode:                              DMA_CBR1_BRSDEC bit
1013      *   BlkRptSrcAddrUpdateMode field is supported only by 2D addressing channels.
1014      * - BlkRptDestAddrUpdateMode:                             DMA_CBR1_BRDDEC bit
1015      *   BlkRptDestAddrUpdateMode field is supported only by 2D addressing channels.
1016      * - SrcAddrUpdateMode:                                    DMA_CBR1_SDEC bit
1017      *   SrcAddrUpdateMode field is supported only by 2D addressing channels.
1018      * - DestAddrUpdateMode:                                   DMA_CBR1_DDEC bit
1019      *   DestAddrUpdateMode field is supported only by 2D addressing channels.
1020      */
1021     pNode->LinkRegisters[reg_counter] = DMA_InitNodeStruct->BlkDataLength;
1022 
1023     /* Update CBR1 register fields for 2D addressing channels */
1024     if (DMA_InitNodeStruct->NodeType == LL_DMA_GPDMA_2D_NODE)
1025     {
1026       pNode->LinkRegisters[reg_counter] |= (DMA_InitNodeStruct->BlkRptDestAddrUpdateMode | \
1027                                             DMA_InitNodeStruct->BlkRptSrcAddrUpdateMode  | \
1028                                             DMA_InitNodeStruct->DestAddrUpdateMode       | \
1029                                             DMA_InitNodeStruct->SrcAddrUpdateMode        | \
1030                                             ((DMA_InitNodeStruct->BlkRptCount << DMA_CBR1_BRC_Pos) & DMA_CBR1_BRC));
1031     }
1032 
1033     /* Increment counter for the next register */
1034     reg_counter++;
1035   }
1036 
1037   /* Check if CSAR register update is enabled */
1038   if ((DMA_InitNodeStruct->UpdateRegisters & LL_DMA_UPDATE_CSAR) == LL_DMA_UPDATE_CSAR)
1039   {
1040     /*-------------------------- DMAx CSAR Configuration -----------------------
1041      * Configure the Transfer Block counters and update mode with parameter :
1042      * - SrcAddress:                                         DMA_CSAR_SA[31:0] bits
1043      */
1044     pNode->LinkRegisters[reg_counter] = DMA_InitNodeStruct->SrcAddress;
1045 
1046     /* Increment counter for the next register */
1047     reg_counter++;
1048   }
1049 
1050 
1051   /* Check if CDAR register update is enabled */
1052   if ((DMA_InitNodeStruct->UpdateRegisters & LL_DMA_UPDATE_CDAR) == LL_DMA_UPDATE_CDAR)
1053   {
1054     /*-------------------------- DMAx CDAR Configuration -----------------------
1055      * Configure the Transfer Block counters and update mode with parameter :
1056      * - DestAddress:                                        DMA_CDAR_DA[31:0] bits
1057      */
1058     pNode->LinkRegisters[reg_counter] = DMA_InitNodeStruct->DestAddress;
1059 
1060     /* Increment counter for the next register */
1061     reg_counter++;
1062   }
1063 
1064 
1065   /* Update CTR3 register fields for 2D addressing channels */
1066   if (DMA_InitNodeStruct->NodeType == LL_DMA_GPDMA_2D_NODE)
1067   {
1068     /* Check if CTR3 register update is enabled */
1069     if ((DMA_InitNodeStruct->UpdateRegisters & LL_DMA_UPDATE_CTR3) == LL_DMA_UPDATE_CTR3)
1070     {
1071       /*-------------------------- DMAx CTR3 Configuration ---------------------
1072       * Configure the Block counters and update mode with parameter :
1073       * - DestAddressOffset:                             DMA_CTR3_DAO[12:0] bits
1074       *   DestAddressOffset field is supported only by 2D addressing channels.
1075       * - SrcAddressOffset:                              DMA_CTR3_SAO[12:0] bits
1076       *   SrcAddressOffset field is supported only by 2D addressing channels.
1077       */
1078       pNode->LinkRegisters[reg_counter] = (DMA_InitNodeStruct->SrcAddrOffset | \
1079                                            ((DMA_InitNodeStruct->DestAddrOffset << DMA_CTR3_DAO_Pos) & DMA_CTR3_DAO));
1080 
1081       /* Increment counter for the next register */
1082       reg_counter++;
1083     }
1084   }
1085 
1086 
1087   /* Update CBR2 register fields for 2D addressing channels */
1088   if (DMA_InitNodeStruct->NodeType == LL_DMA_GPDMA_2D_NODE)
1089   {
1090     /* Check if CBR2 register update is enabled */
1091     if ((DMA_InitNodeStruct->UpdateRegisters & LL_DMA_UPDATE_CBR2) == LL_DMA_UPDATE_CBR2)
1092     {
1093       /*-------------------------- DMAx CBR2 Configuration ---------------------
1094       * Configure the Block counters and update mode with parameter :
1095       * - BlkRptDestAddrOffset:                       DMA_CBR2_BRDAO[31:16] bits
1096       *   BlkRptDestAddrOffset field is supported only by 2D addressing channels.
1097       * - BlkRptSrcAddrOffset:                        DMA_CBR2_BRSAO[15:0] bits
1098       *   BlkRptSrcAddrOffset field is supported only by 2D addressing channels.
1099       */
1100       pNode->LinkRegisters[reg_counter] = (DMA_InitNodeStruct->BlkRptSrcAddrOffset | \
1101                                            ((DMA_InitNodeStruct->BlkRptDestAddrOffset << DMA_CBR2_BRDAO_Pos) & \
1102                                             DMA_CBR2_BRDAO));
1103 
1104       /* Increment counter for the next register */
1105       reg_counter++;
1106     }
1107   }
1108 
1109   /* Check if CLLR register update is enabled */
1110   if ((DMA_InitNodeStruct->UpdateRegisters & LL_DMA_UPDATE_CLLR) == LL_DMA_UPDATE_CLLR)
1111   {
1112     /*-------------------------- DMAx CLLR Configuration -----------------------
1113     * Configure the Transfer Block counters and update mode with parameter :
1114     * - UpdateRegisters                                         DMA_CLLR_UT1 bit
1115     * - UpdateRegisters                                         DMA_CLLR_UT2 bit
1116     * - UpdateRegisters                                         DMA_CLLR_UB1 bit
1117     * - UpdateRegisters                                         DMA_CLLR_USA bit
1118     * - UpdateRegisters                                         DMA_CLLR_UDA bit
1119     * - UpdateRegisters                                         DMA_CLLR_UT3 bit
1120     *   DMA_CLLR_UT3 bit is discarded for linear addressing channels.
1121     * - UpdateRegisters                                         DMA_CLLR_UB2 bit
1122     *   DMA_CLLR_UB2 bit is discarded for linear addressing channels.
1123     * - UpdateRegisters                                         DMA_CLLR_ULL bit
1124     */
1125     pNode->LinkRegisters[reg_counter] = ((DMA_InitNodeStruct->UpdateRegisters & (DMA_CLLR_UT1 | DMA_CLLR_UT2 | \
1126                                                                                  DMA_CLLR_UB1 | DMA_CLLR_USA | \
1127                                                                                  DMA_CLLR_UDA | DMA_CLLR_ULL)));
1128 
1129     /* Update CLLR register fields for 2D addressing channels */
1130     if (DMA_InitNodeStruct->NodeType == LL_DMA_GPDMA_2D_NODE)
1131     {
1132       pNode->LinkRegisters[reg_counter] |= (DMA_InitNodeStruct->UpdateRegisters & (DMA_CLLR_UT3 | DMA_CLLR_UB2));
1133     }
1134   }
1135 
1136   return (uint32_t)SUCCESS;
1137 }
1138 
1139 /**
1140   * @brief  Connect Linked list Nodes.
1141   * @param  pPrevLinkNode Pointer to previous linked list node to be connected to new Linked list node.
1142   * @param  PrevNodeCLLRIdx Offset of Previous Node CLLR register.
1143   *         This parameter can be a value of @ref DMA_LL_EC_CLLR_OFFSET.
1144   * @param  pNewLinkNode Pointer to new Linked list.
1145   * @param  NewNodeCLLRIdx Offset of New Node CLLR register.
1146   *         This parameter can be a value of @ref DMA_LL_EC_CLLR_OFFSET.
1147   * @retval None
1148   */
LL_DMA_ConnectLinkNode(LL_DMA_LinkNodeTypeDef * pPrevLinkNode,uint32_t PrevNodeCLLRIdx,LL_DMA_LinkNodeTypeDef * pNewLinkNode,uint32_t NewNodeCLLRIdx)1149 void LL_DMA_ConnectLinkNode(LL_DMA_LinkNodeTypeDef *pPrevLinkNode, uint32_t PrevNodeCLLRIdx,
1150                             LL_DMA_LinkNodeTypeDef *pNewLinkNode, uint32_t NewNodeCLLRIdx)
1151 {
1152   pPrevLinkNode->LinkRegisters[PrevNodeCLLRIdx] = (((uint32_t)pNewLinkNode & DMA_CLLR_LA)                        | \
1153                                                    (pNewLinkNode->LinkRegisters[NewNodeCLLRIdx] & (DMA_CLLR_UT1  | \
1154                                                        DMA_CLLR_UT2 | DMA_CLLR_UB1 | DMA_CLLR_USA | DMA_CLLR_UDA | \
1155                                                        DMA_CLLR_UT3 | DMA_CLLR_UB2 | DMA_CLLR_ULL)));
1156 }
1157 
1158 /**
1159   * @brief  Disconnect the next linked list node.
1160   * @param  pLinkNode Pointer to linked list node to be disconnected from the next one.
1161   * @param  LinkNodeCLLRIdx Offset of Link Node CLLR register.
1162   * @retval None.
1163   */
LL_DMA_DisconnectNextLinkNode(LL_DMA_LinkNodeTypeDef * pLinkNode,uint32_t LinkNodeCLLRIdx)1164 void LL_DMA_DisconnectNextLinkNode(LL_DMA_LinkNodeTypeDef *pLinkNode, uint32_t LinkNodeCLLRIdx)
1165 {
1166   pLinkNode->LinkRegisters[LinkNodeCLLRIdx] = 0;
1167 }
1168 
1169 /**
1170   * @}
1171   */
1172 
1173 /**
1174   * @}
1175   */
1176 
1177 /**
1178   * @}
1179   */
1180 
1181 #endif /* (defined (GPDMA1) || defined (LPDMA1)) */
1182 
1183 /**
1184   * @}
1185   */
1186 
1187 #endif /* defined (USE_FULL_LL_DRIVER) */
1188 
1189