cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407ze throws hard fault on executing code from RAM.

Neolithic
Associate III

https://stackoverflow.com/questions/72826600/stm32f407ze-throws-hard-fault-on-executing-code-from-ram

Please check the details of my linker and startup scripts on the above link.

8 REPLIES 8

Debug as usually with hardfaults, i.e. start with stacked PC and observe the code before that, which lead to the fault.

JW

Start by making sure the startup.s copies the code where you expect it.

Look at the .MAP file for addresses the linker used/report

Disassemble the .ELF to see what's in it, and the instruction words associated with your code.

Then compare these with the Memory View as you debug/step your code.

Remember the function pointer/address for Thumb code will be ODD, the MCU will fault if you try to go to an EVEN address.

Have a Hard Fault routine that outputs useful and actionable information.

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

I have shared the detailed pictures. Did you have a chance to look at that?

Indeed it should be odd, but what is surprising for me is that when i am executing the code from flash, the function addresses are not necessarily odd yet they execute just fine. Did you have a chance to look at the link i provided.? there i have shown disassembly and register view as well.

Just slipped my mind, actually the instruction should have a high bit in lsb instead of the address of the function itself for thumb mode.

> I have shared the detailed pictures.

I don't see hardfault on those pictures, nor code in SRAM.

JW

Neolithic
Associate III

@Community member​ I just updated the post with more pictures and information. @Community member​ The code does start to execute from the RAM. Just for information, the segment of RAM I am using is totally free and not being used for anything else, so no chance of conflicts (race condition). The disassembly shows the hardfault is thrown in one of the veneer calls.

00 in RAM at place where you expect the functions to reside, probably means, that the startup code did not copy the function from FLASH to RAM.

JW

Do you know any examples for the correct startup and linker script for this purpose which I can follow? I have read several forums posts and followed official note of st as well, but none of it seems to work for the distinc segmemts.

What i did was that i generated linker and startup scripts from cubeMx for a test project where there was only a single memory segment used for heap and stack (sram) and that worked just fine for execution of code as well.

However, when i make use of CCMRAM for heap and stack along with global data and SRAM dinstinctly for code execution it does not seem to work properly even though the linker and startup script are exactly the same as is mentioned in STs manual. The CCMRAM cannot be used for code execution since it is connected only to data port of CPU. ​