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
6.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 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 "lwip.h"
  23. #include "tim.h"
  24. #include "usart.h"
  25. #include "gpio.h"
  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. /* Private variables ---------------------------------------------------------*/
  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. /* Private function prototypes -----------------------------------------------*/
  47. /* USER CODE END PFP */
  48. /* Private user code ---------------------------------------------------------*/
  49. /* USER CODE BEGIN 0 */
  50. /* USER CODE END 0 */
  51. /**
  52. * @brief The application entry point.
  53. * @retval int
  54. */
  55. int main(void)
  56. {
  57. /* USER CODE BEGIN 1 */
  58. /* USER CODE END 1 */
  59. /* MCU Configuration--------------------------------------------------------*/
  60. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  61. HAL_Init();
  62. /* USER CODE BEGIN Init */
  63. /* USER CODE END Init */
  64. /* Configure the system clock */
  65. SystemClock_Config();
  66. /* USER CODE BEGIN SysInit */
  67. /* USER CODE END SysInit */
  68. /* Initialize all configured peripherals */
  69. MX_GPIO_Init();
  70. MX_TIM6_Init();
  71. MX_USART1_UART_Init();
  72. MX_TIM4_Init();
  73. /* USER CODE BEGIN 2 */
  74. /* USER CODE END 2 */
  75. /* Call init function for freertos objects (in freertos.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. /** Configure the main internal regulator output voltage
  98. */
  99. __HAL_RCC_PWR_CLK_ENABLE();
  100. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  101. /** Initializes the RCC Oscillators according to the specified parameters
  102. * in the RCC_OscInitTypeDef structure.
  103. */
  104. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  105. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  106. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  107. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  108. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  109. RCC_OscInitStruct.PLL.PLLM = 8;
  110. RCC_OscInitStruct.PLL.PLLN = 168;
  111. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  112. RCC_OscInitStruct.PLL.PLLQ = 4;
  113. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  114. {
  115. Error_Handler();
  116. }
  117. /** Initializes the CPU, AHB and APB buses clocks
  118. */
  119. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  120. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  121. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  122. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  123. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  124. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  125. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  126. {
  127. Error_Handler();
  128. }
  129. }
  130. /* USER CODE BEGIN 4 */
  131. /* USER CODE END 4 */
  132. /**
  133. * @brief Period elapsed callback in non blocking mode
  134. * @note This function is called when TIM1 interrupt took place, inside
  135. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  136. * a global variable "uwTick" used as application time base.
  137. * @param htim : TIM handle
  138. * @retval None
  139. */
  140. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  141. {
  142. /* USER CODE BEGIN Callback 0 */
  143. /* USER CODE END Callback 0 */
  144. if (htim->Instance == TIM1) {
  145. HAL_IncTick();
  146. }
  147. /* USER CODE BEGIN Callback 1 */
  148. /* USER CODE END Callback 1 */
  149. }
  150. /**
  151. * @brief This function is executed in case of error occurrence.
  152. * @retval None
  153. */
  154. void Error_Handler(void)
  155. {
  156. /* USER CODE BEGIN Error_Handler_Debug */
  157. /* User can add his own implementation to report the HAL error return state */
  158. while(1)
  159. {
  160. }
  161. /* USER CODE END Error_Handler_Debug */
  162. }
  163. #ifdef USE_FULL_ASSERT
  164. /**
  165. * @brief Reports the name of the source file and the source line number
  166. * where the assert_param error has occurred.
  167. * @param file: pointer to the source file name
  168. * @param line: assert_param error line source number
  169. * @retval None
  170. */
  171. void assert_failed(uint8_t *file, uint32_t line)
  172. {
  173. /* USER CODE BEGIN 6 */
  174. /* User can add his own implementation to report the file name and line number,
  175. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  176. /* USER CODE END 6 */
  177. }
  178. #endif /* USE_FULL_ASSERT */