cancel
Showing results for 
Search instead for 
Did you mean: 

"Safely" removing a USB from a system

alex_embedded
Associate III

Hi all,

I am currently learning how to interface with a USB using an stm32f2 as a host.

I am using the fatfs library and it is working quite well.

I have a question relating how removing a USB from the system. Similar to Windows for example, they have an "eject" button so you can safely remove a USB.

Is there a way to do this on an STM32 system so I don't corrupt the USB or is it not necessary?

Currently I mount the drive, open a file and write to it, then close the file and unmount. Is there anything I should do after this prior to removing the USB?

I have been testing this on the Nucleo F207ZG.

Thanks for you help!

1 ACCEPTED SOLUTION

Accepted Solutions

The flush and unmount should be sufficient, the STM32 isn't caching a whole bunch of data, or doing deferred writes to the media.

You can warn the drive via a SCSI LOAD/UNLOAD command, which would give it an opportunity to find its safe space.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

1 REPLY 1

The flush and unmount should be sufficient, the STM32 isn't caching a whole bunch of data, or doing deferred writes to the media.

You can warn the drive via a SCSI LOAD/UNLOAD command, which would give it an opportunity to find its safe space.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..