cancel
Showing results for 
Search instead for 
Did you mean: 

HARDFAULT STM32G0 TreadX

fernandogamax
Associate III

I’m working with an STM32G0 running ThreadX (Azure RTOS).
The system UART is configured in circular DMA mode with an IDLE event interrupt for data reception.

Symptoms
Intermittently, after hundreds of successful receptions, the system enters HardFault_Handler.
The fault always occurs at the same point in the code (on a C division instruction, inside a function unrelated to DMA).

The register values at the HardFault are shown in Image 1.

When it runs without triggering a hard fault, the registers are:
xPSR = 0x01000000 and CONTROL = 2.

When the hard fault occurs, these registers are:
xPSR = 0x00000000 and CONTROL = 0.

The failure does not depend on the received data.

The thread stack (PSP) has sufficient space.

I believe the intermittent HardFault is not related to the operation itself:
If I modify the code—adding new instructions or removing code—sometimes it reproduces, and other times it still reproduces but in different parts of the code.

Question
What can I do to determine the root cause of this hard fault? I can’t figure out what the problem is.

2 REPLIES 2
Saket_Om
ST Employee

Hello @fernandogamax 

Please follow the instruction in the article below to debug your HardFault:

How to debug a HardFault on an Arm® Cortex®-M STM3... - STMicroelectronics Community

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
fernandogamax
Associate III

Hello @Saket_Om
I have followed the steps you indicated. I'm working with an M0+ STM32G0B0, so I cannot access the hardfault analyzer.

r0 0x0
r1 0x0
r2 0x0
r3 0x2000437b
r4 0x0
r5 0x24
r6 0x1c
r7 0x20004360
r8 0x0
r9 0x0
r10 0x0
r11 0x0
r12 0x1
sp 0x20004360
lr 0x8040291
pc 0x80402a0
xpsr 0x0
msp 0x20023fc8
psp 0x20004360
primask 0x0
basepri 0x0
faultmask 0x0
control 0x0

 

centesimas=(int)parte_decimal%((int)multipliccador2/10);
0804029a: adds r3, r7, r6
0804029c: ldrb r4, [r3, #0]
0804029e: adds r3, r7, r5
080402a0: ldrh r3, [r3, #0]


The instruction ldrh r3, [r3, #0] is using an odd address in r3 (0x2000437b). Could this be the cause of the hardfault? But what is causing this in the first place?"