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.

232 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
2 years ago
2 years ago
2 years 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. /* USER CODE BEGIN 2 */
  84. /* USER CODE END 2 */
  85. /* Call init function for freertos objects (in cmsis_os2.c) */
  86. MX_FREERTOS_Init();
  87. /* Start scheduler */
  88. osKernelStart();
  89. /* We should never get here as control is now taken by the scheduler */
  90. /* Infinite loop */
  91. /* USER CODE BEGIN WHILE */
  92. while (1)
  93. {
  94. /* USER CODE END WHILE */
  95. /* USER CODE BEGIN 3 */
  96. }
  97. /* USER CODE END 3 */
  98. }
  99. /**
  100. * @brief System Clock Configuration
  101. * @retval None
  102. */
  103. void SystemClock_Config(void)
  104. {
  105. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  106. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  107. /** Configure the main internal regulator output voltage
  108. */
  109. __HAL_RCC_PWR_CLK_ENABLE();
  110. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  111. /** Initializes the RCC Oscillators according to the specified parameters
  112. * in the RCC_OscInitTypeDef structure.
  113. */
  114. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  115. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  116. RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  117. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  118. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  119. RCC_OscInitStruct.PLL.PLLM = 4;
  120. RCC_OscInitStruct.PLL.PLLN = 144;
  121. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  122. RCC_OscInitStruct.PLL.PLLQ = 6;
  123. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  124. {
  125. Error_Handler();
  126. }
  127. /** Initializes the CPU, AHB and APB buses clocks
  128. */
  129. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  130. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  131. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  132. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  133. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  134. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  135. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  136. {
  137. Error_Handler();
  138. }
  139. }
  140. /* USER CODE BEGIN 4 */
  141. // #if 0
  142. /* USER CODE END 4 */
  143. /**
  144. * @brief Period elapsed callback in non blocking mode
  145. * @note This function is called when TIM11 interrupt took place, inside
  146. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  147. * a global variable "uwTick" used as application time base.
  148. * @param htim : TIM handle
  149. * @retval None
  150. */
  151. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  152. {
  153. /* USER CODE BEGIN Callback 0 */
  154. /* USER CODE END Callback 0 */
  155. if (htim->Instance == TIM11) {
  156. HAL_IncTick();
  157. }
  158. /* USER CODE BEGIN Callback 1 */
  159. /* USER CODE END Callback 1 */
  160. }
  161. /**
  162. * @brief This function is executed in case of error occurrence.
  163. * @retval None
  164. */
  165. void Error_Handler(void)
  166. {
  167. /* USER CODE BEGIN Error_Handler_Debug */
  168. /* User can add his own implementation to report the HAL error return state */
  169. __disable_irq();
  170. while (1)
  171. {
  172. }
  173. /* USER CODE END Error_Handler_Debug */
  174. }
  175. #ifdef USE_FULL_ASSERT
  176. /**
  177. * @brief Reports the name of the source file and the source line number
  178. * where the assert_param error has occurred.
  179. * @param file: pointer to the source file name
  180. * @param line: assert_param error line source number
  181. * @retval None
  182. */
  183. void assert_failed(uint8_t *file, uint32_t line)
  184. {
  185. /* USER CODE BEGIN 6 */
  186. /* User can add his own implementation to report the file name and line number,
  187. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  188. /* USER CODE END 6 */
  189. }
  190. #endif /* USE_FULL_ASSERT */