cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F767ZI Hard fault when using ITCM RAM

bradleybare
Associate II
Posted on August 30, 2016 at 19:05

I am playing with the ITCM RAM on a Nucleo-144 board. 

I am having problems with the ITCM RAM causing a hard fault when I call a subroutine from inside a subroutine. I have successfully used the ITCM RAM to store a function that increments a variable. I however, get a hard fault if I try to call more than a function in a function.

In my linker file I have defined the proper memory areas. I also modified the startup file to move the data and functions to memory at startup.

I can run both functions independently but if I try to call one inside the other it goes straight to a HardFault. I have tried with the other function inside and outside of ITCM RAM. It faults in both cases.

I looked in the data sheets and arm manuals but I could not find information on calling functions from inside ITCM RAM functions. Does anyone have experience with this problem? Can I call functions from inside ITCM functions? Could you point me to a manual where I can read about this?

I have attached my linker script, and startup file. 
4 REPLIES 4
bradleybare
Associate II
Posted on August 30, 2016 at 19:25

I kept playing with single ITCM functions and found I get a hard fault if the functions get more complex than a single while loop.

I can't use for loops or more than 1 if or while statement or I get a hard fault.

I hope someone can help. I have tried debugging but I am not the best at it. I don't understand how to fix this.

I have also attached my latest map file. You can see the functions inc1 and inc20 (my test functions) are in the correct memory location.

________________

Attachments :

out.map : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0hH&d=%2Fa%2F0X0000000bca%2Fu1C2EHQRjIGop2HRGuUJfpYz9SfkYaBBRQC0LByjcms&asPdf=false
bradleybare
Associate II
Posted on August 31, 2016 at 02:08

Ok so I did a ton of digging and found a few interesting things that may help.

I found that the hardfault was a forced hardfault. So I printed the registers to show what fault led to the hardfault. It was a usage fault due to an unaligned access. The unaligned access did not seem right so I checked the PC. I popped the value directly from the stack from the hardfault handler ISR. The PC showed a value of 0x6 which I thought was really weird. So I am having a problem with an unaligned access. The question is why? So I used objdump to show the generated assembly code for my two functions in the ITCM RAM and this is what I get

Disassembly of section ._ITCM_RAM:
00000000 <
inc1
>:
0: 3001 adds r0, #1
2: 4770 bx lr
00000004 <
inc20
>:
4: 2314 movs r3, #20
6: 3b01 subs r3, #1
8: d1fd bne.n 6 <
inc20
+0x2>
a: 3014 adds r0, #20
c: 4770 bx lr
e: bf00 nop

So it does seem like I am loading the PC with the value 6. Can anybody make something from this data? Does the bne.n 6 actually branch to the label 6: or does it load the PC with the value 6? I have also tried placing the functions in the .data section of memory so the function will be loaded into ram at startup. The functions work. So what could I be forgetting that is causing the ITCM RAM to malfunction?
bradleybare
Associate II
Posted on August 31, 2016 at 02:26

Disassembly of section .data:
00000000 <
inc1
>:
0: 3001 adds r0, #1
2: 4770 bx lr
00000004 <
inc20
>:
4: 2314 movs r3, #20
6: 3b01 subs r3, #1
8: d1fd bne.n 6 <
inc20
+0x2>
a: 3014 adds r0, #20
c: 4770 bx lr

Ok well this is when I place the functions in .data section to be loaded in ram. Nothing in the Assembly changed so it is something with the ITCM I believe. Come on someone has to know something. EDIT: actually this dissassembly does not contain nop. Could that be an issue? I seriously do not know how to figure this out.
Posted on August 31, 2016 at 09:30

You appear to use some task switching. I'd look for problems there first, or, in other words, I'd try running from ITCM without that (and without DMA and LCD and whatnot). Small steps first.

JW