stm32 study notes systick timer

Publisher:数据迷航者Latest update time:2016-08-25 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
When developing STM32, I encountered some simple tasks that require timing, such as delay, etc. The most convenient one is the systick it provides.

Systick was originally designed to provide a ticking clock for the convenience of porting operating systems.

I came into contact with STM32 again a few days ago and used the V3.5 library. Suddenly I found that the cumbersome Systick usage was simplified into one sentence.

Right now:

 void SysTick_Configuration(void)
{
  if (SysTick_Config(SystemCoreClock / 1000000))//72, 1us per tick
  {
    /* Capture error */
    while (1);
  }
}

The Systick_Config function has replaced all previous setup processes.

The systick.c file was also deleted, and the function was directly included in the kernel file core_cm3.h.

/* ##################################    SysTick function  ############################################ */

#if (!defined (__Vendor_SysTickConfig)) || (__Vendor_SysTickConfig == 0)

/**
 * @brief  Initialize and start the SysTick counter and its interrupt.
 *
 * @param   ticks   number of ticks between two interrupts
 * @return  1 = failed, 0 = successful
 *
 * Initialise the system tick timer and its interrupt and start the
 * system tick timer / counter in free running mode to generate 
 * periodical interrupts.
 */
static __INLINE uint32_t SysTick_Config(uint32_t ticks)

  if (ticks > SysTick_LOAD_RELOAD_Msk)  return (1);            /* Reload value impossible */
                                                               
  SysTick->LOAD  = (ticks & SysTick_LOAD_RELOAD_Msk) - 1;      /* set reload register */
  NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);  /* set Priority for Cortex-M0 System Interrupts */
  SysTick->VAL   = 0;                                          /* Load the SysTick Counter Value */
  SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk | 
                   SysTick_CTRL_TICKINT_Msk   | 
                   SysTick_CTRL_ENABLE_Msk;                    /* Enable SysTick IRQ and SysTick Timer */
  return (0);                                                  /* Function successful */
}

#endif

The advantage is that the setup is quite simple.

The downside is that the control is not as flexible as before, and once enabled, there is really no library function to easily overload or disable it.

Keywords:stm32 Reference address:stm32 study notes systick timer

Previous article:The difference between STM32 large and small capacity chips
Next article:stm32 study notes system clock

Recommended ReadingLatest update time:2024-11-16 21:01

STM32 Novice Growth Record---General Timer Application
1. Principle of STM32 general timer                             The STM32 series CPU has up to 8 timers, of which TIM1 and TIM8 are advanced timers that can generate three pairs of PWM complementary outputs, commonly used to drive three-phase motors, and their clocks are generated by the output of APB2. The other 6 ar
[Microcontroller]
STM32 Novice Growth Record---General Timer Application
STM32: STM32 learning record 4: serial port
Configuration process: 1: System clock initialization, including system clock and the clock configuration of the IO port and serial port to be opened. The clock of the serial port must be opened!!! RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1,ENABLE);. 2: IO port initialization, including pi
[Microcontroller]
A preliminary study on how to process multiple sets of data when STM32 SPI2 interrupts
1. Description         The SPI communication between the two STM32 boards uses SPI2. The host sends multiple sets of data continuously (the data format is half word, i.e. 16 bits), and the slave uses SPI2 interrupt mode to receive multiple sets of data sent by the host. I tried two methods for slave interrupt acce
[Microcontroller]
STM32_keil compiled memory size analysis
Program Size: Code=28784 RO-data=6480 RW-data=60 ZI-data=3900 Meaning 1. Code: The size of the FLASH space occupied by the program, stored in FLASH. 2. RO-data: Read-only-data, program-defined constants, stored in FLASH. 3. RW-data: Read-write-data, initialized variables, stored in SRAM. 4. ZI-data: Zero-Init-data,
[Microcontroller]
STM32_keil compiled memory size analysis
Frequency and duty cycle of PWM wave of STM32
I saw an article online. It's not very complete, but it helps me understand. I think it's okay. There are a lot of specific codes on the Internet. You can refer to it and calculate it. The following is the timer logic diagram of stm32, which is helpful for understanding: TIM3's ARR register and PSC register, Dete
[Microcontroller]
Frequency and duty cycle of PWM wave of STM32
STM32 Learning: Timer Interrupt
Timer Interrupt   The timer function of STM32 is very powerful. There are advanced timers such as TIME1 and TIME8, general timers such as TIME2~TIME5, and basic timers such as TIME6 and TIME7. In this chapter, we will use the timer interrupt of TIM3 to control the flip of DS1, and use the flip of DS0 in the main func
[Microcontroller]
Implementation of PWM music playback function based on STM32 timer
    Based on the 32-bit STM32F103, the audio signal generated by PWM is used to drive the buzzer to play music, realizing the application design of the music player. The player can realize 21 scales from bass to treble, and can play complete music according to the score. The test results show that the output signal of
[Microcontroller]
Implementation of PWM music playback function based on STM32 timer
Design of remote temperature control system using STM32
Temperature control is one of the main objects of industrial control. The commonly used mathematical model for temperature control is first-order inertia plus a pure lag link, but it varies greatly with different heating objects and environmental conditions. Because the temperature control object has a relativ
[Microcontroller]
Design of remote temperature control system using STM32
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号