对于一些莫名奇妙的错误
未定义异常错误函数 在汇编里面
UsageFault_Handler\
PROC
; get current context
TST lr, #0x04 ; if(!EXC_RETURN[2])
ITE EQ
MRSEQ r0, msp ; [2]=0 ==> Z=1, get fault context from handler.
MRSNE r0, psp ; [2]=1 ==> Z=0, get fault context from thread.
STMFD r0!, {r4 - r11} ; push r4 - r11 register
STMFD r0!, {lr} ; push exec_return register
TST lr, #0x04 ; if(!EXC_RETURN[2])
ITE EQ
MSREQ msp, r0 ; [2]=0 ==> Z=1, update stack pointer to MSP.
MSRNE psp, r0 ; [2]=1 ==> Z=0, update stack pointer to PSP.
PUSH {lr}
BL rt_hw_hard_fault_exception
POP {lr}
ORR lr, lr, #0x04
BX lr
ENDP
找到原来的HardFault_Handler函数,替换为一下类容
#if 0
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
#else
#define rt_uint32_t unsigned int
struct exception_info
{
rt_uint32_t exc_return;
rt_uint32_t r4;
rt_uint32_t r5;
rt_uint32_t r6;
rt_uint32_t r7;
rt_uint32_t r8;
rt_uint32_t r9;
rt_uint32_t r10;
rt_uint32_t r11;
rt_uint32_t r0;
rt_uint32_t r1;
rt_uint32_t r2;
rt_uint32_t r3;
rt_uint32_t r12;
rt_uint32_t lr;
rt_uint32_t pc;
rt_uint32_t psr;
};
/*
* fault exception handler
*/
void rt_hw_hard_fault_exception(struct exception_info * exception_info)
{
unsigned int *app_sp;
int i;
app_sp = (unsigned int *)(exception_info + 1); /* context + 16*4 */
printf("psr: 0x%08x\r\n", exception_info->psr);
printf("r00: 0x%08x\r\n", exception_info->r0);
printf("r01: 0x%08x\r\n", exception_info->r1);
printf("r02: 0x%08x\r\n", exception_info->r2);
printf("r03: 0x%08x\r\n", exception_info->r3);
printf("r04: 0x%08x\r\n", exception_info->r4);
printf("r05: 0x%08x\r\n", exception_info->r5);
printf("r06: 0x%08x\r\n", exception_info->r6);
printf("r07: 0x%08x\r\n", exception_info->r7);
printf("r08: 0x%08x\r\n", exception_info->r8);
printf("r09: 0x%08x\r\n", exception_info->r9);
printf("r10: 0x%08x\r\n", exception_info->r10);
printf("r11: 0x%08x\r\n", exception_info->r11);
printf("r12: 0x%08x\r\n", exception_info->r12);
printf(" lr: 0x%08x\r\n", exception_info->lr);
printf(" pc: 0x%08x\r\n", exception_info->pc);
printf("stacks: \r\n");
i = 0;
for (i = 0; i < 1024; )
{
printf("%08x ", *app_sp);
app_sp++;
i++;
if (i % 16 == 0)
printf("\r\n");
}
printf("\r\n");
while (1);
}
#endif
fromelf --text -a -c --output=all.dis F103_Moduel\F103_Moduel.axf
fromelf --bin --output=test.bin F103_Moduel\F103_Moduel.axf
先要启动这个函数才能定义未定义指令的异常
void UsageFaultInit(void)
{
SCB->SHCSR |= (SCB_SHCSR_USGFAULTENA_Msk);
}
传入的参数为0,参数被破坏了
文章来源:https://www.toymoban.com/news/detail-712653.html
总结,当函数发生异常时。找到函数的起始地址,查看当前寄存器的值,对着 汇编文件看,文章来源地址https://www.toymoban.com/news/detail-712653.html
到了这里,关于调试绝招—断点的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!