cancel
Showing results for 
Search instead for 
Did you mean: 

Hello! I am currently working on STM32F205 using Keil uvision. I have been getting an INVPC hard fault repeatedly. So I increased the stack size from 0x400 to 0x800 and set the stack alignment bit in CCR register at power on. This removed the INVPC hard

TBhil.1
Associate II

fault but instead I got Precise Bus Fault with following stack frame :

R0 = 28000134 R1 = 1 R2 = 40000000 R3 = 1 R12 = ae60cd5 LR = 80015b9 PC = 80015be PSR = 2100002c- FSR/FAR: CFSR = 8200 HFSR = 40000000 DFSR = 0 AFSR = 0 BFAR = 28000130

By disassembling the code, I found that the faulty instruction given below which was inside the Timer 2 ISR :

   0x080015bc:  4877    wH   LDR   r0,[pc,#476] ; [0x800179c] = 0x20000130

This is done in attempt to increment a global counter uint16_t uiTimeCounter = 0;

It appears that the memory address got corrupted. Any insights on how should I proceed to solve this would really be helpful. Thank you.

3 REPLIES 3
TDK
Guru

I would guess it is a stack overflow or an out of bounds array access.

>   0x080015bc:  4877    wH   LDR   r0,[pc,#476] ; [0x800179c] = 0x20000130

I don't see anything wrong with this. Perhaps I'm missing it.

If you feel a post has answered your question, please click "Accept as Solution".

Please note that the actual address of the variable is 0x20000130, but the controller tries to access 0x28000130 as pointed by the BFAR register causing hard fault as 0x28000130 is out of the valid range of RAM addresses.  It appears that an extra bit is getting set. Also this fault does not occur every single time. In one board, the fault occurs within 15 mins after power on. While in another board, the fault occurs after more than 1 hour.

TDK
Guru

Double check for valid clock settings, voltage and wait states.

If you feel a post has answered your question, please click "Accept as Solution".