-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.3: addded exceptions.c and reworked stdream module
- Loading branch information
Showing
6 changed files
with
240 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*!\file exceptions.c | ||
** \author SMFSW | ||
** \version v0.3 | ||
** \date 2017 | ||
** \copyright MIT (c) 2017, SMFSW | ||
** \brief Debug tool helpers functions | ||
**/ | ||
|
||
#include <string.h> | ||
|
||
#include "exceptions.h" | ||
|
||
#include "stdream_rdir.h" | ||
|
||
|
||
void stackDump(uint32_t stack[]) | ||
{ | ||
enum { r0, r1, r2, r3, r12, lr, pc, psr}; | ||
|
||
printf("r0 = 0x%08lx\n", stack[r0]); | ||
printf("r1 = 0x%08lx\n", stack[r1]); | ||
printf("r2 = 0x%08lx\n", stack[r2]); | ||
printf("r3 = 0x%08lx\n", stack[r3]); | ||
printf("r12 = 0x%08lx\n", stack[r12]); | ||
printf("lr = 0x%08lx\n", stack[lr]); | ||
printf("pc = 0x%08lx\n", stack[pc]); | ||
printf("psr = 0x%08lx\n", stack[psr]); | ||
} | ||
|
||
|
||
void HardFault_Handler_callback(uint32_t stack[]) | ||
{ | ||
printf("Hard Fault handler\t"); | ||
printf("SCB->HFSR = 0x%08lx\n", SCB->HFSR); | ||
|
||
if ((SCB->HFSR & (1 << 30)) != 0) | ||
{ | ||
uint32_t CFSRValue = SCB->CFSR; | ||
|
||
printf("Hard Fault\t"); | ||
printf("SCB->CFSR = 0x%08lx\n", CFSRValue); | ||
if ((SCB->CFSR & 0xFFFF0000) != 0) | ||
{ | ||
printf("Usage fault: "); | ||
CFSRValue >>= 16; // right shift to lsb | ||
if((CFSRValue & (1 << 9)) != 0) { printf("Zero div\n"); } | ||
} | ||
|
||
if ((SCB->CFSR & 0xFF00) != 0) | ||
{ | ||
CFSRValue = ((CFSRValue & 0x0000FF00) >> 8); // mask and shift | ||
printf("Bus fault: 0x%02lx\n", CFSRValue); | ||
} | ||
|
||
if ((SCB->CFSR & 0xFF) != 0) { | ||
CFSRValue &= 0x000000FF; // mask other faults | ||
printf("Memory Management fault: 0x%02lx\n", CFSRValue); | ||
} | ||
} | ||
|
||
stackDump(stack); | ||
|
||
__BKPT(01); | ||
while(1); | ||
} | ||
|
||
|
||
void Error_Handler_callback(uint32_t stack[]) | ||
{ | ||
// TODO: maybe pass by another asm code to retrieve HAL error code if not in stack | ||
printf("Error handler\t"); | ||
stackDump(stack); | ||
|
||
// __BKPT(01); | ||
// while(1); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*!\file exceptions.h | ||
** \author SMFSW | ||
** \version v0.3 | ||
** \date 2017 | ||
** \copyright MIT (c) 2017, SMFSW | ||
** \brief Debug tool and helpers declaration | ||
**/ | ||
/****************************************************************/ | ||
#ifndef __EXCEPTIONS_H | ||
#define __EXCEPTIONS_H | ||
/****************************************************************/ | ||
|
||
#include "sarmfsw.h" | ||
#include CMSIS_INC | ||
#include CMSIS_CFG | ||
|
||
|
||
#define exception_Handler(e) \ | ||
__asm( "tst lr, #4 \n" \ | ||
"ite EQ \n" \ | ||
"mrseq r0, MSP \n" \ | ||
"mrsne r0, PSP \n" \ | ||
"b " #e "_Handler_callback \n") //!< The exception_Handler should be called with corresponding exception name \b e as parameter | ||
|
||
|
||
#define dump_stack() \ | ||
__asm( "tst lr, #4 \n" \ | ||
"ite EQ \n" \ | ||
"mrseq r0, MSP \n" \ | ||
"mrsne r0, PSP \n" \ | ||
"b stackDump \n") | ||
|
||
|
||
/* Handled callbacks for reference | ||
** (not really needed as called by assembly from macro) | ||
** use macros to pass stack pointer properly */ | ||
void HardFault_Handler_callback(uint32_t stack[]); // HardFault handler | ||
void Error_Handler_callback(uint32_t stack[]); // HAL Error handler | ||
|
||
|
||
/****************************************************************/ | ||
#endif | ||
/****************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters