diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c
index 607a736a78d29a04457c7de83a8f6826bc512364..b408dca0c836db6d1820b16602e97ad24e5552d4 100644
--- a/extmod/vfs_fat.c
+++ b/extmod/vfs_fat.c
@@ -32,7 +32,7 @@
 #include "py/runtime.h"
 #include "lib/fatfs/ff.h"
 #include "lib/fatfs/diskio.h"
-#include "stmhal/file.h"
+#include "extmod/vfs_fat_file.h"
 #include "fsusermount.h"
 
 #define mp_obj_fat_vfs_t fs_user_mount_t
diff --git a/stmhal/file.c b/extmod/vfs_fat_file.c
similarity index 98%
rename from stmhal/file.c
rename to extmod/vfs_fat_file.c
index 20400a572fdc8d2c545f39db9755d005eb2141df..0c0ea84b310e2a366e60a8b0e8b343f2e7c5dba0 100644
--- a/stmhal/file.c
+++ b/extmod/vfs_fat_file.c
@@ -24,6 +24,9 @@
  * THE SOFTWARE.
  */
 
+#include "py/mpconfig.h"
+#if MICROPY_FSUSERMOUNT
+
 #include <stdio.h>
 #include <errno.h>
 
@@ -31,7 +34,7 @@
 #include "py/runtime.h"
 #include "py/stream.h"
 #include "lib/fatfs/ff.h"
-#include "file.h"
+#include "extmod/vfs_fat_file.h"
 
 #if MICROPY_VFS_FAT
 #define mp_type_fileio fatfs_type_fileio
@@ -284,3 +287,5 @@ mp_obj_t fatfs_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw
     mp_arg_parse_all(n_args, args, kwargs, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals);
     return file_open(&mp_type_textio, arg_vals);
 }
+
+#endif // MICROPY_FSUSERMOUNT
diff --git a/stmhal/file.h b/extmod/vfs_fat_file.h
similarity index 100%
rename from stmhal/file.h
rename to extmod/vfs_fat_file.h
diff --git a/py/py.mk b/py/py.mk
index 9391bbdfb8ca628bc88bda8d3983f0a0090b7fb3..2213e6a0a273af3684a90500f94e8df519c0e752 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -172,6 +172,7 @@ PY_O_BASENAME = \
 	../extmod/fsusermount.o \
 	../extmod/vfs_fat.o \
 	../extmod/vfs_fat_diskio.o \
+	../extmod/vfs_fat_file.o \
 	../extmod/moduos_dupterm.o \
 
 # prepend the build destination prefix to the py object files
diff --git a/stmhal/Makefile b/stmhal/Makefile
index cd565a6f4a73efe35649dc40cb9c40c2ad562400..884a40fda9d4d5d1d0dce99a9e13da78434dab57 100644
--- a/stmhal/Makefile
+++ b/stmhal/Makefile
@@ -153,7 +153,6 @@ SRC_C = \
 	rtc.c \
 	flash.c \
 	storage.c \
-	file.c \
 	builtin_open.c \
 	sdcard.c \
 	fatfs_port.c \
diff --git a/stmhal/builtin_open.c b/stmhal/builtin_open.c
index c7e183f91bea4b89307fd1ceccb041bdecdcc074..697eec8eaaf80afdeb18957174ce8ca425c10957 100644
--- a/stmhal/builtin_open.c
+++ b/stmhal/builtin_open.c
@@ -25,6 +25,6 @@
  */
 
 #include "py/runtime.h"
-#include "file.h"
+#include "extmod/vfs_fat_file.h"
 
 MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, fatfs_builtin_open);
diff --git a/stmhal/moduos.c b/stmhal/moduos.c
index 293fbabafcb983b3f91a351f74f43873463cc606..75cb8986d06b3574b639d19568cbe5ce854648b8 100644
--- a/stmhal/moduos.c
+++ b/stmhal/moduos.c
@@ -36,7 +36,7 @@
 #include "timeutils.h"
 #include "rng.h"
 #include "uart.h"
-#include "file.h"
+#include "extmod/vfs_fat_file.h"
 #include "sdcard.h"
 #include "extmod/fsusermount.h"
 #include "portmodules.h"
diff --git a/unix/Makefile b/unix/Makefile
index 342786debec3ce7a23d6ee445729d2c51889b16a..18186ec5669ab3ada5475f4817dbcb6f10d78b6d 100644
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -148,8 +148,7 @@ SRC_C = \
 	$(SRC_MOD)
 
 STMHAL_SRC_C = \
-	stmhal/ffconf.c \
-	stmhal/file.c
+	stmhal/ffconf.c
 
 # Include builtin package manager in the standard build (and coverage)
 ifeq ($(PROG),micropython)