0
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * File Name : main.c
|
|
4 * Description : Main program body
|
|
5 ******************************************************************************
|
|
6 *
|
|
7 * COPYRIGHT(c) 2017 STMicroelectronics
|
|
8 *
|
|
9 * Redistribution and use in source and binary forms, with or without modification,
|
|
10 * are permitted provided that the following conditions are met:
|
|
11 * 1. Redistributions of source code must retain the above copyright notice,
|
|
12 * this list of conditions and the following disclaimer.
|
|
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14 * this list of conditions and the following disclaimer in the documentation
|
|
15 * and/or other materials provided with the distribution.
|
|
16 * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
17 * may be used to endorse or promote products derived from this software
|
|
18 * without specific prior written permission.
|
|
19 *
|
|
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30 *
|
|
31 ******************************************************************************
|
|
32 */
|
|
33 /* Includes ------------------------------------------------------------------*/
|
|
34 #include "main.h"
|
|
35 #include "stm32l4xx_hal.h"
|
|
36 #include "usart.h"
|
|
37 #include "gpio.h"
|
|
38
|
|
39 /* USER CODE BEGIN Includes */
|
|
40
|
|
41 /* USER CODE END Includes */
|
|
42
|
|
43 /* Private variables ---------------------------------------------------------*/
|
|
44
|
|
45 /* USER CODE BEGIN PV */
|
|
46 /* Private variables ---------------------------------------------------------*/
|
|
47
|
|
48 /* USER CODE END PV */
|
|
49
|
|
50 /* Private function prototypes -----------------------------------------------*/
|
|
51 void SystemClock_Config(void);
|
|
52 void Error_Handler(void);
|
|
53
|
|
54 /* USER CODE BEGIN PFP */
|
|
55 /* Private function prototypes -----------------------------------------------*/
|
|
56
|
|
57 /* USER CODE END PFP */
|
|
58
|
|
59 /* USER CODE BEGIN 0 */
|
|
60
|
|
61 /* USER CODE END 0 */
|
|
62
|
|
63 int main(void)
|
|
64 {
|
|
65
|
|
66 /* USER CODE BEGIN 1 */
|
|
67
|
|
68 /* USER CODE END 1 */
|
|
69
|
|
70 /* MCU Configuration----------------------------------------------------------*/
|
|
71
|
|
72 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
73 HAL_Init();
|
|
74
|
|
75 /* Configure the system clock */
|
|
76 SystemClock_Config();
|
|
77
|
|
78 /* Initialize all configured peripherals */
|
|
79 MX_GPIO_Init();
|
|
80 MX_USART2_UART_Init();
|
|
81
|
|
82 /* USER CODE BEGIN 2 */
|
|
83
|
|
84 /* USER CODE END 2 */
|
|
85
|
|
86 /* Infinite loop */
|
|
87 /* USER CODE BEGIN WHILE */
|
|
88 while (1)
|
|
89 {
|
|
90 /* USER CODE END WHILE */
|
|
91
|
|
92 /* USER CODE BEGIN 3 */
|
|
93
|
|
94 }
|
|
95 /* USER CODE END 3 */
|
|
96
|
|
97 }
|
|
98
|
|
99 /** System Clock Configuration
|
|
100 */
|
|
101 void SystemClock_Config(void)
|
|
102 {
|
|
103
|
|
104 RCC_OscInitTypeDef RCC_OscInitStruct;
|
|
105 RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
|
106 RCC_PeriphCLKInitTypeDef PeriphClkInit;
|
|
107
|
|
108 /**Initializes the CPU, AHB and APB busses clocks
|
|
109 */
|
|
110 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
|
111 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
|
112 RCC_OscInitStruct.HSICalibrationValue = 16;
|
|
113 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
114 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
|
115 RCC_OscInitStruct.PLL.PLLM = 1;
|
|
116 RCC_OscInitStruct.PLL.PLLN = 10;
|
|
117 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
|
|
118 RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
|
|
119 RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
|
120 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
121 {
|
|
122 Error_Handler();
|
|
123 }
|
|
124
|
|
125 /**Initializes the CPU, AHB and APB busses clocks
|
|
126 */
|
|
127 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
128 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
129 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
130 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
131 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
|
132 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
133
|
|
134 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
|
135 {
|
|
136 Error_Handler();
|
|
137 }
|
|
138
|
|
139 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
|
|
140 PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
|
|
141 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
142 {
|
|
143 Error_Handler();
|
|
144 }
|
|
145
|
|
146 /**Configure the main internal regulator output voltage
|
|
147 */
|
|
148 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
|
|
149 {
|
|
150 Error_Handler();
|
|
151 }
|
|
152
|
|
153 /**Configure the Systick interrupt time
|
|
154 */
|
|
155 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
|
|
156
|
|
157 /**Configure the Systick
|
|
158 */
|
|
159 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
|
160
|
|
161 /* SysTick_IRQn interrupt configuration */
|
|
162 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
|
163 }
|
|
164
|
|
165 /* USER CODE BEGIN 4 */
|
|
166
|
|
167 /* USER CODE END 4 */
|
|
168
|
|
169 /**
|
|
170 * @brief Period elapsed callback in non blocking mode
|
|
171 * @note This function is called when TIM6 interrupt took place, inside
|
|
172 * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
173 * a global variable "uwTick" used as application time base.
|
|
174 * @param htim : TIM handle
|
|
175 * @retval None
|
|
176 */
|
|
177 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
178 {
|
|
179 /* USER CODE BEGIN Callback 0 */
|
|
180
|
|
181 /* USER CODE END Callback 0 */
|
|
182 if (htim->Instance == TIM6) {
|
|
183 HAL_IncTick();
|
|
184 }
|
|
185 /* USER CODE BEGIN Callback 1 */
|
|
186
|
|
187 /* USER CODE END Callback 1 */
|
|
188 }
|
|
189
|
|
190 /**
|
|
191 * @brief This function is executed in case of error occurrence.
|
|
192 * @param None
|
|
193 * @retval None
|
|
194 */
|
|
195 void Error_Handler(void)
|
|
196 {
|
|
197 /* USER CODE BEGIN Error_Handler */
|
|
198 /* User can add his own implementation to report the HAL error return state */
|
|
199 while(1)
|
|
200 {
|
|
201 }
|
|
202 /* USER CODE END Error_Handler */
|
|
203 }
|
|
204
|
|
205 #ifdef USE_FULL_ASSERT
|
|
206
|
|
207 /**
|
|
208 * @brief Reports the name of the source file and the source line number
|
|
209 * where the assert_param error has occurred.
|
|
210 * @param file: pointer to the source file name
|
|
211 * @param line: assert_param error line source number
|
|
212 * @retval None
|
|
213 */
|
|
214 void assert_failed(uint8_t* file, uint32_t line)
|
|
215 {
|
|
216 /* USER CODE BEGIN 6 */
|
|
217 /* User can add his own implementation to report the file name and line number,
|
|
218 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
219 /* USER CODE END 6 */
|
|
220
|
|
221 }
|
|
222
|
|
223 #endif
|
|
224
|
|
225 /**
|
|
226 * @}
|
|
227 */
|
|
228
|
|
229 /**
|
|
230 * @}
|
|
231 */
|
|
232
|
|
233 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|