求助,gd32的systick_handler进不去,感谢大佬帮忙看看

[复制链接]
2655|7
 楼主| zuyilu 发表于 2022-5-25 15:14 | 显示全部楼层 |阅读模式
AN, TI, ic, ck
下面这个系统时钟配置,都是官方给的例程,直接复制的。我现在想用us函数,然后用了方式2,结果无法进入SysTick_Handler。感谢大家帮忙
  1. void systick_config(void)
  2. {
  3.         #if 方式1,可以进入SysTick_Handler
  4.         /* setup systick timer for 1000Hz interrupts */
  5.     if(SysTick_Config(SystemCoreClock / 1000U)){
  6.         /* capture error */
  7.         while(1){
  8.         }
  9.     }
  10.     /* configure the systick handler priority */
  11.     NVIC_SetPriority(SysTick_IRQn, 0x00U);
  12.         #endif
  13.        
  14.         #if 方式2,无法进入SysTick_Handler,但是我需要用us延时函数
  15.     /* systick clock source is from HCLK/8 */
  16.     systick_clksource_set(SYSTICK_CLKSOURCE_HCLK_DIV8);
  17.     count_1us = (float)SystemCoreClock/8000000;
  18.     count_1ms = (float)count_1us * 1000;
  19.         #endif
  20. }


 楼主| zuyilu 发表于 2022-5-25 15:20 | 显示全部楼层
方式1的完整代码
  1. void systick_config(void)
  2. {
  3.     /* setup systick timer for 1000Hz interrupts */
  4.     if(SysTick_Config(SystemCoreClock / 1000U)){
  5.         /* capture error */
  6.         while(1){
  7.         }
  8.     }
  9.     /* configure the systick handler priority */
  10.     NVIC_SetPriority(SysTick_IRQn, 0x00U);
  11. }
  12. void delay_1ms(uint32_t count)
  13. {
  14.     delay = count;

  15.     while(0U != delay){
  16.     }
  17. }
  18. void delay_decrement(void)
  19. {
  20.     if(0U != delay){
  21.         delay--;
  22.     }
  23. }
 楼主| zuyilu 发表于 2022-5-25 15:23 | 显示全部楼层
方式2的完整代码
  1. void systick_config(void)
  2. {
  3.     /* systick clock source is from HCLK/8 */
  4.     systick_clksource_set(SYSTICK_CLKSOURCE_HCLK_DIV8);
  5.     count_1us = (float)SystemCoreClock/8000000;
  6.     count_1ms = (float)count_1us * 1000;
  7. }
  8. void delay_1us(uint32_t count)
  9. {
  10.     uint32_t ctl;
  11.    
  12.     /* reload the count value */
  13.     SysTick->LOAD = (uint32_t)(count * count_1us);
  14.     /* clear the current count value */
  15.     SysTick->VAL = 0x0000U;
  16.     /* enable the systick timer */
  17.     SysTick->CTRL = SysTick_CTRL_ENABLE_Msk;
  18.     /* wait for the COUNTFLAG flag set */
  19.     do{
  20.         ctl = SysTick->CTRL;
  21.     }while((ctl&SysTick_CTRL_ENABLE_Msk)&&!(ctl & SysTick_CTRL_COUNTFLAG_Msk));
  22.     /* disable the systick timer */
  23.     SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
  24.     /* clear the current count value */
  25.     SysTick->VAL = 0x0000U;
  26. }
  27. void delay_1ms(uint32_t count)
  28. {
  29.     uint32_t ctl;
  30.    
  31.     /* reload the count value */
  32.     SysTick->LOAD = (uint32_t)(count * count_1ms);
  33.     /* clear the current count value */
  34.     SysTick->VAL = 0x0000U;
  35.     /* enable the systick timer */
  36.     SysTick->CTRL = SysTick_CTRL_ENABLE_Msk;
  37.     /* wait for the COUNTFLAG flag set */
  38.     do{
  39.         ctl = SysTick->CTRL;
  40.     }while((ctl&SysTick_CTRL_ENABLE_Msk)&&!(ctl & SysTick_CTRL_COUNTFLAG_Msk));
  41.     /* disable the systick timer */
  42.     SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
  43.     /* clear the current count value */
  44.     SysTick->VAL = 0x0000U;
  45. }
lifeforrent 发表于 2022-5-25 15:39 | 显示全部楼层
官方例程中,方式1是使用中断实现延时,而且尽量保证10us以上产生一次中断;所以延时时间数量级一般是10us;方式2的延时是不用中断的,延时时间一般是1us数量级;如果你要用方式2采用中断实现延时,必须考虑进出中断的时间
 楼主| zuyilu 发表于 2022-5-25 16:19 | 显示全部楼层
lifeforrent 发表于 2022-5-25 15:39
官方例程中,方式1是使用中断实现延时,而且尽量保证10us以上产生一次中断;所以延时时间数量级一般是10us ...

厉害厉害,专业啊,那我就用中断方式吧。我把所有微秒延时都改毫秒了,竟然可以运行。感谢感谢
sonicll 发表于 2022-5-26 09:04 | 显示全部楼层
方式2的原理是给systick设置你想要的计数值,然后轮询等待计数值减到0,这个过程不需要中断。方式2有一个限制,因为systick的计数寄存器是24位的,所以你自己要确保count*count_1us不能超过24bit,这样就会导致最大延时值有限制。而方式1是不存在最大延时值限制的
 楼主| zuyilu 发表于 2022-5-26 16:14 | 显示全部楼层
sonicll 发表于 2022-5-26 09:04
方式2的原理是给systick设置你想要的计数值,然后轮询等待计数值减到0,这个过程不需要中断。方式2有一个限 ...

原来是这样,怪不得,那我明白了,非常感谢啊[强][强]
zhangpeizhong 发表于 2022-6-11 17:32 | 显示全部楼层
我在嘉立创做板子,SMT,采用了GD32F103C8T6,调试通不过。发现这批次GD32F103C8T6有问题。具体是systick的功能不良。导致delay函数无法正常工作。调试过程,其它正常,一旦涉及systick,就不正常。我另外购买了有GD32F103C8T6芯片的开发板进行对比验证,开发板跑《1.GPIO输出实验》正常;同样在这次SMT板,跑到delay(涉及systick)就不行了,程序死在systick相关环节delay函数中。
   开发板与SMT板核心电路基本一样,下载、调试功能均正常。就是这次SMT板涉及systick相关环节就出问题。而开发板则正常。更换其它官方测试程序,也是一样效果。判断这批次GD32F103C8T6有问题。现在还在与嘉立创协调中。
      楼主是否与我这个情况是否相同原因。
      188862a4611ab88cc.png

     
      

1.GPIO输出实验(测试程序).zip

319.55 KB, 下载次数: 0

您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

10

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部