RT-Thread论坛
直播中

陈伟

7年用户 1454经验值
私信 关注

使用RT-Thread studio stlink调试时会卡死的原因?

在使用 RT-Thread studio stlink调试 很简单的一个示例调试有时卡死,


int main(void)
{
   tim_init();
    while (1)
   {
        //rt_thread_mdelay(2000);
   }
    return RT_EOK;
}
============================================================
#ifndef APP_TIM_H_
#define APP_TIM_H_
#include
#include
void tim_init();
#endif /* APP_TIM_H_ */
============================================================
#include "tim.h"
/*
*  软件定时器
*
* */
rt_timer_t  tim1 =NULL ;
struct rt_timer tim2;
rt_err_t ret ;
void tim1_timeout(void *parameter) //定时器1回调(每到定时时间就进来一次)
{
    rt_kprintf("ONE is OK\n ");
}
void tim2_timeout(void* parameter)//定时器2回调 (每到定时时间就进来一次)
{
    //rt_kprintf("TWO is OK\n ");
    static  int  count =0 ;
    if(count >=2)
    {
        rt_kprintf("TWO is OK\n ");
        count =0 ;
    }
    else {
        count ++;
    }
}
void tim_init()
{
    /*动态创建*/
    tim1 = rt_timer_create("tim1 demo",
                                tim1_timeout,
                                RT_NULL,
                                2000,  //定时时间2s一次
                                RT_TIMER_FLAG_ONE_SHOT );//单次定时
     /*静态创建*/
     rt_timer_init(&tim2,
                       "tim2 demo ",
                       tim2_timeout,
                       RT_NULL,
                       1000, ////定时时间1s一次
                       RT_TIMER_FLAG_PERIODIC );//周期定时
    if(tim1 !=NULL )
    {
        rt_timer_start(tim1);
    }
         //启动定时器
             rt_timer_start(tim1);
             //rt_timer_start(&tim2);
}

回帖(1)

陈萍

2024-2-19 16:55:24
你这主函数while() 循环中延时注释掉了? 那样无法执行其他任务了吧
举报

更多回帖

发帖
×
20
完善资料,
赚取积分