Postby vonnieda » Wed Apr 17, 2019 5:40 pm
Create a FreeRTOS task that prints out the free memory every 5 seconds or so. Once your app is up, watch the printout and see if the memory continues to go down. If it does, start commenting out code until the memory stops going down. Then find the culprit. I also recommend printing out internal memory as well.
For reference, here are the ones I print out when I am trying to track something down:
heap_caps_get_free_size(MALLOC_CAP_8BIT),
heap_caps_get_free_size(MALLOC_CAP_32BIT),
heap_caps_get_free_size(MALLOC_CAP_32BIT) - heap_caps_get_free_size(MALLOC_CAP_8BIT),
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_free_size(MALLOC_CAP_DMA),
Additionally, if you are creating and deleting tasks, make sure you are not keeping the IDLE task from running. IDLE is responsible for cleaning up deleted tasks. This will happen if you have a higher priority task that never sleeps.
Also, I can tell you that the i2c master library is pretty darn stable for me. I run tens of transactions per second to multiple devices in my app for weeks at a time without any problems.
Finally, when you see a stack dump that points to a line number that is the end of a function, you can't really trust that stack dump. I don't know the exact reason why this happens - I suspect it's due to stack corruption - but when it does the error is seldom actually in the function indicates by the stack dump.
Jason