blob: 96c9f09993e07a65874da308036cc477e6efa708 [file] [log] [blame]
Milko.Denis68c0bbc2019-10-22 00:46:35 +03001/* 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 Ultimate Liberty license
13 * SLA0044, the "License"; You may not use this file except in compliance with
14 * the License. You may obtain a copy of the License at:
15 * www.st.com/SLA0044
16 *
17 ******************************************************************************
18 */
19/* USER CODE END Header */
20
21/* Includes ------------------------------------------------------------------*/
22#include "main.h"
23#include "usb_host.h"
24
25/* Private includes ----------------------------------------------------------*/
26/* USER CODE BEGIN Includes */
27
28/* USER CODE END Includes */
29
30/* Private typedef -----------------------------------------------------------*/
31/* USER CODE BEGIN PTD */
32
33/* USER CODE END PTD */
34
35/* Private define ------------------------------------------------------------*/
36/* USER CODE BEGIN PD */
37
38/* USER CODE END PD */
39
40/* Private macro -------------------------------------------------------------*/
41/* USER CODE BEGIN PM */
42
43/* USER CODE END PM */
44
45/* Private variables ---------------------------------------------------------*/
46I2C_HandleTypeDef hi2c1;
47
48I2S_HandleTypeDef hi2s3;
49
50SPI_HandleTypeDef hspi1;
51
52/* USER CODE BEGIN PV */
53
54/* USER CODE END PV */
55
56/* Private function prototypes -----------------------------------------------*/
57void SystemClock_Config(void);
58static void MX_GPIO_Init(void);
59static void MX_I2C1_Init(void);
60static void MX_I2S3_Init(void);
61static void MX_SPI1_Init(void);
62void MX_USB_HOST_Process(void);
63
64
65
66/* USER CODE BEGIN PFP */
67void flash();
68
69/* USER CODE END PFP */
70
71/* Private user code ---------------------------------------------------------*/
72/* USER CODE BEGIN 0 */
73
74/* USER CODE END 0 */
75
76/**
77 * @brief The application entry point.
78 * @retval int
79 */
80int main(void)
81{
82 /* USER CODE BEGIN 1 */
83
84 /* USER CODE END 1 */
85
86
87 /* MCU Configuration--------------------------------------------------------*/
88
89 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
90 HAL_Init();
91
92 /* USER CODE BEGIN Init */
93
94 /* USER CODE END Init */
95
96 /* Configure the system clock */
97 SystemClock_Config();
98
99 /* USER CODE BEGIN SysInit */
100
101 /* USER CODE END SysInit */
102
103 /* Initialize all configured peripherals */
104 MX_GPIO_Init();
105 MX_I2C1_Init();
106 MX_I2S3_Init();
107 MX_SPI1_Init();
108 MX_USB_HOST_Init();
109 /* USER CODE BEGIN 2 */
110
111 /* USER CODE END 2 */
112
113 /* Infinite loop */
114 /* USER CODE BEGIN WHILE */
115 while (1)
116 {
117 /* USER CODE END WHILE */
118 MX_USB_HOST_Process();
119
120 /* USER CODE BEGIN 3 */
121 flash();
122 }
123 /* USER CODE END 3 */
124}
125void flash() {
126 /* USER CODE BEGIN 3 */
127 HAL_GPIO_WritePin(LD6_GPIO_Port, LD6_Pin, GPIO_PIN_SET);
128 HAL_Delay(500);
129 HAL_GPIO_WritePin(LD6_GPIO_Port, LD6_Pin, GPIO_PIN_RESET);
130 HAL_Delay(500);
131}
132/**
133 * @brief System Clock Configuration
134 * @retval None
135 */
136void SystemClock_Config(void)
137{
138 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
139 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
140 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
141
142 /** Configure the main internal regulator output voltage
143 */
144 __HAL_RCC_PWR_CLK_ENABLE();
145 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
146 /** Initializes the CPU, AHB and APB busses clocks
147 */
148 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
149 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
150 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
151 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
152 RCC_OscInitStruct.PLL.PLLM = 8;
153 RCC_OscInitStruct.PLL.PLLN = 336;
154 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
155 RCC_OscInitStruct.PLL.PLLQ = 7;
156 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
157 {
158 Error_Handler();
159 }
160 /** Initializes the CPU, AHB and APB busses clocks
161 */
162 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
163 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
164 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
165 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
166 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
167 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
168
169 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
170 {
171 Error_Handler();
172 }
173 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S;
174 PeriphClkInitStruct.PLLI2S.PLLI2SN = 192;
175 PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
176 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
177 {
178 Error_Handler();
179 }
180}
181
182/**
183 * @brief I2C1 Initialization Function
184 * @param None
185 * @retval None
186 */
187static void MX_I2C1_Init(void)
188{
189
190 /* USER CODE BEGIN I2C1_Init 0 */
191
192 /* USER CODE END I2C1_Init 0 */
193
194 /* USER CODE BEGIN I2C1_Init 1 */
195
196 /* USER CODE END I2C1_Init 1 */
197 hi2c1.Instance = I2C1;
198 hi2c1.Init.ClockSpeed = 100000;
199 hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
200 hi2c1.Init.OwnAddress1 = 0;
201 hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
202 hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
203 hi2c1.Init.OwnAddress2 = 0;
204 hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
205 hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
206 if (HAL_I2C_Init(&hi2c1) != HAL_OK)
207 {
208 Error_Handler();
209 }
210 /* USER CODE BEGIN I2C1_Init 2 */
211
212 /* USER CODE END I2C1_Init 2 */
213
214}
215
216/**
217 * @brief I2S3 Initialization Function
218 * @param None
219 * @retval None
220 */
221static void MX_I2S3_Init(void)
222{
223
224 /* USER CODE BEGIN I2S3_Init 0 */
225
226 /* USER CODE END I2S3_Init 0 */
227
228 /* USER CODE BEGIN I2S3_Init 1 */
229
230 /* USER CODE END I2S3_Init 1 */
231 hi2s3.Instance = SPI3;
232 hi2s3.Init.Mode = I2S_MODE_MASTER_TX;
233 hi2s3.Init.Standard = I2S_STANDARD_PHILIPS;
234 hi2s3.Init.DataFormat = I2S_DATAFORMAT_16B;
235 hi2s3.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
236 hi2s3.Init.AudioFreq = I2S_AUDIOFREQ_96K;
237 hi2s3.Init.CPOL = I2S_CPOL_LOW;
238 hi2s3.Init.ClockSource = I2S_CLOCK_PLL;
239 hi2s3.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_DISABLE;
240 if (HAL_I2S_Init(&hi2s3) != HAL_OK)
241 {
242 Error_Handler();
243 }
244 /* USER CODE BEGIN I2S3_Init 2 */
245
246 /* USER CODE END I2S3_Init 2 */
247
248}
249
250/**
251 * @brief SPI1 Initialization Function
252 * @param None
253 * @retval None
254 */
255static void MX_SPI1_Init(void)
256{
257
258 /* USER CODE BEGIN SPI1_Init 0 */
259
260 /* USER CODE END SPI1_Init 0 */
261
262 /* USER CODE BEGIN SPI1_Init 1 */
263
264 /* USER CODE END SPI1_Init 1 */
265 /* SPI1 parameter configuration*/
266 hspi1.Instance = SPI1;
267 hspi1.Init.Mode = SPI_MODE_MASTER;
268 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
269 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
270 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
271 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
272 hspi1.Init.NSS = SPI_NSS_SOFT;
273 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
274 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
275 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
276 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
277 hspi1.Init.CRCPolynomial = 10;
278 if (HAL_SPI_Init(&hspi1) != HAL_OK)
279 {
280 Error_Handler();
281 }
282 /* USER CODE BEGIN SPI1_Init 2 */
283
284 /* USER CODE END SPI1_Init 2 */
285
286}
287
288/**
289 * @brief GPIO Initialization Function
290 * @param None
291 * @retval None
292 */
293static void MX_GPIO_Init(void)
294{
295 GPIO_InitTypeDef GPIO_InitStruct = {0};
296
297 /* GPIO Ports Clock Enable */
298 __HAL_RCC_GPIOE_CLK_ENABLE();
299 __HAL_RCC_GPIOC_CLK_ENABLE();
300 __HAL_RCC_GPIOH_CLK_ENABLE();
301 __HAL_RCC_GPIOA_CLK_ENABLE();
302 __HAL_RCC_GPIOB_CLK_ENABLE();
303 __HAL_RCC_GPIOD_CLK_ENABLE();
304
305 /*Configure GPIO pin Output Level */
306 HAL_GPIO_WritePin(CS_I2C_SPI_GPIO_Port, CS_I2C_SPI_Pin, GPIO_PIN_RESET);
307
308 /*Configure GPIO pin Output Level */
309 HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET);
310
311 /*Configure GPIO pin Output Level */
312 HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin
313 |Audio_RST_Pin, GPIO_PIN_RESET);
314
315 /*Configure GPIO pin : CS_I2C_SPI_Pin */
316 GPIO_InitStruct.Pin = CS_I2C_SPI_Pin;
317 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
318 GPIO_InitStruct.Pull = GPIO_NOPULL;
319 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
320 HAL_GPIO_Init(CS_I2C_SPI_GPIO_Port, &GPIO_InitStruct);
321
322 /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */
323 GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin;
324 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
325 GPIO_InitStruct.Pull = GPIO_NOPULL;
326 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
327 HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);
328
329 /*Configure GPIO pin : PDM_OUT_Pin */
330 GPIO_InitStruct.Pin = PDM_OUT_Pin;
331 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
332 GPIO_InitStruct.Pull = GPIO_NOPULL;
333 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
334 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
335 HAL_GPIO_Init(PDM_OUT_GPIO_Port, &GPIO_InitStruct);
336
337 /*Configure GPIO pin : B1_Pin */
338 GPIO_InitStruct.Pin = B1_Pin;
339 GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
340 GPIO_InitStruct.Pull = GPIO_NOPULL;
341 HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
342
343 /*Configure GPIO pin : BOOT1_Pin */
344 GPIO_InitStruct.Pin = BOOT1_Pin;
345 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
346 GPIO_InitStruct.Pull = GPIO_NOPULL;
347 HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
348
349 /*Configure GPIO pin : CLK_IN_Pin */
350 GPIO_InitStruct.Pin = CLK_IN_Pin;
351 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
352 GPIO_InitStruct.Pull = GPIO_NOPULL;
353 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
354 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
355 HAL_GPIO_Init(CLK_IN_GPIO_Port, &GPIO_InitStruct);
356
357 /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin
358 Audio_RST_Pin */
359 GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin
360 |Audio_RST_Pin;
361 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
362 GPIO_InitStruct.Pull = GPIO_NOPULL;
363 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
364 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
365
366 /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */
367 GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin;
368 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
369 GPIO_InitStruct.Pull = GPIO_NOPULL;
370 HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct);
371
372 /*Configure GPIO pin : MEMS_INT2_Pin */
373 GPIO_InitStruct.Pin = MEMS_INT2_Pin;
374 GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
375 GPIO_InitStruct.Pull = GPIO_NOPULL;
376 HAL_GPIO_Init(MEMS_INT2_GPIO_Port, &GPIO_InitStruct);
377
378}
379
380/* USER CODE BEGIN 4 */
381
382/* USER CODE END 4 */
383
384/**
385 * @brief This function is executed in case of error occurrence.
386 * @retval None
387 */
388void Error_Handler(void)
389{
390 /* USER CODE BEGIN Error_Handler_Debug */
391 /* User can add his own implementation to report the HAL error return state */
392
393 /* USER CODE END Error_Handler_Debug */
394}
395
396#ifdef USE_FULL_ASSERT
397/**
398 * @brief Reports the name of the source file and the source line number
399 * where the assert_param error has occurred.
400 * @param file: pointer to the source file name
401 * @param line: assert_param error line source number
402 * @retval None
403 */
404void assert_failed(uint8_t *file, uint32_t line)
405{
406 /* USER CODE BEGIN 6 */
407 /* User can add his own implementation to report the file name and line number,
408 tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
409 /* USER CODE END 6 */
410}
411#endif /* USE_FULL_ASSERT */
412
413/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/