xref: /btstack/port/stm32-f4discovery-cc256x/Src/main.c (revision 2d8556b2db643312186f7d316b34bb060fd253a0)
1225f4ba4SMatthias Ringwald /* USER CODE BEGIN Header */
2225f4ba4SMatthias Ringwald /**
3225f4ba4SMatthias Ringwald   ******************************************************************************
4225f4ba4SMatthias Ringwald   * @file           : main.c
5225f4ba4SMatthias Ringwald   * @brief          : Main program body
6225f4ba4SMatthias Ringwald   ******************************************************************************
7225f4ba4SMatthias Ringwald   * @attention
8225f4ba4SMatthias Ringwald   *
9225f4ba4SMatthias Ringwald   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10225f4ba4SMatthias Ringwald   * All rights reserved.</center></h2>
11225f4ba4SMatthias Ringwald   *
12225f4ba4SMatthias Ringwald   * This software component is licensed by ST under BSD 3-Clause license,
13225f4ba4SMatthias Ringwald   * the "License"; You may not use this file except in compliance with the
14225f4ba4SMatthias Ringwald   * License. You may obtain a copy of the License at:
15225f4ba4SMatthias Ringwald   *                        opensource.org/licenses/BSD-3-Clause
16225f4ba4SMatthias Ringwald   *
17225f4ba4SMatthias Ringwald   ******************************************************************************
18225f4ba4SMatthias Ringwald   */
19225f4ba4SMatthias Ringwald /* USER CODE END Header */
20225f4ba4SMatthias Ringwald 
21225f4ba4SMatthias Ringwald /* Includes ------------------------------------------------------------------*/
22225f4ba4SMatthias Ringwald #include "main.h"
23225f4ba4SMatthias Ringwald #include "dma.h"
24225f4ba4SMatthias Ringwald #include "usart.h"
25225f4ba4SMatthias Ringwald #include "gpio.h"
26225f4ba4SMatthias Ringwald 
27225f4ba4SMatthias Ringwald /* Private includes ----------------------------------------------------------*/
28225f4ba4SMatthias Ringwald /* USER CODE BEGIN Includes */
29225f4ba4SMatthias Ringwald #include "port.h"
30225f4ba4SMatthias Ringwald /* USER CODE END Includes */
31225f4ba4SMatthias Ringwald 
32225f4ba4SMatthias Ringwald /* Private typedef -----------------------------------------------------------*/
33225f4ba4SMatthias Ringwald /* USER CODE BEGIN PTD */
34225f4ba4SMatthias Ringwald 
35225f4ba4SMatthias Ringwald /* USER CODE END PTD */
36225f4ba4SMatthias Ringwald 
37225f4ba4SMatthias Ringwald /* Private define ------------------------------------------------------------*/
38225f4ba4SMatthias Ringwald /* USER CODE BEGIN PD */
39225f4ba4SMatthias Ringwald 
40225f4ba4SMatthias Ringwald /* USER CODE END PD */
41225f4ba4SMatthias Ringwald 
42225f4ba4SMatthias Ringwald /* Private macro -------------------------------------------------------------*/
43225f4ba4SMatthias Ringwald /* USER CODE BEGIN PM */
44225f4ba4SMatthias Ringwald 
45225f4ba4SMatthias Ringwald /* USER CODE END PM */
46225f4ba4SMatthias Ringwald 
47225f4ba4SMatthias Ringwald /* Private variables ---------------------------------------------------------*/
48225f4ba4SMatthias Ringwald 
49225f4ba4SMatthias Ringwald /* USER CODE BEGIN PV */
50225f4ba4SMatthias Ringwald 
51225f4ba4SMatthias Ringwald /* USER CODE END PV */
52225f4ba4SMatthias Ringwald 
53225f4ba4SMatthias Ringwald /* Private function prototypes -----------------------------------------------*/
54225f4ba4SMatthias Ringwald void SystemClock_Config(void);
55225f4ba4SMatthias Ringwald /* USER CODE BEGIN PFP */
56225f4ba4SMatthias Ringwald 
57225f4ba4SMatthias Ringwald /* USER CODE END PFP */
58225f4ba4SMatthias Ringwald 
59225f4ba4SMatthias Ringwald /* Private user code ---------------------------------------------------------*/
60225f4ba4SMatthias Ringwald /* USER CODE BEGIN 0 */
61225f4ba4SMatthias Ringwald 
62225f4ba4SMatthias Ringwald /* USER CODE END 0 */
63225f4ba4SMatthias Ringwald 
64225f4ba4SMatthias Ringwald /**
65225f4ba4SMatthias Ringwald   * @brief  The application entry point.
66225f4ba4SMatthias Ringwald   * @retval int
67225f4ba4SMatthias Ringwald   */
main(void)68225f4ba4SMatthias Ringwald int main(void)
69225f4ba4SMatthias Ringwald {
70225f4ba4SMatthias Ringwald   /* USER CODE BEGIN 1 */
71225f4ba4SMatthias Ringwald 
72225f4ba4SMatthias Ringwald   /* USER CODE END 1 */
73225f4ba4SMatthias Ringwald 
74225f4ba4SMatthias Ringwald   /* MCU Configuration--------------------------------------------------------*/
75225f4ba4SMatthias Ringwald 
76225f4ba4SMatthias Ringwald   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
77225f4ba4SMatthias Ringwald   HAL_Init();
78225f4ba4SMatthias Ringwald 
79225f4ba4SMatthias Ringwald   /* USER CODE BEGIN Init */
80225f4ba4SMatthias Ringwald 
81225f4ba4SMatthias Ringwald   /* USER CODE END Init */
82225f4ba4SMatthias Ringwald 
83225f4ba4SMatthias Ringwald   /* Configure the system clock */
84225f4ba4SMatthias Ringwald   SystemClock_Config();
85225f4ba4SMatthias Ringwald 
86225f4ba4SMatthias Ringwald   /* USER CODE BEGIN SysInit */
87225f4ba4SMatthias Ringwald 
88225f4ba4SMatthias Ringwald   /* USER CODE END SysInit */
89225f4ba4SMatthias Ringwald 
90225f4ba4SMatthias Ringwald   /* Initialize all configured peripherals */
91225f4ba4SMatthias Ringwald   MX_GPIO_Init();
92225f4ba4SMatthias Ringwald   MX_DMA_Init();
93225f4ba4SMatthias Ringwald   MX_USART2_UART_Init();
94225f4ba4SMatthias Ringwald   MX_USART3_UART_Init();
95225f4ba4SMatthias Ringwald   /* USER CODE BEGIN 2 */
96225f4ba4SMatthias Ringwald   // jump to BTstack port
97225f4ba4SMatthias Ringwald   port_main();
98225f4ba4SMatthias Ringwald   /* USER CODE END 2 */
99225f4ba4SMatthias Ringwald 
100225f4ba4SMatthias Ringwald   /* Infinite loop */
101225f4ba4SMatthias Ringwald   /* USER CODE BEGIN WHILE */
102225f4ba4SMatthias Ringwald   while (1)
103225f4ba4SMatthias Ringwald   {
104225f4ba4SMatthias Ringwald     /* USER CODE END WHILE */
105225f4ba4SMatthias Ringwald 
106225f4ba4SMatthias Ringwald     /* USER CODE BEGIN 3 */
107225f4ba4SMatthias Ringwald   }
108225f4ba4SMatthias Ringwald   /* USER CODE END 3 */
109225f4ba4SMatthias Ringwald }
110225f4ba4SMatthias Ringwald 
111225f4ba4SMatthias Ringwald /**
112225f4ba4SMatthias Ringwald   * @brief System Clock Configuration
113225f4ba4SMatthias Ringwald   * @retval None
114225f4ba4SMatthias Ringwald   */
SystemClock_Config(void)115225f4ba4SMatthias Ringwald void SystemClock_Config(void)
116225f4ba4SMatthias Ringwald {
117225f4ba4SMatthias Ringwald   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
118225f4ba4SMatthias Ringwald   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
119225f4ba4SMatthias Ringwald 
120225f4ba4SMatthias Ringwald   /** Configure the main internal regulator output voltage
121225f4ba4SMatthias Ringwald   */
122225f4ba4SMatthias Ringwald   __HAL_RCC_PWR_CLK_ENABLE();
123225f4ba4SMatthias Ringwald   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
124*2d8556b2SDirk Helbig   /** Initializes the RCC Oscillators according to the specified parameters
125*2d8556b2SDirk Helbig   * in the RCC_OscInitTypeDef structure.
126225f4ba4SMatthias Ringwald   */
127*2d8556b2SDirk Helbig   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
128*2d8556b2SDirk Helbig   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
129225f4ba4SMatthias Ringwald   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
130*2d8556b2SDirk Helbig   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
131*2d8556b2SDirk Helbig   RCC_OscInitStruct.PLL.PLLM = 4;
132*2d8556b2SDirk Helbig   RCC_OscInitStruct.PLL.PLLN = 192;
133*2d8556b2SDirk Helbig   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV6;
134*2d8556b2SDirk Helbig   RCC_OscInitStruct.PLL.PLLQ = 8;
135225f4ba4SMatthias Ringwald   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
136225f4ba4SMatthias Ringwald   {
137225f4ba4SMatthias Ringwald     Error_Handler();
138225f4ba4SMatthias Ringwald   }
139*2d8556b2SDirk Helbig   /** Initializes the CPU, AHB and APB buses clocks
140225f4ba4SMatthias Ringwald   */
141225f4ba4SMatthias Ringwald   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
142225f4ba4SMatthias Ringwald                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
143225f4ba4SMatthias Ringwald   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
144225f4ba4SMatthias Ringwald   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
145225f4ba4SMatthias Ringwald   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
146*2d8556b2SDirk Helbig   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
147225f4ba4SMatthias Ringwald 
148225f4ba4SMatthias Ringwald   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
149225f4ba4SMatthias Ringwald   {
150225f4ba4SMatthias Ringwald     Error_Handler();
151225f4ba4SMatthias Ringwald   }
152225f4ba4SMatthias Ringwald }
153225f4ba4SMatthias Ringwald 
154225f4ba4SMatthias Ringwald /* USER CODE BEGIN 4 */
155225f4ba4SMatthias Ringwald 
156225f4ba4SMatthias Ringwald /* USER CODE END 4 */
157225f4ba4SMatthias Ringwald 
158225f4ba4SMatthias Ringwald /**
159225f4ba4SMatthias Ringwald   * @brief  This function is executed in case of error occurrence.
160225f4ba4SMatthias Ringwald   * @retval None
161225f4ba4SMatthias Ringwald   */
Error_Handler(void)162225f4ba4SMatthias Ringwald void Error_Handler(void)
163225f4ba4SMatthias Ringwald {
164225f4ba4SMatthias Ringwald   /* USER CODE BEGIN Error_Handler_Debug */
165225f4ba4SMatthias Ringwald   /* User can add his own implementation to report the HAL error return state */
166225f4ba4SMatthias Ringwald 
167225f4ba4SMatthias Ringwald   /* USER CODE END Error_Handler_Debug */
168225f4ba4SMatthias Ringwald }
169225f4ba4SMatthias Ringwald 
170225f4ba4SMatthias Ringwald #ifdef  USE_FULL_ASSERT
171225f4ba4SMatthias Ringwald /**
172225f4ba4SMatthias Ringwald   * @brief  Reports the name of the source file and the source line number
173225f4ba4SMatthias Ringwald   *         where the assert_param error has occurred.
174225f4ba4SMatthias Ringwald   * @param  file: pointer to the source file name
175225f4ba4SMatthias Ringwald   * @param  line: assert_param error line source number
176225f4ba4SMatthias Ringwald   * @retval None
177225f4ba4SMatthias Ringwald   */
assert_failed(uint8_t * file,uint32_t line)178225f4ba4SMatthias Ringwald void assert_failed(uint8_t *file, uint32_t line)
179225f4ba4SMatthias Ringwald {
180225f4ba4SMatthias Ringwald   /* USER CODE BEGIN 6 */
181225f4ba4SMatthias Ringwald   /* User can add his own implementation to report the file name and line number,
182225f4ba4SMatthias Ringwald      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
183225f4ba4SMatthias Ringwald   /* USER CODE END 6 */
184225f4ba4SMatthias Ringwald }
185225f4ba4SMatthias Ringwald #endif /* USE_FULL_ASSERT */
186225f4ba4SMatthias Ringwald 
187225f4ba4SMatthias Ringwald /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
188