main.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 "cmsis_os.h"
  22. #include "usart.h"
  23. #include "gpio.h"
  24. #include "ffx_master.h"
  25. /* Private includes ----------------------------------------------------------*/
  26. /* USER CODE BEGIN Includes */
  27. /* USER CODE END Includes */
  28. /* Private typedef -----------------------------------------------------------*/
  29. /* USER CODE BEGIN PTD */
  30. /* USER CODE END PTD */
  31. /* Private define ------------------------------------------------------------*/
  32. /* USER CODE BEGIN PD */
  33. /* USER CODE END PD */
  34. /* Private macro -------------------------------------------------------------*/
  35. /* USER CODE BEGIN PM */
  36. /* USER CODE END PM */
  37. /* Private variables ---------------------------------------------------------*/
  38. /* USER CODE BEGIN PV */
  39. /* USER CODE END PV */
  40. /* Private function prototypes -----------------------------------------------*/
  41. void SystemClock_Config(void);
  42. void MX_FREERTOS_Init(void);
  43. /* USER CODE BEGIN PFP */
  44. /* USER CODE END PFP */
  45. /* Private user code ---------------------------------------------------------*/
  46. /* USER CODE BEGIN 0 */
  47. /* USER CODE END 0 */
  48. /**
  49. * @brief The application entry point.
  50. * @retval int
  51. */
  52. int main(void)
  53. {
  54. /* USER CODE BEGIN 1 */
  55. /* USER CODE END 1 */
  56. /* MCU Configuration--------------------------------------------------------*/
  57. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  58. HAL_Init();
  59. /* USER CODE BEGIN Init */
  60. /* USER CODE END Init */
  61. /* Configure the system clock */
  62. SystemClock_Config();
  63. /* USER CODE BEGIN SysInit */
  64. /* USER CODE END SysInit */
  65. /* Initialize all configured peripherals */
  66. MX_GPIO_Init();
  67. MX_UART4_Init();
  68. MX_USART2_UART_Init();
  69. MX_USART3_UART_Init();
  70. /* USER CODE BEGIN 2 */
  71. ffx_master_init();
  72. /* USER CODE END 2 */
  73. /* Init scheduler */
  74. osKernelInitialize();
  75. /* Call init function for freertos objects (in cmsis_os2.c) */
  76. MX_FREERTOS_Init();
  77. /* Start scheduler */
  78. osKernelStart();
  79. /* We should never get here as control is now taken by the scheduler */
  80. /* Infinite loop */
  81. /* USER CODE BEGIN WHILE */
  82. while (1)
  83. {
  84. /* USER CODE END WHILE */
  85. /* USER CODE BEGIN 3 */
  86. }
  87. /* USER CODE END 3 */
  88. }
  89. /**
  90. * @brief System Clock Configuration
  91. * @retval None
  92. */
  93. void SystemClock_Config(void)
  94. {
  95. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  96. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  97. /** Initializes the RCC Oscillators according to the specified parameters
  98. * in the RCC_OscInitTypeDef structure.
  99. */
  100. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  101. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  102. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  103. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  104. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  105. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  106. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  107. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  108. {
  109. Error_Handler();
  110. }
  111. /** Initializes the CPU, AHB and APB buses clocks
  112. */
  113. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  114. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  115. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  116. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  117. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  118. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  119. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  120. {
  121. Error_Handler();
  122. }
  123. }
  124. /* USER CODE BEGIN 4 */
  125. /* USER CODE END 4 */
  126. /**
  127. * @brief Period elapsed callback in non blocking mode
  128. * @note This function is called when TIM1 interrupt took place, inside
  129. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  130. * a global variable "uwTick" used as application time base.
  131. * @param htim : TIM handle
  132. * @retval None
  133. */
  134. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  135. {
  136. /* USER CODE BEGIN Callback 0 */
  137. /* USER CODE END Callback 0 */
  138. if (htim->Instance == TIM1) {
  139. HAL_IncTick();
  140. }
  141. /* USER CODE BEGIN Callback 1 */
  142. /* USER CODE END Callback 1 */
  143. }
  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 */