嵌入式技术论坛
直播中

哔哔哔-

8年用户 1265经验值
擅长:电源/新能源
私信 关注
[问答]

RT-Thread call stack一直在乱飞是怎么回事

12年开发的一个项目一直在使用rt-thread,因为客户要求修改产品功能。只在应用程序中增加了一行代码。却导到芯片一直复位。J-LINK跟踪发现call stack非常零乱,未按正常的调用逻辑在显示。然后将原来的RT-THREAD版本 V1.0.1更新到V2.0.2版本。程序能正常运行。但因为版本间的差异,原来我添加的设备不能正常工作了,跟踪发现当前版本需要调用rt_device_open函数。在代码中添加了open函数后,问题复原了,call stack一直在乱飞。

void rt_hw_chip_24c08_init(void)

{

rt_err_t err; 

chip_24c08.type    = RT_Device_Class_MTD; 

/* register rtc device */

chip_24c08.init      = RT_NULL; 

chip_24c08.open  = rt_chip_24c08_open; 

chip_24c08.close  = RT_NULL; 

chip_24c08.read   = rt_chip_24c08_read; 

chip_24c08.write  = rt_chip_24c08_write; 

chip_24c08.control = RT_NULL; 

/* no private */

//chip_24c08.private = RT_NULL; 

I2C_GPIO_Config(); 

//rt_device_init(&chip_24c08);     

err = rt_device_register(&chip_24c08, "EEPROM", RT_DEVICE_FLAG_RDWR); 

if(err != RT_EOK) { 

    rt_kprintf("register eeprom failed!

");

} else { 

    chip_24c08.ref_count = 1; 

    //rt_device_open(&chip_24c08, RT_DEVICE_FLAG_RDWR); 

} 

return;

}

将添加的代码删除也不能再正常恢复工作。。。

程序一直在重启。

在退出当前函数,接近退出上级函数时,看call stack的变化

硬件平台为:

ARM Cortex-M3 STM32F107VCT6

编译器:

程序编译结果大小为:

Build target 'RT-Thread STM32'

linking...

Program Size: Code=124356 RO-data=65336 RW-data=1084 ZI-data=46180

FromELF: creating hex file...

".obj

tthread-stm32.axf" - 0 Error(s), 0 Warning(s).

出现问题后,将.sp/stm32f107/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/arm/startup_stm32f10x_cl.s文件内部定义的栈也进行了加大

Stack_Size EQU 0x00000600

AREA    STACK, NOINIT, READWRITE, ALIGN=3

Stack_Mem SPACE Stack_Size

__initial_sp

; Heap Configuration

; Heap Size (in Bytes) 0x0-0xFFFFFFFF:8

;

Heap_Size EQU 0x00000400

AREA    HEAP, NOINIT, READWRITE, ALIGN=3

__heap_base

Heap_Mem SPACE Heap_Size

__heap_limit

对创建的任务栈也进行了加大

int rt_application_init()

{

rt_thread_t netsw_main_thread;    

rt_thread_t init_thread;

#if (RT_THREAD_PRIORITY_MAX==32)

init_thread = rt_thread_create("ETHTASK",

    rt_init_thread_entry, RT_NULL, 2560, 8, 20

);

#else

init_thread = rt_thread_create("ETHTASK",

    rt_init_thread_entry, RT_NULL, 2048, 80, 20

);

#endif

if (init_thread != RT_NULL) { 

    rt_thread_startup(init_thread);     

}

//network main thread

netsw_main_thread = rt_thread_create("SWTASK",

    ekongyun_NetSwitch_main, RT_NULL, 512, 20, 10

);

if (netsw_main_thread != RT_NULL)  { 

    rt_thread_startup(netsw_main_thread); 

}

return 0;

}

这个处理后,故障依旧!

面对这种问题,还应该做什么? 如何让这个故障不再重演呢?

回帖(1)

王平

2022-8-5 10:21:01
控制台一直在打印系统LOGO,因为程序弹栈运行到rt_thread_exit()函数后,程序自动复位了

  1. | /

  2. RT - Thread Operating System
  3. / | 2.0.2 build Mar 2 2016
  4. 2006 - 2015 Copyright by rt-thread team
  5. rtc had synchro…
  6. TCP/IP initialized!
  7. finsh>>
  8. | /
  9. RT - Thread Operating System
  10. / | 2.0.2 build Mar 2 2016
  11. 2006 - 2015 Copyright by rt-thread team
  12. rtc had synchro…
  13. TCP/IP initialized!
  14. finsh>>
  15. | /
  16. RT - Thread Operating System
  17. / | 2.0.2 build Mar 2 2016
  18. 2006 - 2015 Copyright by rt-thread team
  19. rtc had synchro…
  20. TCP/IP initialized!
  21. finsh>>
举报

更多回帖

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