1 /* USER CODE BEGIN Header */
2 /**
3 ******************************************************************************
4 * @file : main.c
5 * @brief : Main program body
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2023 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 */
18 /* USER CODE END Header */
19 /* Includes ------------------------------------------------------------------*/
20 #include "main.h"
21
22 /* Private includes ----------------------------------------------------------*/
23 /* USER CODE BEGIN Includes */
24
25 /* USER CODE END Includes */
26
27 /* Private typedef -----------------------------------------------------------*/
28 /* USER CODE BEGIN PTD */
29
30 /* USER CODE END PTD */
31
32 /* Private define ------------------------------------------------------------*/
33 /* USER CODE BEGIN PD */
34
35 /* USER CODE END PD */
36
37 /* Private macro -------------------------------------------------------------*/
38 /* USER CODE BEGIN PM */
39
40 /* USER CODE END PM */
41
42 /* Private variables ---------------------------------------------------------*/
43
44 UART_HandleTypeDef huart1;
45
46 /* USER CODE BEGIN PV */
47
48 /* USER CODE END PV */
49
50 /* Private function prototypes -----------------------------------------------*/
51 void SystemClock_Config(void);
52 static void SystemPower_Config(void);
53 static void MX_GPIO_Init(void);
54 static void MX_USART1_UART_Init(void);
55 /* USER CODE BEGIN PFP */
56
57 /* USER CODE END PFP */
58
59 /* Private user code ---------------------------------------------------------*/
60 /* USER CODE BEGIN 0 */
61
62 /* USER CODE END 0 */
63
64 /**
65 * @brief The application entry point.
66 * @retval int
67 */
main(void)68 int main(void)
69 {
70 /* USER CODE BEGIN 1 */
71
72 /* USER CODE END 1 */
73
74 /* MCU Configuration--------------------------------------------------------*/
75
76 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
77 HAL_Init();
78
79 /* USER CODE BEGIN Init */
80
81 /* USER CODE END Init */
82
83 /* Configure the system clock */
84 SystemClock_Config();
85
86 /* Configure the System Power */
87 SystemPower_Config();
88
89 /* USER CODE BEGIN SysInit */
90
91 /* USER CODE END SysInit */
92
93 /* Initialize all configured peripherals */
94 MX_GPIO_Init();
95 MX_USART1_UART_Init();
96 /* USER CODE BEGIN 2 */
97
98 /* USER CODE END 2 */
99
100 /* Infinite loop */
101 /* USER CODE BEGIN WHILE */
102 while (1)
103 {
104 /* USER CODE END WHILE */
105
106 /* USER CODE BEGIN 3 */
107 }
108 /* USER CODE END 3 */
109 }
110
111 /**
112 * @brief System Clock Configuration
113 * @retval None
114 */
SystemClock_Config(void)115 void SystemClock_Config(void)
116 {
117 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
118 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
119
120 /** Configure the main internal regulator output voltage
121 */
122 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
123 {
124 Error_Handler();
125 }
126
127 /** Initializes the CPU, AHB and APB buses clocks
128 */
129 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
130 RCC_OscInitStruct.MSIState = RCC_MSI_ON;
131 RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
132 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_4;
133 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
134 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
135 RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;
136 RCC_OscInitStruct.PLL.PLLM = 1;
137 RCC_OscInitStruct.PLL.PLLN = 80;
138 RCC_OscInitStruct.PLL.PLLP = 2;
139 RCC_OscInitStruct.PLL.PLLQ = 2;
140 RCC_OscInitStruct.PLL.PLLR = 2;
141 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_0;
142 RCC_OscInitStruct.PLL.PLLFRACN = 0;
143 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
144 {
145 Error_Handler();
146 }
147
148 /** Initializes the CPU, AHB and APB buses clocks
149 */
150 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
151 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
152 |RCC_CLOCKTYPE_PCLK3;
153 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
154 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
155 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
156 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
157 RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
158
159 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
160 {
161 Error_Handler();
162 }
163 }
164
165 /**
166 * @brief Power Configuration
167 * @retval None
168 */
SystemPower_Config(void)169 static void SystemPower_Config(void)
170 {
171
172 /*
173 * Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
174 */
175 HAL_PWREx_DisableUCPDDeadBattery();
176 /* USER CODE BEGIN PWR */
177 /* USER CODE END PWR */
178 }
179
180 /**
181 * @brief USART1 Initialization Function
182 * @param None
183 * @retval None
184 */
MX_USART1_UART_Init(void)185 static void MX_USART1_UART_Init(void)
186 {
187
188 /* USER CODE BEGIN USART1_Init 0 */
189
190 /* USER CODE END USART1_Init 0 */
191
192 /* USER CODE BEGIN USART1_Init 1 */
193
194 /* USER CODE END USART1_Init 1 */
195 huart1.Instance = USART1;
196 huart1.Init.BaudRate = 115200;
197 huart1.Init.WordLength = UART_WORDLENGTH_8B;
198 huart1.Init.StopBits = UART_STOPBITS_1;
199 huart1.Init.Parity = UART_PARITY_NONE;
200 huart1.Init.Mode = UART_MODE_TX_RX;
201 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
202 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
203 huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
204 huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
205 huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
206 if (HAL_UART_Init(&huart1) != HAL_OK)
207 {
208 Error_Handler();
209 }
210 if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
211 {
212 Error_Handler();
213 }
214 if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
215 {
216 Error_Handler();
217 }
218 if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
219 {
220 Error_Handler();
221 }
222 /* USER CODE BEGIN USART1_Init 2 */
223
224 /* USER CODE END USART1_Init 2 */
225
226 }
227
228 /**
229 * @brief GPIO Initialization Function
230 * @param None
231 * @retval None
232 */
MX_GPIO_Init(void)233 static void MX_GPIO_Init(void)
234 {
235 /* USER CODE BEGIN MX_GPIO_Init_1 */
236 /* USER CODE END MX_GPIO_Init_1 */
237
238 /* GPIO Ports Clock Enable */
239 __HAL_RCC_GPIOA_CLK_ENABLE();
240
241 /* USER CODE BEGIN MX_GPIO_Init_2 */
242 /* USER CODE END MX_GPIO_Init_2 */
243 }
244
245 /* USER CODE BEGIN 4 */
246
247 /* USER CODE END 4 */
248
249 /**
250 * @brief This function is executed in case of error occurrence.
251 * @retval None
252 */
Error_Handler(void)253 void Error_Handler(void)
254 {
255 /* USER CODE BEGIN Error_Handler_Debug */
256 /* User can add his own implementation to report the HAL error return state */
257 __disable_irq();
258 while (1)
259 {
260 }
261 /* USER CODE END Error_Handler_Debug */
262 }
263
264 #ifdef USE_FULL_ASSERT
265 /**
266 * @brief Reports the name of the source file and the source line number
267 * where the assert_param error has occurred.
268 * @param file: pointer to the source file name
269 * @param line: assert_param error line source number
270 * @retval None
271 */
assert_failed(uint8_t * file,uint32_t line)272 void assert_failed(uint8_t *file, uint32_t line)
273 {
274 /* USER CODE BEGIN 6 */
275 /* User can add his own implementation to report the file name and line number,
276 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
277 /* USER CODE END 6 */
278 }
279 #endif /* USE_FULL_ASSERT */
280