So, I reduced the size to 10000. That causes it to fail in a different way. Now, the very first entry mismatches when I read it back. When I use 10000, it gets guru meditation and that's all for that run.19:32:02.862 -> Array should have 9600 bytes.
19:32:02.862 -> Array located at 0x3ffb2068
19:32:02.862 -> Last element located at 0x3ffbb668
19:32:02.862 -> FreeHeapSize before malloc 290752, after 280936,
19:32:02.862 -> used: 9816
19:32:02.862 -> Array located at 0x3ffb2068
None of this makes any sense! There is plenty of memory. It allocates it for me but in an address area that is invalid. And random other errors. I will put specifics next and the test program last. Yes, it works just fine in PSRAM but the unit I want to use for this program does not have PSRAM.
The same program fails on T14, T7 and T5 T-Display. All want to allocate invalid memory addresses.
The first lines are setting array elements to 100000 - i. They print back good in the loop but print back bad when reprinted. They also are bad in the checking routine. Locations 0 and 38400 are OK. But anything above 0x40000000 is good, then bad. No idea why it prints good once then bad immediately afterwards. Same print line (code) prints in both places:
Code: Select all
Serial.printf("Location %i contains %i\n", i, array[i]);
Now I change the array size from 76800 to 10000 via:19:12:46.898 -> Setting location 76797 at address 0x4000c0fc to 23203
19:12:46.898 -> Location 76797 contains 23203
19:12:46.898 -> Setting location 76798 at address 0x4000c100 to 23202
19:12:46.898 -> Location 76798 contains 23202
19:12:46.898 -> Setting location 76799 at address 0x4000c104 to 23201
19:12:46.898 -> Location 76799 contains 23201
19:12:46.898 -> Location 0 contains 100000
19:12:46.898 -> Location 38400 contains 61600
19:12:46.898 -> Location 76797 contains 124004104
19:12:46.898 -> Location 76798 contains 860554088
19:12:46.898 -> Location 76799 contains 1430979945
19:12:46.898 -> /***************************************************************************/
19:12:46.898 -> /***************************************************************************/
19:12:46.898 -> Checking array
19:12:46.898 -> /***************************************************************************/
19:12:46.898 -> /***************************************************************************/
19:12:46.898 -> Array size to check: 76800
19:12:46.933 -> Location 64446 mismatch at address 0x40000000
19:12:46.933 -> Should be 35554, contains 273270016
19:12:46.933 -> Location 0 contains 100000
19:12:46.933 -> Location 38400 contains 61600
19:12:46.933 -> Location 76797 contains 124004104
19:12:46.933 -> Location 76798 contains 860554088
19:12:46.933 -> Location 76799 contains 1430979945
Code: Select all
const uint32_t buffSize = 10000;
This dump decoder does not return any lines at all in the bottom window. It has no idea what it is looking at. That makes 2 of us!19:19:27.895 -> Setting location 998 at address 0x3ffb3000 to 99002
19:19:27.895 -> Location 998 contains 99002
19:19:27.895 -> Setting location 999 at address 0x3ffb3004 to 99001
19:19:27.895 -> Location 999 contains 99001
19:19:27.975 -> Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled.
19:19:27.975 -> Core 1 register dump:
19:19:27.975 -> PC : 0x4008bf1e PS : 0x00050033 A0 : 0x4008be27 A1 : 0x3ffb1e30
19:19:27.975 -> A2 : 0x00016ea3 A3 : 0x00000000 A4 : 0x00000001 A5 : 0x4008bda8
19:19:27.975 -> A6 : 0x3ff000e0 A7 : 0x00000001 A8 : 0x80085139 A9 : 0x3ffbeb20
19:19:27.975 -> A10 : 0x3ffbeb58 A11 : 0x00000001 A12 : 0x00000001 A13 : 0x00000001
19:19:27.975 -> A14 : 0x00060021 A15 : 0x00000000 SAR : 0x00000017 EXCCAUSE: 0x0000001d
19:19:27.975 -> EXCVADDR: 0x00016ea3 LBEG : 0x400882d5 LEND : 0x400882e5 LCOUNT : 0xffffffff
19:19:27.975 ->
19:19:27.975 -> ELF file SHA256: 0000000000000000
19:19:27.975 ->
19:19:27.975 -> Backtrace: 0x4008bf1e:0x3ffb1e30 0x4008be24:0x3ffb1e40
This makes NO SENSE! A smaller array crashes. A larger array works but gets into invalid memory space.
I tried using "static" for the pointer but that did not work any better. Please help me understand what is going on here. I am getting no help from Espressif. They seem mystified although they have all the tools to look into this stuff, nothing is happening. If you want any more tests, please copy the code, below, and try it in the Arduino IDE.
Thanks for any help solving this. Mike.
Code: Select all
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
const uint32_t buffSize = 10000; // TFT_HEIGHT * TFT_WIDTH;
int preHeapSize;
//static unsigned int *workBuff;
long int i;
/***************************************************************************/
void setup()
/***************************************************************************/
{
Serial.begin(500000); delay(1000);
Serial.printf("\n\nArray should have %i bytes.\n", buffSize);
preHeapSize = xPortGetFreeHeapSize();
static unsigned int *workBuff = (unsigned int*)malloc(buffSize); // Fails
// workBuff = (unsigned int*)ps_malloc(buffSize);
// workBuff = (uint32_t*)malloc(buffSize);
Serial.printf("Array located at %p\n", workBuff);
Serial.printf("Last element located at %p\n", workBuff + buffSize);
Serial.printf("FreeHeapSize before malloc %i, after %i, \nused: %i\n",
preHeapSize, xPortGetFreeHeapSize(),
preHeapSize - xPortGetFreeHeapSize());
Serial.printf("Array located at %p\n", workBuff);
workBuff[0] = 12; // Just checking...
FillArray(workBuff);
CheckArray(workBuff);
}
/***************************************************************************/
void FillArray (unsigned int *array)
/***************************************************************************/
{
Serial.printf("Filling array\n");
Serial.println(array[0]); // Just checking...
array[0] = 24; // Just checking...
Serial.println(array[0]); // Just checking...
for (i = 0; i < buffSize; i++) {
if (i > buffSize - 500 || i < 1000) {
Serial.printf("Setting location %i at address %p to %i\n",
i, array + i, 100000 - i);
}
array[i] = 100000 - i;
if (i > buffSize - 500 || i < 1000) {
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
}
delay(0);
}
i = 0;
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
i = buffSize / 2;
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
i = buffSize - 3;
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
i = buffSize - 2;
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
i = buffSize - 1;
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
}
/***************************************************************************/
void CheckArray (unsigned int *array)
/***************************************************************************/
{
Serial.println("/***************************************************************************/");
Serial.println("/***************************************************************************/");
Serial.printf("Checking array\n");
Serial.println("/***************************************************************************/");
Serial.println("/***************************************************************************/");
Serial.printf("Array size to check: %i\n", buffSize);
for (i = 0; i < buffSize; i++) {
if (i > buffSize - 500)
Serial.printf("Verify location %i contains %i\n", i, array[i]); // Just checking...
if (array[i] != 100000 - i) {
Serial.printf("Location %i mismatch at address %p\n", i, array + i);
Serial.printf("Should be %i, contains %i\n", 100000 - i, array[i]);
break;
}
}
i = 0;
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
i = buffSize / 2;
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
i = buffSize - 3;
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
i = buffSize - 2;
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
i = buffSize - 1;
Serial.printf("Location %i contains %i\n", i, array[i]); // Just checking...
}
void loop() { }