kosyak (02.02.2013 13:05, просмотров: 95) ответил vmp на Никому не попадался продвинутый обработчик Usage Fault и прочих фаултов для Cortex-M3? Хочется, чтобы он расписывал на терминале всю информацию о причине отказа в удобочитаемом виде.
Пользую хардфаулт в таком виде - void HardFaultException( void )
{
unsigned int contr_reg;
contr_reg = __get_CONTROL();
if(contr_reg&2)
{
asm("MRS R0, PSP");
}
else{
asm("MRS R0, MSP");
}
asm("B (Hard_fault_handler_c)"); //top of stack is in R0. It is passed to C-function.
while (1)
{
}
}
void Hard_fault_handler_c(unsigned long* hard_fault_args)
{
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]);
stacked_psr = ((unsigned long) hardfault_args[7]);
printf ("[Hard fault handler]\n");
printf ("R0 = %x\n", stacked_r0);
printf ("R1 = %x\n", stacked_r1);
printf ("R2 = %x\n", stacked_r2);
printf ("R3 = %x\n", stacked_r3);
printf ("R12 = %x\n", stacked_r12);
printf ("LR = %x\n", stacked_lr);
printf ("PC = %x\n", stacked_pc);
printf ("PSR = %x\n", stacked_psr);
}