1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
32
33
34
37
38
39
40
41
42
43
44
49
50
51
52
53
54
63
64
65
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
91
92
93
99
104
105
110
111
112
113
114
115
116
121
122
123
124
125
126
127
132
146
147
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
172
177
178
179
180
181
182
183
184
185
186
187
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
224
225
226
227
228
229
230
231
234
235
236
237
238
241
242
243
244
245
246
247
248
249
250
251
252
253
254
273
274
277
278
/* ... */
#include "main.h"
/* ... */
/* ... */
Includes
#define BUFFER_SIZE 36
Private define
__IO uint32_t uwCRCValue = 0;
static const uint8_t aDataBuffer[BUFFER_SIZE] =
{
0x21, 0x10, 0x00, 0x00, 0x63, 0x30, 0x42, 0x20, 0xa5, 0x50, 0x84, 0x40,
0xe7, 0x70, 0xc6, 0x60, 0x4a, 0xa1, 0x29, 0x91, 0x8c, 0xc1, 0x6b, 0xb1,
0xce, 0xe1, 0xad, 0xd1, 0x31, 0x12, 0xef, 0xf1, 0x52, 0x22, 0x73, 0x32,
...};
uint32_t uwExpectedCRCValue = 0xFF813A5C;
Private variables
void SystemClock_Config(void);
void Configure_CRC(void);
uint32_t Calculate_CRC(uint32_t);
void CheckCRCResultValue(void);
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_CRC();
uwCRCValue = Calculate_CRC(BUFFER_SIZE);
CheckCRCResultValue();
while (1)
{
}while (1) { ... }
}{ ... }
/* ... */
void Configure_CRC(void)
{
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_CRC);
}{ ... }
/* ... */
uint32_t Calculate_CRC(uint32_t BufferSize)
{
register uint32_t data = 0;
register uint32_t index = 0;
for (index = 0; index < (BufferSize / 4); index++)
{
data = (uint32_t)((aDataBuffer[4 * index + 3] << 24) | (aDataBuffer[4 * index + 2] << 16) | (aDataBuffer[4 * index + 1] << 8) | aDataBuffer[4 * index]);
LL_CRC_FeedData32(CRC, data);
}for (index = 0; index < (BufferSize / 4); index++) { ... }
return(LL_CRC_ReadData32(CRC));
}{ ... }
/* ... */
void CheckCRCResultValue(void)
{
if (uwCRCValue != uwExpectedCRCValue)
{
LED_Blinking(LED_BLINK_ERROR);
}if (uwCRCValue != uwExpectedCRCValue) { ... }
else
{
LED_On();
}else { ... }
}{ ... }
/* ... */
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)
{
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;
}{ ... }
#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
/* ... */
/* ... */