cancel
Showing results for 
Search instead for 
Did you mean: 

Reading some SCB SFRs does not work from within the fault handler

Alex7
Associate

Hello,

I'm debugging the following piece of code that is executed as part of the fault handler:

currentExceptionData.data.CFSR = SCB->CFSR;
currentExceptionData.data.HFSR = SCB->HFSR;
currentExceptionData.data.DFSR = SCB->DFSR; //TODO: Not copied correctly!
currentExceptionData.data.MMFAR = SCB->MMFAR; //TODO: Not copied correctly!
currentExceptionData.data.BFAR = SCB->BFAR; //TODO: Not copied correctly!

The target CPU is STM32L4P5, the code is built using IAR studio. In order to get io the fault handler, I execute an erroneous code that fires the Usage Fault.

I am able to read (via the code) correctly the CSFR and HFSR values only. The DFSR is read as 0, the MMFAR and BFAR registers are read as their addresses. I compare these values to the register values read by debugger.

The underlying assembly code is:

currentExceptionData.data.DFSR = SCB->DFSR; //TODO: Not copied correctly! was 00000002 then 00000003
0x805'839e: 0xf10d 0x0015 ADD.W R0, SP, #21 ; 0x15
0x805'83a2: 0x4910 LDR.N R1, [PC, #0x40] ; DFSR
0x805'83a4: 0x6809 LDR R1, [R1]
0x805'83a6: 0x6001 STR R1, [R0]

Is there any reason that only part of SFRs can be readable from within the fault handler?

I also tried using the inline assembly, for example:

register uint32_t generalRegister;
generalRegister = 0xE000ED30;
__ASM volatile ("LDR %0, [%1]\n" : "=r" (generalRegister) : "r" (generalRegister) );
currentExceptionData.data.DFSR = generalRegister;

It worked in single step disassembly debugging for DFSR only, nope for MMFAR/BFAR.

Any ideas?

 

0 REPLIES 0