2 定时器相关

2.1 Delay function;

1,HAL layer delay function;:(Equivalent to the instruction loop in while, and will not switch to other threads during the delay;)

HAL_Delay(10); /* 延时10ms */
HAL_Delay_us(10); /* 延时10us */

2,RTT interface delay function;:
When the RTT interface delay function is executed, it will switch to other threads;,For example, the ilde thread will enter Standby sleep when the sleep threshold is lower than the delay duration;

rt_thread_delay(100); /* 延时100ms */

2.2 Get timestamp; Tick值和RC10K振荡频率

1,Get timestamp;:

/* 32768 crystal clock, will add 1 to the register value every 1/32768 second;*/
/* RC10K clock, will add 1 to the register value approximately every 1/9000 second;*/
uint32_t start_time = HAL_GTIMER_READ(); 

2,Get Tick value incremented by 1m seconds;:

rt_tick_t start_timer = rt_tick_get(); /* RTT system function, return value will add 1 every 1m second; */
uint32_t tickstart = HAL_GetTick();  /* HAL layer function, return value will add 1 every 1m second; */

3,Get current clock frequency;:

/* 32768 crystal clock, will return 32768;*/
/* RC10K clock, will return a value between 8k-10k;*/
uint32_t mcuOscData = HAL_LPTIM_GetFreq(); 

2.3 Serial port command to view existing timers;

list_timer


alt text
Description of list_timer status;:
The first column “timer” is the timer name;;
The second column “periodic” is the timer period (in hexadecimal, unit ms);;
The third column “timeout” is the timestamp for the next timer arrival;;
The fourth column “flag” indicates whether the timer is active;,
如上图,The only effective timer is the “main” timer (the delay function is also a timer), with a wake-up period of 0xbb8 (3000ms);。