SRTOS
Loading...
Searching...
No Matches
fault.h File Reference

Fault handling interface for SRTOS. More...

#include "mcu_macros.h"
#include <stdint.h>
Include dependency graph for fault.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 __attribute ((naked)) uint32_t *systemGet_Fault_SP(__attribute__((unused)) uint32_t faultLR)
 Returns the Stack Pointer after a fault.
void systemHandle_Fault (uint32_t *faultSP)
 This function will handle a system fault. The default behavior is to log the fault SP to non-volatile memory.
 __attribute__ ((naked)) void HardFault_Handler()
 This function will get the fault Stack Pointer and call the fault handler.

Detailed Description

Fault handling interface for SRTOS.

Declares fault handling routines for capturing and processing system exceptions.

Definition in file fault.h.

Function Documentation

◆ __attribute()

__attribute ( (naked) )

Returns the Stack Pointer after a fault.

Parameters
faultLRThis is the link register, which will be used to return to the function's caller. It is marked unused to suppress the unused paramter compiler warning.
Note
This function will only be called by Inline Assembly.
Warning
This function should not be called by user code.

Definition at line 11 of file fault.c.

13{
14 __asm volatile ("TST r0, #4\n"
15 "ITE eq\n"
16 "MRSEQ r0, msp\n"
17 "MRSNE r0, psp\n"
18 "BX lr\n");
19}
Here is the call graph for this function:

◆ __attribute__()

__attribute__ ( (naked) )

This function will get the fault Stack Pointer and call the fault handler.

Note
This function is merely an intermediary step to the fault handler. The user should not need to change this function.
Warning
This function should not be called by user code.

Definition at line 79 of file fault.c.

81{
82 __asm volatile ("MOV r0, lr\n"
83 "BL systemGet_Fault_SP\n"
84 "LDR r1, =systemHandle_Fault\n"
85 "BX r1\n");
86}
Here is the caller graph for this function:

◆ systemHandle_Fault()

void systemHandle_Fault ( uint32_t * faultSP)

This function will handle a system fault. The default behavior is to log the fault SP to non-volatile memory.

This function can be editted as the user needs. There is not one specific action that needs to be done here, it just depends on how the user wants to handle faults.

Parameters
faultSPThe fault Stack Pointer that, by default, will be written to non-volatile memory. This will be the best representation of why the system faulted.
Warning
This function must not return.
This function should not be called by user code.

Definition at line 22 of file fault.c.

23{
26
27 while (FLASH_SR & (1U << FLASH_SR_BSY_BIT))
28 ;
29
30 /* PSIZE -> 0b10 which is a 32 bit parallelism size */
32 FLASH_CR &= ~(1U << (FLASH_CR_PSIZE_BIT_START + 1));
33 FLASH_CR |= (1U << (FLASH_CR_PSIZE_BIT_START + 1));
34
35 while (FLASH_SR & (1U << FLASH_SR_BSY_BIT))
36 ;
37
38 /* Activate Sector Erase */
39 FLASH_CR |= (1U << FLASH_CR_SER_BIT);
40
41 /* Erase Sector 7 (FAULT_DATA) */
42 FLASH_CR &= ~(0xFU << FLASH_CR_SNB_BIT_START);
44
45 FLASH_CR |= (1U << FLASH_CR_STRT_BIT);
46
47 while (FLASH_SR & (1U << FLASH_SR_BSY_BIT))
48 ;
49
50 FLASH_CR |= (1U << FLASH_CR_PG_BIT);
51
52 /*
53 * Push order:
54 * r0
55 * r1
56 * r2
57 * r3
58 * r12
59 * lr
60 * pc
61 * psr
62 * */
63
64 volatile uint32_t *curWriteAddr
65 = (volatile uint32_t *)FAULT_DATA_FLASH_START_ADDR;
66 for (int i = 0; i < 8; i++)
67 {
68 *(curWriteAddr) = faultSP[i];
69 curWriteAddr += 1;
70 }
71
72 while (FLASH_SR & (1U << FLASH_SR_BSY_BIT))
73 ;
74
75 while (1)
76 ;
77}
#define FLASH_CR_PSIZE_BIT_START
Definition mcu_macros.h:35
#define FLASH_SR_BSY_BIT
Definition mcu_macros.h:33
#define FLASH_SR
Definition mcu_macros.h:32
#define FLASH_KEYR
Definition mcu_macros.h:29
#define FLASH_CR_SNB_BIT_START
Definition mcu_macros.h:37
#define FLASH_CR_PG_BIT
Definition mcu_macros.h:39
#define FLASH_UNLOCK_KEY2
Definition mcu_macros.h:31
#define FLASH_CR_SER_BIT
Definition mcu_macros.h:36
#define FLASH_CR_STRT_BIT
Definition mcu_macros.h:38
#define FLASH_UNLOCK_KEY1
Definition mcu_macros.h:30
#define FLASH_CR
Definition mcu_macros.h:34
#define FAULT_DATA_FLASH_START_ADDR
Definition mcu_macros.h:40