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.

231 lines
6.0 KiB

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