main.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2024 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. #include "usb_device.h"
  22. #include "usbd_audio_if.h"
  23. #define OSA_BUF_SIZE 16
  24. int16_t adc_buffer[OSA_BUF_SIZE * AUDIO_IN_PACKET / 2] = {0};
  25. extern USBD_HandleTypeDef hUsbDeviceFS;
  26. /* Private includes ----------------------------------------------------------*/
  27. /* USER CODE BEGIN Includes */
  28. /* USER CODE END Includes */
  29. /* Private typedef -----------------------------------------------------------*/
  30. /* USER CODE BEGIN PTD */
  31. /* USER CODE END PTD */
  32. /* Private define ------------------------------------------------------------*/
  33. /* USER CODE BEGIN PD */
  34. /* USER CODE END PD */
  35. /* Private macro -------------------------------------------------------------*/
  36. /* USER CODE BEGIN PM */
  37. /* USER CODE END PM */
  38. /* Private variables ---------------------------------------------------------*/
  39. /* USER CODE BEGIN PV */
  40. /* USER CODE END PV */
  41. /* Private function prototypes -----------------------------------------------*/
  42. void SystemClock_Config(void);
  43. static void MX_GPIO_Init(void);
  44. /* USER CODE BEGIN PFP */
  45. /* USER CODE END PFP */
  46. /* Private user code ---------------------------------------------------------*/
  47. /* USER CODE BEGIN 0 */
  48. /* USER CODE END 0 */
  49. /**
  50. * @brief The application entry point.
  51. * @retval int
  52. */
  53. void ADC_to_MIC(void)
  54. {
  55. //HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buffer, OSA_BUF_SIZE * (AUDIO_IN_PACKET / 2)); // Start ADC transfer into oversampling buffer
  56. }
  57. int main(void)
  58. {
  59. /* USER CODE BEGIN 1 */
  60. /* USER CODE END 1 */
  61. /* MCU Configuration--------------------------------------------------------*/
  62. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  63. HAL_Init();
  64. /* USER CODE BEGIN Init */
  65. /* USER CODE END Init */
  66. /* Configure the system clock */
  67. SystemClock_Config();
  68. /* USER CODE BEGIN SysInit */
  69. /* USER CODE END SysInit */
  70. /* Initialize all configured peripherals */
  71. MX_GPIO_Init();
  72. MX_USB_DEVICE_Init();
  73. /* USER CODE BEGIN 2 */
  74. /* USER CODE END 2 */
  75. /* Infinite loop */
  76. /* USER CODE BEGIN WHILE */
  77. while (1)
  78. {
  79. /* USER CODE END WHILE */
  80. /* USER CODE BEGIN 3 */
  81. }
  82. /* USER CODE END 3 */
  83. }
  84. /**
  85. * @brief System Clock Configuration
  86. * @retval None
  87. */
  88. void SystemClock_Config(void)
  89. {
  90. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  91. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  92. /** Configure the main internal regulator output voltage
  93. */
  94. __HAL_RCC_PWR_CLK_ENABLE();
  95. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  96. /** Initializes the RCC Oscillators according to the specified parameters
  97. * in the RCC_OscInitTypeDef structure.
  98. */
  99. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
  100. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  101. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  102. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  103. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  104. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  105. RCC_OscInitStruct.PLL.PLLM = 15;
  106. RCC_OscInitStruct.PLL.PLLN = 144;
  107. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  108. RCC_OscInitStruct.PLL.PLLQ = 5;
  109. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  110. {
  111. Error_Handler();
  112. }
  113. /** Initializes the CPU, AHB and APB buses clocks
  114. */
  115. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  116. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  117. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  118. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  119. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  120. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  121. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  122. {
  123. Error_Handler();
  124. }
  125. }
  126. /**
  127. * @brief GPIO Initialization Function
  128. * @param None
  129. * @retval None
  130. */
  131. static void MX_GPIO_Init(void)
  132. {
  133. /* USER CODE BEGIN MX_GPIO_Init_1 */
  134. /* USER CODE END MX_GPIO_Init_1 */
  135. /* GPIO Ports Clock Enable */
  136. __HAL_RCC_GPIOC_CLK_ENABLE();
  137. __HAL_RCC_GPIOH_CLK_ENABLE();
  138. __HAL_RCC_GPIOA_CLK_ENABLE();
  139. /* USER CODE BEGIN MX_GPIO_Init_2 */
  140. /* USER CODE END MX_GPIO_Init_2 */
  141. }
  142. /* USER CODE BEGIN 4 */
  143. /* USER CODE END 4 */
  144. /**
  145. * @brief This function is executed in case of error occurrence.
  146. * @retval None
  147. */
  148. void Error_Handler(void)
  149. {
  150. /* USER CODE BEGIN Error_Handler_Debug */
  151. /* User can add his own implementation to report the HAL error return state */
  152. __disable_irq();
  153. while (1)
  154. {
  155. }
  156. /* USER CODE END Error_Handler_Debug */
  157. }
  158. #ifdef USE_FULL_ASSERT
  159. /**
  160. * @brief Reports the name of the source file and the source line number
  161. * where the assert_param error has occurred.
  162. * @param file: pointer to the source file name
  163. * @param line: assert_param error line source number
  164. * @retval None
  165. */
  166. void assert_failed(uint8_t *file, uint32_t line)
  167. {
  168. /* USER CODE BEGIN 6 */
  169. /* User can add his own implementation to report the file name and line number,
  170. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  171. /* USER CODE END 6 */
  172. }
  173. #endif /* USE_FULL_ASSERT */