3 years, 9 months ago.

Could not open file for write SDCard, STM32F446

I upload this program

  1. include "mbed.h"
  2. include "SDFileSystem.h"

SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name) SDFileSystem sd(D11, D12, D13, D10, "sd");

int main() { printf("Hello World!\n");

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

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

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

from https://developer.mbed.org/handbook/SDFileSystem

the output is

Hello World! Could not open file for write

I have check my SDcard module. it works fine on Arduino.

For more information. I use STM32F446RE and 8GB VGEN microSD with FAT32 format. In my computer, the SD card's name is SDHC. My SDcard module is CATALEX MicroSD Card adapter V1.0 11/01/2013.

Question relating to:

Since mbed won't let me reply twice I have to add this. Very frustrating. You need to re-read the links I sent. The SDFile from mbed doesn't work. Be sure to include the full library from this link https://developer.mbed.org/users/neilt6/code/SDFileSystem_HelloWorld/

posted by Bill Bellis 22 May 2017

i've tried that too, for more information my micro sd module do not have any DAT1 and DAT2 pin

posted by Fransiskus Yoga Esa Wibowo 22 May 2017

1 Answer

3 years, 9 months ago.

There was a similar question the other day. I too have an F446 and was finally able to make it work. Please take a look at this thread and look at my reply. Any more questions post back. https://developer.mbed.org/questions/78055/Problems-with-Nucleo-L152RE-F401RE-and-S/#answer12689

I change sdcard assignment like this SDFileSystem sd(D11, D12, D13, D8, "sd", NC, SDFileSystem::SWITCH_NONE, 1400000); Then I got this comment Error: Class "SDFileSystem" has no member "SWITCH_NONE" in "main.cpp", Line: 5, Col: 61 Error: No instance of constructor "SDFileSystem::SDFileSystem" matches the argument list in "main.cpp", Line: 5, Col: 18

posted by Fransiskus Yoga Esa Wibowo 21 May 2017