Arm Mbed OS support forum

LPC1768 microSD read and write files

Hi everyone,
I am trying to read and write files into microSD with LPC1768. I am using MBED Studio 1.3.1 in windows 10 with the target set to “mbed LPC1768”, build profile in “Debug”, mbed-os 6.6.0 and the code what I am implementing is the next:

#include “mbed.h”
#include “SDBlockDevice.h”
#include “FATFileSystem.h”

SDBlockDevice sd(p5, p6, p7, p8);
FATFileSystem fs(“fs”);

int main()
{
int error = fs.mount(&sd);
if (error != 0)
{
printf(“Mount failed %d.\r\n”, error);
return -1;
}
else {
printf(“Mount sucess with error = %d.\r\n”, error);
error = fs.unmount();
if (error != 0)
{
printf(“Unmount failed %d.\r\n”, error);
return -1;
}
else {
printf(“Unmount sucess with error = %d.\r\n”, error);
}
}
}

When I run this code I get as output “Mount failed -22.”. What am I doing wrong?

Many thanks for your help
Best Regards

I found a solution in others threads, I needed to change buid profile “Debug” to “Release”. I don’t know why this happens but now my code is working.

Have a nice day :slightly_smiling_face: