You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
5.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2023 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 "iwdg.h"
  23. #include "lwip.h"
  24. #include "tim.h"
  25. #include "usart.h"
  26. #include "gpio.h"
  27. /* Private includes ----------------------------------------------------------*/
  28. /* USER CODE BEGIN Includes */
  29. /* USER CODE END Includes */
  30. /* Private typedef -----------------------------------------------------------*/
  31. /* USER CODE BEGIN PTD */
  32. /* USER CODE END PTD */
  33. /* Private define ------------------------------------------------------------*/
  34. /* USER CODE BEGIN PD */
  35. /* USER CODE END PD */
  36. /* Private macro -------------------------------------------------------------*/
  37. /* USER CODE BEGIN PM */
  38. /* USER CODE END PM */
  39. /* Private variables ---------------------------------------------------------*/
  40. /* USER CODE BEGIN PV */
  41. /* USER CODE END PV */
  42. /* Private function prototypes -----------------------------------------------*/
  43. void SystemClock_Config(void);
  44. void MX_FREERTOS_Init(void);
  45. /* USER CODE BEGIN PFP */
  46. /* USER CODE END PFP */
  47. /* Private user code ---------------------------------------------------------*/
  48. /* USER CODE BEGIN 0 */
  49. /* USER CODE END 0 */
  50. /**
  51. * @brief The application entry point.
  52. * @retval int
  53. */
  54. int main(void)
  55. {
  56. /* USER CODE BEGIN 1 */
  57. /* USER CODE END 1 */
  58. /* MCU Configuration--------------------------------------------------------*/
  59. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  60. HAL_Init();
  61. /* USER CODE BEGIN Init */
  62. /* USER CODE END Init */
  63. /* Configure the system clock */
  64. SystemClock_Config();
  65. /* USER CODE BEGIN SysInit */
  66. /* USER CODE END SysInit */
  67. /* Initialize all configured peripherals */
  68. MX_GPIO_Init();
  69. MX_IWDG_Init();
  70. MX_TIM6_Init();
  71. MX_USART1_UART_Init();
  72. /* USER CODE BEGIN 2 */
  73. extern void hardware_main();
  74. hardware_main();
  75. /* USER CODE END 2 */
  76. /* Call init function for freertos objects (in freertos.c) */
  77. MX_FREERTOS_Init();
  78. /* Start scheduler */
  79. osKernelStart();
  80. /* We should never get here as control is now taken by the scheduler */
  81. /* Infinite loop */
  82. /* USER CODE BEGIN WHILE */
  83. while (1)
  84. {
  85. /* USER CODE END WHILE */
  86. /* USER CODE BEGIN 3 */
  87. }
  88. /* USER CODE END 3 */
  89. }
  90. /**
  91. * @brief System Clock Configuration
  92. * @retval None
  93. */
  94. void SystemClock_Config(void)
  95. {
  96. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  97. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  98. /** Configure the main internal regulator output voltage
  99. */
  100. __HAL_RCC_PWR_CLK_ENABLE();
  101. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  102. /** Initializes the RCC Oscillators according to the specified parameters
  103. * in the RCC_OscInitTypeDef structure.
  104. */
  105. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
  106. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  107. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  108. RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  109. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  110. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  111. RCC_OscInitStruct.PLL.PLLM = 16;
  112. RCC_OscInitStruct.PLL.PLLN = 336;
  113. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  114. RCC_OscInitStruct.PLL.PLLQ = 4;
  115. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  116. {
  117. Error_Handler();
  118. }
  119. /** Initializes the CPU, AHB and APB buses clocks
  120. */
  121. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  122. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  123. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  124. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  125. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  126. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  127. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  128. {
  129. Error_Handler();
  130. }
  131. }
  132. /* USER CODE BEGIN 4 */
  133. /* USER CODE END 4 */
  134. /**
  135. * @brief Period elapsed callback in non blocking mode
  136. * @note This function is called when TIM1 interrupt took place, inside
  137. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  138. * a global variable "uwTick" used as application time base.
  139. * @param htim : TIM handle
  140. * @retval None
  141. */
  142. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  143. {
  144. /* USER CODE BEGIN Callback 0 */
  145. /* USER CODE END Callback 0 */
  146. if (htim->Instance == TIM1) {
  147. HAL_IncTick();
  148. }
  149. /* USER CODE BEGIN Callback 1 */
  150. /* USER CODE END Callback 1 */
  151. }
  152. /**
  153. * @brief This function is executed in case of error occurrence.
  154. * @retval None
  155. */
  156. void Error_Handler(void)
  157. {
  158. /* USER CODE BEGIN Error_Handler_Debug */
  159. /* User can add his own implementation to report the HAL error return state */
  160. __disable_irq();
  161. while (1)
  162. {
  163. }
  164. /* USER CODE END Error_Handler_Debug */
  165. }
  166. #ifdef USE_FULL_ASSERT
  167. /**
  168. * @brief Reports the name of the source file and the source line number
  169. * where the assert_param error has occurred.
  170. * @param file: pointer to the source file name
  171. * @param line: assert_param error line source number
  172. * @retval None
  173. */
  174. void assert_failed(uint8_t *file, uint32_t line)
  175. {
  176. /* USER CODE BEGIN 6 */
  177. /* User can add his own implementation to report the file name and line number,
  178. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  179. /* USER CODE END 6 */
  180. }
  181. #endif /* USE_FULL_ASSERT */