Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 5 months ago.
I cannot write to sd card means can't open file for writing
when i flash bin file to my MKL25Z128VLK4 following error show:
Hello World!
++ MbedOS Error Info ++
Error Status: 0x80040103
Error Code: 256
Error Module: 255
Error Message: FATAL Run -time error
Error Location: 0x74D3
Error Value: 0x00005566
Current Thread: Id: 0x200024A8 EntryFn: 0x0000FB0D StackSize: 0x00001000 StackMem: 0x200014A8 SP: 0x2002FFD8
-- MbedOS Error Info --
Could not open file for write
i am using eclipse oxygen ide and writing to sd card with mbed-os
here i am inseted my code below:
#include "mbed.h"
#include "SDBlockDevice.h"
#include "FATFileSystem.h"
#include "stdio.h"
#define SD_MOUNT_PATH "sd"
SDBlockDevice sd(PTD6, PTD7, PTD5, PTE31);
FATFileSystem fs(SD_MOUNT_PATH);
int main()
{
sd.init();
fs.mount(&sd);
printf("Hello World!\n");
FILE *fp = fopen("/sd/mydir/myfile.txt", "a");
if (fp == NULL) {
error("Could not open file for write\n");
}
fprintf(fp, "SD card is running successfully,Thank you");
fclose(fp);
printf("Goodbye World!\n");
fs.unmount();
sd.deinit();
}
1 Answer
7 years, 4 months ago.
Hello Dipak,
Can you try running this program here?:
https://github.com/ARMmbed/mbed-os-example-sd-driver
If you look at the mbed_lib.json file, it has the pins for SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName cs) configured for the FRDM-KL25Z as:
"KL25Z": {
"SPI_MOSI": "PTD2",
"SPI_MISO": "PTD3",
"SPI_CLK": "PTD1",
"SPI_CS": "PTD0"
},
If you want, you can try changing those pin configurations within your own program to see if that will also run. Hope this helps!
-Karen, team Mbed
If this solved your question, please make sure to click the "Thanks" link below!