7 years ago.

SD Card not working from offline compiler

Hi,

I tried the following simple code to check the SD card on my STM32L476VG board. If I compile it from the online compiler and download the binary, I am able to read the SD Card fine, however, on compiling it offline with Visual GDB ( v5.3R7), it says "Couldnt Open file for write".

Any points would be appreciated

Code is below:

  1. include "mbed.h"
  2. include "SDFileSystem.h" Serial pc(USBTX, USBRX); SDFileSystem sd(PD_4, PD_3, PD_1, PA_1, "sd"); the pinout on the mbed Cool Components workshop board DigitalOut enable1(PE_2); DigitalOut enable2(PC_8);

int main() { enable1 = 1; enable2 = 1; wait(1); pc.baud(9600); pc.printf("Hello World!\n");

mkdir("/sd/mydir2", 0777);

FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); if (fp == NULL) { pc.printf("File Open Failed\n"); error("Could not open file for write\n"); } else { pc.printf("File Open SUCCESS\n"); fprintf(fp, "Hello fun SD Card World!"); } fclose(fp);

pc.printf("Goodbye World!\n"); }

Regards Ash

2 Answers

7 years ago.

Hey Ash,

For mbed-os5, you need to move to FatFileSystem and BlockDevice. It took me a couple days to make the change, but that's what I use now. SDFileSystem does not work with os5.

https://os.mbed.com/docs/v5.6/reference/storage.html

...kevin

7 years ago.

I have successfully used this sd-driver library on mbed-os 5.4.2 and the Disco-L476VG. Appears to have been tested up to 5.6.1 as well.

https://github.com/ARMmbed/sd-driver