main.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. ******************************************************************************
  3. * File Name : main.c
  4. * Description : Main program body
  5. ******************************************************************************
  6. *
  7. * COPYRIGHT(c) 2019 STMicroelectronics
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. * 1. Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. ******************************************************************************
  32. */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm32f2xx_hal.h"
  35. #include "dma.h"
  36. #include "sdio.h"
  37. #include "spi.h"
  38. #include "tim.h"
  39. #include "usart.h"
  40. #include "usb_device.h"
  41. #include "usb_otg_fs.h"
  42. #include "gpio.h"
  43. #include "fsmc.h"
  44. /* USER CODE BEGIN Includes */
  45. /* USER CODE END Includes */
  46. /* Private variables ---------------------------------------------------------*/
  47. /* USER CODE BEGIN PV */
  48. /* Private variables ---------------------------------------------------------*/
  49. /* USER CODE END PV */
  50. /* Private function prototypes -----------------------------------------------*/
  51. void SystemClock_Config(void);
  52. /* USER CODE BEGIN PFP */
  53. /* Private function prototypes -----------------------------------------------*/
  54. void mainEarlyInit();
  55. void mainInit();
  56. void mainLoop();
  57. /* USER CODE END PFP */
  58. /* USER CODE BEGIN 0 */
  59. /* USER CODE END 0 */
  60. int main(void)
  61. {
  62. /* USER CODE BEGIN 1 */
  63. mainEarlyInit();
  64. /* USER CODE END 1 */
  65. /* MCU Configuration----------------------------------------------------------*/
  66. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  67. HAL_Init();
  68. /* Configure the system clock */
  69. SystemClock_Config();
  70. /* Initialize all configured peripherals */
  71. MX_GPIO_Init();
  72. MX_DMA_Init();
  73. SystemClock_Config();
  74. MX_FSMC_Init();
  75. MX_SDIO_SD_Init();
  76. MX_SPI1_Init();
  77. MX_TIM4_Init();
  78. MX_USB_DEVICE_Init();
  79. MX_UART4_Init();
  80. MX_USB_OTG_FS_PCD_Init();
  81. /* USER CODE BEGIN 2 */
  82. mainInit();
  83. /* USER CODE END 2 */
  84. /* Infinite loop */
  85. /* USER CODE BEGIN WHILE */
  86. while (1)
  87. {
  88. /* USER CODE END WHILE */
  89. /* USER CODE BEGIN 3 */
  90. mainLoop();
  91. }
  92. /* USER CODE END 3 */
  93. }
  94. /** System Clock Configuration
  95. */
  96. void SystemClock_Config(void)
  97. {
  98. RCC_OscInitTypeDef RCC_OscInitStruct;
  99. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  100. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  101. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  102. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  103. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  104. RCC_OscInitStruct.PLL.PLLM = 20;
  105. RCC_OscInitStruct.PLL.PLLN = 432;
  106. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  107. RCC_OscInitStruct.PLL.PLLQ = 9;
  108. HAL_RCC_OscConfig(&RCC_OscInitStruct);
  109. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
  110. |RCC_CLOCKTYPE_PCLK2;
  111. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  112. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  113. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  114. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  115. HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
  116. HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_1);
  117. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  118. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  119. /* SysTick_IRQn interrupt configuration */
  120. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  121. }
  122. /* USER CODE BEGIN 4 */
  123. /* USER CODE END 4 */
  124. #ifdef USE_FULL_ASSERT
  125. /**
  126. * @brief Reports the name of the source file and the source line number
  127. * where the assert_param error has occurred.
  128. * @param file: pointer to the source file name
  129. * @param line: assert_param error line source number
  130. * @retval None
  131. */
  132. void assert_failed(uint8_t* file, uint32_t line)
  133. {
  134. /* USER CODE BEGIN 6 */
  135. /* User can add his own implementation to report the file name and line number,
  136. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  137. /* USER CODE END 6 */
  138. }
  139. #endif
  140. /**
  141. * @}
  142. */
  143. /**
  144. * @}
  145. */
  146. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/