1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
62
63
64
68
69
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
103
104
105
106
107
108
109
110
111
112
113
114
119
120
121
122
123
124
125
126
127
128
129
132
133
134
135
136
137
138
139
140
141
142
143
144
145
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
169
170
171
176
177
178
186
187
/* ... */
#include <string.h>
#include <stdio.h>
#include "main.h"
#include "cmsis_os.h"
#if (configAPPLICATION_ALLOCATED_HEAP == 1)
uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
#endif
static void SystemClock_Config(void);
static void RNG_Init(void);
static void MainThread(void const * argument);
RNG_HandleTypeDef RngHandle;
int main()
{
#ifdef USE_LCD
uint8_t sdram_status = SDRAM_OK;
#endif
HAL_Init();
SystemClock_Config();
BSP_LED_Init(LED1);
BSP_LED_Init(LED3);
RNG_Init();
#ifdef USE_LCD
sdram_status = BSP_SDRAM_Init();
if(sdram_status != SDRAM_OK)
{
Error_Handler();
}if (sdram_status != SDRAM_OK) { ... }
/* ... */
/* ... */
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS);
BSP_LCD_SelectLayer(1);
LCD_LOG_Init();
LCD_LOG_SetHeader((uint8_t *)("SSL Server Application"));
/* ... */
#endif
osThreadDef(Start, MainThread, osPriorityAboveNormal, 0, configMINIMAL_STACK_SIZE * 2);
osThreadCreate (osThread(Start), NULL);
osKernelStart();
Error_Handler();
}{ ... }
/* ... */
static void MainThread(void const * argument)
{
UNUSED(argument);
#ifdef USE_LCD
LCD_UsrLog("\r\n Starting Main Thread...\n");
#endif
osThreadDef(Server, SSL_Server, osPriorityHigh, 0, configMINIMAL_STACK_SIZE * 20);
osThreadCreate(osThread(Server), NULL);
for( ;; )
{
osThreadTerminate(NULL);
}for (;;) { ... }
}{ ... }
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
__HAL_RCC_PWR_CLK_ENABLE();
/* ... */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
/* ... */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
}{ ... }
static void RNG_Init(void)
{
RngHandle.Instance = RNG;
if (HAL_RNG_DeInit(&RngHandle) != HAL_OK)
{
Error_Handler();
}if (HAL_RNG_DeInit(&RngHandle) != HAL_OK) { ... }
if (HAL_RNG_Init(&RngHandle) != HAL_OK)
{
Error_Handler();
}if (HAL_RNG_Init(&RngHandle) != HAL_OK) { ... }
}{ ... }
void Error_Handler(void)
{
while (1)
{
BSP_LED_Toggle(LED3);
osDelay(100);
}while (1) { ... }
}{ ... }
void Success_Handler(void)
{
while (1)
{
BSP_LED_Toggle(LED1);
osDelay(200);
}while (1) { ... }
}{ ... }