Hey guys, I seem to be experiencing serious memory problems with fopen() while trying to use SDFileSystem with mbed-rtos. Now, I realize this has come up several times before, and the usual solution is to increase the SD card thread's stack size to 2.25x the default stack size, but my problem is much more severe than that. In my case, I couldn't get fopen() to work until I increased the stack size to at least 1600B on an LPC11U24, 3.125x the default stack size! Furthermore, repeated calls to fopen() eventually causes a hang, presumably due to a memory leak. Using this modified version of the official test program, fopen() will hang the system after just 10 seconds, or about 100 calls:
main.cpp
#include "mbed.h"
#include "rtos.h"
#include "SDFileSystem.h"
DigitalOut myled(LED1);
DigitalOut sdled(LED2);
SDFileSystem sd(p5, p6, p7, p20, "sd");
void sd_thread(void const *argument)
{
while (true) {
sdled = !sdled;
FILE* fp = fopen("/sd/test.txt", "w");
if (fp != NULL) {
fclose(fp);
} else {
error("Failed to open file!\n");
}
Thread::wait(100);
}
}
int main()
{
Thread sdTask(sd_thread, NULL, osPriorityNormal, 1600);
while (true) {
myled = !myled;
Thread::wait(100);
}
}
Occasionally I'll get an error pattern instead of a hang, but no text will print telling me what it is. I've also tried this with my new and improved SDFileSystem library with similar results.
UPDATE: Apparently the number of calls to fopen() before a hang is dependent on the program. I just tried a more comprehensive version that tests fread() in another thread, and it hung on the 3rd call to fopen().
Hey guys, I seem to be experiencing serious memory problems with fopen() while trying to use SDFileSystem with mbed-rtos. Now, I realize this has come up several times before, and the usual solution is to increase the SD card thread's stack size to 2.25x the default stack size, but my problem is much more severe than that. In my case, I couldn't get fopen() to work until I increased the stack size to at least 1600B on an LPC11U24, 3.125x the default stack size! Furthermore, repeated calls to fopen() eventually causes a hang, presumably due to a memory leak. Using this modified version of the official test program, fopen() will hang the system after just 10 seconds, or about 100 calls:
main.cpp
Occasionally I'll get an error pattern instead of a hang, but no text will print telling me what it is. I've also tried this with my new and improved SDFileSystem library with similar results.
UPDATE: Apparently the number of calls to fopen() before a hang is dependent on the program. I just tried a more comprehensive version that tests fread() in another thread, and it hung on the 3rd call to fopen().