Sd card corrupted after asynchronous power down

Hi there,

I have developed a datalogger based on the Cerbuine, the application logs data and events to the sd card regularly.
Files are continuously opened but flushed every 5 seconds.
The logger operates perfectly weeks or months in case no writes are issued during a power down or reset…as.it seems…But sometimes the sd card seems to be corrupted
Question: is there a documented way to shut down without corrupting the file system, or the sd card?

Always nice to see some of my shared fragments are useful for others :slight_smile:

Sorry that is not an answer to my question. Perhaps my question was not clear…What. I meant:

How can I avoid to corrupt the file system in case of a power down or Reset event that could occur during a write action?

Or: can I detect a power down or manual reset event, so I am able to close the files that are opened?

At my main project reset is delayed by 3 seconds and external power is monitored and buffered with a big cap that allows to close and flush all files.

[edit] and in these events i call the freesd proc.

Thanks for the suggestions. It covers part of the risks. What about asynchronous removal of the sd? When you read on the web on this issue you open Pandora’s box

Write to a new file every hour. This way if one file is corrupt the data will be preserved from the others.

that is is exactly what I already do, and still there are some problems…After a reset I reopen the last hour-file, (which could be corrupted) and start to write in this file again.
Then the trouble starts it seems. I think the best option now is to follwow the suggestion to add a battery and clean- shutdown button…as NETMF has no TFAT available.

GHI FAT implementation on Premium offer is extremely unreliable for industrial applications. I’ve wasted lots of time on it and eventually gave up. The biggest problem is that once the filesystem gets corrupted, it cannot be recovered in at embedded level, and the whole SD card becomes useless. The only way to recover is to plug the card into a PC and fix the problems. It always helps, and I never lost any data this way. So apparently whatever goes wrong, it’s not actually corrupting data, it only makes SD card unusable.

Thanks for the input , saves me a lot trial and error research.
But in case the embedded system must operate in the field, recovering via a PC is not an option.
Do you see any alternatives?
1: other storage medium
2: formatting the medium, and yes losing data?
3: other OS
4: …

  1. For a very sensitive information, like configuration files, I use FRAM and TinyFileSystem.
  2. Formatting didn’t work for me either; but it was some time ago, maybe ir works now?
  3. I’m going to try ALFAT, also from GHI. It is supposed to work reliably…
  4. I also use 0.47F supercapacitor on the power line. Keeps my G400 alive for a second or two.

Are option 1 and 3 available for the Cerbuino Incl NETMF?

Yes, they are SPI (FRAM/flash) and UART (ALFAT), so they will work on any NETMF device…

ALFAT is not only support UART but also SPI, I2C

:wink: