To follow on with my comment earlier today:
At some point I should probably learn what do all of these types of memory mean? i.e. what is the difference betwen ITCM and DTCM? Sometimes I hate 3 or 4 letter acronyms!
...
I know that I can use searches for this, and do find things like:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0198e/ch05s02s03.html
ITCM: Instruction Tightly Coupled Memory(can contain data)
DTCM: Data Tightly Coupled Memory (Can only be data?)
OCRAM: On Chip RAM
Again maybe the WIKI

should contain some information like on T4, what the different keywords like: PROGMEM, DMAMEM, const, static... imply like which section does each go into and what are the implications to code? Like either don't do DMA from/to ... Or if you do, you need to do ...
In case there are others who also are unclear as I am/was about some of this and also trying to understand how these things are initialized, and relationships between them.
And in my case trying to get more of a handle why a program like unCannyEyes crashed and/or wiped out memory if the large data structures are stored in DTCM versus in program space...
I am not sure if I should continue it here or in it's own thread. But again maybe someone else may find this interesting?
The version of UncannyEyes that had tendency to wipe out USB, sometimes could recover using program button, other times the 15+ second recover...
Code:
"D:\\arduino-1.8.9\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-size" -A "C:\\Users\\kurte\\AppData\\Local\\Temp\\arduino_build_666019/uncannyEyes0.ino.elf"
Sketch uses 211648 bytes (20%) of program storage space. Maximum is 1048576 bytes.
Global variables use 5768 bytes (2%) of dynamic memory, leaving 256376 bytes for local variables. Maximum is 262144 bytes.
I then used the nm command to dump the names of the structures and the like (same thing that Frank used to print out additional information...
There are several interesting sections of manual talking about memory:
Chapter 30: Talks about the FlexRAM of the T4, which I believe has 512KB, and this RAM is divided up into 16 Banks of memory or 32Kb per bank. And each of these banks
can be assigned to ITCM, or DTCM or OCRAM
Chapter 2: Shows the Arm Platform Memory map: Things like:
0-0x7FFFF - ITCM (512KB)
0x20000000 - 0x2007FFFF - DTCM (512KB)
0x20200000 - 0x2027FFFF - OCRMA2 (512KB)
0x60000000 - 0x6FFFFFFF - FLEXSPI ...
Note: There are some Hardware registers setup at startup time that controls some of this.
Now what does some of this stuff mean?
If we look at the start of ResetHandler we see:
Code:
__attribute__((section(".startup"), optimize("no-tree-loop-distribute-patterns"), naked))
void ResetHandler(void)
{
unsigned int i;
#if defined(__IMXRT1062__)
IOMUXC_GPR_GPR17 = (uint32_t)&_flexram_bank_config;
IOMUXC_GPR_GPR16 = 0x00000007;
IOMUXC_GPR_GPR14 = 0x00AA0000;
__asm__ volatile("mov sp, %0" : : "r" ((uint32_t)&_estack) : );
#endif
// pin 13 - if startup crashes, use this to turn on the LED early for troubleshooting
//IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_03 = 5;
//IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_03 = IOMUXC_PAD_DSE(7);
//IOMUXC_GPR_GPR27 = 0xFFFFFFFF;
//GPIO7_GDIR |= (1<<3);
//GPIO7_DR_SET = (1<<3); // digitalWrite(13, HIGH);
// Initialize memory
memory_copy(&_stext, &_stextload, &_etext);
memory_copy(&_sdata, &_sdataload, &_edata);
memory_clear(&_sbss, &_ebss);
First we have: IOMUXC_GPR_GPR17 = (uint32_t)&_flexram_bank_config;
Which defines what each of the 16 banks of FlexMemory is used for (00 not used, 01 OCRAM, 10 DTCM, 11 ITCM).
Which from my dump of symbols for this case is defined: aaaaaaaf A _flexram_bank_config
So in my case First two Banks or 64K is ITCM, the other 14 banks or 448K is DTCM
Next: IOMUXC_GPR_GPR16 = 0x00000007;
Says: Use FLEXRAM_BANK_CFG to configure, DTCM is enabled, ITCM is enabled
Next: IOMUXC_GPR_GPR14 = 0x00AA0000;
Says DTCM and ITCM are both 512KB? Again not sure what that means other than to say that space is valid but maybe does not have memory backing it?
Also I don't fully understand relationship with which banks are allocated to ITCM versus DTCM and which addresses in ITCM and DTCM ranges are valid? i.e. could I choose any two random banks to be the ITCM and it would work the same? Or does choosing the first two, imply address starting at 0 (in ITCM case), but if first bank was DTCM and second was ITCM then you should put code at 32K starting?
We then setup stack pointer: __asm__ volatile("mov sp, %0" : : "r" ((uint32_t)&_estack) : );
20070000 B _estack
Which looks valid? It is at the boundary just above 14*32KB, but I am assuming it will decrement this value before it actually writes to it...
Then we have two memory copies (dest, source, dest_last)
First copy: memory_copy(&_stext, &_stextload, &_etext);
00000000 T _stext
60001880 A _stextload
00009af0 T _etext
So we are copying: 39664 bytes to ITCM starting at 0
Then second copy: memory_copy(&_sdata, &_sdataload, &_edata);
20000000 D _sdata
6000b37c A _sdataload
20029320 D _edata
Or again we are copying: 168736 bytes to DTCM
And then it clears a memory range: memory_clear(&_sbss, &_ebss);
20029320 B _sbss
2002d2c0 B _ebss
Or again clearing out another: 16288 bytes.
So far I have not found anything obvious where we are going out of bounds or the like. So again maybe barking at the wrong tree. I may also extract some of the same data sizes and the like for a version of the program that told all of the large data arrays to stay in program space.
Also want to look a little more into see if there is something that configures if all of the memory banks are active or not. That is I thought I saw some reference to maybe some of the banks are maybe not active in low power mode or... But again need to look a bit more.
EDIT Some data from a version that add PROGMEM onto the large structures:
------------------------
Code:
"D:\\arduino-1.8.9\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-size" -A "C:\\Users\\kurte\\AppData\\Local\\Temp\\arduino_build_746535/uncannyEyes_async_st7735.ino.elf"
Sketch uses 209312 bytes (10%) of program storage space. Maximum is 2031616 bytes.
Global variables use 62640 bytes (5%) of dynamic memory, leaving 985936 bytes for local variables. Maximum is 1048576 bytes.
Code:
aaaaaaaf A _flexram_bank_config
20070000 B _estack
00000000 T _stext
600286d0 A _stextload
000091f0 T _etext
20000000 D _sdata
600318cc A _sdataload
200018e0 D _edata
200018e0 B _sbss
200062c0 B _ebss
Also again sorry for this long rambling. I am just trying to get more of handle on how all of these memory pieces played with each other...