STM32 reset/clock control

Publisher:mu22Latest update time:2016-10-08 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
========================== Reset/Clock Control ==================== === 
1. Clock Security System (CSS) 
   After the clock safety system is activated, the clock monitor will monitor the external high-speed oscillator in real time; if the HSE clock fails, the external oscillator is automatically turned off and a clock safety interrupt is generated, which is connected to the NMI interrupt of the Cortex-M3; at the same time, the CSS switches the internal RC oscillator to the system clock source of the STM32 (for the STM32F103, the clock failure event will also be sent to the brake input of the advanced timer TIM1 to implement motor protection control). 
   Operating procedures: 
   1) Start the clock security system CSS: RCC_ClockSecuritySystemCmd(ENABLE); (NMI interrupt is not maskable!) 
 
   2) When the external oscillator fails, an NMI interrupt is generated, and the corresponding interrupt program is: 
    void NMIException(void) 
    { 
      if (RCC_GetITStatus(RCC_IT_CSS) != RESET) 
        { // HSE and PLL are disabled (but PLL settings remain unchanged) 
          …… // Customer adds corresponding system protection code 
               // The following is the preset code after HSE recovery 
          RCC_HSEConfig(RCC_HSE_ON); // Enable HSE 
          RCC_ITConfig(RCC_IT_HSERDY, ENABLE); // Enable HSE ready interrupt 
          RCC_ITConfig(RCC_IT_PLLRDY, ENABLE); // Enable PLL ready interrupt 
          RCC_ClearITPendingBit(RCC_IT_CSS); // Clear the pending bit of the clock security system interrupt 
          // At this point, once the HSE clock is restored, an HSERDY interrupt will occur. In the RCC interrupt handler, the system clock can be set to its previous state 
        } 
    } 
 
   3) In the RCC interrupt handler, HSE and PLL are processed accordingly. 
 
Note: Once CSS is activated, a CSS interrupt will be generated when the HSE clock fails, and NMI will be automatically generated. NMI will be executed continuously until the CSS interrupt pending bit is cleared. Therefore, the CSS interrupt must be cleared in the NMI handler by setting the CSSC bit in the clock interrupt register (RCC_CIR). 
 
2. SysTick Working Principle 
   The Cortex-M3 core contains a SysTick clock. SysTick is a 24-bit down counter. After SysTick is set to an initial value and enabled, the count value decreases by 1 after each system clock cycle. When the count reaches 0, the SysTick counter automatically reloads the initial value and continues counting. At the same time, the internal COUNTFLAG flag is set to trigger an interrupt (if the interrupt is enabled). 
 
 
3. Internal clock output PA.8 (MCO) 
   The PA.8 pin of STM32 has a multiplexing function - clock output (MCO), which can output the internal clock of STM32 through PA.8. 
   Operating procedures: 
   1) Set PA.8 to multiplexed Push-Pull mode. 
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; 
    GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz; 
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
    GPIO_Init(GPIOA, &GPIO_InitStructure); 
 
   2) Select the output clock source. 
    The clock selection is controlled by the MCO[2:0] bits in the clock configuration register (RCC_CFGR). 
    RCC_MCOConfig(RCC_MCO); 
    The parameter RCC_MCO is the internal clock to be output: 
      RCC_MCO_NoClock --- No clock output 
      RCC_MCO_SYSCLK --- Output system clock (SysCLK) 
      RCC_MCO_HSI --- Output internal high speed 8MHz RC oscillator clock (HSI) 
      RCC_MCO_HSE --- Output high-speed external clock signal (HSE) 
      RCC_MCO_PLLCLK_Div2 --- Output PLL divided-by-two clock after frequency multiplication (PLLCLK/2) 
 
Note: Since the maximum response frequency of the STM32 GPIO output pin is 50MHz, if the output frequency exceeds 50MHz, the output waveform will be distorted. 
 
