main.c 7.2 KB

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