1.SysTick register:
register |
illustrate |
address |
CTRL |
SysTick Control and Status Register |
0xE000E010 |
LOAD |
Systick reload value register |
0xE000E014 |
VAL |
Systick Current Value Register |
0xE000E018 |
CALIB |
SysTick Calibration Value Register |
0xE000E01C |
l
CLKSOURCE bit: CM3 allows two clock sources to be selected for SysTick. The first is the core's "free running clock" FCLK. "Free" means that it does not come from the system clock HCLK, so FCLK continues to run when the system clock stops. The second is an external reference clock. However, when using an external clock, because it is sampled internally by FCLK, its period must be at least twice that of FCLK (sampling theorem). In many cases, chip manufacturers will ignore this external reference clock, so it is usually not available.
COUNTFLAG bit: When the SysTick timer counts from 1 to 0, it will set the COUNTFLAG bit; the following method can clear it:
Read the SysTick control and status register (STCSR);
Write any data to the SysTick Current Value Register (STCVR).
l
l
l
Schematic diagram of each register:
2. SysTick function
The STM32 firmware library after version 3.0 removes the SysTick driver in the standard peripheral library, so users must call the CMSIS-defined functions.
CMSIS only provides a SysTick setting function, which replaces all the functions of the original SysTick driver of STM32.
- SysTick_Config(uint32_t ticks);
This function sets the value of the auto-reload counter (LOAD), the priority of the SysTick IRQ, resets the value of the counter (VAL), starts counting and enables the SysTick IRQ interrupt. The SysTick clock uses the system clock by default.
In addition, you can use the SysTick_CLKSourceConfig function to change the clock source and use NVIC_SetPriority to set the interrupt priority (more on this later).
SysTick_CLKSourceConfig function
Function name |
SysTick_CLKSourceConfig |
Function prototype |
SysTick_CLKSourceConfig(u32 SysTick_CLKSource) |
Behavior Description |
Configure the SysTick clock source |
Input parameters |
SysTick_CLKSource: Clock source of SysTick |
Output parameters |
none |
return value |
none |
Prerequisites |
none |
Call functions |
none |
SysTick_CLKSource allowed values
SysTick_CLKSource |
describe |
SysTick_CLKSource_HCLK_Div8 |
The SysTick clock source is 1/8 of the AHB clock |
SysTick_CLKSource_HCLK |
The SysTick clock source is the AHB clock |
[page]
example:
Select 1/8 of the AHB clock as the SysTick clock source
- SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
3. Routines
3.1 Program Code
This example code is modified from the example code for lighting up the LED lamp, using SysTick timing delay. Except for the delay, other codes remain unchanged, and the statements related to SysTick are commented.
- #include "stm32f10x.h"
- void Delay(u32 nTime); //Declare delay function
- void GPIO_Configuration(void);
- int main(void)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
- GPIO_Configuration();
- while(SysTick_Config(SystemCoreClock/1000)!=0); //Configure SysTick and load the initial value. The load value depends on the clock source frequency. A 72MHz clock source generates a 1ms interrupt and the load value needs to be (72000000/1000)
- while(1)
- {
- GPIO_ResetBits(GPIOC,GPIO_Pin_7|GPIO_Pin_9);
- GPIO_SetBits(GPIOC,GPIO_Pin_6|GPIO_Pin_8);
- Delay(1000);
- GPIO_ResetBits(GPIOC,GPIO_Pin_6|GPIO_Pin_8);
- GPIO_SetBits(GPIOC,GPIO_Pin_7|GPIO_Pin_9);
- Delay(1000);
- GPIO_Write(GPIOC,0x0140);
- Delay(1000);
- GPIO_Write(GPIOC,0x0280);
- Delay(1000);
- }
- }
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDefGPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_Init(GPIOC,&GPIO_InitStructure);
- }
- volatile u32 TimingDelay; //define global variables, which are declared in stm32f10x_it.c
- void Delay(u32 nTime) //define delay function
- {
- TimingDelay=nTime; //Assign the delay number to the global variable
- while(TimingDelay!=0);
- }
Among them, in stm32f10x_it.c:
- extern volatile u32 TimingDelay; //declare global variables
- void SysTick_Handler(void)
- {
- TimingDelay--;
- }
3.2 Results
After compiling and burning into the development board, the LEDs will flash alternately with an accurate interval of 1 second.
references:
[1] Joseph Yiu, translated by Song Yan. "Cortex-M3 Authoritative Guide" [EB/OL]. http://ishare.iask.sina.com.cn/f/11378333.html?retcode=0, 2010-11-05/2012-09-09.
[2] ST. "Comparison of STM32 firmware library 2.0.3 and 3.0 versions (Chinese version)" [EB/OL]. http://ishare.iask.sina.com.cn/f/18297257.html?from=like, 2011-08-22/2012-09-09.
[3]Xxbing8.STM32_SysTick[EB/OL].http://hi.baidu.com/xxbing8/item/c99ea4f53f996ad042c36ab8
Previous article:STM32 study notes - using the general timer TIM2 for precise delay
Next article:STM32 learning notes-preparation
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Does anyone know what chip the silkscreen 95360E is? I guess it is the 5V regulator?
- The Bluetooth headset is cracked, open it and take a look
- Suggestion: The weight of moderator work points should be based on high-quality posts
- [Welcome to the New Year and National Day] DCExpert takes you to "full stack" hands-on: rechargeable touch-controlled creative LED lamp based on ESP8266
- Mir MYC-YT507 development board review: Play NES games with the Famicom
- [RT-Thread reading notes] Week 4: Digest the first six chapters and fill in the gaps
- Steam oven water level detection - which one is more suitable, the float type or the photoelectric type?
- POE PD+DCDC non-isolated solution
- Help: Transformer detection of low frequency or DC residual current
- How to realize network remote control of balance car? ?