main.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2022 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 "spi.h"
  22. #include "gpio.h"
  23. /* Private includes ----------------------------------------------------------*/
  24. /* USER CODE BEGIN Includes */
  25. /* USER CODE END Includes */
  26. /* Private typedef -----------------------------------------------------------*/
  27. /* USER CODE BEGIN PTD */
  28. /* USER CODE END PTD */
  29. /* Private define ------------------------------------------------------------*/
  30. /* USER CODE BEGIN PD */
  31. /* USER CODE END PD */
  32. /* Private macro -------------------------------------------------------------*/
  33. /* USER CODE BEGIN PM */
  34. /* USER CODE END PM */
  35. /* Private variables ---------------------------------------------------------*/
  36. /* USER CODE BEGIN PV */
  37. /* USER CODE END PV */
  38. /* Private function prototypes -----------------------------------------------*/
  39. void SystemClock_Config(void);
  40. /* USER CODE BEGIN PFP */
  41. /* USER CODE END PFP */
  42. /* Private user code ---------------------------------------------------------*/
  43. /* USER CODE BEGIN 0 */
  44. /* USER CODE END 0 */
  45. /**
  46. * @brief The application entry point.
  47. * @retval int
  48. */
  49. int main(void)
  50. {
  51. /* USER CODE BEGIN 1 */
  52. /* USER CODE END 1 */
  53. /* MCU Configuration--------------------------------------------------------*/
  54. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  55. LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SYSCFG);
  56. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
  57. /* SysTick_IRQn interrupt configuration */
  58. NVIC_SetPriority(SysTick_IRQn, 3);
  59. /* USER CODE BEGIN Init */
  60. /* USER CODE END Init */
  61. /* Configure the system clock */
  62. SystemClock_Config();
  63. /* USER CODE BEGIN SysInit */
  64. /* USER CODE END SysInit */
  65. /* Initialize all configured peripherals */
  66. MX_GPIO_Init();
  67. MX_SPI1_Init();
  68. /* USER CODE BEGIN 2 */
  69. maincpp();
  70. /* USER CODE END 2 */
  71. /* Infinite loop */
  72. /* USER CODE BEGIN WHILE */
  73. while (1)
  74. {
  75. /* USER CODE END WHILE */
  76. /* USER CODE BEGIN 3 */
  77. }
  78. /* USER CODE END 3 */
  79. }
  80. /**
  81. * @brief System Clock Configuration
  82. * @retval None
  83. */
  84. void SystemClock_Config(void)
  85. {
  86. LL_FLASH_SetLatency(LL_FLASH_LATENCY_1);
  87. while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_1)
  88. {
  89. }
  90. LL_RCC_HSI_Enable();
  91. /* Wait till HSI is ready */
  92. while(LL_RCC_HSI_IsReady() != 1)
  93. {
  94. }
  95. LL_RCC_HSI_SetCalibTrimming(16);
  96. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI_DIV_2, LL_RCC_PLL_MUL_12);
  97. LL_RCC_PLL_Enable();
  98. /* Wait till PLL is ready */
  99. while(LL_RCC_PLL_IsReady() != 1)
  100. {
  101. }
  102. LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  103. LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
  104. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  105. /* Wait till System clock is ready */
  106. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
  107. {
  108. }
  109. LL_Init1msTick(48000000);
  110. LL_SetSystemCoreClock(48000000);
  111. }
  112. /* USER CODE BEGIN 4 */
  113. /* USER CODE END 4 */
  114. /**
  115. * @brief This function is executed in case of error occurrence.
  116. * @retval None
  117. */
  118. void Error_Handler(void)
  119. {
  120. /* USER CODE BEGIN Error_Handler_Debug */
  121. /* User can add his own implementation to report the HAL error return state */
  122. __disable_irq();
  123. while (1)
  124. {
  125. }
  126. /* USER CODE END Error_Handler_Debug */
  127. }
  128. #ifdef USE_FULL_ASSERT
  129. /**
  130. * @brief Reports the name of the source file and the source line number
  131. * where the assert_param error has occurred.
  132. * @param file: pointer to the source file name
  133. * @param line: assert_param error line source number
  134. * @retval None
  135. */
  136. void assert_failed(uint8_t *file, uint32_t line)
  137. {
  138. /* USER CODE BEGIN 6 */
  139. /* User can add his own implementation to report the file name and line number,
  140. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  141. /* USER CODE END 6 */
  142. }
  143. #endif /* USE_FULL_ASSERT */