RT-Thread论坛
直播中

凌流浪

9年用户 1063经验值
擅长:可编程逻辑 电源/新能源
私信 关注

调用rt_timer_check函数就报错,为什么?

调用rt_timer_check函数就报错

(rt_interrupt_get_nest() > 0) assertion failed at function:rt_timer_check, line number:677
[W/kernel.service] rt_hw_backtrace_frame_unwind is not implemented
please use: addr2line -e rtthread.elf -a -f 0x800320e[W/kernel.service] rt_hw_backtrace_frame_unwind is not implemented

回帖(1)

h1654155275.5748

2025-6-17 18:04:44

这个错误是由于在非中断上下文中调用了 rt_timer_check() 函数导致的。让我们一步步分析原因和解决方案:


错误原因分析




  1. 上下文检查失败

    rt_timer_check() 是 RT-Thread 内核的 内部函数,设计为只在中断上下文(尤其是时钟中断)中调用

    错误信息中的断言 (rt_interrupt_get_nest() > 0) 检查失败,表明你在非中断环境(如线程/任务)中调用了此函数。




  2. 错误调用场景:  



    • 错误发生在 rt_timer_check 的第 677 行,检测到 rt_interrupt_get_nest() == 0(即不在中断嵌套中)。

    • 堆栈回溯信息(如 0x800320e)指向调用源的位置(需要通过 addr2line 工具定位具体代码)。




  3. 堆栈回溯未实现

    提示 rt_hw_backtrace_frame_unwind is not implemented 表示当前硬件平台未实现堆栈回溯功能,需要你手动分析调用路径。






解决方案


1. 停止在非中断环境中调用 rt_timer_check()



  • 此函数是内核定时器调度的内部接口,用户代码不应直接调用

  • 正确做法:通过系统提供的定时器 API 操作:
     rt_timer_t my_timer = rt_timer_create(...);  // 创建定时器
    rt_timer_start(my_timer);                   // 启动定时器


2. 定位错误调用点


使用 addr2line 分析错误日志中的地址:


   addr2line -e rtthread.elf -a -f 0x800320e


  • 输出将显示调用 rt_timer_check() 的具体文件及行号。

  • 检查该位置的代码逻辑,移除对 rt_timer_check() 的直接调用。


3. 检查定时器回调函数


如果错误发生在定时器超时回调中:



  • 确保回调函数 不调用阻塞型 API(如 rt_thread_delay())。

  • 检查回调中是否误用了其他内部函数(如 rt_timer_* 系列)。


4. 检查中断配置



  • 确认系统时钟中断(如 SysTick_Handler())正确启用了 rt_timer_check() 的调用。

  • 禁止在自定义中断中手动调用此函数。




关键原则



  • rt_timer_check() 是内核私有函数,仅由中断处理流程调用。

  • 用户定时器操作 应使用官方 API:

    rt_timer_create(), rt_timer_start(), rt_timer_stop(), 等。


调试建议



  1. 全局搜索代码中的 rt_timer_check,删除所有调用。

  2. 使用 addr2line 定位问题代码后,检查其所属模块的定时器使用方式。

  3. 若问题在中断中发生,确认中断嵌套处理是否正确(如 rt_interrupt_enter()/exit())。


通过上述修正,即可解决断言失败问题。务必确保不直接调用内核内部未公开接口。

举报

更多回帖

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