LPCUSBlib + FatFS + freeRTOS: USB Write Error while powering down periodically

Hi, I have been using LPCUSBlib and FatFS in my freeRTOS project to support USB as a host. In my project, I store data to the USB device periodically. It was working smooth until I introduce a power save option. I tried to power down the USB when it is not in use. It saved me a lot of power conception. I was happy, and it looked working but some USB devices doesn’t like this power down. I found data loss on these USB’s. I loss the data which I write to the last file. Starting Up Create folder1->file1 and write some data Create folder2->file2 and write some data Create folder3->file3 and write some data Power Down the USB … Power Up the USB Append some data to folder1->file1 Append some data to folder2->file2 Append some data to folder3->file3 Power Down the USB When I check the files, data in the file3 found missing. Any help is appreciated. Thanks in advance.

LPCUSBlib + FatFS + freeRTOS: USB Write Error while powering down periodically

You may need to make sure that you have flushed any caches, and that the action is totally completed before powering down. For a device out on USB, that may mean giving it some time or asking if it is completed, before you power it down, remember powering down the USB may power off the device, so if it hasn’t finished all its writes to its internal storage, that data may be lost.

LPCUSBlib + FatFS + freeRTOS: USB Write Error while powering down periodically

Thank you Richard, Thanks for the response. I tried to wait around 1 minute after writing to USB. And used a function to flush the cache. This is not happening to every device. Some devices showing this. Is there any problem with powering down the USB so often?