8 years, 6 months ago.

mbed SD card causing code to freeze

I was using an SD reader/card in my system and it was working fine. I was using a USB adapter to check the data on my desktop when the USB suddenly became unrecognizable. I used a regular SD card adapter and that still worked, although windows gave me a warning to scan/fix errors.

After that, whenever I tried using the SD card at all during my programs, the execution seems to halt whenever it reaches a line regarding the SD card. Even a program I know has run successfully before freezes.

SD Card

#include "mbed.h"
#include "SDFileSystem.h"
#include "uLCD_4DGL.h"

SDFileSystem sd(p5, p6, p7, p8, "sd");
uLCD_4DGL uLCD(p28,p27,p29);

int main()
{
    uLCD.printf("Hello!\n");
    mkdir("/sd/mydir",0777);
    uLCD.printf("Directory made");
    FILE *fp =fopen("/sd/mydir/sdtest.txt","w");
    if(fp==NULL)
    {
        uLCD.printf("Error open \n");
    }
    fprintf(fp,"File opened");
    fclose(fp);
    uLCD.printf("DONE");
}

With this code, I create an LCD panel object and an SD card object. The LCD prints "Hello!" just fine, but fails to perform any line after that.

I've tried formatting my SD card using the SD format tool found here: https://developer.mbed.org/cookbook/SD-Card-File-System but to no avail.

I haven't been able to get my hands on another SD card to test currently, I was wondering if any of you guys can help me solve this issue. Any help is appreciated!

1 Answer

8 years, 6 months ago.

When I get problems with a SD card or warnings, I prefer to reformat the card and reload my last backup. The best reformat is the official SD https://www.sdcard.org/downloads/formatter_4/ I use often the operating system reformat , because I use Linux.

If you do a test with "write" and there occurs a lock, you filesystem is destroyed or not reliable: you have to reformat. This is the reason why you should do a first test with - file created on your desktop - read functions within the mbed ) Good luck