stm32 article--system initialization

Publisher:tau29Latest update time:2018-12-21 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Following the program execution flow, main is the program entry, where various initializations are performed.


1. Clock configuration

      First is RCC_Configuration(), which performs basic clock initialization. STM32 has multiple clock sources: (1) HSI is enabled by default when powered on, and has low precision; (2) HSE external high-speed clock, which is generally used by the system clock and multiplied by PLL; (3) LSE external low-speed clock, which is generally used for RTC; (4) LSI internal low-speed clock, which has low precision and is generally used for IWDGCLK;



void RCC_Configuration(void)

{

  RCC_DeInit(); //Reset RCC to default value

  RCC_HSEConfig(RCC_HSE_ON); //Turn on the HSE clock as the clock source for the PLL

  HSEStartUpStatus = RCC_WaitForHSEStartUp(); //Get HSE clock status

  if(HSEStartUpStatus == SUCCESS) //If HSE starts successfully

  {

    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // Enable FLASH prefetch function

    RCC_HCLKConfig(RCC_SYSCLK_Div1);   //配置HCLK,PCLK2,PCLK1,PLL

    RCC_PCLK2Config(RCC_HCLK_Div1); 

    RCC_PCLK1Config(RCC_HCLK_Div1);

    RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);

    while(RCC_GetSYSCLKSource() != 0x04) // Check whether HSE is used as system clock after frequency multiplication

    {

    }

  }

 }


   In this way, the clock is initialized. First reset the RCC, then configure each clock source, get the status and wait for success. If we want to use a certain function or pin, we need to turn on the relevant clock source.

 

2. Interrupt vector setting


void NVIC_Configuration(void)

{

#ifdef  VECT_TAB_RAM  

  /* Set the Vector Table base location at 0x20000000 */ 

  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); 

#else  /* VECT_TAB_FLASH  */

  /* Set the Vector Table base location at 0x08000000 */ 

  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   

#endif

}

NVIC_SetVectorTable sets the position and offset of the vector table

NVIC_ VectTab Description

NVIC_VectTab_FLASH vector table is located in FLASH

NVIC_VectTab_RAM The vector table is located in RAM and is used to set the priority of various interrupts, the address of the vector table, etc.

Keywords:stm32 Reference address:stm32 article--system initialization

Previous article:stm32 executes the initialization function in the interrupt function
Next article:STM32 GPIO Operation (by woody)

Recommended ReadingLatest update time:2024-11-23 07:59

Summary of STM32 encoder counting and overflow processing debugging
Error 1: PC6 and PC7 are used for other purposes, and the GPIO mode is configured incorrectly, resulting in inaccurate counting; Error 2: The pin mode is set incorrectly. It should be set to GPIO_Mode_IPD; //GPIO_Mode_IPU GPIO_Mode_IN_FLOATING is OK; Error 3: Pin remapping does not enable AFIO clock; Summarize Regardi
[Microcontroller]
STM32 (Cortex-M3) startup process + detailed explanation of xcl and icf files in IAR
1: STM32 (Cortex-M3) startup process (entry address) When ARM7 and ARM9 are started, the reset interrupt program is executed from the absolute address 0X00000000, that is, the starting address after reset is fixed, but the position of the interrupt vector table is variable.  The Cortex-M3 core specifies that the first
[Microcontroller]
[STM32 Motor Vector Control] Record 8——ADC Three-Resistor Sampling
The basic principle of ADC:         ADC, the abbreviation of Analog-to-Digital Converter, refers to analog/digital converter or analog-to-digital converter. It is a device that converts continuously changing analog signals into discrete digital signals.        The corresponding DAC, Digital-to-Analog Converter, is the
[Microcontroller]
[STM32 Motor Vector Control] Record 8——ADC Three-Resistor Sampling
STM32 timer brief introduction_1
Look at the timer for the whole week and organize your study notes for the week.   The timer consists of four parts: clock selection unit, time base unit, input capture, and output comparison!   1. Clock selection unit:        Internal clock (CK_INT)   External clock mode 1: external pin input   External c
[Microcontroller]
STM32 timer brief introduction_1
Common library functions for STM32 MCU
1.GPIO initialization function usage: voidGPIO_Configuration(void) { GPIO_InitTypeDefGPIO_InitStructure; //GPIO status restores default parameters GPIO_InitStructure.GPIO_Pin=GPIO_Pin_label|GPIO_Pin_label; //Pin position definition, the label can be NONE, ALL, 0 to 15. GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
[Microcontroller]
Problems encountered during stm32 transplantation
1.Warning: L6305W: Image does not have an entry point. (Not specified or not set due to multiple choices.)    In the Linker---Misc controls of Options for Target, add the entry address: --entry Reset_Handler  2. Error: L6915E: Library reports error: __use_no_semihosting was requested, but __user_initial_stackheap
[Microcontroller]
Problems encountered during stm32 transplantation
Design of electric vehicle battery management system based on STM32 and CAN bus
 With the widespread application of battery energy, the depletion of oil resources and environmental pollution, electric vehicles have attracted more and more attention for their advantages of energy saving and environmental protection. In the research and development of electric vehicles, the research and manufacture
[Power Management]
Design of electric vehicle battery management system based on STM32 and CAN bus
EMS LCD touch screen design based on STM32
0 Introduction Electric vehicles have always been a focus of attention for their cleanliness and environmental protection. With the intensification of the energy crisis and the continuous rise in oil prices, electric vehicles are becoming more and more popular among users. Electric vehicles are generally powere
[Microcontroller]
EMS LCD touch screen design based on STM32
Latest Microcontroller Articles
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号