正点原子开发板 alientek_develop_board cancmder
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.

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