Problems with SD card module

I have the following issue:

I start my debugger in VS and i mount the sd card. Write some files and directories as my program runs. Now when i press stop in visual studio, the sd card is not unmounted, which results is a loss of files. But the worst thing is that when i press f5 again in VS, the program won’t start and visual studio keeps saying that the device is not in an initialized state, rebooting…

The only way to be able to use the board again is to disconnect the power supply (usb).

My question is, do i have to unmount the sd card EVERY time i wrote something to it. or is it possible to trigger the unmounting method when you press pause in visual studio??

Not sure if there’s a method to unmount SD card in Gadgeteer…

Do you call

 every time you write something? It forces to write all the buffers to the card immediately. Otherwise flush happens many seconds later — thus you loose data if you stop program.

@ Sebasnap - It is highly recommended in both embedded and consumer electronics that the media is unmounted prior to removal. You can set a button to trigger the unmount process. The same process is required by all major operating systems and phones to ensure data integrity.

Using Simon’s suggestion will force the FAT table to be written, but can not guarantee that the system will not attempt to access the SD card at the time of removal.

1 Like

Also remember that stopping debugging does NOT stop your application on the host board. It just disconnects the debugger between the board and your PC. The app still runs and runs and runs…

1 Like