Advertisement
Guest User

Untitled

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