I am not sure how interesting this part might be, but with the uncannyeyes, which it appears like at least some of the issues we were running into is caused by unitialized members of the st7735_t3 code, which you will only ever see if you do a new of the display class...
But while debugging some of this stuff, I did add to my version of the sketch a couple of functions, to help me debug some stuff:
Code:
// from the linker
// extern unsigned long _stextload;
extern unsigned long _stext;
extern unsigned long _etext;
// extern unsigned long _sdataload;
extern unsigned long _sdata;
extern unsigned long _edata;
extern unsigned long _sbss;
extern unsigned long _ebss;
// extern unsigned long _flexram_bank_config;
extern unsigned long _estack;
void DumpMemoryInfo() {
#if defined(__IMXRT1062__)
uint32_t flexram_config = IOMUXC_GPR_GPR17;
Serial.printf("IOMUXC_GPR_GPR17:%x IOMUXC_GPR_GPR16:%x IOMUXC_GPR_GPR14:%x\n",
flexram_config, IOMUXC_GPR_GPR16, IOMUXC_GPR_GPR14);
Serial.printf("Initial Stack pointer: %x\n", &_estack);
uint32_t dtcm_size = 0;
uint32_t itcm_size = 0;
for (; flexram_config; flexram_config >>= 2) {
if ((flexram_config & 0x3) == 0x2) dtcm_size += 32768;
else if ((flexram_config & 0x3) == 0x3) itcm_size += 32768;
}
Serial.printf("ITCM allocated: %u DTCM allocated: %u\n", itcm_size, dtcm_size);
Serial.printf("ITCM init range: %x - %x Count: %u\n", &_stext, &_etext, (uint32_t)&_etext - (uint32_t)&_stext);
Serial.printf("DTCM init range: %x - %x Count: %u\n", &_sdata, &_edata, (uint32_t)&_edata - (uint32_t)&_sdata);
Serial.printf("DTCM cleared range: %x - %x Count: %u\n", &_sbss, &_ebss, (uint32_t)&_ebss - (uint32_t)&_sbss);
Serial.println("Now fill rest of DTCM with known pattern"); Serial.flush(); //
// Guess of where it is safe to fill memory... Maybe address of last variable we have defined - some slop...
for (uint32_t *pfill = (&_ebss + 32); pfill < (&itcm_size - 10); pfill++) {
*pfill = 0x01020304; // some random value
}
#endif
}
void EstimateStackUsage() {
#if defined(__IMXRT1062__)
uint32_t *pmem = (&_ebss + 32);
while (*pmem == 0x01020304) pmem++;
Serial.printf("Estimated max stack usage: %d\n", (uint32_t)&_estack-(uint32_t)pmem);
#endif
}
Which I call the first one early on in setup. I call the second one when I print out how many frames per second are output...
Code:
IOMUXC_GPR_GPR17:aaaaaaaf IOMUXC_GPR_GPR16:7 IOMUXC_GPR_GPR14:aa0000
Initial Stack pointer: 20070000
ITCM allocated: 65536 DTCM allocated: 458752
ITCM init range: 0 - 9c70 Count: 40048
DTCM init range: 20000000 - 20001ad0 Count: 6864
DTCM cleared range: 20001ad0 - 200062c0 Count: 18416
Now fill rest of DTCM with known pattern
C:\Users\kurte\Documents\Arduino\uncannyEyes_async_st7735\uncannyEyes_async_st7735.ino Aug 24 2019 08:49:51
Init
Create display #0
Create display #1
ST7789_t3::init mode: 0
Init ST77xx display #0
Rotate
ST7789_t3::init mode: 0
Init ST77xx display #1
Rotate
done
Display logo
$0: Using Frame buffer
$1: Using Frame buffer
36
Estimated max stack usage: 1616
36
Estimated max stack usage: 1616
36
Estimated max stack usage: 1616
36
Estimated max stack usage: 1616
36
Estimated max stack usage: 1616
Note: the sketch has now run for maybe an hour and the estimated Max size is now up to 1696.
This information as well as the information I printed as part of this build:
Code:
FlexRAM section ITCM+DTCM = 512 KB
Config : aaaaaaaf
ITCM : 40048 B (61.11% of 64 KB)
DTCM : 25280 B ( 5.51% of 448 KB)
Available for Stack: 433472
OCRAM: 512KB
DMAMEM: 0 B ( 0.00% of 512 KB)
Available for Heap: 524288 B (100.00% of 512 KB)
Flash: 212352 B (10.45% of 1984 KB)
Which if we assume that this stack will not grow above 2K needed, implies we have over 400K in lower memory, that we might want to make available for usage.
Example currently in the ST7789_t3 DMA update code, I currently have the displays malloc their frame buffer. Yes I also have the option to allocate this myself and tell the display to use my own buffer... But if the user object does not do that, maybe it might want to give preference to having the frame buffer in DTCM where you don't have DMA cache issues...
Likewise currently I define a structure with some smaller buffers as well as DMASetting and DMAChannel structures and I define a set of three static ones for this class on the off chance the user will do a new of this display class. Might be good if again we could simply allocate lower memory on the fly when we need it.
Maybe does not need to be anything more than just allocate (ie. maybe don't support free or realloc...)
Thoughts?