Skip to main content
HAlzo
Associate III
April 14, 2021
Solved

Moving Function from flash to ITCM cause hard fault on sTM32H743

  • April 14, 2021
  • 1 reply
  • 2452 views

Hi,

I am following the guide lines to move some functions from flash to ITCM .

1st I modified the linker file , then add itcm section parameters as extern variables in main file and after that I copied this function code after start up from flash to itcm section and finaly used section attribute to tell the linked to move this function to itcm section.

Always I get a hard fault at exiting from the moved function.

after some investigations I found that the called function push {lr} only when it's called on the other hand at the end of the function it pop {r4,r7,pc} and hard fault is caused at this point.

If I don't move this function to itcm section it will push {r4,r7,lr} and pop {r4,r7,pc} and will not cause any fault.

If I modified the stack so it pops the correct values in pc , it didn't cause hard fault.

in the generated list file I found that it push {r4,r7,lr} which is not consistent with actual assembly.

code is compiled from c with g3 and o0 options for debugging and optimizations.

How I can overcome this problem?

Thanks

This topic has been closed for replies.
Best answer by Tesla DeLorean

The disassembly of the instruction at zero is not consistent with the code shown previously.

You really want to see the hex opcodes printed out in the disassembly listing.

Pretty sure push {nothing} is an illegal opcode.

1 reply

Tesla DeLorean
Guru
April 14, 2021

>>How I can overcome this problem?

Perhaps by looking at how you're doing the control transfer to the subroutine?

Using the debugger, inspecting the stack and reporting what's there. Review that in the context of how the MCU is documented to function, and the expectations for registers, etc.

Watch also that you copy literals to RAM properly, and the code doesn't call any other functions outside it's scope. ie relative calls to functions you haven't copied.

Hard Faults are an indication you're doing something fundamentally incorrect, understand how the core functions.

Pushing LR implies you have other dependencies, the subroutine is not free-standing and calls other things.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
HAlzo
HAlzoAuthor
Associate III
April 15, 2021

Should all functions which are called from the function moved to ITCM be located as well in ITCM?!

I tried to use very simple function for testing, just a function which returns one value without calling any function, it cases hard fault at the befgining of the function at instruction push{}

Tesla DeLorean
Guru
April 15, 2021

What address are you calling? Is it odd?​ What about the stack?

Provide some register dumps, it shouldn't be necessary to guess what's wrong.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..