4. Programmable Voltage Monitor (PVD) 
   STM32 has a built-in PVD function for monitoring the MCU power supply voltage VDD. The PLS[2:0] bit in the power control register can be used to set the threshold of the monitoring voltage and monitor the power supply by comparing the external voltage. When the condition is triggered, the system needs to enter a special protection state and perform an emergency shutdown task: save some system data and perform corresponding protection operations on peripherals. 
   Operating procedures: 
    1) Start PVD after the system starts and enable the corresponding interrupts. 
    PWR_PVDLevelConfig(PWR_PVDLevel_2V8); //Set monitoring threshold  
    PWR_PVDCmd(ENABLE); // Enable PVD  
    EXTI_StructInit(&EXTI_InitStructure);  
    EXTI_InitStructure.EXTI_Line = EXTI_Line16; // PVD is connected to interrupt line 16  
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //Use interrupt mode  
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Raising; //Interrupt occurs when the voltage is lower than the threshold  
    EXTI_InitStructure.EXTI_LineCmd = ENABLE; // Enable interrupt line  
    EXTI_Init(&EXTI_InitStructure); // Initial 
       EXTI_InitStructure.EXTI_Trigger assignment options: 
              EXTI_Trigger_Rising---Indicates that an interrupt is generated when the voltage drops from high to below the set threshold; 
       EXTI_Trigger_Falling---Indicates that an interrupt is generated when the voltage rises from low to above the set threshold; 
              EXTI_Trigger_Rising_Falling---Indicates that an interrupt is generated when the voltage rises or falls beyond the set threshold. 
 
    2) When the working voltage is lower than the set threshold, a PVD interrupt will be generated and the corresponding processing will be performed in the interrupt program: 
    void PVD_IRQHandler(void)  
    { 
      EXTI_ClearITPendingBit(EXTI_Line16); 
      …… // User adds emergency processing code 
    } 
Keywords:STM32 Reference address:STM32 reset/clock control

Previous article:STM32 timer generates PWM full application
Next article:STM32 interrupt vector, priority

Recommended ReadingLatest update time:2024-11-16 13:29

STM32 simulates IIC reading and writing 24C02 program code
Pin definition and configuration: #define SCL           GPIO_Pin_6 //24C02 SCL #define SDA           GPIO_Pin_7 //24C02 SDA void GPIO_Configuration(void) {   RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |                          RCC_APB2Periph_GPIOC | RCC_APB2Perip
[Microcontroller]
STM32-light up the LED (GPIO configuration)
Lighting up the LED should be the first experiment for everyone to learn hardware! From 51 to 32 and then to ARM, let's stop talking nonsense and start using STM32 to light up the LED.  GPIO: also known as general input and output port, is an indispensable peripheral unit of the microcontroller, used to transmit signa
[Microcontroller]
STM32 learning notes: the voltage value sampled by adc is sent to pc using 485
Using channel 10 of adc1, the collected voltage value is sent to the PC display using 485.  First, the schematic diagram is attached.      The source code is in the attachment.  Here are a few points to note:  1. The voltage input by ad is divided by R42 and R44, so the voltage value displayed by the PC will be halve
[Microcontroller]
STM32 learning notes: the voltage value sampled by adc is sent to pc using 485
STM32-1-LED on and off
led.c file #include "led.h" void LED_Init(void){     //¶¨ÒåÒ»¸öGPIO_InitTypeDefÀàÐ͵ĽṹÌå   GPIO_InitTypeDef GPIO_InitStructure;      //¿ªÆôPA¿ÚʱÖÓ   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);      //Ñ¡ÔñÒª¿ØÖƵÄPA¿Ú   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;   //Eugene   GPIO_I
[Microcontroller]
[STM32] RTC real-time clock overview, registers, library functions (RTC general steps)
STM32F1xx official information: "STM32 Chinese Reference Manual V10" - Chapter 16 Real-time Clock (RTC) RTC Real Time Clock Introduction to RTC Real Time Clock The real-time clock is an independent timer. The RTC module has a set of counters that count continuously, and can provide clock calendar functions under t
[Microcontroller]
[STM32] RTC real-time clock overview, registers, library functions (RTC general steps)
STM32 xPSR affected conditional instructions
I'm studying ARM Cortex-M3 recently, and I found a book called "An Definitive Guide to The ARM Cortex-M3" which is considered a classic. This series of study notes is actually the reading notes I made while studying this book. Unconditional jump instruction Jump instructions are divided into two categories: unconditi
[Microcontroller]
STM32 xPSR affected conditional instructions
STM32 timer realizes PWM output control of passive buzzer (HAL)
1. PWM concept and principle Pulse Width Modulation (PWM), short for "Pulse Width Modulation", is a very effective technology that uses the digital output of a microprocessor to control analog circuits. PWM principle diagram The figure above is a simple PWM principle diagram. In the figure, we assume that the t
[Microcontroller]
STM32 timer realizes PWM output control of passive buzzer (HAL)
Implementing DMA of USART in STM32
For those who have not played DMA, here is a brief introduction to DMA. Let me put it in my own words. That is, from a certain position If you don't use DMA to transfer data to a certain location, the CPU must be involved in the operation, moving byte by byte, or more efficiently , moving word by word. But when you u
[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号