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.

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