cancel
Showing results for 
Search instead for 
Did you mean: 

I am working on cortex M4 (STM32F407) with ucOSII, now I have found low probability that enter the hard fault exception, in the hard fault hanler we can get the PSP address (task stack) , but the LR/PC value stored in the stack are 0xFFFFFFFF.

KLian.1
Associate II

typedef struct

{

UINT32 R0;

UINT32 R1;

UINT32 R2;

UINT32 R3;

UINT32 R12;  

UINT32 LR;

UINT32 PC;

UINT32 IPSR;  

}STACK_DATA_TYPE;

4 REPLIES 4
KLian.1
Associate II

The PSP address indicates the stack top of the pre-exception thread task. When hard fault exception handler excute, it would push R0/1/2/3/12/LR/PC/IPSR into the task stack, so through the PSP value, also get the LR/PC value. But why the LR/PC value are equal 0xFFFFFFFF, now how can find the bug?

typedef struct

{

UINT32 R0;

UINT32 R1;

UINT32 R2;

UINT32 R3;

UINT32 R12;  

UINT32 LR;

UINT32 PC;

UINT32 IPSR;  

}STACK_DATA_TYPE;

void HardFaultISP(void)

{

unsigned int u32LR_Bak, u32PC_Bak;

STACK_DATA_TYPE *pSP;

pSP = (STACK_DATA_TYPE *)__get_PSP();

u32LR_Bak = pSP->LR;

u32PC_Bak = pSP->PC;

}

Are you looking at the right stack?

LR as passed (not stacked) should be a magic value imparting the stack to use.

Probably want the entry code in assembler, be easier that way.

https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
KLian.1
Associate II

Thank your answer�?

You meaning through the function "__get_PSP()" ​ running in the hardFaultIsp() , we can't get the correct process stack address ?