1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
33
34
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
61
62
63
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
150
151
152
153
154
155
156
157
158
165
180
181
186
187
188
189
190
191
192
193
194
195
200
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
255
256
257
258
259
260
261
262
265
266
267
268
269
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
293
294
295
296
297
302
303
304
305
306
307
313
318
319
320
339
340
343
344
/* ... */
#include "main.h"
/* ... */
/* ... */
Includes
#define BUFFER_SIZE 32
Private define
static const uint32_t aSRC_Const_Buffer[BUFFER_SIZE] =
{
0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20,
0x21222324, 0x25262728, 0x292A2B2C, 0x2D2E2F30,
0x31323334, 0x35363738, 0x393A3B3C, 0x3D3E3F40,
0x41424344, 0x45464748, 0x494A4B4C, 0x4D4E4F50,
0x51525354, 0x55565758, 0x595A5B5C, 0x5D5E5F60,
0x61626364, 0x65666768, 0x696A6B6C, 0x6D6E6F70,
0x71727374, 0x75767778, 0x797A7B7C, 0x7D7E7F80
...};
static uint32_t aDST_Buffer[BUFFER_SIZE];
Private variables
void SystemClock_Config(void);
void Configure_DMA(void);
uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint32_t BufferLength);
void LED_Init(void);
void LED_On(void);
void LED_Blinking(uint32_t Period);
Private function prototypes
/* ... */
int main(void)
{
SystemClock_Config();
LED_Init();
Configure_DMA();
LL_DMA_EnableStream(DMA2, LL_DMA_STREAM_0);
while (1)
{
}while (1) { ... }
}{ ... }
/* ... */
void Configure_DMA(void)
{
LL_DMA_InitTypeDef dma_initstruct;
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA2);
if (LL_DMA_DeInit(DMA2, LL_DMA_STREAM_0) != SUCCESS)
{
LED_Blinking(LED_BLINK_ERROR);
}if (LL_DMA_DeInit(DMA2, LL_DMA_STREAM_0) != SUCCESS) { ... }
/* ... */
dma_initstruct.PeriphOrM2MSrcAddress = (uint32_t)&aSRC_Const_Buffer;
dma_initstruct.MemoryOrM2MDstAddress = (uint32_t)&aDST_Buffer;
dma_initstruct.Direction = LL_DMA_DIRECTION_MEMORY_TO_MEMORY;
dma_initstruct.Mode = LL_DMA_MODE_NORMAL;
dma_initstruct.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_INCREMENT;
dma_initstruct.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT;
dma_initstruct.PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_WORD;
dma_initstruct.MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_WORD;
dma_initstruct.NbData = BUFFER_SIZE;
dma_initstruct.Priority = LL_DMA_PRIORITY_HIGH;
dma_initstruct.FIFOMode = LL_DMA_FIFOMODE_DISABLE;
dma_initstruct.Channel = LL_DMA_CHANNEL_0;
if (LL_DMA_Init(DMA2, LL_DMA_STREAM_0, &dma_initstruct) != SUCCESS)
{
LED_Blinking(LED_BLINK_ERROR);
}if (LL_DMA_Init(DMA2, LL_DMA_STREAM_0, &dma_initstruct) != SUCCESS) { ... }
LL_DMA_EnableIT_TC(DMA2, LL_DMA_STREAM_0);
LL_DMA_EnableIT_TE(DMA2, LL_DMA_STREAM_0);
NVIC_SetPriority(DMA2_Stream0_IRQn, 0);
NVIC_EnableIRQ(DMA2_Stream0_IRQn);
}{ ... }
/* ... */
uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint32_t BufferLength)
{
while (BufferLength--)
{
if (*pBuffer1 != *pBuffer2)
{
return 1;
}if (*pBuffer1 != *pBuffer2) { ... }
pBuffer1++;
pBuffer2++;
}while (BufferLength--) { ... }
return 0;
}{ ... }
/* ... */
void LED_Init(void)
{
LED2_GPIO_CLK_ENABLE();
LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT);
}{ ... }
/* ... */
void LED_On(void)
{
LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN);
}{ ... }
/* ... */
void LED_Blinking(uint32_t Period)
{
LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN);
while (1)
{
LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);
LL_mDelay(Period);
}while (1) { ... }
}{ ... }
/* ... */
void SystemClock_Config(void)
{
LL_RCC_HSE_EnableBypass();
LL_RCC_HSE_Enable();
while(LL_RCC_HSE_IsReady() != 1)
{
}while (LL_RCC_HSE_IsReady() != 1) { ... };
LL_FLASH_SetLatency(LL_FLASH_LATENCY_3);
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_8, 400, LL_RCC_PLLP_DIV_4);
LL_RCC_PLL_Enable();
while(LL_RCC_PLL_IsReady() != 1)
{
}while (LL_RCC_PLL_IsReady() != 1) { ... };
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
{
}while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { ... };
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
SysTick_Config(100000000 / 1000);
SystemCoreClock = 100000000;
}{ ... }
/* ... */
void TransferComplete()
{
if (Buffercmp((uint32_t*)aSRC_Const_Buffer, (uint32_t*)aDST_Buffer, BUFFER_SIZE) == 1)
{
LED_Blinking(LED_BLINK_ERROR);
}if (Buffercmp((uint32_t*)aSRC_Const_Buffer, (uint32_t*)aDST_Buffer, BUFFER_SIZE) == 1) { ... }
LED_On();
}{ ... }
/* ... */
void TransferError()
{
LED_Blinking(LED_BLINK_ERROR);
}{ ... }
#ifdef USE_FULL_ASSERT
/* ... */
void assert_failed(uint8_t *file, uint32_t line)
{
/* ... */
while (1)
{
}while (1) { ... }
}assert_failed (uint8_t *file, uint32_t line) { ... }
/* ... */#endif
/* ... */
/* ... */