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