main.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2026 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 "i2c.h"
  22. #include "ltdc.h"
  23. #include "quadspi.h"
  24. #include "usart.h"
  25. #include "gpio.h"
  26. #include "fmc.h"
  27. /* Private includes ----------------------------------------------------------*/
  28. /* USER CODE BEGIN Includes */
  29. #include "stdio.h"
  30. #include "string.h"
  31. #include "Int_sdram.h"
  32. #include "Int_mpu.h"
  33. #include "Int_lcd.h"
  34. #include "FreeRTOS.h"
  35. #include "task.h"
  36. #include "App_freertosTask.h"
  37. /* USER CODE END Includes */
  38. /* Private typedef -----------------------------------------------------------*/
  39. /* USER CODE BEGIN PTD */
  40. /* USER CODE END PTD */
  41. /* Private define ------------------------------------------------------------*/
  42. /* USER CODE BEGIN PD */
  43. /* USER CODE END PD */
  44. /* Private macro -------------------------------------------------------------*/
  45. /* USER CODE BEGIN PM */
  46. /* USER CODE END PM */
  47. /* Private variables ---------------------------------------------------------*/
  48. /* USER CODE BEGIN PV */
  49. /* USER CODE END PV */
  50. /* Private function prototypes -----------------------------------------------*/
  51. void SystemClock_Config(void);
  52. static void MPU_Config(void);
  53. /* USER CODE BEGIN PFP */
  54. /* USER CODE END PFP */
  55. /* Private user code ---------------------------------------------------------*/
  56. /* USER CODE BEGIN 0 */
  57. void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
  58. {
  59. printf("Task stack overflow");
  60. while (1) {
  61. }
  62. }
  63. /* USER CODE END 0 */
  64. /**
  65. * @brief The application entry point.
  66. * @retval int
  67. */
  68. int main(void)
  69. {
  70. /* USER CODE BEGIN 1 */
  71. /* USER CODE END 1 */
  72. /* MPU Configuration--------------------------------------------------------*/
  73. MPU_Config();
  74. /* Enable the CPU Cache */
  75. /* Enable I-Cache---------------------------------------------------------*/
  76. SCB_EnableICache();
  77. /* Enable D-Cache---------------------------------------------------------*/
  78. SCB_EnableDCache();
  79. /* MCU Configuration--------------------------------------------------------*/
  80. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  81. HAL_Init();
  82. /* USER CODE BEGIN Init */
  83. /* USER CODE END Init */
  84. /* Configure the system clock */
  85. SystemClock_Config();
  86. /* USER CODE BEGIN SysInit */
  87. /* USER CODE END SysInit */
  88. /* Initialize all configured peripherals */
  89. MX_GPIO_Init();
  90. MX_FMC_Init();
  91. MX_QUADSPI_Init();
  92. MX_USART1_UART_Init();
  93. MX_I2C2_Init();
  94. MX_LTDC_Init();
  95. /* USER CODE BEGIN 2 */
  96. printf("hello h743\r\n");
  97. Int_sdram_init();
  98. Int_lcd_init();
  99. printf("System Init OK\r\n");
  100. /* USER CODE END 2 */
  101. /* Infinite loop */
  102. /* USER CODE BEGIN WHILE */
  103. App_Task_Create();
  104. vTaskStartScheduler();
  105. while (1)
  106. {
  107. printf("FreeRTOS scheduler exited unexpectedly!\r\n");
  108. /* USER CODE END WHILE */
  109. /* USER CODE BEGIN 3 */
  110. }
  111. /* USER CODE END 3 */
  112. }
  113. /**
  114. * @brief System Clock Configuration
  115. * @retval None
  116. */
  117. void SystemClock_Config(void)
  118. {
  119. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  120. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  121. /** Supply configuration update enable
  122. */
  123. HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
  124. /** Configure the main internal regulator output voltage
  125. */
  126. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
  127. while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
  128. /** Initializes the RCC Oscillators according to the specified parameters
  129. * in the RCC_OscInitTypeDef structure.
  130. */
  131. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  132. RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
  133. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  134. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  135. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  136. RCC_OscInitStruct.PLL.PLLM = 4;
  137. RCC_OscInitStruct.PLL.PLLN = 60;
  138. RCC_OscInitStruct.PLL.PLLP = 2;
  139. RCC_OscInitStruct.PLL.PLLQ = 2;
  140. RCC_OscInitStruct.PLL.PLLR = 2;
  141. RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
  142. RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
  143. RCC_OscInitStruct.PLL.PLLFRACN = 0;
  144. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  145. {
  146. Error_Handler();
  147. }
  148. /** Initializes the CPU, AHB and APB buses clocks
  149. */
  150. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  151. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
  152. |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
  153. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  154. RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
  155. RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
  156. RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
  157. RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
  158. RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
  159. RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
  160. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  161. {
  162. Error_Handler();
  163. }
  164. }
  165. /* USER CODE BEGIN 4 */
  166. /* USER CODE END 4 */
  167. /* MPU Configuration */
  168. void MPU_Config(void)
  169. {
  170. /* Disables the MPU */
  171. HAL_MPU_Disable();
  172. /* Enables the MPU */
  173. HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
  174. }
  175. /**
  176. * @brief Period elapsed callback in non blocking mode
  177. * @note This function is called when TIM2 interrupt took place, inside
  178. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  179. * a global variable "uwTick" used as application time base.
  180. * @param htim : TIM handle
  181. * @retval None
  182. */
  183. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  184. {
  185. /* USER CODE BEGIN Callback 0 */
  186. /* USER CODE END Callback 0 */
  187. if (htim->Instance == TIM2)
  188. {
  189. HAL_IncTick();
  190. }
  191. /* USER CODE BEGIN Callback 1 */
  192. /* USER CODE END Callback 1 */
  193. }
  194. /**
  195. * @brief This function is executed in case of error occurrence.
  196. * @retval None
  197. */
  198. void Error_Handler(void)
  199. {
  200. /* USER CODE BEGIN Error_Handler_Debug */
  201. /* User can add his own implementation to report the HAL error return state */
  202. __disable_irq();
  203. while (1)
  204. {
  205. }
  206. /* USER CODE END Error_Handler_Debug */
  207. }
  208. #ifdef USE_FULL_ASSERT
  209. /**
  210. * @brief Reports the name of the source file and the source line number
  211. * where the assert_param error has occurred.
  212. * @param file: pointer to the source file name
  213. * @param line: assert_param error line source number
  214. * @retval None
  215. */
  216. void assert_failed(uint8_t *file, uint32_t line)
  217. {
  218. /* USER CODE BEGIN 6 */
  219. /* User can add his own implementation to report the file name and line number,
  220. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  221. /* USER CODE END 6 */
  222. }
  223. #endif /* USE_FULL_ASSERT */