STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Loading...
Searching...
No Matches
fault.c
Go to the documentation of this file.
1
5#include "fault.h"
6
11
13
19
20void faultCapture(FaultRecord_t *record, const ScbRegisters_t *scb, const uint32_t *frame,
21 uint32_t exc_return)
22{
23 uint32_t cfsr = scb->CFSR;
24
26 record->exc_return = exc_return;
27 record->cfsr = cfsr;
28 record->hfsr = scb->HFSR;
29 record->mmfar = scb->MMFAR;
30 record->bfar = scb->BFAR;
31 record->frame_valid = ((cfsr & (SCB_CFSR_MSTKERR | SCB_CFSR_STKERR)) == 0U);
32
33 if (record->frame_valid)
34 {
35 record->r0 = frame[0];
36 record->r1 = frame[1];
37 record->r2 = frame[2];
38 record->r3 = frame[3];
39 record->r12 = frame[4];
40 record->lr = frame[5];
41 record->pc = frame[6];
42 record->xpsr = frame[7];
43 }
44 else
45 {
46 record->r0 = 0U;
47 record->r1 = 0U;
48 record->r2 = 0U;
49 record->r3 = 0U;
50 record->r12 = 0U;
51 record->lr = 0U;
52 record->pc = 0U;
53 record->xpsr = 0U;
54 }
55}
56
Fault driver: enable the configurable faults and record a fault for the debugger.
void faultEnable(ScbRegisters_t *scb)
Give MemManage, BusFault and UsageFault their own handlers, and trap integer division by zero.
Definition fault.c:14
void faultCapture(FaultRecord_t *record, const ScbRegisters_t *scb, const uint32_t *frame, uint32_t exc_return)
Fill record from the fault status registers and the stacked frame.
Definition fault.c:20
FaultRecord_t faultRecord
Filled by Fault_Handler; read it from the debugger.
Definition fault.c:12
#define SCB_SHCSR_BUSFAULTENA
Enable BusFault (otherwise it escalates to HardFault).
Definition scb_reg.h:195
#define SCB_CFSR_MSTKERR
MemManage: fault while stacking on exception entry.
Definition scb_reg.h:215
#define SCB_ICSR_VECTACTIVE_Msk
<span class="regaccess">ro</span> Number of the active exception (0 in Thread mode).
Definition scb_reg.h:111
#define SCB_SHCSR_USGFAULTENA
Enable UsageFault (otherwise it escalates to HardFault).
Definition scb_reg.h:198
#define SCB_CFSR_STKERR
BusFault: fault while stacking on exception entry.
Definition scb_reg.h:236
#define SCB_CCR_DIV_0_TRP
Trap divide by zero.
Definition scb_reg.h:150
#define SCB_SHCSR_MEMFAULTENA
Enable MemManage (otherwise it escalates to HardFault).
Definition scb_reg.h:192
#define SCB_ICSR_VECTACTIVE_Pos
Bits 8:0.
Definition scb_reg.h:109
What Fault_Handler saw.
Definition fault.h:35
uint32_t bfar
BFAR; the fault address only if CFSR.BFARVALID.
Definition fault.h:41
uint32_t exception
ICSR.VECTACTIVE: 3 HardFault, 4 MemManage, 5 BusFault, 6 UsageFault.
Definition fault.h:36
uint32_t lr
Stacked LR: the faulting function's return address.
Definition fault.h:51
uint32_t r1
Stacked R1.
Definition fault.h:47
bool frame_valid
The registers below were read from the stacked frame.
Definition fault.h:45
uint32_t pc
Stacked PC: the faulting instruction, or the next one for an imprecise fault.
Definition fault.h:52
uint32_t mmfar
MMFAR; the fault address only if CFSR.MMARVALID.
Definition fault.h:40
uint32_t xpsr
Stacked xPSR.
Definition fault.h:53
uint32_t exc_return
LR on entry; bit 2 set means the frame is on PSP.
Definition fault.h:37
uint32_t cfsr
CFSR: MMFSR (7:0), BFSR (15:8), UFSR (31:16).
Definition fault.h:38
uint32_t r0
Stacked R0.
Definition fault.h:46
uint32_t r2
Stacked R2.
Definition fault.h:48
uint32_t r3
Stacked R3.
Definition fault.h:49
uint32_t r12
Stacked R12.
Definition fault.h:50
uint32_t hfsr
HFSR: FORCED means a configurable fault escalated.
Definition fault.h:39
SCB register block.
Definition scb_reg.h:41
volatile uint32_t BFAR
0x38: BusFault address
Definition scb_reg.h:56
volatile uint32_t CCR
0x14: configuration and control
Definition scb_reg.h:47
volatile uint32_t MMFAR
0x34: MemManage fault address
Definition scb_reg.h:55
volatile uint32_t HFSR
0x2C: HardFault status
Definition scb_reg.h:53
volatile uint32_t CFSR
0x28: configurable fault status (MMFSR, BFSR, UFSR)
Definition scb_reg.h:52
volatile uint32_t ICSR
0x04: interrupt control and state
Definition scb_reg.h:43
volatile uint32_t SHCSR
0x24: system handler control and state
Definition scb_reg.h:51