Skip to main content
Wowa
Associate III
December 21, 2021
Question

STM32F7: How to place selected modules' code to ITCM along with their readonly (const) data (IAR)?

  • December 21, 2021
  • 0 replies
  • 1882 views

Hi,

I want to place parts of code in ITCM (using IAR). The manual (IAR ARM Development Guide), as I could find, has instructions only for general case when you put all the code in RAM. But my app does not fit in ITCM, so I need a way to specify which modules go to RAM.

I found the example with AN4667 which has a test for different configurations (project called "stm32f7_performances"), one of which is CodeInITCM+DataInDTCM. There is an .icf for this case which compiles fine.

But, for some reason, it starts to behave badly if some modules contain constants placed in code. I isolated the following minimum main.c file (see below) which produces warnings on linking which lead to unworking final hex image. My project includes just startup_stm32f756xx.s, main.c and the 5-RamITCM_rwRAM-DTCM.icf linker file from the example which I include below. Trying to build this, I get the following warnings:

- Building: -------------------------------------------------------

Building configuration: Project - 5-RamITCM_rwRAM-DTCM 

main.c  

Linking 

Warning[Lp005]: placement includes a mix of sections with content (example "ro code section .text in main.o symbols: [SystemInit, main]") and sections without content (example "rw data section .rodata in main.o") 

Warning[Lp006]: placement includes a mix of writable sections (example "rw data section .rodata in main.o") and non-writable sections (example "ro code section .text in main.o symbols: [SystemInit, main]") 

Total number of errors: 0 

Total number of warnings: 2 

----------------------------------------------------------------------

This is the minimal case just to illustrate the problem, so it lacks any hw init etc. When I build my real program and try to load/execute it, it fails to load correctly, so these warnings apparently are critical.

If I put all the code in Program_RAM_ITCM_region using "place in Program_RAM_ITCM_region { ro };" command in .icf file, it builds and runs good, but my real app's code size is larger than ITCM size, so I need to be able to select modules which go to ITCM.

Can anyone tell me the reason for this behavior and how to solve this issue?

Thank you,

Vladimir Pavlenko

- main.c file: -------------------------------------------------------

void SystemInit(void) {}
 
volatile static int iii = 0;	
 
void Test(char *s)
{
 for (int i = 0; i < 10; i++) iii = s[i] ? 1:0;
}
 
int main(void)
{
 Test("=======================================================\r\n");
}

- 5-RamITCM_rwRAM-DTCM.icf file: -------------------------------------

/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x00200000;
 
/*= Code region(s) ===================================== */
/* -- Program region in internal Flash ----------------- */
define symbol __ICFEDIT_Program_In_FLASHTCM_start__ = 0x00200000;
define symbol __ICFEDIT_Program_In_FLASHTCM_end__ = 0x002FFFFF;
/* -- Program region in RAM ITCM ----------------------- */
define symbol __ICFEDIT_Program_In_RAM_ITCM_start__ = 0x00000000;
define symbol __ICFEDIT_Program_In_RAM_ITCM_end__ = 0x00003FFF;
 
/*= Data region(s) ===================================== */
/* RAM -- +RW +ZI region ------------------------------- */
/* The RW and Zero Initialized data will be in RAM-DTCM (0x4000 = 16k)
 All global variables will be located in this section. */
define symbol __ICFEDIT_region_RW_ZI_RAM_DTCM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RW_ZI_RAM_DTCM_end__ = 0x20003FFF;
 
/* RAM -- STACK region --------------------------------- */
/* The Stack of the main application will be in RAM-DTCM (0x4000 = 16k)
 All internal variables of called functions will be located in this region. */
define symbol __ICFEDIT_region_STACK_RAM_DTCM_start__ = 0x20004000;
define symbol __ICFEDIT_region_STACK_RAM_DTCM_end__ = 0x20007FFF;
 
/* RAM -- HEAP region ---------------------------------- */
/* The Heap of the main application will be in RAM-DTCM (0x8000 = 32k)
 All dynamic allocations data got by malloc, realloc, calloc... will be located
 in this region.*/
define symbol __ICFEDIT_region_HEAP_RAM_DTCM_start__ = 0x20008000;
define symbol __ICFEDIT_region_HEAP_RAM_DTCM_end__ = 0x2000FFFF;
 
/*= STACK and Heap Sizes =============================== */
define symbol __ICFEDIT_size_cstack__ = 0x4000; /* 16k */
define symbol __ICFEDIT_size_heap__ = 0x8000; /* 32k */
/**** End of ICF editor section. ###ICF###*/
 
/*= Memory regions definition ========================== */
define memory mem with size = 4G;
define region Program_FlashAXI_region = mem:[from __ICFEDIT_Program_In_FLASHTCM_start__ to __ICFEDIT_Program_In_FLASHTCM_end__];
define region Program_RAM_ITCM_region = mem:[from __ICFEDIT_Program_In_RAM_ITCM_start__ to __ICFEDIT_Program_In_RAM_ITCM_end__];
define region RAM_DTCM_RW_ZI_region = mem:[from __ICFEDIT_region_RW_ZI_RAM_DTCM_start__ to __ICFEDIT_region_RW_ZI_RAM_DTCM_end__];
define region RAM_DTCM_STACK_region = mem:[from __ICFEDIT_region_STACK_RAM_DTCM_start__ to __ICFEDIT_region_STACK_RAM_DTCM_end__];
define region RAM_DTCM_HEAP_region = mem:[from __ICFEDIT_region_HEAP_RAM_DTCM_start__ to __ICFEDIT_region_HEAP_RAM_DTCM_end__];
 
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
 
initialize by copy { readwrite, //ro
 /* Copy also the constants of these objects in RAM-ITCM */
	ro object main.o
}; 
 
do not initialize { section .noinit };
 
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
 
place in Program_FlashAXI_region { readonly };
 
//place in Program_RAM_ITCM_region { ro };
 
place in Program_RAM_ITCM_region {
 section .text object main.o,
 /* Place also const data in ITCM-RAM. */
 section .rodata object main.o,
};
 
place in RAM_DTCM_RW_ZI_region { readwrite };
place in RAM_DTCM_STACK_region { block CSTACK };
place in RAM_DTCM_HEAP_region { block HEAP };

This topic has been closed for replies.