AnsweredAssumed Answered

ITCM and DTCM with STM32F7 Discovery

Question asked by bens on Mar 30, 2016
Latest reply on Mar 31, 2016 by dembek.radoslaw.001

I am fairly new to embedded development and I am trying to setup a project (using Eclipse GNU ARM environment) to use ITCM and DTCM on a STM32F7 Discovery board.
It seems the default linker script already uses DTCM by defining a global RAM section starting at the DTCM address 0x20000000 (although I would like to decide which data to put in the DTCM as my data is larger than the DTCM). But, more importantly, I am having trouble enabling ITCM. I have looked at the "Performance test" example & notes as well as the template examples from the STM32F7 firmware, plus forum pages about the subject... but it seems I couldn't find the correct answer, or at least it is not working for me. I have also looked at other parties linker scripts and tried applying them to the STM32F7, with no luck.

Here is what I would ideally like to achieve:
1) put specific part of the code (or an entire object functions) into ITCM
2) put specific data into the DTCM 

I added the following section to the mem.ld linker script

ITCM_RAM(xr): ORIGIN = 0x00000000, LENGTH = 16K

Then, I understand there are two ways of putting code into the ITCM:

1) by including the entire .o code into a "section" allocated to the ITCM

.code_TCM 0x00000000:
  AT ( _itcm_lma )
  _sitcm = .;
  myobject.o (.text.*)
  myobject.o (.rodata)
  _eitcm = .;
  } > ITCM_RAM

Also adding this to the _startup.c method, right before the main(..) call (I was not sure yet if the _startup.c code was handling this situation, and I assume this is not a problem to do perform the copy again):

/* copy code_TCM from flash to ITCM */
             volatile char *dst = &_sitcm;
             volatile char *src = &_itcm_lma;
             while(dst < &_eitcm){
                   *dst++ = *src++;

2) by tagging methods using the __attribute__((section(".code_TCM"))) e.g.

void  __attribute((section(".code_TCM"))) Run() {
code here

And the following linker script:

.code_TCM :
  . = ALIGN(4);
  *(.code_TCM)         /* .section_name section */
  *(.code_TCM*)        /* .section_name* sub-sections if any */
  . = ALIGN(4);

When adding the object into the ITCM section (method 1), I am having linking errors with duplicate definitions ... 
If I tag a method into the ITCM (method 2) and try to call this method, I get a hard fault ...

I am currently testing this using C methods but my engine is mostly written in C++ so my first question is: can I use C++ classes and put their member functions into ITCM? 
In the ideal case, would somebody have an example of a linker script that allows __attribute__ use to put data/code into DTCM/ITCM? Any help is greatly appreciated !!

Thank you