You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

101 rivejä
3.2 KiB

  1. /* Includes ------------------------------------------------------------------*/
  2. #include "main.h"
  3. #include "stm32f4xx.h"
  4. #include "./led/bsp_led.h"
  5. static void SystemClock_Config(void);
  6. /**
  7. * @brief 主函数
  8. * @param 无
  9. * @retval 无
  10. */
  11. int main(void)
  12. {
  13. /* 系统时钟初始化成168MHz */
  14. SystemClock_Config();
  15. /* LED 端口初始化 */
  16. LED_GPIO_Config();
  17. /* 控制LED灯 */
  18. while (1)
  19. {
  20. LED1( ON ); // 亮
  21. HAL_Delay(100);
  22. LED1( OFF ); // 灭
  23. LED2( ON ); // 亮
  24. HAL_Delay(100);
  25. LED2( OFF ); // 灭
  26. }
  27. }
  28. /**
  29. * @brief System Clock Configuration
  30. * The system Clock is configured as follow :
  31. * System Clock source = PLL (HSE)
  32. * SYSCLK(Hz) = 168000000
  33. * HCLK(Hz) = 168000000
  34. * AHB Prescaler = 1
  35. * APB1 Prescaler = 4
  36. * APB2 Prescaler = 2
  37. * HSE Frequency(Hz) = 8000000
  38. * PLL_M = 25
  39. * PLL_N = 336
  40. * PLL_P = 2
  41. * PLL_Q = 7
  42. * VDD(V) = 3.3
  43. * Main regulator output voltage = Scale1 mode
  44. * Flash Latency(WS) = 5
  45. * @param None
  46. * @retval None
  47. */
  48. static void SystemClock_Config(void)
  49. {
  50. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  51. RCC_OscInitTypeDef RCC_OscInitStruct;
  52. /* Enable Power Control clock */
  53. __HAL_RCC_PWR_CLK_ENABLE();
  54. /* The voltage scaling allows optimizing the power consumption when the device is
  55. clocked below the maximum system frequency, to update the voltage scaling value
  56. regarding system frequency refer to product datasheet. */
  57. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  58. /* Enable HSE Oscillator and activate PLL with HSE as source */
  59. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  60. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  61. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  62. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  63. RCC_OscInitStruct.PLL.PLLM = 25;
  64. RCC_OscInitStruct.PLL.PLLN = 336;
  65. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  66. RCC_OscInitStruct.PLL.PLLQ = 7;
  67. if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  68. {
  69. while(1) {};
  70. }
  71. /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
  72. clocks dividers */
  73. RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  74. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  75. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  76. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  77. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  78. if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  79. {
  80. while(1) {};
  81. }
  82. /* STM32F405x/407x/415x/417x Revision Z devices: prefetch is supported */
  83. if (HAL_GetREVID() == 0x1001)
  84. {
  85. /* Enable the Flash prefetch */
  86. __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
  87. }
  88. }
  89. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/