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 /* USER CODE END PD */
35 
36 /* Private macro -------------------------------------------------------------*/
37 /* USER CODE BEGIN PM */
38 
39 /* USER CODE END PM */
40 
41 /* Private variables ---------------------------------------------------------*/
42 
43 UART_HandleTypeDef huart6;
44 
45 /* USER CODE BEGIN PV */
46 
47 /* USER CODE END PV */
48 
49 /* Private function prototypes -----------------------------------------------*/
50 void SystemClock_Config(void);
51 static void MPU_Config(void);
52 static void MX_GPIO_Init(void);
53 static void MX_USART6_UART_Init(void);
54 /* USER CODE BEGIN PFP */
55 
56 /* USER CODE END PFP */
57 
58 /* Private user code ---------------------------------------------------------*/
59 /* USER CODE BEGIN 0 */
60 
61 /* USER CODE END 0 */
62 
63 /**
64   * @brief  The application entry point.
65   * @retval int
66   */
main(void)67 int main(void)
68 {
69   /* USER CODE BEGIN 1 */
70 
71   /* USER CODE END 1 */
72 
73   /* MPU Configuration--------------------------------------------------------*/
74   MPU_Config();
75 
76   /* MCU Configuration--------------------------------------------------------*/
77 
78   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
79   HAL_Init();
80 
81   /* USER CODE BEGIN Init */
82 
83   /* USER CODE END Init */
84 
85   /* Configure the system clock */
86   SystemClock_Config();
87 
88   /* USER CODE BEGIN SysInit */
89 
90   /* USER CODE END SysInit */
91 
92   /* Initialize all configured peripherals */
93   MX_GPIO_Init();
94   MX_USART6_UART_Init();
95   /* USER CODE BEGIN 2 */
96 
97   /* USER CODE END 2 */
98 
99   /* Infinite loop */
100   /* USER CODE BEGIN WHILE */
101   while (1)
102   {
103     /* USER CODE END WHILE */
104 
105     /* USER CODE BEGIN 3 */
106   }
107   /* USER CODE END 3 */
108 }
109 
110 /**
111   * @brief System Clock Configuration
112   * @retval None
113   */
SystemClock_Config(void)114 void SystemClock_Config(void)
115 {
116   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
117   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
118 
119   /** Configure the main internal regulator output voltage
120   */
121   __HAL_RCC_PWR_CLK_ENABLE();
122   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
123 
124   /** Initializes the RCC Oscillators according to the specified parameters
125   * in the RCC_OscInitTypeDef structure.
126   */
127   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
128   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
129   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
130   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
131   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
132   RCC_OscInitStruct.PLL.PLLM = 8;
133   RCC_OscInitStruct.PLL.PLLN = 216;
134   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
135   RCC_OscInitStruct.PLL.PLLQ = 2;
136   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
137   {
138     Error_Handler();
139   }
140 
141   /** Activate the Over-Drive mode
142   */
143   if (HAL_PWREx_EnableOverDrive() != 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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
153   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
154   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
155   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
156 
157   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
158   {
159     Error_Handler();
160   }
161 }
162 
163 /**
164   * @brief USART6 Initialization Function
165   * @param None
166   * @retval None
167   */
MX_USART6_UART_Init(void)168 static void MX_USART6_UART_Init(void)
169 {
170 
171   /* USER CODE BEGIN USART6_Init 0 */
172 
173   /* USER CODE END USART6_Init 0 */
174 
175   /* USER CODE BEGIN USART6_Init 1 */
176 
177   /* USER CODE END USART6_Init 1 */
178   huart6.Instance = USART6;
179   huart6.Init.BaudRate = 115200;
180   huart6.Init.WordLength = UART_WORDLENGTH_8B;
181   huart6.Init.StopBits = UART_STOPBITS_1;
182   huart6.Init.Parity = UART_PARITY_NONE;
183   huart6.Init.Mode = UART_MODE_TX_RX;
184   huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
185   huart6.Init.OverSampling = UART_OVERSAMPLING_16;
186   huart6.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
187   huart6.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
188   if (HAL_UART_Init(&huart6) != HAL_OK)
189   {
190     Error_Handler();
191   }
192   /* USER CODE BEGIN USART6_Init 2 */
193 
194   /* USER CODE END USART6_Init 2 */
195 
196 }
197 
198 /**
199   * @brief GPIO Initialization Function
200   * @param None
201   * @retval None
202   */
MX_GPIO_Init(void)203 static void MX_GPIO_Init(void)
204 {
205 
206   /* GPIO Ports Clock Enable */
207   __HAL_RCC_GPIOA_CLK_ENABLE();
208   __HAL_RCC_GPIOC_CLK_ENABLE();
209 
210 }
211 
212 /* USER CODE BEGIN 4 */
213 
214 /* USER CODE END 4 */
215 
216 /* MPU Configuration */
217 
MPU_Config(void)218 void MPU_Config(void)
219 {
220   MPU_Region_InitTypeDef MPU_InitStruct = {0};
221 
222   /* Disables the MPU */
223   HAL_MPU_Disable();
224 
225   /** Initializes and configures the Region and the memory to be protected
226   */
227   MPU_InitStruct.Enable = MPU_REGION_ENABLE;
228   MPU_InitStruct.Number = MPU_REGION_NUMBER0;
229   MPU_InitStruct.BaseAddress = 0x0;
230   MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
231   MPU_InitStruct.SubRegionDisable = 0x87;
232   MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
233   MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
234   MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
235   MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
236   MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
237   MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
238 
239   HAL_MPU_ConfigRegion(&MPU_InitStruct);
240   /* Enables the MPU */
241   HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
242 
243 }
244 
245 /**
246   * @brief  This function is executed in case of error occurrence.
247   * @retval None
248   */
Error_Handler(void)249 void Error_Handler(void)
250 {
251   /* USER CODE BEGIN Error_Handler_Debug */
252   /* User can add his own implementation to report the HAL error return state */
253   __disable_irq();
254   while (1)
255   {
256   }
257   /* USER CODE END Error_Handler_Debug */
258 }
259 
260 #ifdef  USE_FULL_ASSERT
261 /**
262   * @brief  Reports the name of the source file and the source line number
263   *         where the assert_param error has occurred.
264   * @param  file: pointer to the source file name
265   * @param  line: assert_param error line source number
266   * @retval None
267   */
assert_failed(uint8_t * file,uint32_t line)268 void assert_failed(uint8_t *file, uint32_t line)
269 {
270   /* USER CODE BEGIN 6 */
271   /* User can add his own implementation to report the file name and line number,
272      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
273   /* USER CODE END 6 */
274 }
275 #endif /* USE_FULL_ASSERT */
276