USB serial error while write sdcard

image

Hello,

when i need to write some data to sdcard, why the USB stop working as image attached?

my code was:

while(1) {
while(gps.readable()) {
myled = 1;
char_gps = gps.getc();
tgps.encode(char_gps);
read_gps = true;
}
if(read_gps){
myled = 0;
read_gps = false;
tgps.f_get_position(&flat, &flon, &age);
FILE *fp = fopen(“/sd/tes.txt”,“a”);
if(fp!=NULL){
sprintf(data,“%f,%f\r\n”, flat, flon);
fprintf(fp,data);
fclose(fp);
}
}
}

if the sdcard is not inserted, the program running well, but when i insert the sdcard, it suddenly stop working.

Hi,

Are you using Mbed OS? The code does not look like to Mbed OS SDBlockDevice class or example using the class.
If you want to use SD card to store application data with Mbed OS look this example / API description:
https://os.mbed.com/docs/mbed-os/v5.15/apis/sdblockdevice.html#sdblockdevice-example-application

Regards,
Pekka