9257 views|4 replies

57

Posts

0

Resources
The OP
 

[liklon plays with GD32F350] 3. SYSTICK realizes simple delay [Copy link]

A little delay is needed during use. There is HAL_Delay in the HAL library that can be used, but the GD standard library is currently used, so systick is still needed to implement a simple delay function. 1. Systick tick timer Those who have used M3 M4 should be familiar with this, so I will not describe it again. In the GD32F3X0_MISC file, there is a function to configure the systick clock source:
  1. /*! \brief set the systick clock source \param[in] systick_clksource: the systick clock source needed to choose \arg SYSTICK_CLKSOURCE_HCLK: systick clock source is from HCLK \arg SYSTICK_CLKSOURCE_HCLK_DIV8: systick clock source is from HCLK/8 \param[out] none \retval none */ void systick_clksource_set(uint32_t systick_clksource) { if(SYSTICK_CLKSOURCE_HCLK == systick_clksource ){ /* set the systick clock source from HCLK */ SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK; }else{ /* set the systick clock source from HCLK/8 */ SysTick->CTRL &= SYSTICK_CLKSOURCE_HCLK_DIV8; } }
复制代码
There is no introduction to the systick register in the gd manual. Here is a picture from the M4 authoritative manual 2. Delay function and verification
  1. #define DELAY_US_FACTOR 108 void delay_init() { systick_clksource_set(SYSTICK_CLKSOURCE_HCLK); } //xus < 155344 void delay_xus(uint32_t xus) { uint32_t xtick = xus * DELAY_US_FACTOR; if(xus > 155000) { return; } SysTick->LOAD = xtick - 1; SysTick->VAL = 0; SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; while((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0x0); } //xms < 155 void delay_xms(uint32_t xms) { uint32_t xtick = xms * DELAY_US_FACTOR * 1000; if(xms > 155) { return; } SysTick- >LOAD = xtick - 1; SysTick->VAL = 0; SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; while((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0x0); }
复制代码
In the while loop, verify that hello world is printed once every 500ms:
  1. while(1) { delay_xms(100); delay_xms(100); delay_xms(100); delay_xms(100); delay_xms(100); uart1_write((uint8_t *)"hello world\n\r", 13); }
复制代码
Looking at the timestamp, it should be successful.

This post is from GD32 MCU

Latest reply

Thanks for sharing   Details Published on 2021-3-11 16:26
 

1368

Posts

6

Resources
2
 
Good, keep it up, it’s great!
This post is from GD32 MCU
 
Personal signature专注智能产品的研究与开发,专注于电子电路的生产与制造……QQ:2912615383,电子爱好者群: void
 
 

38

Posts

0

Resources
3
 
Hello, I use the timer interrupt to turn on and off the LED light, and it feels that the interrupt time is more than 10 times different.
This post is from GD32 MCU

Comments

Do you use timer interrupts? You can take a look at my other post, General Timer 1  Details Published on 2018-9-7 14:07
 
 
 

57

Posts

0

Resources
4
 
lsj306 posted on 2018-9-7 14:02 Hello, I use the timer interrupt to turn on and off the LED light, and it feels that the interrupt time difference is more than 10 times
Do you use the timer interrupt? You can take a look at my other post, General Timer 1
This post is from GD32 MCU
 
 
 

661

Posts

0

Resources
5
 

Thanks for sharing

This post is from GD32 MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list