diff --git a/cc3200/mods/modmachine.c b/cc3200/mods/modmachine.c
index 896aa9917f32be66cf5e16546e2f7ef45e286145..ed24951a6052f23eba5dbc3d6cf00570f304eca0 100644
--- a/cc3200/mods/modmachine.c
+++ b/cc3200/mods/modmachine.c
@@ -39,7 +39,6 @@
 #include "inc/hw_uart.h"
 #include "rom_map.h"
 #include "prcm.h"
-#include "pyexec.h"
 #include "pybuart.h"
 #include "pybpin.h"
 #include "pybrtc.h"
diff --git a/cc3200/mptask.c b/cc3200/mptask.c
index 7346ddaf29709d79816e703b31db64942e8ea8bd..96a4001ad002874862f63f54ddd1f8d1e36ec6ce 100644
--- a/cc3200/mptask.c
+++ b/cc3200/mptask.c
@@ -43,7 +43,7 @@
 #include "pybuart.h"
 #include "pybpin.h"
 #include "pybrtc.h"
-#include "pyexec.h"
+#include "lib/utils/pyexec.h"
 #include "gccollect.h"
 #include "gchelper.h"
 #include "readline.h"
diff --git a/esp8266/main.c b/esp8266/main.c
index 0d8b3723ca7099caca9336b643c04974986c5ba2..178ad8b7c2fa9650d0fd31a572fcf315ca4ec07f 100644
--- a/esp8266/main.c
+++ b/esp8266/main.c
@@ -35,7 +35,7 @@
 #include "py/frozenmod.h"
 #include "py/mphal.h"
 #include "py/gc.h"
-#include "pyexec.h"
+#include "lib/utils/pyexec.h"
 #include "gccollect.h"
 #include "user_interface.h"
 
diff --git a/esp8266/modpyb.c b/esp8266/modpyb.c
index 36a9d6bf2a52d184919c16302e02526747139c49..a9daef9c7e5a69794fa4e1f3e01f83832f95b708 100644
--- a/esp8266/modpyb.c
+++ b/esp8266/modpyb.c
@@ -31,7 +31,6 @@
 #include "py/gc.h"
 #include "py/mphal.h"
 #include "gccollect.h"
-#include "pyexec.h"
 #include "user_interface.h"
 #include "modpyb.h"
 
