diff --git a/stmhal/pyexec.c b/stmhal/pyexec.c
index d62b2a373ca3bdabb433834bdbf47414279a0d58..00cd95362dbc2b73b79f958c7b7615dc9cb21866 100644
--- a/stmhal/pyexec.c
+++ b/stmhal/pyexec.c
@@ -42,7 +42,9 @@
 #include "repl.h"
 #include "gc.h"
 #include "gccollect.h"
+#ifdef MICROPY_HAL_H
 #include MICROPY_HAL_H
+#endif
 #include "systick.h"
 #include "readline.h"
 #include "pyexec.h"