STM32F103 external crystal oscillator changed from 8M to 12M

Publisher:平稳心绪Latest update time:2017-09-02 Source: elecfansKeywords:STM32F103 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the official library file, HSE (external high-speed clock) defaults to 8MHz, and the highest main frequency is 8*9=72MHz. If HSE is changed to 12MHz without modifying the library file, the highest main frequency becomes 12*9=108MHz. The most typical problem is that USART can communicate, but the received data is inconsistent with the sent data, and I can't find the reason. It made me toss around for a whole day. The following are the places that need to be modified.

1. Modify HSE_VALUE in stm32f10x.h. The original code is as follows:

  1. #if !defined HSE_VALUE  

  2.  #ifdef STM32F10X_CL     

  3.   #define HSE_VALUE ((uint32_t)25000000)   

  4.  #else   

  5.   #define HSE_VALUE ((uint32_t)8000000)   

  6.  #endif   

  7. #endif   

 


The modified version is as follows:

 

  1. #if !defined HSE_VALUE  

  2.  #ifdef STM32F10X_CL     

  3.   #define HSE_VALUE ((uint32_t)25000000)   

  4.  #else   

  5.   #define HSE_VALUE ((uint32_t)12000000)   

  6.  #endif   

  7. #endif   


2. Modify the clock configuration in system_stm32f10x.c. First find void SystemInit(void)---》SetSysClock()---》SetSysClockTo72(), change the 9x frequency to 6x frequency, 12*6=72MHz. The original code is as follows:

  1. #ifdef STM32F10X_CL  

  2.       

  3.             

  4.     RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |  

  5.                               RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);  

  6.     RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |  

  7.                              RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);  

  8.           

  9.     RCC->CR |= RCC_CR_PLL2ON;  

  10.       

  11.     while((RCC->CR & RCC_CR_PLL2RDY) == 0)  

  12.     {  

  13.     }  

  14.       

  15.      

  16.        

  17.     RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);  

  18.     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |   

  19.                             RCC_CFGR_PLLMULL9);   

  20. #else      

  21.       

  22.     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |  

  23.                                         RCC_CFGR_PLLMULL));  

  24.     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9);  

  25. #endif   


The modified version is as follows:

  1. #ifdef STM32F10X_CL  

  2.       

  3.       

  4.       

  5.           

  6.     RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |  

  7.                               RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);  

  8.     RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |  

  9.                              RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);  

  10.     

  11.       

  12.     RCC->CR |= RCC_CR_PLL2ON;  

  13.       

  14.     while((RCC->CR & RCC_CR_PLL2RDY) == 0)  

  15.     {  

  16.     }  

  17.       

  18.      

  19.        

  20.     RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);  

  21.     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |   

  22.                             RCC_CFGR_PLLMULL9);  

  23.   

  24. #else      

  25.       

  26.     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |  

  27.                                         RCC_CFGR_PLLMULL));  

  28.     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL6);  

  29. #endif   


Keywords:STM32F103 Reference address:STM32F103 external crystal oscillator changed from 8M to 12M

Previous article:STM32 uses PA13/PA14/PA15 as a normal IO port
Next article:Design of digital voltage-stabilized power supply for test system

Recommended ReadingLatest update time:2024-11-16 15:04

STM32F103ZET6 boot mode
The storage media corresponding to the three startup modes of STM32 are all built-in to the chip, they are: 1) User Flash = Flash built into the chip. 2) SRAM = RAM area built into the chip, which is the memory. 3) System Memory = A specific area inside the chip. A Bootloader is pre-installed in this area when the chi
[Microcontroller]
STM32F103 encoder mode summary
/************************************************************************** Function: Initialize TIM2 to encoder interface mode Entry parameters: None Return value: None **************************************************************************/ void Encoder_Init_TIM2(void) { RCC- APB1ENR|=1 0; //TIM2 clock enable RCC
[Microcontroller]
STM32F103 encoder mode summary
SPI driver OLED of STM32F103RCT6
Hardware conditions: Use Zhongjingyuan Electronics 0.96-inch OLED, 7 lines are as follows: VCC-------- Power Supply GND------- Ground D0--------- SCK, connected to SCK of SPI1, PA5 D1--------- MOSI, MCU as host output, OLED as slave receiver, connected to PA7 RST-------- Reset interface, very important, PC0 DC--------
[Microcontroller]
STM32F103 clock configuration source code learning record
      The clock configuration source code is in the file system_stm32f10x.c. The program first determines the type of f10 chip used and selects the system clock frequency SYSCLK you want. The chip I use has a maximum system frequency of 72Mhz and the chip capacity is large, so after pre-compilation, I selected SYSCLK_
[Microcontroller]
STM32F103, STM32F107 startup files
I recently learned about the RT-Thread system based on STM32F107. I have written some simple STM32F103 programs before, which were modified using official routines. However, there were problems when burning them into STM32F107. Later, I found out that the startup file was not set correctly. - startup_stm32f10x_ld_v
[Microcontroller]
Development and application of the new generation embedded microprocessor STM32F103
Abstract: The STM 32F103 series chip based on the Cortex-M3 core is a new type of 32-bit embedded microprocessor. It is an ARM that does not require an operating system. Its performance is much higher than that of the 51 series microcontroller, but its development process is as simple as that of the 51 series micro
[Security Electronics]
Development and application of the new generation embedded microprocessor STM32F103
STM32f103xxxxz interrupt understanding notes
Interrupt: When an external factor that must be executed is generated during the execution of the program, the program will execute the interrupt service function corresponding to the external factor, and then return to the normal program. This is a simple understanding of interrupt. However, when another interrupt
[Microcontroller]
[STM32F103 siege notes] PWM function practice
The system clock is the default HSI frequency of 8MHz! This will affect the counting frequency of the timer, so you need to know this frequency to ensure that you can control the frequency of the PWM output waveform according to the frequency division in the future! This is very important for the development of actual
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号