Using gcc -finstrumental-functions for profiling on cortex-m1

qmor wrote on Thursday, October 13, 2016:

Hello, i have a project for cortex-m1 with FreeRTOS and i’m trying to find out hard faults reasons. Because of that i want to use -finstrumental-functions of GCC compiler. Unfortunatelly this option cause new Hard Fault somethere at the beginning of execution. Did someone try to use this option on ARM arch? Thich FreeRTOS function should be marked with attribute((no_instrument_function))? Or maybe i need to use some other tricks?

Thanks in advance

xz8987f wrote on Thursday, October 13, 2016:

Hi Oleg,
yes, I have used that function both for M0+ and M4, but not for M1 (which is available only for FPGA’s?). See https://mcuoneclipse.com/2015/04/04/poor-mans-trace-free-of-charge-function-entryexit-trace-with-gnu-tools/
But I think you won’t find easier your problem with that option: what you need is a hard fault handler (have you used one? See https://mcuoneclipse.com/2012/11/24/debugging-hard-faults-on-arm-cortex-m/).

I hope this helps,
Erich

qmor wrote on Thursday, October 13, 2016:

But I think you won't find easier your problem with that option: what you need is a hard fault handler (have you used one? 

Thanks. I have Hard Fault handler, but unfortunatelly it’s not easy to understand that’s wrong with code.For example stacked_pc points to code like

add r3,#8

Why it could cause Fault?

xz8987f wrote on Thursday, October 13, 2016:

keep in mind that the PC usually is after the instruction who caused the problem. And you need to check the stacked LR as well.

qmor wrote on Thursday, October 13, 2016:

Okay. Thanks a lot. I’ll describe my problem more deeper. I’ve got an application with a several tasks. Couple of these tasks is using for external interface communication (CAN and 1553B) and one of the tasks is using to compute some math. If we are enable this task sooner or later app will end in Hard Fault. Usualy it’s crashes at the same place, and it’s looks like some unaligment access. I dont understand how function may be executed for a thousands times without any problem and then suddenly crash with unaligment memory access. Can you suggest something to check?

xz8987f wrote on Thursday, October 13, 2016:

Are you indeed running on an FPGA model? I suggest to run your code on a real M0+ as it could be that your syntesized model has an issue?
Is that unaligned access on the stack (so maybe a stack problem)?

qmor wrote on Friday, October 14, 2016:

Are you indeed running on an FPGA model?

No, i’m using Russian SoC 1986VE1T which is real SoC.

Is that unaligned access on the stack (so maybe a stack problem)?

I think the same, because of that i want to trace execution to see which functions called just before hard fault, i hope this will help me to find a problem.