Chum_A (25.06.2015 15:44 - 15:47, просмотров: 132) ответил Nikolay801_ на там еще есть такая полезная штука, для поиска источника проблемы
Мопед не мой, с "Миландровского форума". И кстати, отладочную печать можно и через SWD/SWO вывести.
void HardFault_Handler()
{
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.
}
void Hard_fault_handler_c(unsigned int* hardfault_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]\r\n");
printf ("R0 = 0x%x\r\n", stacked_r0);
printf ("R1 = 0x%x\r\n", stacked_r1);
printf ("R2 = 0x%x\r\n", stacked_r2);
printf ("R3 = 0x%x\r\n", stacked_r3);
printf ("R12 = 0x%x\r\n", stacked_r12);
printf ("LR = 0x%x\r\n", stacked_lr);
printf ("PC = 0x%x\r\n", stacked_pc);
printf ("PSR = 0x%x\r\n", stacked_psr);
while(1);
}
ЗЫ
прототип fputc должен быть переопределен для работы с функцией printf.
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
PUTCHAR_PROTOTYPE{
UART_SendData(MDR_UART_DEBUG, (uint8_t) ch);
// Loop until the end of transmission
while (UART_GetFlagStatus(MDR_UART_DEBUG, UART_FLAG_TXFF) == SET);
return ch;
}