diff --git a/esp8266/uart.c b/esp8266/uart.c
index 55841fe39678e0ed466c9d05591ccec13a5a6683..49fc9bb87cbcdd8d2b15f3f6ed86fb82bb4c0440 100644
--- a/esp8266/uart.c
+++ b/esp8266/uart.c
@@ -207,7 +207,7 @@ void ICACHE_FLASH_ATTR uart_reattach() {
 // Task-based UART interface
 
 #include "py/obj.h"
-#include "stmhal/pyexec.h"
+#include "lib/utils/pyexec.h"
 
 void soft_reset(void);
 
diff --git a/lib/utils/pyexec.c b/lib/utils/pyexec.c
index abf74d6db978bac059bfd05bb37c1160566a8c10..295d0594330ed001f63a7ec0121b53cd26fb7a03 100644
--- a/lib/utils/pyexec.c
+++ b/lib/utils/pyexec.c
@@ -39,7 +39,7 @@
 #include "usb.h"
 #endif
 #include "readline.h"
-#include "pyexec.h"
+#include "lib/utils/pyexec.h"
 #include "genhdr/mpversion.h"
 
 pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
diff --git a/stmhal/pyexec.h b/lib/utils/pyexec.h
similarity index 91%
rename from stmhal/pyexec.h
rename to lib/utils/pyexec.h
index 0728b91333cef2b53af5f57e2b77f8b4b704c447..96bb481a541a28dcb47f7385f1af223585cbafd1 100644
--- a/stmhal/pyexec.h
+++ b/lib/utils/pyexec.h
@@ -23,6 +23,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#ifndef __MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H__
+#define __MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H__
 
 typedef enum {
     PYEXEC_MODE_RAW_REPL,
@@ -41,3 +43,5 @@ void pyexec_event_repl_init(void);
 int pyexec_event_repl_process_char(int c);
 
 MP_DECLARE_CONST_FUN_OBJ(pyb_set_repl_info_obj);
+
+#endif // __MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H__
diff --git a/minimal/main.c b/minimal/main.c
index dc34d89bc0b44ebdd11943ef33b4d7d112d6b244..cb3b6250855e57e456b86ec288bd41ee1cba950d 100644
--- a/minimal/main.c
+++ b/minimal/main.c
@@ -7,7 +7,7 @@
 #include "py/runtime.h"
 #include "py/repl.h"
 #include "py/gc.h"
-#include "pyexec.h"
+#include "lib/utils/pyexec.h"
 
 void do_str(const char *src, mp_parse_input_kind_t input_kind) {
     mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
diff --git a/pic16bit/main.c b/pic16bit/main.c
index ad6f9e3644051fa3db4810c183aac192a41aa656..b8e9b46ead0117664b4881955f1a4937974f7b11 100644
--- a/pic16bit/main.c
+++ b/pic16bit/main.c
@@ -33,7 +33,7 @@
 #include "py/runtime.h"
 #include "py/gc.h"
 #include "py/mphal.h"
-#include "pyexec.h"
+#include "lib/utils/pyexec.h"
 #include "readline.h"
 #include "board.h"
 #include "modpyb.h"
diff --git a/stmhal/main.c b/stmhal/main.c
index de52cac8fe49ca776448cbfece8e8acd8432197e..f6d6ada703e8d1ccde40ee9e93dc2de50ba3ad06 100644
--- a/stmhal/main.c
+++ b/stmhal/main.c
@@ -36,13 +36,13 @@
 #include "py/gc.h"
 #include "py/mphal.h"
 
+#include "lib/utils/pyexec.h"
 #include "lib/fatfs/ff.h"
 
 #include "systick.h"
 #include "pendsv.h"
 #include "gccollect.h"
 #include "readline.h"
-#include "pyexec.h"
 #include "i2c.h"
 #include "spi.h"
 #include "uart.h"
diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c
index b7df53f674904cc3b964316d844b9f128f953d4e..e8dcd57a0f75a2fccdd8b2bd7816a7be1f670506 100644
--- a/stmhal/modpyb.c
+++ b/stmhal/modpyb.c
@@ -33,12 +33,12 @@
 #include "py/nlr.h"
 #include "py/obj.h"
 #include "py/gc.h"
+#include "lib/utils/pyexec.h"
 #include "lib/fatfs/ff.h"
 #include "lib/fatfs/diskio.h"
 #include "gccollect.h"
 #include "irq.h"
 #include "systick.h"
-#include "pyexec.h"
 #include "led.h"
 #include "pin.h"
 #include "timer.h"
diff --git a/teensy/main.c b/teensy/main.c
index 417bde78bedb00c647832c673167840917d4800f..ac73259095172fc6d299c37aa916e333153cfda4 100644
--- a/teensy/main.c
+++ b/teensy/main.c
@@ -11,7 +11,7 @@
 #include "py/gc.h"
 #include "py/mphal.h"
 #include "gccollect.h"
-#include "pyexec.h"
+#include "lib/utils/pyexec.h"
 #include "readline.h"
 #include "lexermemzip.h"
 
diff --git a/teensy/modpyb.c b/teensy/modpyb.c
index 8429191af9048699fde74e19b1ad76347f2de9fd..aa62f78703ac989771cc32070ecb5b24dfbf820d 100644
--- a/teensy/modpyb.c
+++ b/teensy/modpyb.c
@@ -33,10 +33,11 @@
 #include "py/gc.h"
 #include "py/mphal.h"
 
+#include "lib/utils/pyexec.h"
+
 #include "gccollect.h"
 #include "irq.h"
 #include "systick.h"
-#include "pyexec.h"
 #include "led.h"
 #include "pin.h"
 #include "timer.h"