sidestep
[mTask.git] / int / nucleo-f767-blinky / cube / nucleo-f767-blinky / Src / main.c
1 /**
2 ******************************************************************************
3 * File Name : main.c
4 * Description : Main program body
5 ******************************************************************************
6 *
7 * COPYRIGHT(c) 2016 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 "stm32f7xx_hal.h"
35 #include "dma.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_DMA_Init();
81 MX_USART3_UART_Init();
82
83 /* USER CODE BEGIN 2 */
84
85 /* USER CODE END 2 */
86
87 /* Infinite loop */
88 /* USER CODE BEGIN WHILE */
89 while (1)
90 {
91 /* USER CODE END WHILE */
92
93 /* USER CODE BEGIN 3 */
94
95 }
96 /* USER CODE END 3 */
97
98 }
99
100 /** System Clock Configuration
101 */
102 void SystemClock_Config(void)
103 {
104
105 RCC_OscInitTypeDef RCC_OscInitStruct;
106 RCC_ClkInitTypeDef RCC_ClkInitStruct;
107 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
108
109 __HAL_RCC_PWR_CLK_ENABLE();
110
111 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
112
113 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
114 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
115 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
116 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
117 RCC_OscInitStruct.PLL.PLLM = 4;
118 RCC_OscInitStruct.PLL.PLLN = 200;
119 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
120 RCC_OscInitStruct.PLL.PLLQ = 2;
121 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
122 {
123 Error_Handler();
124 }
125
126 if (HAL_PWREx_EnableOverDrive() != HAL_OK)
127 {
128 Error_Handler();
129 }
130
131 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
132 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
133 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
134 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
135 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
136 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
137 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) != HAL_OK)
138 {
139 Error_Handler();
140 }
141
142 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3;
143 PeriphClkInitStruct.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
144 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
145 {
146 Error_Handler();
147 }
148
149 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
150
151 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
152
153 /* SysTick_IRQn interrupt configuration */
154 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
155 }
156
157 /* USER CODE BEGIN 4 */
158
159 /* USER CODE END 4 */
160
161 /**
162 * @brief This function is executed in case of error occurrence.
163 * @param None
164 * @retval None
165 */
166 void Error_Handler(void)
167 {
168 /* USER CODE BEGIN Error_Handler */
169 /* User can add his own implementation to report the HAL error return state */
170 while(1)
171 {
172 }
173 /* USER CODE END Error_Handler */
174 }
175
176 #ifdef USE_FULL_ASSERT
177
178 /**
179 * @brief Reports the name of the source file and the source line number
180 * where the assert_param error has occurred.
181 * @param file: pointer to the source file name
182 * @param line: assert_param error line source number
183 * @retval None
184 */
185 void assert_failed(uint8_t* file, uint32_t line)
186 {
187 /* USER CODE BEGIN 6 */
188 /* User can add his own implementation to report the file name and line number,
189 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
190 /* USER CODE END 6 */
191
192 }
193
194 #endif
195
196 /**
197 * @}
198 */
199
200 /**
201 * @}
202 */
203
204 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/