Stm32 system clock configuration function

Source: Internet
Author: User
  1. /*************************************** *************************************
  2. *
  3. * Name: rcc_configuration
  4. *
  5. * Description: sets the system clock.
  6. *
  7. * Return value: None
  8. *
  9. **************************************** ************************************/
  10. Void rcc_configuration (void)
  11. {
  12. Errorstatus hsestartupstatus;
  13. Rcc_deinit (); // RCC Reset
  14. Rcc_hseconfig (rcc_hse_on); // enable external clock
  15. Hsestartupstatus = rcc_waitforhsestartup (); // wait until the external clock is ready
  16. If (hsestartupstatus = success)
  17. {
  18. Flash_prefetchbuffercmd (flash_prefetchbuffer_enable); // prefetch address cache enabling
  19. Flash_setlatency (flash_latency_2); // two-period flash memory latency
  20. Rcc_hclkconfig (rcc_sysclk_div1); // set the AHB clock to the system clock.
  21. Rcc_pclk2config (rcc_hclk_div1); // set high-speed clock to AHB clock
  22. Rcc_pclk1config (rcc_hclk_div2); // set the low-speed clock to AHB clock-2.
  23. Rcc_pllconfig (rcc_pllsource_hse_div1, rcc_pllmul_9); // set the PLL to 72 m
  24. Rcc_pllcmd (enable); // enable PLL
  25. While (rcc_getflagstatus (rcc_flag_pllrdy) = reset) // wait for the PLL
  26. {
  27. }
  28. Rcc_sysclkconfig (rcc_sysclksource_pllclk); // set the PLL to the system clock.
  29. While (rcc_getsysclksource ()! = 0x08) // wait until the setting is complete
  30. {
  31. }
  32. }
  33. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.