PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/p1/workspace/STM32Cube_FW_F4_V1.19.0/Projects/STM32F411RE-Nucleo/Examples_LL/UTILS/UTILS_ConfigureSystemClock/Src/main.c

https://bitbucket.org/pedromalagon/lse2018
C | 176 lines | 41 code | 25 blank | 110 comment | 2 complexity | 94266568c3c6f53b5c03db6adee9a898 MD5 | raw file
  1. /**
  2. ******************************************************************************
  3. * @file Examples_LL/UTILS/UTILS_ConfigureSystemClock/Src/main.c
  4. * @author MCD Application Team
  5. * @brief This example describes how to configure system clock using PLL with
  6. * HSI as source clock through the STM32F4xx UTILS LL API.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  11. *
  12. * Redistribution and use in source and binary forms, with or without modification,
  13. * are permitted provided that the following conditions are met:
  14. * 1. Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  29. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  31. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ******************************************************************************
  35. */
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "main.h"
  38. /** @addtogroup STM32F4xx_LL_Examples
  39. * @{
  40. */
  41. /** @addtogroup UTILS_ConfigureSystemClock
  42. * @{
  43. */
  44. /* Private typedef -----------------------------------------------------------*/
  45. /* Private define ------------------------------------------------------------*/
  46. /* Private macro -------------------------------------------------------------*/
  47. /* Private variables ---------------------------------------------------------*/
  48. /* Variable to store PLL parameters */
  49. /* Configuration will allow to reach a SYSCLK frequency set to 100MHz:
  50. Syst freq = ((HSI_VALUE / PLLM) * PLLN)/ PLLR)
  51. ((16MHz /8) * 200)/ 4) = 100MHz */
  52. LL_UTILS_PLLInitTypeDef sUTILS_PLLInitStruct = {LL_RCC_PLLM_DIV_8, 200, LL_RCC_PLLP_DIV_4};
  53. /* Variable to store AHB and APB buses clock configuration */
  54. /* Settings to have HCLK set to 100MHz, APB1 to 54MHz and APB2 to 100MHz */
  55. LL_UTILS_ClkInitTypeDef sUTILS_ClkInitStruct = {LL_RCC_SYSCLK_DIV_1, LL_RCC_APB1_DIV_2, LL_RCC_APB2_DIV_1};
  56. /* Private function prototypes -----------------------------------------------*/
  57. void LED_Init(void);
  58. void MCO_ConfigGPIO(void);
  59. /* Private functions ---------------------------------------------------------*/
  60. /**
  61. * @brief Main program
  62. * @param None
  63. * @retval None
  64. */
  65. int main(void)
  66. {
  67. /* System started with default clock used after reset */
  68. /* Set FLASH latency */
  69. LL_FLASH_SetLatency(LL_FLASH_LATENCY_3);
  70. /* Switch to PLL with HSI as clock source */
  71. LL_PLL_ConfigSystemClock_HSI(&sUTILS_PLLInitStruct, &sUTILS_ClkInitStruct);
  72. /*
  73. CMSIS variable automatically updated according to new configuration.
  74. SystemCoreClock should be equal to calculated HCLK frequency.
  75. FLASH latency is also tuned according to system constraints described
  76. in the reference manual.
  77. */
  78. /* Set Systick to 1ms in using frequency set to SystemCoreClock */
  79. LL_Init1msTick(SystemCoreClock);
  80. /* Initialize LED2 */
  81. LED_Init();
  82. /* Configure SYSCLK for MCO */
  83. MCO_ConfigGPIO();
  84. /* Toggle LED2 in an infinite loop with a period of 1Hz */
  85. while (1)
  86. {
  87. LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);
  88. LL_mDelay(1000);
  89. }
  90. }
  91. /**
  92. * @brief Initialize LED2.
  93. * @param None
  94. * @retval None
  95. */
  96. void LED_Init(void)
  97. {
  98. /* Enable the LED2 Clock */
  99. LED2_GPIO_CLK_ENABLE();
  100. /* Configure IO in output push-pull mode to drive external LED2 */
  101. LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT);
  102. /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */
  103. //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL);
  104. /* Reset value is LL_GPIO_SPEED_FREQ_LOW */
  105. //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW);
  106. /* Reset value is LL_GPIO_PULL_NO */
  107. //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO);
  108. }
  109. /**
  110. * @brief Configure MCO pin (PA8).
  111. * @param None
  112. * @retval None
  113. */
  114. void MCO_ConfigGPIO(void)
  115. {
  116. /* MCO Clock Enable */
  117. LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
  118. /* Configure the MCO pin in alternate function mode */
  119. LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_8, LL_GPIO_MODE_ALTERNATE);
  120. LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_8, LL_GPIO_OUTPUT_PUSHPULL);
  121. LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_8, LL_GPIO_SPEED_FREQ_HIGH);
  122. LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_8, LL_GPIO_PULL_NO);
  123. LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_8, LL_GPIO_AF_0);
  124. /* Select MCO clock source and prescaler */
  125. LL_RCC_ConfigMCO(LL_RCC_MCO1SOURCE_PLLCLK, LL_RCC_MCO1_DIV_4);
  126. }
  127. #ifdef USE_FULL_ASSERT
  128. /**
  129. * @brief Reports the name of the source file and the source line number
  130. * where the assert_param error has occurred.
  131. * @param file: pointer to the source file name
  132. * @param line: assert_param error line source number
  133. * @retval None
  134. */
  135. void assert_failed(uint8_t *file, uint32_t line)
  136. {
  137. /* User can add his own implementation to report the file name and line number,
  138. ex: printf("Wrong parameters value: file %s on line %d", file, line) */
  139. /* Infinite loop */
  140. while (1)
  141. {
  142. }
  143. }
  144. #endif
  145. /**
  146. * @}
  147. */
  148. /**
  149. * @}
  150. */
  151. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/