Skip to main content
CBerg
Senior II
February 11, 2025
Solved

H7A3 - Code not loaded into ITCM-RAM

  • February 11, 2025
  • 2 replies
  • 2030 views

Hi all,

i have an issue with an STM32-H7A3, which is going into hard fault, when calling a function, which is moved to the ITCM-RAM.

I have defined a section for ITCM-RAM in the Linker-Script:

 

 

_siitcmram = LOADADDR(.itcmram);	/* size of ITCM-RAM */

.itcmram : {			/* ITCM-RAM Section */
	. = ALIGN(4);		/* Alignment: 4 Bytes - "Word" - u32 */
	_sitcmram = .; 		/* define a global symbols at itcmram start */
	*(.itcmram)
	*(.itcmram*)
	. = ALIGN(4);
	_eitcmram = .; 		/* define a global symbols at itcmram end */
} >ITCMRAM AT> FLASH	/* reseve memory in flash for this section */

 

 

I copy the code from the flash to the ITCM-RAM in the startup

 

 

// BEGIN MODIFICATION - STM-CubeMX Code above

 /* Copy from flash to ITCMRAM */
 ldr r0, = _sitcmram		// start: itcmram start
 ldr r1, = _eitcmram		// end: itcmram end
 ldr r2, = _siitcmram		// size
 movs r3, #0
 b LoopCopyCCMInit

CopyCCMInit:
 ldr r4, [r2, r3]
 str r4, [r0, r3]
 adds r3, r3, #4

LoopCopyCCMInit:
 adds r4, r0, r3
 cmp r4, r1
 bcc CopyCCMInit
/* End of copy to ITCMRAM */

// END MODIFICATION - STM-CubeMX Code below

 

 

basically the code above is just a "Copy & Paste" of the section above, where the data get copied from Flash to RAM. I Just edited the names and symbols.

I got the same ruinning - with the same functions - in a Test Project without any issues. The only issue I had at the beginning in the test project was, that I did not copy the code from flash to the ITCM-RAM, but when I did that it worked as intended.

But in this case i can litterally see, that somthing is wrong, because when I step through my code in the debugger, I can not jump (with "step into (F5)") into the function. The debugger simply steps over and quickly goes into hard fault. So my asumption is: for some reason the code is not copied into the ITCMRAM, and the copied functions seem to have the address 0x00 - which is the reason why it goes into hard fault quickly.

Obviously I am missing something. But I don't know what. Can anyone help me out?

Additional Info:

In the CubeIDE Memory Details, I can see the code that should be in the ITCM-RAM is allocated in the ITCM-RAM. There is also a ITCM-RAM section in the flash, where the code that gets copied is stored.

Best answer by TDK

While debugging, in the Memory Browser tab, view the ITCMRAM (0x0 address) and right click the word that gets modified and selection "Add Watchpoint (C/C++)...". That will add a breakpoint that gets hit when it's modified.

2 replies

Senior III
February 11, 2025
CBerg
CBergAuthor
Senior II
February 11, 2025

thanks for the input. It's a nice tutorial to explain how to use the ITCM-RAM.

If it is your tutorial I have 2 comments: 
a) typo the 3rd line, the ITCM RAM has 16 kB not 16 MB

b) i wonder how the tutorial works without copying the flash contents into the ITCM-RAM? AFAIK this is "mandatory" to copy the ITCM-Code from the Flash into the ITCM-RAM at the startup ...

but I used your input to check the Memory in the Memory Viewer. And the result is: the whole ITCM-RAM starting at 0x00 seems to be full with random data. This means my code in the startup script somehow has no effect. The same code is working in another project on the same Nucleo, and I wonder why it works in one build but not in another? Thats weird ...

Ozone
Principal
February 11, 2025

I don't have a H7 device, nor I'm really experienced with this variants.
However, two points you might consider.


First, I assume the code you copy is linked for this address, or PIC.


And second, the issues might be related to clock / system setup. I had similiar issues with external RAM, which is of course a different matter.
But perhaps you can try to copy the code after the setup.


Another possible reason might be the MPU, if you use it in your application.

CBerg
CBergAuthor
Senior II
February 11, 2025

some additional info: it looks like the copy function is working.

This is the content of the Flash

Code in FlashCode in Flash

and this is the content of the ITCM-RAM after startup:

ITCM-RAMITCM-RAM

a visual comparison tells me the contents are almost identical, except one word (3rd line) which i marked red.

In the Build Analyzer it looks like it should look like - according to the tutorial @ahsrabrifat linked in his post, with sections for the .itcmram in "FLASH" as well as "ITCMRAM"

When I remove the code to copy the memory contents and restart the Nucleo (remove power, wait 30) seconds, the memory contents look different ...