简体   繁体   English

使用CubeMX生成STM32F103C8的系统时钟配置

[英]Generating system clock configuration for STM32F103C8 with CubeMX

I am trying to generate system_stm32f1xx.c which will set up my clock as shown on the picture. 我正在尝试生成system_stm32f1xx.c,它将设置我的时钟,如图所示。 系统时钟配置

The problem is that, when I generate the code with CubeMX, I don't get this configuration. 问题是,当我使用CubeMX生成代码时,没有得到此配置。 Instead, I get the (I guess) default configuration with internal RC clock enabled. 取而代之的是,我获得了启用内部RC时钟的默认配置。

I had many problem with configuring timers and USART before I find out that some thing is wrong with my clock configuration. 在发现时钟配置有些问题之前,我在配置计时器和USART时遇到了许多问题。

Content of the system_init() function. system_init()函数的内容。

void SystemInit (void)
{
  /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
  /* Set HSION bit */
  RCC->CR |= 0x00000001U;

  /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
#if !defined(STM32F105xC) && !defined(STM32F107xC)
  RCC->CFGR &= 0xF8FF0000U;
#else
  RCC->CFGR &= 0xF0FF0000U;
#endif /* STM32F105xC */   

  /* Reset HSEON, CSSON and PLLON bits */
  RCC->CR &= 0xFEF6FFFFU;

  /* Reset HSEBYP bit */
  RCC->CR &= 0xFFFBFFFFU;

  /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
  RCC->CFGR &= 0xFF80FFFFU;

#if defined(STM32F105xC) || defined(STM32F107xC)
  /* Reset PLL2ON and PLL3ON bits */
  RCC->CR &= 0xEBFFFFFFU;

  /* Disable all interrupts and clear pending bits  */
  RCC->CIR = 0x00FF0000U;

  /* Reset CFGR2 register */
  RCC->CFGR2 = 0x00000000U;
#elif defined(STM32F100xB) || defined(STM32F100xE)
  /* Disable all interrupts and clear pending bits  */
  RCC->CIR = 0x009F0000U;

  /* Reset CFGR2 register */
  RCC->CFGR2 = 0x00000000U;      
#else
  /* Disable all interrupts and clear pending bits  */
  RCC->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->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
#else
  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
#endif 
}

The clock configuration function is in the generated by the CubeMx main.c file and is called SystemClock_Config . 时钟配置函数在CubeMx main.c文件生成的文件中,称为SystemClock_Config The SystemInit does not set the clock. SystemInit不会设置时钟。 I do not know why my previos answer was removed as it answers the question. 我不知道为什么我的previos答案被删除了,因为它回答了这个问题。

The clock configuration function is in tge main.c file. 时钟配置功能在tge main.c文件中。 Do not touch the system files unless you know what you are doing. 除非您知道自己在做什么,否则请勿触摸系统文件。

SystemInit does something else and you should leave it as it is SystemInit还有其他事情,您应该保持原样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM