title: Generating system clock configuration for STM32F103C8 with CubeMX
body: <p>I am trying to generate system_stm32f1xx.c which will set up my clock as shown on the picture.
  <a href="https://i.stack.imgur.com/lN6HF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lN6HF.png" alt="System clock configuration"></a></p>
  
  <p>The problem is that, when I generate the code with CubeMX, I don't get this configuration. Instead, I get the (I guess) default configuration with internal RC clock enabled.</p>
  
  <p>I had many problem with configuring timers and USART before I find out that some thing is wrong with my clock configuration.</p>
  
  <p>Content of the system_init() function.</p>
  
  <pre><code>void SystemInit (void)
  {
    /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
    /* Set HSION bit */
    RCC-&gt;CR |= 0x00000001U;
  
    /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
  #if !defined(STM32F105xC) &amp;&amp; !defined(STM32F107xC)
    RCC-&gt;CFGR &amp;= 0xF8FF0000U;
  #else
    RCC-&gt;CFGR &amp;= 0xF0FF0000U;
  #endif /* STM32F105xC */   
  
    /* Reset HSEON, CSSON and PLLON bits */
    RCC-&gt;CR &amp;= 0xFEF6FFFFU;
  
    /* Reset HSEBYP bit */
    RCC-&gt;CR &amp;= 0xFFFBFFFFU;
  
    /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
    RCC-&gt;CFGR &amp;= 0xFF80FFFFU;
  
  #if defined(STM32F105xC) || defined(STM32F107xC)
    /* Reset PLL2ON and PLL3ON bits */
    RCC-&gt;CR &amp;= 0xEBFFFFFFU;
  
    /* Disable all interrupts and clear pending bits  */
    RCC-&gt;CIR = 0x00FF0000U;
  
    /* Reset CFGR2 register */
    RCC-&gt;CFGR2 = 0x00000000U;
  #elif defined(STM32F100xB) || defined(STM32F100xE)
    /* Disable all interrupts and clear pending bits  */
    RCC-&gt;CIR = 0x009F0000U;
  
    /* Reset CFGR2 register */
    RCC-&gt;CFGR2 = 0x00000000U;      
  #else
    /* Disable all interrupts and clear pending bits  */
    RCC-&gt;CIR = 0x009F0000U;
  #endif /* STM32F105xC */
  
  #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
    #ifdef DATA_IN_ExtSRAM
      SystemInit_ExtMemCtl(); 
    #endif /* DATA_IN_ExtSRAM */
  #endif 
  
  #ifdef VECT_TAB_SRAM
    SCB-&gt;VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
  #else
    SCB-&gt;VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
  #endif 
  }
  </code></pre>