我以前也是这么想,用的uCOS-II操作系统,异常时,把任务堆栈内容打印出来,看看PC和LR的值,大致定位程序出错在那一段代码。
SystemDebug(SYSDBG_USART, "R0 : 0x%08x\n\r", *(p_sp + 0x01));
SystemDebug(SYSDBG_USART, "R1 : 0x%08x\n\r", *(p_sp + 0x02));
SystemDebug(SYSDBG_USART, "R2 : 0x%08x\n\r", *(p_sp + 0x03));
SystemDebug(SYSDBG_USART, "R3 : 0x%08x\n\r", *(p_sp + 0x04));
SystemDebug(SYSDBG_USART, "R4 : 0x%08x\n\r", *(p_sp + 0x05));
SystemDebug(SYSDBG_USART, "R5 : 0x%08x\n\r", *(p_sp + 0x06));
SystemDebug(SYSDBG_USART, "R6 : 0x%08x\n\r", *(p_sp + 0x07));
SystemDebug(SYSDBG_USART, "R7 : 0x%08x\n\r", *(p_sp + 0x08));
SystemDebug(SYSDBG_USART, "R8 : 0x%08x\n\r", *(p_sp + 0x09));
SystemDebug(SYSDBG_USART, "R9 : 0x%08x\n\r", *(p_sp + 0x0A));
SystemDebug(SYSDBG_USART, "R10 : 0x%08x\n\r", *(p_sp + 0x0B));
SystemDebug(SYSDBG_USART, "R11 : 0x%08x\n\r", *(p_sp + 0x0C));
SystemDebug(SYSDBG_USART, "R12 : 0x%08x\n\r", *(p_sp + 0x0D));
SystemDebug(SYSDBG_USART, "SP : 0x%08x\n\r", p_sp);
SystemDebug(SYSDBG_USART, "LR : 0x%08x\n\r", *(p_sp + 0x0E));
SystemDebug(SYSDBG_USART, "PC : 0x%08x\n\r", *(p_sp + 0x0F));
SystemDebug(SYSDBG_USART, "CPSR: 0x%08x\n\r\n\r", *(p_sp + 0x00)); |