{"id":454,"date":"2021-09-27T05:50:50","date_gmt":"2021-09-27T05:50:50","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=454"},"modified":"2021-09-27T05:50:53","modified_gmt":"2021-09-27T05:50:53","slug":"changing-core-frequency-of-stm32f411-using-registers-only","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=454","title":{"rendered":"Changing core frequency of STM32F411 using registers only"},"content":{"rendered":"\n<p>In this guide, we shall use registers to change the core frequency from default 16MHz to 100MHz (maximum for F411RE).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-medium\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"229\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/depositphotos_107252360-stock-illustration-maximum-speed-logo-icon-300x229.jpg\" alt=\"\" class=\"wp-image-455\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/depositphotos_107252360-stock-illustration-maximum-speed-logo-icon-300x229.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/depositphotos_107252360-stock-illustration-maximum-speed-logo-icon-768x587.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/depositphotos_107252360-stock-illustration-maximum-speed-logo-icon-750x573.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/depositphotos_107252360-stock-illustration-maximum-speed-logo-icon-400x305.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/depositphotos_107252360-stock-illustration-maximum-speed-logo-icon-250x191.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/depositphotos_107252360-stock-illustration-maximum-speed-logo-icon.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n\n\n\n<p>We shall use both keil uVision and STM32CubeIDE to change the core frequency to 100MHz.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Open CubMX <\/h2>\n\n\n\n<p>After you select your MCU, head to RCC and select external oscillator<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"480\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.19.24-AM-1024x480.png\" alt=\"\" class=\"wp-image-457\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.19.24-AM-1024x480.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.19.24-AM-300x141.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.19.24-AM-768x360.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.19.24-AM-1536x720.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.19.24-AM-2048x959.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.19.24-AM-1150x539.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.19.24-AM-750x351.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.19.24-AM-400x187.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.19.24-AM-250x117.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then open clock configuration and set the external oscillator to one on your board (in my case is 8MHz).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"746\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.25.23-AM-1024x746.png\" alt=\"\" class=\"wp-image-458\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.25.23-AM-1024x746.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.25.23-AM-300x219.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.25.23-AM-768x559.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.25.23-AM-1536x1119.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.25.23-AM-2048x1492.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.25.23-AM-1150x838.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.25.23-AM-750x546.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.25.23-AM-400x291.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.25.23-AM-250x182.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Note the following Values:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>PLL_M<\/li><li>PLL_N<\/li><li>PLL_P<\/li><li>Also, APB1 and APB2 prescalers<\/li><\/ul>\n\n\n\n<p>In my case they are the 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;}\">#define PLL_M      4\n#define PLL_N      200\n#define PLL_P      4<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">2. Start new project<\/h2>\n\n\n\n<p>Open either CubeIDE or Keil uVision and start new project <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Open system_stm32f4xx.c<\/h2>\n\n\n\n<p>Open system_stm32f4xx.c file and change the external frequency from 25MHz to one on your board (8MHz in my case).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"746\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.29.22-AM-1024x746.png\" alt=\"\" class=\"wp-image-459\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.29.22-AM-1024x746.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.29.22-AM-300x219.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.29.22-AM-768x559.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.29.22-AM-1536x1119.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.29.22-AM-2048x1492.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.29.22-AM-1150x838.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.29.22-AM-750x546.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.29.22-AM-400x291.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-27-at-8.29.22-AM-250x182.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4. Start the configuration<\/h2>\n\n\n\n<p>We start of by enabling external clock and waiting for the external clock to be ready<\/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;}\">__IO uint32_t StartUpCounter = 0, HSEStatus = 0;\n\n\n  RCC-&gt;CR |= ((uint32_t)RCC_CR_HSEON);\n\n\n  do\n  {\n    HSEStatus = RCC-&gt;CR &amp; RCC_CR_HSERDY;\n    StartUpCounter++;\n  } while((HSEStatus == 0) &amp;&amp; (StartUpCounter != 3000));<\/pre><\/div>\n\n\n\n<p>then if the external clock is enable, proceed to change the core frequency 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;}\">if ((RCC-&gt;CR &amp; RCC_CR_HSERDY) != RESET) \/\/HSE enabled\n  {\n    HSEStatus = (uint32_t)0x01;\n  }\n  else\n  {\n    HSEStatus = (uint32_t)0x00;\n  }\n\n  if (HSEStatus == (uint32_t)0x01)\n  {\n\n    RCC-&gt;APB1ENR |= RCC_APB1ENR_PWREN; \/\/enable opwer regultor\n    PWR-&gt;CR &amp;= (uint32_t)~(PWR_CR_VOS); \/\/reset VOS (mode 3 selected)\n\n\n    RCC-&gt;CFGR |= RCC_CFGR_HPRE_DIV1; \/\/configure AHB1 bus prescaler to 1\n\n\n    RCC-&gt;CFGR |= RCC_CFGR_PPRE2_DIV1; \/\/APB2 prescaler to 1\n\n\n    RCC-&gt;CFGR |= RCC_CFGR_PPRE1_DIV2; \/\/APB2 prescaler to 2\n\n\n    RCC-&gt;PLLCFGR = PLL_M | (PLL_N &lt;&lt; 6) | (((PLL_P &gt;&gt; 1) -1) &lt;&lt; 16) | \/\/set PLL_M,PLL_N,PLL_P \n                   (RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q &lt;&lt; 24);\n\n\n    RCC-&gt;CR |= RCC_CR_PLLON; \/\/turn on the PLL\n\n\n    while((RCC-&gt;CR &amp; RCC_CR_PLLRDY) == 0) \/\/wait untill PLL is active\n    {\n    }\n\n    \/* Configure Flash prefetch, Instruction cache, Data cache and wait state *\/\n    FLASH-&gt;ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_3WS;\n\n    \/* Select the main PLL as system clock source *\/\n    RCC-&gt;CFGR &amp;= (uint32_t)((uint32_t)~(RCC_CFGR_SW));\n    RCC-&gt;CFGR |= RCC_CFGR_SW_PLL;\n\n    \/* Wait till the main PLL is used as system clock source *\/\n    while ((RCC-&gt;CFGR &amp; (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL)\n    {;}\n  }\n  else\n  { \/* If HSE fails to start-up, the application will have wrong clock\n         configuration. User can add here some code to deal with this error *\/\n  }<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">5. Testing using SysTick delay<\/h2>\n\n\n\n<p>We can test the core frequency using SysTick to generate delay 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;}\">void delay(int ms)\n{\n\tSysTick-&gt;LOAD=100000-1;\n\tSysTick-&gt;VAL=0;\n\tSysTick-&gt;CTRL=0x5;\n\t\tfor (int i=0;i&lt;ms;i++)\n\t\t{\n\t\t\twhile(!(SysTick-&gt;CTRL &amp;0x10000)){}\n\t\t}\n\tSysTick-&gt;CTRL=0;\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">6. Download source Code<\/h2>\n\n\n\n<p>You may download the entire project from here<\/p>\n\n\n\n<p>Keil uVison version<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Change-core-100MHz.zip\">Change-core-100MHz<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Change-core-100MHz.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p>STM32CubeIDE version<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/100MHz.zip\">100MHz<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/100MHz.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">7. Demo<\/h2>\n\n\n\n<figure class=\"wp-block-video\"><video controls src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/IMG_6565.mp4\"><\/video><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall use registers to change the core frequency from default 16MHz to 100MHz (maximum for F411RE). We shall use both keil uVision and STM32CubeIDE to change the core frequency to 100MHz. 1. Open CubMX After you select your MCU, head to RCC and select external oscillator Then open clock configuration and [&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-454","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\/454"}],"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=454"}],"version-history":[{"count":3,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/454\/revisions"}],"predecessor-version":[{"id":464,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/454\/revisions\/464"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}