STM32 novice initialization function and delay function

Publisher:堕落的猫Latest update time:2018-07-20 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. STM32 clock configuration initialization function:


void Stm32_Clock_Init(){

unsigned char temp = 0; //define an unsigned char type variable named temp

MYRCC_DeInit(); //Reset and configure the vector table. This function is automatically written by Keil, so you don't need to worry about it.

RCC->CR |= 0x00010000; //Set the 16th bit of the clock control register of stm32 to 1 to enable the external clock (HSE). For details, see the description of the RCC_CR register on page 85 of the STM32 reference manual.

while(! (RCC->CR>>17)); //Judge the 17th bit of the RCC_CR register, that is, whether the external high-speed clock is ready

RCC->CFGR = 0x00000400; //Set the 10th to 8th bits of the clock configuration register to make the APB1 clock not exceed 36MHz to prevent system disorder caused by APB1 clock exceeding 36MHz

PLL-=2; //Subtract 2 from the PLL value to configure the system's phase-locked loop frequency multiplication factor. For specific requirements, see bits 21-18 of the RCC_CFGR register.

RCC_CFGR |=(PLL<<18); // Shift the PLL value minus 2 by 18 bits and perform an OR operation with the original RCC_CFGR value to configure the PLL value.

RCC_CFGR|=(1<<16); //Use external clock as system clock

FLASH_ACR |= 0x32; //Delay FLASH by two cycles. For details, refer to the ST document PM0042 programming manual "STM32F10XXX Flash Programming"

 

RCC_CR |= 0x01000000; // Enable PLL

while(!(RCC->CR>>25)); //Judge whether PLL is enabled successfully

RCC_CFGR |= 0x0000002; //Use PLL output as system clock

while(temp!=0x02) { //Wait for PLL output to be set as system clock successfully

temp=RCC-CFGR>>2;

temp&=0x03;

}

 

 

}


Keywords:STM32 Reference address:STM32 novice initialization function and delay function

Previous article:STM32F407ZGT6 uses Systic timer to achieve delay
Next article:STM32 SysTick timer delay function

Recommended ReadingLatest update time:2024-11-16 16:00

stm32 interrupt line IO mode reading and writing notes
1. How to use the stm32 interrupt line: 1. Interrupt line configuration: void EXTI_Configuration(void) {   EXTI_InitTypeDef EXTI_InitStructure; //EXTI initialization structure definition   GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource3); //Pin selection   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
[Microcontroller]
stm32-GPIO operation (library function)
It's rare to have time, so I want to write about the basics of stm32 recently. 8 ways of GPIO  1. Floating input GPIO_IN_FLOATING ——Floating input, can be used for KEY recognition, RX1        2. GPIO_IPU with pull-up input——IO internal pull-up resistor input        3. GPIO_IPD with pull-down input——IO internal pul
[Microcontroller]
STM32 motor control synchronous electrical angle test description
Preface When using the ST   FOC motor library , when using the Hall signal as the position signal, it is necessary to input the synchronous electrical angle data. This data is input according to the characteristics of the current motor in use, and the electrical angle will be synchronized every time the Hall signal ch
[Microcontroller]
STM32 motor control synchronous electrical angle test description
STM32 Product Unique Identification Register (96 bits) Flash Capacity Register
Unique product identifiers are ideal for: ● Used as a serial number (such as a USB character serial number or other terminal applications) ● Used as a password. When programming the flash memory, this unique identifier is used in combination with the software encryption and decryption algorithm to improve the securit
[Microcontroller]
STM32 Product Unique Identification Register (96 bits) Flash Capacity Register
STM32 IAP upgrade has a small probability of running away
Use IAP technology to automatically upgrade the MCU. The official source code is generally modified according to needs. For example, because our products are everywhere, it is impossible to let construction workers press buttons one by one to trigger the upgrade, so the serial port command trigger upgrade is obviously
[Microcontroller]
STM32: Flash erase and read and write operations
Application platform: STM32F030F4P6 ST official library: STM32Cube_FW_F0_V1.9.0 background knowledge For most MCUs and microcontrollers (ARM, x86), the address space is in bytes, which means that one address is one byte. Flash memory has a characteristic that it can only write 0, not 1. So if there is data at the
[Microcontroller]
STM32 RCC configuration process
    There are 5 clock sources in STM32: ①. HSI is a high-speed internal clock, RC oscillator, with a frequency of 8MHz. ②. HSE is a high-speed external clock that can be connected to a quartz/ceramic resonator or an external clock source with a frequency range of 4MHz~16MHz. ③. LSI is a low-speed intern
[Microcontroller]
STM32 RCC configuration process
Several reasons why STM32 cannot run after compilation
1. The compilation and linking can pass, but uVision MDK cannot run at full speed and stops as soon as it runs. The reason is that the Option->Target->Code Generation->Use MicroLIB checkbox is not checked. Generally speaking, for the situation where it stops as soon as it runs, check Use MicroLIB, recompile, and the ru
[Microcontroller]
Several reasons why STM32 cannot run after compilation
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号