main.c 7.8 KB

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