From a29e3cd5d88bede7fb60d6f63488925cfddcee5b Mon Sep 17 00:00:00 2001 From: Rajkumar Kanagaraj Date: Mon, 11 Jan 2021 10:56:43 -0800 Subject: [PATCH] f_mount() (http://www.elm-chan.org/fsw/ff/00index_e.html - third party libary) API is called from both mount() and unmount() Mbed OS APIs. f_mount() is doing both initializing (via find_volume() -> disk_initialize() where disk_initialize api calls Mbed OS init() function) underlying block device and register filesystem but in case of "unmount" calls this f_mount is doing deregister filesystem and missed to a deinitializing block device. So added the Mbed OS "deint()" call in unmount API to deinitialize block device as f_mount API doesn't have a way to call deinit(). --- storage/filesystem/fat/source/FATFileSystem.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/storage/filesystem/fat/source/FATFileSystem.cpp b/storage/filesystem/fat/source/FATFileSystem.cpp index 9fefb0222f..3285d1a4ba 100644 --- a/storage/filesystem/fat/source/FATFileSystem.cpp +++ b/storage/filesystem/fat/source/FATFileSystem.cpp @@ -330,6 +330,11 @@ int FATFileSystem::unmount() } FRESULT res = f_mount(NULL, _fsid, 0); + int err = _ffs[_id]->deinit(); + if (err) { + unlock(); + return err; + } _ffs[_id] = NULL; _id = -1; unlock();