IAR⽤于调试的HardFault异常处理
⽤于调试的hardfault
在编写STM32程序代码时由于⾃⼰的粗⼼会发现有时候程序跑着跑着就进⼊了
HardFault_Handler中断,按照经验来说进⼊HardFault_Handler故障的原因主要有两个⽅⾯:
1:内存溢出或则访问越界。
2:堆栈溢出。
发⽣异常后我们可以⾸先查看LR寄存器的值,确认当前使⽤的堆栈是MSP还是PSP,然后找到相对应的堆栈指针,并在内存中查看相对应堆栈的内容,内核将R0~R3,R12,LR,PC,XPRS寄存器依次⼊栈,其中LR即为发⽣异常前PC将要执⾏的下⼀条指令地址。mba如何报名
/******************************************************************************/
/* Cortex-M4 Processor Interruption and Exception Handlers */
/******************************************************************************/
线性代数试卷
void hard_fault_handler_c( unsigned int* hardfault_args )
{
unsigned char svc_num;
unsigned int stacked_r0;
unsigned int stacked_r1;
unsigned int stacked_r2;
unsigned int stacked_r3;
unsigned int stacked_r12;
unsigned int stacked_lr;
unsigned int stacked_pc;
unsigned int stacked_psr;
stacked_r0 = ( ( unsigned long )hardfault_args[0] );
stacked_r1 = ( ( unsigned long )hardfault_args[1] );
stacked_r2 = ( ( unsigned long )hardfault_args[2] );
stacked_r3 = ( ( unsigned long )hardfault_args[3] );
stacked_r12 = ( ( unsigned long )hardfault_args[4] );
stacked_lr = ( ( unsigned long )hardfault_args[5] );
stacked_pc = ( ( unsigned long )hardfault_args[6] );
bargainingstacked_psr = ( ( unsigned long ) hardfault_args[7] );
svc_num = ( ( char* )stacked_r0 )[-2];
女英文名大全
/******************* Add yourdebug trace here ***********************/
hardfault_args[0] = stacked_r0 + stacked_r1;
printf("r0: %x\r\n", stacked_r0);
workout造句......
while(1)
{
}
}
#if defined ( __ICCARM__ )
void HardFault_Handler( void )
{
__ASM("TST lr, #4\n");
__ASM("ITE EQ\n"
"MRSEQ r0, MSP\n"
"MRSNE r0, PSP\n");
__ASM("MOV r1, LR\n");
__ASM("B hard_fault_handler_c");
}
#el//#if defined ( __CC_ARM )
注意上边汇编哪⾥
IAR Embedded Workbench for ARM version 7.30 (and earlier) accepted constructions like:
[...]
__ASM("ITE EQ");
__ASM("MRSEQ R0, MSP");
高中英语单词听力
__ASM("MRSNE R0, PSP");
汉英字典>glbt[...]
The above is a bug which is corrected in IAR Embedded Workbench for ARM version 7.40.1.
paul george
The code above will generate diagnostic messages like:
Error[Ta117]: IT-block ends prematurely, or there is a label within the IT-block
Discussion
The construction above is unsafe, as in-between the asm()-statements it was possible to place ordinary C source code.
Suggested rewrite
Change the construction into a single inline asbler statement, with multiple lines.
The above construction should be rewritten to:
[…]
__ASM(“ITE EQ \n”
“MRSEQ R0, MSP \n”
muzak“MRSNE R0, PSP”);
[…]