diff --git a/stmhal/diskio.c b/extmod/vfs_fat_diskio.c
similarity index 99%
rename from stmhal/diskio.c
rename to extmod/vfs_fat_diskio.c
index 03be24188ed9740b92a3604c25141e949831b3cb..7acdc82972ef989e8b14dd380aab1af170caf3c9 100644
--- a/stmhal/diskio.c
+++ b/extmod/vfs_fat_diskio.c
@@ -27,6 +27,9 @@
  * THE SOFTWARE.
  */
 
+#include "py/mpconfig.h"
+#if MICROPY_FSUSERMOUNT
+
 #include <stdint.h>
 #include <stdio.h>
 
@@ -248,3 +251,5 @@ DRESULT disk_ioctl (
     }
 }
 #endif
+
+#endif // MICROPY_FSUSERMOUNT
diff --git a/py/py.mk b/py/py.mk
index 61faf08920e6453172d4ad937b8333571cf11656..9391bbdfb8ca628bc88bda8d3983f0a0090b7fb3 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -171,6 +171,7 @@ PY_O_BASENAME = \
 	../extmod/modurandom.o \
 	../extmod/fsusermount.o \
 	../extmod/vfs_fat.o \
+	../extmod/vfs_fat_diskio.o \
 	../extmod/moduos_dupterm.o \
 
 # prepend the build destination prefix to the py object files
diff --git a/stmhal/Makefile b/stmhal/Makefile
index 3cad7d1da4cd9a4f47aeda87fc81b2851be132ed..cd565a6f4a73efe35649dc40cb9c40c2ad562400 100644
--- a/stmhal/Makefile
+++ b/stmhal/Makefile
@@ -156,7 +156,6 @@ SRC_C = \
 	file.c \
 	builtin_open.c \
 	sdcard.c \
-	diskio.c \
 	fatfs_port.c \
 	ffconf.c \
 	lcd.c \
diff --git a/unix/Makefile b/unix/Makefile
index 42f0edf81138c19c17e3680ffb80b474a42d59d6..342786debec3ce7a23d6ee445729d2c51889b16a 100644
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -148,7 +148,6 @@ SRC_C = \
 	$(SRC_MOD)
 
 STMHAL_SRC_C = \
-	stmhal/diskio.c \
 	stmhal/ffconf.c \
 	stmhal/file.c