main.c.bak 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. /* USER CODE END 2 */
  70. /* Infinite loop */
  71. /* USER CODE BEGIN WHILE */
  72. while (1)
  73. {
  74. /* USER CODE END WHILE */
  75. /* USER CODE BEGIN 3 */
  76. }
  77. /* USER CODE END 3 */
  78. }
  79. /**
  80. * @brief System Clock Configuration
  81. * @retval None
  82. */
  83. void SystemClock_Config(void)
  84. {
  85. LL_FLASH_SetLatency(LL_FLASH_LATENCY_1);
  86. while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_1)
  87. {
  88. }
  89. LL_RCC_HSI_Enable();
  90. /* Wait till HSI is ready */
  91. while(LL_RCC_HSI_IsReady() != 1)
  92. {
  93. }
  94. LL_RCC_HSI_SetCalibTrimming(16);
  95. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI_DIV_2, LL_RCC_PLL_MUL_12);
  96. LL_RCC_PLL_Enable();
  97. /* Wait till PLL is ready */
  98. while(LL_RCC_PLL_IsReady() != 1)
  99. {
  100. }
  101. LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  102. LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
  103. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  104. /* Wait till System clock is ready */
  105. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
  106. {
  107. }
  108. LL_Init1msTick(48000000);
  109. LL_SetSystemCoreClock(48000000);
  110. }
  111. /* USER CODE BEGIN 4 */
  112. /* USER CODE END 4 */
  113. /**
  114. * @brief This function is executed in case of error occurrence.
  115. * @retval None
  116. */
  117. void Error_Handler(void)
  118. {
  119. /* USER CODE BEGIN Error_Handler_Debug */
  120. /* User can add his own implementation to report the HAL error return state */
  121. __disable_irq();
  122. while (1)
  123. {
  124. }
  125. /* USER CODE END Error_Handler_Debug */
  126. }
  127. #ifdef USE_FULL_ASSERT
  128. /**
  129. * @brief Reports the name of the source file and the source line number
  130. * where the assert_param error has occurred.
  131. * @param file: pointer to the source file name
  132. * @param line: assert_param error line source number
  133. * @retval None
  134. */
  135. void assert_failed(uint8_t *file, uint32_t line)
  136. {
  137. /* USER CODE BEGIN 6 */
  138. /* User can add his own implementation to report the file name and line number,
  139. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  140. /* USER CODE END 6 */
  141. }
  142. #endif /* USE_FULL_ASSERT */