{"id":1172,"date":"2022-08-24T04:15:50","date_gmt":"2022-08-24T04:15:50","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1172"},"modified":"2022-08-24T04:18:02","modified_gmt":"2022-08-24T04:18:02","slug":"hanging-core-frequency-of-stm32l053-using-registers-only","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1172","title":{"rendered":"Changing core frequency of STM32L053 using registers only"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" 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\" width=\"300\" height=\"229\" 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>In this guide, we shall see how to push STM32L053 to run at 32MHz rather than the default frequency of 2.096 MHz.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Steps:<\/h2>\n\n\n\n<p>In order to push STM32L053 to maximum, we shall use external oscillator. Since the Nucleo-L053 has built-in 8Mhz generated from ST-Link, we shall use that as our oscillator. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The steps are as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Set flash latency to 1WS (waiting cycle).<\/li><li>Bypass the HSE oscillator.<\/li><li>Enable HSE.<\/li><li>Disable the PLL.<\/li><li>Configure the PLL.<\/li><li>Enable the PLL.<\/li><li>Select the PLL as the clock source.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Coding:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>Create a new source and header file with name of core.c and core.h<\/p>\n\n\n\n<p>Inside core.c, create a 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 config_core_32mhz()\n{\n}<\/pre><\/div>\n\n\n\n<p>Inside the function:<\/p>\n\n\n\n<p>Set flash latency to 1WS and wait for the value to set:<\/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;}\">\tFLASH-&gt;ACR |= FLASH_ACR_LATENCY; \/* (1) *\/\n\twhile (!(FLASH-&gt;ACR &amp; FLASH_ACR_LATENCY));<\/pre><\/div>\n\n\n\n<p>Bypass the HSE:<\/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;}\">\tRCC-&gt;CR|=RCC_CR_HSEBYP;<\/pre><\/div>\n\n\n\n<p>Enable the HSE and wait for the HSE 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;}\">\tRCC-&gt;CR|=RCC_CR_HSEON;\n\twhile(!(RCC-&gt;CR &amp; RCC_CR_HSERDY));<\/pre><\/div>\n\n\n\n<p>Disable the PLL and wait for the PLL to be disabled:<\/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;}\">\tRCC-&gt;CR &amp;= ~RCC_CR_PLLON; \/* (3) *\/\n\twhile ((RCC-&gt;CR &amp; RCC_CR_PLLRDY));<\/pre><\/div>\n\n\n\n<p>Set the PLL multiplication to 8, divider to 2 and source to be HSE:<\/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;}\">\tRCC-&gt;CFGR |= RCC_CFGR_PLLMUL8;\n\tRCC-&gt;CFGR |= RCC_CFGR_PLLDIV2;\n\tRCC-&gt;CFGR |= RCC_CFGR_PLLSRC_HSE;<\/pre><\/div>\n\n\n\n<p>Enable the PLL and wait until the PLL is 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;}\">\tRCC-&gt;CR |= RCC_CR_PLLON;\n\twhile (!(RCC-&gt;CR &amp; RCC_CR_PLLRDY));<\/pre><\/div>\n\n\n\n<p>Switch to PLL to be the source:<\/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;}\">\tRCC-&gt;CFGR |= RCC_CFGR_SW_PLL;\n\twhile (!(RCC-&gt;CFGR &amp; RCC_CFGR_SWS_PLL) );<\/pre><\/div>\n\n\n\n<p>Thats it for the source file.<\/p>\n\n\n\n<p>For the header:<\/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;}\">#ifndef CORE_H_\n#define CORE_H_\nvoid config_core_32mhz();\n\n\n#endif \/* CORE_H_ *\/\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">3. Testing Using Systick:<\/h2>\n\n\n\n<p>In main.c:<\/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;delay.h&quot;\n#include &quot;stm32l0xx.h&quot;\nextern void config_core_32mhz();\nint main(void)\n{\n\tconfig_core_32mhz();\n\t__disable_irq();\n\tSysTick-&gt;LOAD=32000-1;\n\tSysTick-&gt;VAL=0;\n\tSysTick-&gt;CTRL=7;\n\t__enable_irq();\n\tRCC-&gt;IOPENR |=RCC_IOPENR_IOPAEN;\n\tGPIOA-&gt;MODER|= GPIO_MODER_MODE5_0; \/\/PA5 as output\n\tGPIOA-&gt;MODER&amp;=~ GPIO_MODER_MODE5_1; \/\/PA5 as output\n\n\twhile(1)\n\t{\n\n\t}\n\n}\n\n\n\nvoid SysTick_Handler(void)\n{\nGPIOA-&gt;ODR^=GPIO_ODR_OD5;\n\n}\n<\/pre><\/div>\n\n\n\n<p>Compile and upload the code to your mcu and using oscilloscope and probe PA5 and you should get the following:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"480\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/10\/DS1Z_QuickPrint1.png\" alt=\"\" class=\"wp-image-537\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/10\/DS1Z_QuickPrint1.png 800w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/10\/DS1Z_QuickPrint1-300x180.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/10\/DS1Z_QuickPrint1-768x461.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/10\/DS1Z_QuickPrint1-750x450.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/10\/DS1Z_QuickPrint1-400x240.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/10\/DS1Z_QuickPrint1-250x150.png 250w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>Since each division of the horizontal line is 500microseconds, and we are getting 2 division high and two division low, thats mean the on time 1 millisecond and 1 millisecond off which as we set it. Thats mean we successfully changed the core frequency from 2.096MHz to 32MHz. Now, you can get the full potential of your mcu.<\/p>\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 push STM32L053 to run at 32MHz rather than the default frequency of 2.096 MHz. 1. Steps: In order to push STM32L053 to maximum, we shall use external oscillator. Since the Nucleo-L053 has built-in 8Mhz generated from ST-Link, we shall use that as our oscillator. The steps are [&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-1172","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\/1172"}],"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=1172"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1172\/revisions"}],"predecessor-version":[{"id":1174,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1172\/revisions\/1174"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}