Skip to main content
alex_embedded
Associate III
Jan 18, 2019 2:08 AM UTC
Solved

"Safely" removing a USB from a system

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!

This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Jan 18, 2019 4:35 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..

1 reply

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Jan 18, 2019 4:35 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..