The SysTick timer is bundled in the NVIC and is used to generate the SysTick exception (exception number: 15). In the past, the operating system and all systems that used a time base had to have a hardware timer to generate the required "tick" interrupt as the time base for the entire system. Tick interrupts are particularly important for operating systems. For example, the operating system can grant different numbers of time slices to multiple tasks to ensure that no task can monopolize the system; or grant a certain time range of each timer cycle to a specific task, etc., and the various timing functions provided by the operating system are all related to this tick timer. Therefore, a timer is needed to generate periodic interrupts, and it is best to prevent user programs from arbitrarily accessing its registers to maintain the rhythm of the operating system's "heartbeat".
The Cortex-M3 processor contains a simple timer. Because all CM3 chips have this timer, porting software between different CM3 devices is simplified. The clock source of this timer can be an internal clock (FCLK, the free running clock on the CM3) or an external clock (STCLK signal on the CM3 processor). However, the specific source of STCLK is determined by the chip designer, so the clock frequency between different products can vary greatly. Therefore, it is necessary to check the device manual of the chip to decide what to choose as the clock source.
The SysTick timer can generate an interrupt, and the CM3 has a special exception type for it and a place for it in the vector table. It makes porting operating systems and other system software between CM3 devices much simpler because SysTick is handled the same way in all CM3 products.
Keywords:STM32 SysTick
Reference address:Use of SysTick under STM32 V3.5 firmware library
There are 4 registers controlling the SysTick timer, as shown in Table 8.9 to Table 8.12. The calibration value register provides a solution that allows the system to generate a constant SysTick interrupt frequency even if it runs on different CM3 products. The simplest approach is to directly write the value of TENMS into the reload register, so that as long as the "elasticity limit" of the system is not exceeded, a SysTick exception can be generated every 10ms. If other SysTick exception periods are required, they can be proportionally calculated according to the value of TENMS. However, in a few cases, the CM3 chip may not accurately provide the value of TENMS (for example, the calibration input signal of the CM3 is pulled low), so for safety reasons, it is best to check the reference manual of the device before using TENMS. In addition to serving the operating system, the SysTick timer can also be used for other purposes: as an alarm, for measuring time, etc. It should be noted that when the processor is halted during debugging, the SysTick timer will also be suspended. In the 3.5 firmware library, SysTick is defined in core_cm3.h:
static __INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if (ticks > SysTick_LOAD_RELOAD_Msk) return (1);
SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1;
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk;
return (0);
}
In the 3.5 library, it is very simple to use SysTick. Just call the SysTick_Config() function to write the reload beat number during initialization. For example, set the SysTick timer to generate an interrupt every 1ms:
{
}
SysTick_Config(72000);//1ms
On this basis, make a Delay function:
void Delay_ms(u16 time)
{
nTime = time;
while(nTime);
}
Among them, nTime is a global variable, and the decrement operation is performed in the SysTick interrupt service program:
void SysTick_Handler(void)
{
nTime--;
}
Previous article:STM32 builds its own project based on the library
Next article:STM32F103 Basics 1
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(14)
- Learn ARM development(15)
- 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)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- 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?
Guess you like
- HC05 and HC06 Bluetooth configuration experience summary
- Sensor wiring issues
- VGA display image
- Two watchdogs of STM32
- [Flower carving hands-on] Interesting and fun music visualization series of small projects (17) - fiber optic lamp
- [NXP Rapid IoT Review] + Mobile Synchronizer 4
- Proteus 8.12 SP0 (Build 30713) is officially released!
- The highest performance broadband GaN power amplifier is here
- The difference between bit rate, baud rate and data transmission rate
- Huawei Comic: What is DSP? - A fast calculator of digital signals