Hi, I've been struggling with dynamically allocating buffer arrays for the sdFat library for several full work days now, and figure it's time to ask for help.
Just to mention it first: Using smaller code snippets everything seems to work fine, but it's when I use a larger project (and subsequently more memory) the problems arise.
I have modified the RamMonitor from this thread to work with Teensy3.6, by adding the following elif to the RAM start address constant:
And I have tried two other libraries to monitor the available RAM (MemoryFree and the sdFatUtil from SdFat). They all seem to roughly agree (within a few hundred bytes at least) that there is a lot of RAM left when my code crashes.
The exact thing my code is trying to do when it crashes is to dynamically allocate an array of size 380 using the new[] operator. The exact line can be found here:
https://github.com/SimenZhor/FerroF...problems/lib/Animation/src/Animation.cpp#L587.
Using the RamMonitor mentioned above I'm printing out this "state" right after that allocation is attempted:
As we can see, the pointer returned to _duty_buf by new[] is 0x0, which, by the way, can't be recognized by the code as nullpointer for some reason.
I think the most important line is this one: "heapfree: 320" which is obviously too small for an array of size 380. But for some reason the total heap size will not expand to allow this allocation to happen. If we compare to a similar printout I do earlier in the code (before any allocation happens), we see that the heaptotal has expanded as expected until this point:
I'm using the PlatformIO environment in VSCode, but I tried to run my code in the Arduino IDE (version: 1.8.9 on Windows 10) as well with the same result.
I've tried to follow the tips from these threads:
https://forum.pjrc.com/threads/46506-3-6-Available-Memory
https://forum.pjrc.com/threads/2655...t-seems-to-just-keep-going-(Teensy-3-1)/page2
There is no other hardware connected to the Teensy except for an SD card in the SD slot.
Just to mention it first: Using smaller code snippets everything seems to work fine, but it's when I use a larger project (and subsequently more memory) the problems arise.
I have modified the RamMonitor from this thread to work with Teensy3.6, by adding the following elif to the RAM start address constant:
Code:
static const uint32_t HWADDRESS_RAMSTART =
#elif defined(__MK66FX1M0__)
0x1FFF0000; // Teensy 3.6 (from https://github.com/PaulStoffregen/cores/blob/238b102ac46d1184e7055943cb5fe60bcb8eabbe/teensy3/mk66fx1m0.ld)
The exact thing my code is trying to do when it crashes is to dynamically allocate an array of size 380 using the new[] operator. The exact line can be found here:
https://github.com/SimenZhor/FerroF...problems/lib/Animation/src/Animation.cpp#L587.
Using the RamMonitor mentioned above I'm printing out this "state" right after that allocation is attempted:
Code:
Pointer to _duty_buf: 0x0,0
Pointer to _frame_buf: 0x1fff3350
==== memory report ====
heapsize: 25788
heapfree: 320
heaptotal: 26108
stacksize: 240
stackfree: 784
stacktotal: 1024
totalfree: 237648
total: 262144
free: 231 Kb (90.4% of 256 Kb)
stack: 1 Kb (0.4% of 256 Kb)
heap: 25 Kb (10.0% of 256 Kb)
I think the most important line is this one: "heapfree: 320" which is obviously too small for an array of size 380. But for some reason the total heap size will not expand to allow this allocation to happen. If we compare to a similar printout I do earlier in the code (before any allocation happens), we see that the heaptotal has expanded as expected until this point:
Code:
==== memory report ====
heapsize: 2940
heapfree: 3304
heaptotal: 6244
stacksize: 160
stackfree: 864
stacktotal: 1024
totalfree: 248904
total: 262144
free: 242 Kb (94.6% of 256 Kb)
stack: 1 Kb (0.4% of 256 Kb)
heap: 6 Kb (2.4% of 256 Kb)
I'm using the PlatformIO environment in VSCode, but I tried to run my code in the Arduino IDE (version: 1.8.9 on Windows 10) as well with the same result.
I've tried to follow the tips from these threads:
https://forum.pjrc.com/threads/46506-3-6-Available-Memory
https://forum.pjrc.com/threads/2655...t-seems-to-just-keep-going-(Teensy-3-1)/page2
There is no other hardware connected to the Teensy except for an SD card in the SD slot.