Skip to main content
KLian.1
Associate
July 6, 2021
Question

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.

  • July 6, 2021
  • 2 replies
  • 1077 views

typedef struct

{

UINT32 R0;

UINT32 R1;

UINT32 R2;

UINT32 R3;

UINT32 R12;  

UINT32 LR;

UINT32 PC;

UINT32 IPSR;  

}STACK_DATA_TYPE;

This topic has been closed for replies.

2 replies

KLian.1
KLian.1Author
Associate
July 6, 2021

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;

}

Tesla DeLorean
Guru
July 6, 2021

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 VenmoUp vote any posts that you find helpful, it shows what's working..
KLian.1
KLian.1Author
Associate
July 8, 2021

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

KLian.1
KLian.1Author
Associate
July 8, 2021

Thank your answer�?