cancel
Showing results for 
Search instead for 
Did you mean: 

Hardfault handler using I2C based Accelerometer

SYLVIA
Associate II

When I plug on my device and run my code on the attolic debugger for 1st time my code is working as per my given logic.However if i stop my debugger and then re-run,my program is getting stuck at hardfault.

7 REPLIES 7
SYLVIA
Associate II

Please help anyone

Ozone
Lead

You provided very little information.

You can:

Use a debugger to find the code line you code hardfaults.

Instrument your code, to do the same without running in the debugger.

Check the values of the SCB registers, to see why it hardfaulted : www.keil.com/appnotes/files/apnt209.pdf

Basically I am using HAL library.So just after HAL_Init() it is going to hard fault..Since I a very new to embedded coding can you tell What exact information you want?

I don't use HAL.

You should be able to step into the HAL_Init() function, down to the line where it faults.

If necessary, you can even switch to disassembly mode in the debugger and single-step to the faulting instruction.

Okay thank you.I will try and update

Perhaps once you step over that critical code line, the reason becomes obvious.

With Cube involved, this is hardly ever the case.

The reverse approach, i.e. stopping your MCU in the hardfault handler, and reading + decoding the fault reason from the SCB register contents, is also highly recommended.

Hi,

Thanks a lot.The problem lied in the debugging process.Once I stop the debugger the code runs fine.Thankyou for your suggestion