{"id":1553,"date":"2023-02-24T04:38:17","date_gmt":"2023-02-24T04:38:17","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1553"},"modified":"2023-02-25T16:46:54","modified_gmt":"2023-02-25T16:46:54","slug":"getting-started-with-stm32f103-pushing-cpu-to-72mhz","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1553","title":{"rendered":"Getting Started with STM32F103:  Pushing CPU to 72MHz"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-medium\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"300\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-300x300.jpeg\" alt=\"\" class=\"wp-image-1554\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-300x300.jpeg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-1024x1024.jpeg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-150x150.jpeg 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-768x768.jpeg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-1536x1536.jpeg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-2048x2048.jpeg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-1150x1150.jpeg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-750x750.jpeg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-400x400.jpeg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/AdobeStock_353303709-250x250.jpeg 250w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n\n\n\n<p>In this guide, we shall see how to configure the core of STM32F103 and make it to run at 72MHz which is the maximum core frequency for F103C8.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Getting the correct parameters from CubeMX.<\/li><li>Setting the core frequency using registers.<\/li><li>Validating the frequency.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Getting the correct parameters from CubeMX:<\/h2>\n\n\n\n<p>Open STM32CubeMX and select the STM32F103 as the main mcu.<\/p>\n\n\n\n<p>After selecting the MUC, head to System Core, RCC and select High speed oscillator as external ceramic oscillator:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_06-56-58-1024x640.png\" alt=\"\" class=\"wp-image-1555\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_06-56-58-1024x640.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_06-56-58-300x188.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_06-56-58-768x480.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_06-56-58-1536x960.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_06-56-58-2048x1280.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_06-56-58-1150x719.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_06-56-58-750x469.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_06-56-58-400x250.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_06-56-58-250x156.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Then from Clock configuration, set the external oscillator to 8MHz, PLL source to be HSE, System Clock Mux from PLL and set the frequency to 72 and hit enter:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-03-30-1024x640.png\" alt=\"\" class=\"wp-image-1556\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-03-30-1024x640.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-03-30-300x188.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-03-30-768x480.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-03-30-1536x960.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-03-30-2048x1280.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-03-30-1150x719.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-03-30-750x469.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-03-30-400x250.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-03-30-250x156.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>After the configuration is finished, take note for the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>PLLMUL=9<\/li><li>AHB Prescaler 1<\/li><li>APB1 Prescaler 2<\/li><li>APB2 Prescaler 1<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>Head back to RCC section is System Core and notice the prefetch if it enabled and flash latency:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"603\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-08-22-1024x603.png\" alt=\"\" class=\"wp-image-1557\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-08-22-1024x603.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-08-22-300x177.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-08-22-768x452.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-08-22-1150x677.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-08-22-750x441.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-08-22-400x235.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-08-22-250x147.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/2023-02-24_07-08-22.png 1196w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In this case, the prefetch is enabled and flash latency is 2WS.<\/p>\n\n\n\n<p>Now, we have all the required information. Next, we shall configure the required register.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Setting the core frequency using registers:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>We start off by creating new source file and name it as core.c.<\/p>\n\n\n\n<p>Within core.c, include the main chip header as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stm32f1xx.h&quot;<\/pre><\/div>\n\n\n\n<p>Declare the following function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void SystemInit(void)<\/pre><\/div>\n\n\n\n<p>This function will be called once the mcu is started before the main function starts.<\/p>\n\n\n\n<p>Within the function:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Set the PLLMUL to 9 as following:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"428\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.16.06-AM-1024x428.png\" alt=\"\" class=\"wp-image-1558\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.16.06-AM-1024x428.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.16.06-AM-300x125.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.16.06-AM-768x321.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.16.06-AM-1536x641.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.16.06-AM-2048x855.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.16.06-AM-1150x480.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.16.06-AM-750x313.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.16.06-AM-400x167.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.16.06-AM-250x104.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t  RCC-&gt;CFGR &amp;= ~RCC_CFGR_PLLMULL_Msk; \/\/Clear\n\t  RCC-&gt;CFGR |= (0x7UL &lt;&lt; RCC_CFGR_PLLMULL_Pos);<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>Set the USB prescaler to 1.5:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"428\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.17.28-AM-1024x428.png\" alt=\"\" class=\"wp-image-1559\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.17.28-AM-1024x428.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.17.28-AM-300x125.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.17.28-AM-768x321.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.17.28-AM-1536x641.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.17.28-AM-2048x855.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.17.28-AM-1150x480.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.17.28-AM-750x313.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.17.28-AM-400x167.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.17.28-AM-250x104.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t  \/\/USB Prescaler = 1.5\n\t  RCC-&gt;CFGR &amp;= ~(0x1UL &lt;&lt; 22);<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>Enable External oscillator and wait until it is ready:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"386\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.18.33-AM-1024x386.png\" alt=\"\" class=\"wp-image-1560\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.18.33-AM-1024x386.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.18.33-AM-300x113.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.18.33-AM-768x289.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.18.33-AM-1536x579.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.18.33-AM-2048x772.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.18.33-AM-1150x433.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.18.33-AM-750x283.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.18.33-AM-400x151.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.18.33-AM-250x94.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t  \/\/Enable HSE Clock\n\t  RCC-&gt;CR |= RCC_CR_HSEON;\n\t  \/\/Wait for HSE to be stable and ready to use\n\t  while((RCC-&gt;CR &amp; RCC_CR_HSERDY) == 0);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Select the source as PLL:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"386\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.20.30-AM-1024x386.png\" alt=\"\" class=\"wp-image-1561\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.20.30-AM-1024x386.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.20.30-AM-300x113.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.20.30-AM-768x289.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.20.30-AM-1536x579.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.20.30-AM-2048x772.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.20.30-AM-1150x433.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.20.30-AM-750x283.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.20.30-AM-400x151.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.20.30-AM-250x94.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t  \/\/HSE as PLL source\n\t  RCC-&gt;CFGR |= RCC_CFGR_PLLSRC;<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>Turn the PLL and wait until it is read:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"355\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.23.53-AM-1024x355.png\" alt=\"\" class=\"wp-image-1562\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.23.53-AM-1024x355.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.23.53-AM-300x104.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.23.53-AM-768x267.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.23.53-AM-1536x533.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.23.53-AM-2048x711.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.23.53-AM-1150x399.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.23.53-AM-750x260.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.23.53-AM-400x139.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.23.53-AM-250x87.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/Enable the PLL\n\t  RCC-&gt;CR |= RCC_CR_PLLON;\n\t  \/\/Wait until PLL is ready\n\t  while((RCC-&gt;CR &amp; RCC_CR_PLLRDY) == 0);<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>Enable prefetch and set the latency of the flash to 2WS:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"719\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.26.22-AM-1024x719.png\" alt=\"\" class=\"wp-image-1563\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.26.22-AM-1024x719.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.26.22-AM-300x211.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.26.22-AM-768x539.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.26.22-AM-1536x1079.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.26.22-AM-2048x1438.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.26.22-AM-1150x808.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.26.22-AM-750x527.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.26.22-AM-400x281.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.26.22-AM-250x176.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t  \/\/Flash pre-fetch enable and wait-state=2\n\t  \/\/0WS: 0-24MHz\n\t  \/\/1WS: 24-48MHz\n\t  \/\/2WS: 48-72MHz\n\t  FLASH-&gt;ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY_1;<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>Select PLL as the main clock source and wait until the source is set:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"393\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.31.52-AM-1024x393.png\" alt=\"\" class=\"wp-image-1564\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.31.52-AM-1024x393.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.31.52-AM-300x115.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.31.52-AM-768x294.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.31.52-AM-1536x589.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.31.52-AM-2048x785.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.31.52-AM-1150x441.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.31.52-AM-750x288.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.31.52-AM-400x153.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.31.52-AM-250x96.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">      \/\/Select PLL as main System Clock source\n\t  RCC-&gt;CFGR &amp;= ~RCC_CFGR_SW;\n\t  RCC-&gt;CFGR |= RCC_CFGR_SW_1;\n\t  \/\/Wait until PLL system source is active\n\t  while((RCC-&gt;CFGR &amp; RCC_CFGR_SWS) != RCC_CFGR_SWS_1);<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>Set the AHB, APB1 and APB2 prescaler and ADC prescaler to 12:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"381\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.33.40-AM-1024x381.png\" alt=\"\" class=\"wp-image-1565\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.33.40-AM-1024x381.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.33.40-AM-300x112.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.33.40-AM-768x286.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.33.40-AM-1536x572.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.33.40-AM-2048x763.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.33.40-AM-1150x428.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.33.40-AM-750x279.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.33.40-AM-400x149.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-24-at-7.33.40-AM-250x93.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/AHB Prescaler = 1\n\t  RCC-&gt;CFGR &amp;= ~RCC_CFGR_HPRE;\n\t  \/\/APB1 divider=2\n\t  RCC-&gt;CFGR &amp;= ~RCC_CFGR_PPRE1;\n\t  RCC-&gt;CFGR |= RCC_CFGR_PPRE1_2;\n\t  \/\/APB2 divider=1\n\t  RCC-&gt;CFGR &amp;= ~RCC_CFGR_PPRE2;\n\t  \/\/ADC prescalar = 12\n\t  RCC-&gt;CFGR &amp;= ~RCC_CFGR_ADCPRE;\n\t  RCC-&gt;CFGR |= RCC_CFGR_ADCPRE_1;\n<\/pre><\/div>\n\n\n\n<p>Thats all for the configuration.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Validating the frequency:<\/h2>\n\n\n\n<p>Now, we shall validate the frequency using timer2 in output compare. For more details check <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=1468\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=1468\" target=\"_blank\">this<\/a> topic.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stm32f1xx.h&quot;\n\n\n\n\n\nint main(void)\n{\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_IOPAEN;\n\n\t\t\/*Configure PA0 as Output Alternate Push\/Pull *\/\n\t\tGPIOA-&gt;CRL|=GPIO_CRL_MODE0;\n\t\tGPIOA-&gt;CRL|=(GPIO_CRL_CNF0_1);\n\t\tGPIOA-&gt;CRL&amp;=~(GPIO_CRL_CNF0_0);\n\n\t\t\/*Don't remap the pin*\/\n\t\tAFIO-&gt;MAPR&amp;=~AFIO_MAPR_TIM2_REMAP;\n\n\n\t\t\/*Enable clock access to timer2*\/\n\t\tRCC-&gt;APB1ENR|=RCC_APB1ENR_TIM2EN;\n\n\t\t\/*Configure timer2*\/\n\t\tTIM2-&gt;PSC=7200-1;\n\t\tTIM2-&gt;ARR=10000-1;\n\t\tTIM2-&gt;CCMR1|=TIM_CCMR1_OC1M_0|TIM_CCMR1_OC1M_1;\n\t\tTIM2-&gt;CCER|=TIM_CCER_CC1E;\n\t\tTIM2-&gt;CR1|=TIM_CR1_CEN;\n\n\twhile(1)\n\t{\n\n\n\t}\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>You should get 1 second toggle rate as shown in this video:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Delay using timer on STM32F1\" width=\"1170\" height=\"658\" src=\"https:\/\/www.youtube.com\/embed\/0EAgGxb0KVQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall see how to configure the core of STM32F103 and make it to run at 72MHz which is the maximum core frequency for F103C8. In this guide, we shall cover the following: Getting the correct parameters from CubeMX. Setting the core frequency using registers. Validating the frequency. 1. Getting the correct [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,12],"tags":[],"class_list":["post-1553","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1553"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1553"}],"version-history":[{"count":3,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1553\/revisions"}],"predecessor-version":[{"id":1573,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1553\/revisions\/1573"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}