xref: /btstack/port/stm32-f4discovery-cc256x/Src/main.c (revision ced70f9bfeafe291ec597a3a9cc862e39e0da3ce)
1 /* USER CODE BEGIN Header */
2 /**
3   ******************************************************************************
4   * @file           : main.c
5   * @brief          : Main program body
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10   * All rights reserved.</center></h2>
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 /* USER CODE END Header */
20 
21 /* Includes ------------------------------------------------------------------*/
22 #include "main.h"
23 #include "dma.h"
24 #include "usart.h"
25 #include "gpio.h"
26 
27 /* Private includes ----------------------------------------------------------*/
28 /* USER CODE BEGIN Includes */
29 #include "port.h"
30 /* USER CODE END Includes */
31 
32 /* Private typedef -----------------------------------------------------------*/
33 /* USER CODE BEGIN PTD */
34 
35 /* USER CODE END PTD */
36 
37 /* Private define ------------------------------------------------------------*/
38 /* USER CODE BEGIN PD */
39 
40 /* USER CODE END PD */
41 
42 /* Private macro -------------------------------------------------------------*/
43 /* USER CODE BEGIN PM */
44 
45 /* USER CODE END PM */
46 
47 /* Private variables ---------------------------------------------------------*/
48 
49 /* USER CODE BEGIN PV */
50 
51 /* USER CODE END PV */
52 
53 /* Private function prototypes -----------------------------------------------*/
54 void SystemClock_Config(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   */
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   /* USER CODE BEGIN SysInit */
87 
88   /* USER CODE END SysInit */
89 
90   /* Initialize all configured peripherals */
91   MX_GPIO_Init();
92   MX_DMA_Init();
93   MX_USART2_UART_Init();
94   MX_USART3_UART_Init();
95   /* USER CODE BEGIN 2 */
96   // jump to BTstack port
97   port_main();
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   */
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   __HAL_RCC_PWR_CLK_ENABLE();
123   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
124   /** Initializes the RCC Oscillators according to the specified parameters
125   * in the RCC_OscInitTypeDef structure.
126   */
127   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
128   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
129   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
130   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
131   RCC_OscInitStruct.PLL.PLLM = 4;
132   RCC_OscInitStruct.PLL.PLLN = 192;
133   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV6;
134   RCC_OscInitStruct.PLL.PLLQ = 8;
135   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
136   {
137     Error_Handler();
138   }
139   /** Initializes the CPU, AHB and APB buses clocks
140   */
141   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
142                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
143   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
144   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
145   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
146   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
147 
148   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
149   {
150     Error_Handler();
151   }
152 }
153 
154 /* USER CODE BEGIN 4 */
155 
156 /* USER CODE END 4 */
157 
158 /**
159   * @brief  This function is executed in case of error occurrence.
160   * @retval None
161   */
162 void Error_Handler(void)
163 {
164   /* USER CODE BEGIN Error_Handler_Debug */
165   /* User can add his own implementation to report the HAL error return state */
166 
167   /* USER CODE END Error_Handler_Debug */
168 }
169 
170 #ifdef  USE_FULL_ASSERT
171 /**
172   * @brief  Reports the name of the source file and the source line number
173   *         where the assert_param error has occurred.
174   * @param  file: pointer to the source file name
175   * @param  line: assert_param error line source number
176   * @retval None
177   */
178 void assert_failed(uint8_t *file, uint32_t line)
179 {
180   /* USER CODE BEGIN 6 */
181   /* User can add his own implementation to report the file name and line number,
182      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
183   /* USER CODE END 6 */
184 }
185 #endif /* USE_FULL_ASSERT */
186 
187 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
188