From 731f359292c0e2630873df1a19c5baac7287024f Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Fri, 30 Oct 2015 23:03:58 +0000
Subject: [PATCH] all: Add py/mphal.h and use it in all ports.

py/mphal.h contains declarations for generic mp_hal_XXX functions, such
as stdio and delay/ticks, which ports should provide definitions for.  A
port will also provide mphalport.h with further HAL declarations.
---
 bare-arm/mphalport.h                     |  1 +
 cc3200/bootmgr/main.c                    |  1 -
 cc3200/fatfs/src/drivers/sd_diskio.c     |  2 +-
 cc3200/fatfs/src/drivers/sflash_diskio.c |  1 -
 cc3200/ftp/ftp.c                         |  1 -
 cc3200/ftp/updater.c                     |  1 -
 cc3200/hal/cc3200_hal.c                  | 10 ++--
 cc3200/hal/cc3200_hal.h                  |  7 ---
 cc3200/main.c                            |  2 +-
 cc3200/misc/FreeRTOSHooks.c              |  2 +-
 cc3200/misc/mperror.c                    |  2 +-
 cc3200/misc/mpirq.c                      |  1 -
 cc3200/misc/mpsystick.c                  |  2 +-
 cc3200/mods/modmachine.c                 |  2 +-
 cc3200/mods/modnetwork.c                 |  2 +-
 cc3200/mods/modubinascii.c               |  1 -
 cc3200/mods/modusocket.c                 |  1 -
 cc3200/mods/modussl.c                    |  1 -
 cc3200/mods/modutime.c                   |  2 +-
 cc3200/mods/modwipy.c                    |  1 -
 cc3200/mods/modwlan.c                    |  2 +-
 cc3200/mods/pybadc.c                     |  1 -
 cc3200/mods/pybi2c.c                     |  2 +-
 cc3200/mods/pybpin.c                     |  1 -
 cc3200/mods/pybrtc.c                     |  1 -
 cc3200/mods/pybsd.c                      |  1 -
 cc3200/mods/pybsleep.c                   |  2 +-
 cc3200/mods/pybspi.c                     |  1 -
 cc3200/mods/pybtimer.c                   |  2 +-
 cc3200/mods/pybuart.c                    |  2 +-
 cc3200/mods/pybwdt.c                     |  2 +-
 cc3200/mpconfigport.h                    |  3 +-
 cc3200/mptask.c                          |  2 +-
 cc3200/serverstask.c                     |  2 +-
 cc3200/telnet/telnet.c                   |  2 +-
 cc3200/util/gccollect.c                  |  1 -
 esp8266/esp_mphal.h                      |  6 ---
 esp8266/main.c                           |  2 +-
 esp8266/modesp.c                         |  1 -
 esp8266/modpyb.c                         |  2 +-
 esp8266/modpybadc.c                      |  1 -
 esp8266/modpybrtc.c                      |  1 -
 esp8266/modutime.c                       |  2 +-
 esp8266/mpconfigport.h                   |  3 +-
 lib/mp-readline/readline.c               |  4 +-
 minimal/mpconfigport.h                   |  9 ----
 minimal/mphalport.h                      |  2 +
 minimal/uart_extra.c                     |  1 +
 pic16bit/main.c                          |  4 +-
 pic16bit/modpyb.c                        |  8 ++--
 pic16bit/mpconfigport.h                  |  3 +-
 pic16bit/pic16bit_mphal.c                | 10 ++--
 pic16bit/pic16bit_mphal.h                |  9 ----
 py/mphal.h                               | 61 ++++++++++++++++++++++++
 py/mpprint.c                             |  1 +
 qemu-arm/mphalport.h                     |  1 +
 stmhal/Makefile                          |  2 +-
 stmhal/adc.c                             |  3 +-
 stmhal/boards/stm32f4xx_prefix.c         |  2 +-
 stmhal/can.c                             |  2 +-
 stmhal/extint.c                          |  2 +-
 stmhal/i2c.c                             |  2 +-
 stmhal/irq.c                             |  3 +-
 stmhal/led.c                             |  3 +-
 stmhal/main.c                            |  2 +-
 stmhal/modmachine.c                      |  2 +-
 stmhal/modnwwiznet5k.c                   |  2 +-
 stmhal/moduselect.c                      |  2 +-
 stmhal/mpconfigport.h                    |  2 -
 stmhal/{mphal.c => mphalport.c}          |  6 +--
 stmhal/{mphal.h => mphalport.h}          |  9 +---
 stmhal/pin.c                             |  2 +-
 stmhal/pin_defs_stmhal.c                 |  1 -
 stmhal/pin_named_pins.c                  |  2 +-
 stmhal/printf.c                          |  4 +-
 stmhal/pybstdio.c                        |  2 +-
 stmhal/pyexec.c                          |  4 +-
 stmhal/spi.c                             |  2 +-
 stmhal/stm32_it.c                        |  2 +-
 stmhal/timer.c                           |  1 -
 stmhal/uart.c                            |  2 +-
 stmhal/usbd_desc.c                       |  2 +-
 stmhal/usrsw.c                           |  2 +-
 teensy/led.c                             |  2 +-
 teensy/main.c                            |  2 +-
 teensy/modpyb.c                          |  3 +-
 teensy/mpconfigport.h                    |  3 +-
 teensy/pin_defs_teensy.c                 |  2 +-
 teensy/teensy_hal.c                      | 10 ++--
 teensy/teensy_hal.h                      |  7 ---
 teensy/timer.c                           |  2 +-
 teensy/uart.c                            |  1 -
 unix/input.c                             |  2 +-
 unix/main.c                              |  2 +-
 unix/mpconfigport.h                      |  2 +-
 unix/unix_mphal.c                        |  4 +-
 unix/unix_mphal.h                        |  8 +---
 windows/mpconfigport.h                   |  2 +-
 windows/windows_mphal.c                  |  6 +--
 windows/windows_mphal.h                  |  1 +
 100 files changed, 156 insertions(+), 174 deletions(-)
 create mode 100644 bare-arm/mphalport.h
 create mode 100644 minimal/mphalport.h
 create mode 100644 py/mphal.h
 create mode 100644 qemu-arm/mphalport.h
 rename stmhal/{mphal.c => mphalport.c} (95%)
 rename stmhal/{mphal.h => mphalport.h} (79%)

diff --git a/bare-arm/mphalport.h b/bare-arm/mphalport.h
new file mode 100644
index 000000000..4bd8276f3
--- /dev/null
+++ b/bare-arm/mphalport.h
@@ -0,0 +1 @@
+// empty file
diff --git a/cc3200/bootmgr/main.c b/cc3200/bootmgr/main.c
index 1ec7d2950..d20cd5dad 100644
--- a/cc3200/bootmgr/main.c
+++ b/cc3200/bootmgr/main.c
@@ -30,7 +30,6 @@
 #include "std.h"
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "hw_ints.h"
 #include "hw_types.h"
 #include "hw_gpio.h"
diff --git a/cc3200/fatfs/src/drivers/sd_diskio.c b/cc3200/fatfs/src/drivers/sd_diskio.c
index cdc0cf0fe..a1fd72375 100644
--- a/cc3200/fatfs/src/drivers/sd_diskio.c
+++ b/cc3200/fatfs/src/drivers/sd_diskio.c
@@ -38,7 +38,7 @@
 #include <stdbool.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "hw_types.h"
 #include "hw_memmap.h"
 #include "hw_ints.h"
diff --git a/cc3200/fatfs/src/drivers/sflash_diskio.c b/cc3200/fatfs/src/drivers/sflash_diskio.c
index 5bb229694..d0cfe0f98 100644
--- a/cc3200/fatfs/src/drivers/sflash_diskio.c
+++ b/cc3200/fatfs/src/drivers/sflash_diskio.c
@@ -3,7 +3,6 @@
 #include "std.h"
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "simplelink.h"
 #include "diskio.h"
diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c
index dc21ebb48..252a3d756 100644
--- a/cc3200/ftp/ftp.c
+++ b/cc3200/ftp/ftp.c
@@ -29,7 +29,6 @@
 #include "std.h"
 
 #include "py/mpstate.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "inc/hw_types.h"
 #include "inc/hw_ints.h"
diff --git a/cc3200/ftp/updater.c b/cc3200/ftp/updater.c
index 2a2d47072..fece70095 100644
--- a/cc3200/ftp/updater.c
+++ b/cc3200/ftp/updater.c
@@ -28,7 +28,6 @@
 #include <stdbool.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "simplelink.h"
 #include "flc.h"
diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c
index e5ac4f088..f0987ae9d 100644
--- a/cc3200/hal/cc3200_hal.c
+++ b/cc3200/hal/cc3200_hal.c
@@ -34,7 +34,7 @@
 
 
 #include "py/mpstate.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "py/runtime.h"
 #include "py/objstr.h"
 #include "inc/hw_types.h"
@@ -104,11 +104,11 @@ void HAL_IncrementTick(void) {
     HAL_tickCount++;
 }
 
-uint32_t mp_hal_ticks_ms(void) {
+mp_uint_t mp_hal_ticks_ms(void) {
     return HAL_tickCount;
 }
 
-void mp_hal_delay_ms(uint32_t delay) {
+void mp_hal_delay_ms(mp_uint_t delay) {
     // only if we are not within interrupt context and interrupts are enabled
     if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0 && query_irq() == IRQ_STATE_ENABLED) {
         #ifdef USE_FREERTOS
@@ -140,7 +140,7 @@ void mp_hal_stdout_tx_str(const char *str) {
     mp_hal_stdout_tx_strn(str, strlen(str));
 }
 
-void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
+void mp_hal_stdout_tx_strn(const char *str, size_t len) {
     if (MP_STATE_PORT(os_term_dup_obj)) {
         if (MP_OBJ_IS_TYPE(MP_STATE_PORT(os_term_dup_obj)->stream_o, &pyb_uart_type)) {
             uart_tx_strn(MP_STATE_PORT(os_term_dup_obj)->stream_o, str, len);
@@ -153,7 +153,7 @@ void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
     telnet_tx_strn(str, len);
 }
 
-void mp_hal_stdout_tx_strn_cooked (const char *str, uint32_t len) {
+void mp_hal_stdout_tx_strn_cooked (const char *str, size_t len) {
     int32_t nslen = 0;
     const char *_str = str;
 
diff --git a/cc3200/hal/cc3200_hal.h b/cc3200/hal/cc3200_hal.h
index c0dc9ebef..054d5035a 100644
--- a/cc3200/hal/cc3200_hal.h
+++ b/cc3200/hal/cc3200_hal.h
@@ -62,14 +62,7 @@
 extern void HAL_SystemInit (void);
 extern void HAL_SystemDeInit (void);
 extern void HAL_IncrementTick(void);
-extern uint32_t mp_hal_ticks_ms(void);
-extern void mp_hal_delay_ms(uint32_t delay);
 extern NORETURN void mp_hal_raise(int errno);
 extern void mp_hal_set_interrupt_char (int c);
 
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, uint32_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
-
 #endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */
diff --git a/cc3200/main.c b/cc3200/main.c
index b217e20a1..78b4e3161 100644
--- a/cc3200/main.c
+++ b/cc3200/main.c
@@ -29,7 +29,7 @@
 #include <ctype.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "mptask.h"
 #include "simplelink.h"
 #include "pybwdt.h"
diff --git a/cc3200/misc/FreeRTOSHooks.c b/cc3200/misc/FreeRTOSHooks.c
index 24971453c..dac9a9282 100644
--- a/cc3200/misc/FreeRTOSHooks.c
+++ b/cc3200/misc/FreeRTOSHooks.c
@@ -29,7 +29,7 @@
 #include <string.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "py/obj.h"
 #include "inc/hw_memmap.h"
 #include "pybuart.h"
diff --git a/cc3200/misc/mperror.c b/cc3200/misc/mperror.c
index 5fa8442fd..044994b11 100644
--- a/cc3200/misc/mperror.c
+++ b/cc3200/misc/mperror.c
@@ -30,9 +30,9 @@
 #include <string.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "hw_ints.h"
 #include "hw_types.h"
 #include "hw_gpio.h"
diff --git a/cc3200/misc/mpirq.c b/cc3200/misc/mpirq.c
index e780c78b6..29cc4a7bd 100644
--- a/cc3200/misc/mpirq.c
+++ b/cc3200/misc/mpirq.c
@@ -27,7 +27,6 @@
 #include "std.h"
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/runtime.h"
 #include "py/gc.h"
diff --git a/cc3200/misc/mpsystick.c b/cc3200/misc/mpsystick.c
index 63b6c2d9d..7c35354e1 100644
--- a/cc3200/misc/mpsystick.c
+++ b/cc3200/misc/mpsystick.c
@@ -26,8 +26,8 @@
  */
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
+#include "py/mphal.h"
 #include "mpsystick.h"
 #include "systick.h"
 #include "inc/hw_types.h"
diff --git a/cc3200/mods/modmachine.c b/cc3200/mods/modmachine.c
index 2508c661c..896aa9917 100644
--- a/cc3200/mods/modmachine.c
+++ b/cc3200/mods/modmachine.c
@@ -30,7 +30,7 @@
 
 #include "py/mpstate.h"
 #include "py/runtime.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "irq.h"
 #include "inc/hw_types.h"
 #include "inc/hw_gpio.h"
diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c
index f8dbd9c53..b11b03638 100644
--- a/cc3200/mods/modnetwork.c
+++ b/cc3200/mods/modnetwork.c
@@ -28,10 +28,10 @@
 #include <std.h>
 
 #include "py/mpstate.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/nlr.h"
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "modnetwork.h"
 #include "mpexception.h"
 #include "serverstask.h"
diff --git a/cc3200/mods/modubinascii.c b/cc3200/mods/modubinascii.c
index 563c44aa6..add46f91b 100644
--- a/cc3200/mods/modubinascii.c
+++ b/cc3200/mods/modubinascii.c
@@ -26,7 +26,6 @@
  */
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/nlr.h"
 #include "py/runtime.h"
 #include "py/binary.h"
diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c
index 6b69e91ee..622a026c2 100644
--- a/cc3200/mods/modusocket.c
+++ b/cc3200/mods/modusocket.c
@@ -30,7 +30,6 @@
 
 #include "simplelink.h"
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/objstr.h"
 #include "py/runtime.h"
diff --git a/cc3200/mods/modussl.c b/cc3200/mods/modussl.c
index ce3067d96..4239c444b 100644
--- a/cc3200/mods/modussl.c
+++ b/cc3200/mods/modussl.c
@@ -29,7 +29,6 @@
 
 #include "simplelink.h"
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/objstr.h"
 #include "py/runtime.h"
diff --git a/cc3200/mods/modutime.c b/cc3200/mods/modutime.c
index 14ac10ad1..c669d32a5 100644
--- a/cc3200/mods/modutime.c
+++ b/cc3200/mods/modutime.c
@@ -29,10 +29,10 @@
 #include <string.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/nlr.h"
 #include "py/obj.h"
 #include "py/smallint.h"
+#include "py/mphal.h"
 #include "timeutils.h"
 #include "inc/hw_types.h"
 #include "inc/hw_ints.h"
diff --git a/cc3200/mods/modwipy.c b/cc3200/mods/modwipy.c
index 08c3f0029..2cfd640b0 100644
--- a/cc3200/mods/modwipy.c
+++ b/cc3200/mods/modwipy.c
@@ -1,5 +1,4 @@
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/runtime.h"
 #include "mperror.h"
diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c
index fb7a8a6fa..2997e8d38 100644
--- a/cc3200/mods/modwlan.c
+++ b/cc3200/mods/modwlan.c
@@ -30,10 +30,10 @@
 
 #include "simplelink.h"
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/objstr.h"
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "inc/hw_types.h"
 #include "inc/hw_ints.h"
 #include "inc/hw_memmap.h"
diff --git a/cc3200/mods/pybadc.c b/cc3200/mods/pybadc.c
index 2cb1cad08..005c36501 100644
--- a/cc3200/mods/pybadc.c
+++ b/cc3200/mods/pybadc.c
@@ -29,7 +29,6 @@
 #include <string.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/nlr.h"
 #include "py/runtime.h"
 #include "py/binary.h"
diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c
index e9c634310..52a0851f2 100644
--- a/cc3200/mods/pybi2c.c
+++ b/cc3200/mods/pybi2c.c
@@ -29,8 +29,8 @@
 #include <string.h>
 
 #include "py/mpstate.h"
-#include MICROPY_HAL_H
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "bufhelper.h"
 #include "inc/hw_types.h"
 #include "inc/hw_i2c.h"
diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c
index 4a2c313ed..ce0e386ff 100644
--- a/cc3200/mods/pybpin.c
+++ b/cc3200/mods/pybpin.c
@@ -30,7 +30,6 @@
 #include <string.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/runtime.h"
 #include "py/gc.h"
diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c
index ce5b12876..8d6b9b13e 100644
--- a/cc3200/mods/pybrtc.c
+++ b/cc3200/mods/pybrtc.c
@@ -28,7 +28,6 @@
 #include <std.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/runtime.h"
 #include "inc/hw_types.h"
diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c
index 74eaa42aa..ea81f30f8 100644
--- a/cc3200/mods/pybsd.c
+++ b/cc3200/mods/pybsd.c
@@ -25,7 +25,6 @@
  */
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/runtime.h"
 #include "inc/hw_types.h"
diff --git a/cc3200/mods/pybsleep.c b/cc3200/mods/pybsleep.c
index e3a9deeac..ced7fef85 100644
--- a/cc3200/mods/pybsleep.c
+++ b/cc3200/mods/pybsleep.c
@@ -28,8 +28,8 @@
 #include <string.h>
 
 #include "py/mpstate.h"
-#include MICROPY_HAL_H
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "inc/hw_types.h"
 #include "inc/hw_ints.h"
 #include "inc/hw_nvic.h"
diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c
index ed3abf588..b7e4310ae 100644
--- a/cc3200/mods/pybspi.c
+++ b/cc3200/mods/pybspi.c
@@ -29,7 +29,6 @@
 #include <string.h>
 
 #include "py/mpstate.h"
-#include MICROPY_HAL_H
 #include "py/runtime.h"
 #include "bufhelper.h"
 #include "inc/hw_types.h"
diff --git a/cc3200/mods/pybtimer.c b/cc3200/mods/pybtimer.c
index 089724b97..95eeb083c 100644
--- a/cc3200/mods/pybtimer.c
+++ b/cc3200/mods/pybtimer.c
@@ -30,11 +30,11 @@
 #include <string.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/nlr.h"
 #include "py/runtime.h"
 #include "py/gc.h"
+#include "py/mphal.h"
 #include "inc/hw_types.h"
 #include "inc/hw_ints.h"
 #include "inc/hw_memmap.h"
diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c
index f4c29d7e2..660453b75 100644
--- a/cc3200/mods/pybuart.c
+++ b/cc3200/mods/pybuart.c
@@ -31,11 +31,11 @@
 #include <string.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/runtime.h"
 #include "py/objlist.h"
 #include "py/stream.h"
+#include "py/mphal.h"
 #include "inc/hw_types.h"
 #include "inc/hw_ints.h"
 #include "inc/hw_memmap.h"
diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c
index 7619404d0..8448054ce 100644
--- a/cc3200/mods/pybwdt.c
+++ b/cc3200/mods/pybwdt.c
@@ -27,9 +27,9 @@
 #include <stdint.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "inc/hw_types.h"
 #include "inc/hw_gpio.h"
 #include "inc/hw_ints.h"
diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h
index 8584eaa03..8e6d1742c 100644
--- a/cc3200/mpconfigport.h
+++ b/cc3200/mpconfigport.h
@@ -180,7 +180,6 @@ typedef void            *machine_ptr_t;             // must be of pointer size
 typedef const void      *machine_const_ptr_t;       // must be of pointer size
 typedef long            mp_off_t;
 
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
 #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
 
 #define MICROPY_BEGIN_ATOMIC_SECTION()              disable_irq()
@@ -204,7 +203,7 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
 // Include board specific configuration
 #include "mpconfigboard.h"
 
-#define MICROPY_HAL_H                               "cc3200_hal.h"
+#define MICROPY_MPHALPORT_H                         "cc3200_hal.h"
 #define MICROPY_PORT_HAS_TELNET                     (1)
 #define MICROPY_PORT_HAS_FTP                        (1)
 #define MICROPY_PY_SYS_PLATFORM                     "WiPy"
diff --git a/cc3200/mptask.c b/cc3200/mptask.c
index ec904f833..7346ddaf2 100644
--- a/cc3200/mptask.c
+++ b/cc3200/mptask.c
@@ -28,10 +28,10 @@
 #include <stdint.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
 #include "py/runtime.h"
 #include "py/gc.h"
+#include "py/mphal.h"
 #include "inc/hw_memmap.h"
 #include "inc/hw_types.h"
 #include "inc/hw_ints.h"
diff --git a/cc3200/serverstask.c b/cc3200/serverstask.c
index e22f7f98f..355966420 100644
--- a/cc3200/serverstask.c
+++ b/cc3200/serverstask.c
@@ -28,9 +28,9 @@
 #include <string.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/misc.h"
 #include "py/nlr.h"
+#include "py/mphal.h"
 #include "serverstask.h"
 #include "simplelink.h"
 #include "debug.h"
diff --git a/cc3200/telnet/telnet.c b/cc3200/telnet/telnet.c
index 70e606886..6980ed51b 100644
--- a/cc3200/telnet/telnet.c
+++ b/cc3200/telnet/telnet.c
@@ -27,8 +27,8 @@
 #include <stdint.h>
 
 #include "py/mpconfig.h"
-#include MICROPY_HAL_H
 #include "py/obj.h"
+#include "py/mphal.h"
 #include "telnet.h"
 #include "simplelink.h"
 #include "modnetwork.h"
diff --git a/cc3200/util/gccollect.c b/cc3200/util/gccollect.c
index a1b0f802a..094ca73bc 100644
--- a/cc3200/util/gccollect.c
+++ b/cc3200/util/gccollect.c
@@ -32,7 +32,6 @@
 #include "py/gc.h"
 #include "gccollect.h"
 #include "gchelper.h"
-#include MICROPY_HAL_H
 
 /******************************************************************************
 DECLARE PRIVATE DATA
diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h
index e3ba0c4fa..dc6a79f2b 100644
--- a/esp8266/esp_mphal.h
+++ b/esp8266/esp_mphal.h
@@ -32,13 +32,7 @@ void ets_isr_mask(unsigned);
 
 void mp_hal_init(void);
 void mp_hal_feed_watchdog(void);
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, uint32_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
 
-uint32_t mp_hal_ticks_ms(void);
-void mp_hal_delay_ms(uint32_t delay);
 void mp_hal_delay_us(uint32_t);
 void mp_hal_set_interrupt_char(int c);
 uint32_t mp_hal_get_cpu_freq(void);
diff --git a/esp8266/main.c b/esp8266/main.c
index 18fd2bd64..0d8b3723c 100644
--- a/esp8266/main.c
+++ b/esp8266/main.c
@@ -33,10 +33,10 @@
 #include "py/runtime.h"
 #include "py/stackctrl.h"
 #include "py/frozenmod.h"
+#include "py/mphal.h"
 #include "py/gc.h"
 #include "pyexec.h"
 #include "gccollect.h"
-#include MICROPY_HAL_H
 #include "user_interface.h"
 
 STATIC char heap[16384];
diff --git a/esp8266/modesp.c b/esp8266/modesp.c
index 5e7d5fb13..4e46b7ae1 100644
--- a/esp8266/modesp.c
+++ b/esp8266/modesp.c
@@ -32,7 +32,6 @@
 #include "py/obj.h"
 #include "py/gc.h"
 #include "py/runtime.h"
-#include MICROPY_HAL_H
 #include "netutils.h"
 #include "queue.h"
 #include "user_interface.h"
diff --git a/esp8266/modpyb.c b/esp8266/modpyb.c
index c5c24c07d..36a9d6bf2 100644
--- a/esp8266/modpyb.c
+++ b/esp8266/modpyb.c
@@ -29,9 +29,9 @@
 #include "py/nlr.h"
 #include "py/obj.h"
 #include "py/gc.h"
+#include "py/mphal.h"
 #include "gccollect.h"
 #include "pyexec.h"
-#include MICROPY_HAL_H
 #include "user_interface.h"
 #include "modpyb.h"
 
diff --git a/esp8266/modpybadc.c b/esp8266/modpybadc.c
index b4dfa6728..ade63dfb3 100644
--- a/esp8266/modpybadc.c
+++ b/esp8266/modpybadc.c
@@ -30,7 +30,6 @@
 #include "py/nlr.h"
 #include "py/obj.h"
 #include "py/runtime.h"
-#include MICROPY_HAL_H
 #include "user_interface.h"
 
 const mp_obj_type_t pyb_adc_type;
diff --git a/esp8266/modpybrtc.c b/esp8266/modpybrtc.c
index 260894881..1156216cc 100644
--- a/esp8266/modpybrtc.c
+++ b/esp8266/modpybrtc.c
@@ -30,7 +30,6 @@
 #include "py/nlr.h"
 #include "py/obj.h"
 #include "py/runtime.h"
-#include MICROPY_HAL_H
 #include "timeutils.h"
 #include "user_interface.h"
 #include "modpyb.h"
diff --git a/esp8266/modutime.c b/esp8266/modutime.c
index 241d3ccf7..5c55833c3 100644
--- a/esp8266/modutime.c
+++ b/esp8266/modutime.c
@@ -32,7 +32,7 @@
 #include "py/obj.h"
 #include "py/gc.h"
 #include "py/runtime.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "modpyb.h"
 #include "modpybrtc.h"
 #include "timeutils.h"
diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h
index 6635d260c..3cc2d9ad5 100644
--- a/esp8266/mpconfigport.h
+++ b/esp8266/mpconfigport.h
@@ -54,7 +54,6 @@ typedef void *machine_ptr_t; // must be of pointer size
 typedef const void *machine_const_ptr_t; // must be of pointer size
 typedef long mp_off_t;
 
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
 #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
 
 // extra built in names to add to the global namespace
@@ -94,7 +93,7 @@ extern const struct _mp_obj_module_t uos_module;
 
 // board specifics
 
-#define MICROPY_HAL_H "esp_mphal.h"
+#define MICROPY_MPHALPORT_H "esp_mphal.h"
 #define MICROPY_HW_BOARD_NAME "ESP module"
 #define MICROPY_HW_MCU_NAME "ESP8266"
 #define MICROPY_PY_SYS_PLATFORM "ESP8266"
diff --git a/lib/mp-readline/readline.c b/lib/mp-readline/readline.c
index 68e0e2474..b7c64aec3 100644
--- a/lib/mp-readline/readline.c
+++ b/lib/mp-readline/readline.c
@@ -30,10 +30,8 @@
 
 #include "py/mpstate.h"
 #include "py/repl.h"
+#include "py/mphal.h"
 #include "readline.h"
-#ifdef MICROPY_HAL_H
-#include MICROPY_HAL_H
-#endif
 
 #if 0 // print debugging info
 #define DEBUG_PRINT (1)
diff --git a/minimal/mpconfigport.h b/minimal/mpconfigport.h
index c585593f1..caa31d3bd 100644
--- a/minimal/mpconfigport.h
+++ b/minimal/mpconfigport.h
@@ -65,7 +65,6 @@ typedef void *machine_ptr_t; // must be of pointer size
 typedef const void *machine_const_ptr_t; // must be of pointer size
 typedef long mp_off_t;
 
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
 #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
 
 // extra built in names to add to the global namespace
@@ -76,14 +75,6 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
 // We need to provide a declaration/definition of alloca()
 #include <alloca.h>
 
-#define mp_hal_ticks_ms() 0
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
-
-static inline void mp_hal_set_interrupt_char(char c) {}
-
 #define MICROPY_HW_BOARD_NAME "minimal"
 #define MICROPY_HW_MCU_NAME "unknown-cpu"
 
diff --git a/minimal/mphalport.h b/minimal/mphalport.h
new file mode 100644
index 000000000..60d68bd2d
--- /dev/null
+++ b/minimal/mphalport.h
@@ -0,0 +1,2 @@
+static inline mp_uint_t mp_hal_ticks_ms(void) { return 0; }
+static inline void mp_hal_set_interrupt_char(char c) {}
diff --git a/minimal/uart_extra.c b/minimal/uart_extra.c
index e266904be..1c3fc2e03 100644
--- a/minimal/uart_extra.c
+++ b/minimal/uart_extra.c
@@ -1,6 +1,7 @@
 #include <string.h>
 #include <unistd.h>
 #include "py/mpconfig.h"
+#include "py/mphal.h"
 
 /*
  * Extra UART functions
diff --git a/pic16bit/main.c b/pic16bit/main.c
index 9b993fda9..ad6f9e364 100644
--- a/pic16bit/main.c
+++ b/pic16bit/main.c
@@ -32,9 +32,9 @@
 #include "py/compile.h"
 #include "py/runtime.h"
 #include "py/gc.h"
+#include "py/mphal.h"
 #include "pyexec.h"
 #include "readline.h"
-#include MICROPY_HAL_H
 #include "board.h"
 #include "modpyb.h"
 
@@ -59,7 +59,7 @@ soft_reset:
     led_state(1, 0);
     led_state(2, 0);
     led_state(3, 1);
-    mp_hal_milli_delay(150);
+    mp_hal_delay_ms(150);
     led_state(3, 0);
 
     // init MicroPython runtime
diff --git a/pic16bit/modpyb.c b/pic16bit/modpyb.c
index f632d9443..f59163a69 100644
--- a/pic16bit/modpyb.c
+++ b/pic16bit/modpyb.c
@@ -27,17 +27,17 @@
 #include <stdio.h>
 
 #include "py/obj.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "modpyb.h"
 
 STATIC mp_obj_t pyb_millis(void) {
-    return MP_OBJ_NEW_SMALL_INT(mp_hal_get_milliseconds());
+    return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms());
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis);
 
 STATIC mp_obj_t pyb_elapsed_millis(mp_obj_t start) {
     uint32_t startMillis = mp_obj_get_int(start);
-    uint32_t currMillis = mp_hal_get_milliseconds();
+    uint32_t currMillis = mp_hal_ticks_ms();
     return MP_OBJ_NEW_SMALL_INT((currMillis - startMillis) & 0x1fff);
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
@@ -45,7 +45,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
 STATIC mp_obj_t pyb_delay(mp_obj_t ms_in) {
     mp_int_t ms = mp_obj_get_int(ms_in);
     if (ms >= 0) {
-        mp_hal_milli_delay(ms);
+        mp_hal_delay_ms(ms);
     }
     return mp_const_none;
 }
diff --git a/pic16bit/mpconfigport.h b/pic16bit/mpconfigport.h
index d58401a90..e5cb666fc 100644
--- a/pic16bit/mpconfigport.h
+++ b/pic16bit/mpconfigport.h
@@ -86,7 +86,6 @@ typedef void *machine_ptr_t; // must be pointer size
 typedef const void *machine_const_ptr_t; // must be pointer size
 typedef int mp_off_t;
 
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
 #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
 
 // extra builtin names to add to the global namespace
@@ -108,6 +107,6 @@ extern const struct _mp_obj_module_t pyb_module;
     char *readline_hist[8]; \
     mp_obj_t keyboard_interrupt_obj; \
 
-#define MICROPY_HAL_H "pic16bit_mphal.h"
+#define MICROPY_MPHALPORT_H "pic16bit_mphal.h"
 #define MICROPY_HW_BOARD_NAME "dsPICSK"
 #define MICROPY_HW_MCU_NAME "dsPIC33"
diff --git a/pic16bit/pic16bit_mphal.c b/pic16bit/pic16bit_mphal.c
index dccea7659..557b1e0da 100644
--- a/pic16bit/pic16bit_mphal.c
+++ b/pic16bit/pic16bit_mphal.c
@@ -25,7 +25,7 @@
  */
 
 #include <string.h>
-#include "pic16bit_mphal.h"
+#include "py/mphal.h"
 #include "board.h"
 
 static int interrupt_char;
@@ -34,12 +34,12 @@ void mp_hal_init(void) {
     MP_STATE_PORT(keyboard_interrupt_obj) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
 }
 
-mp_uint_t mp_hal_get_milliseconds(void) {
+mp_uint_t mp_hal_ticks_ms(void) {
     // TODO
     return 0;
 }
 
-void mp_hal_milli_delay(mp_uint_t ms) {
+void mp_hal_delay_ms(mp_uint_t ms) {
     // tuned for fixed CPU frequency
     for (int i = ms; i > 0; i--) {
         for (volatile int j = 0; j < 5000; j++) {
@@ -63,13 +63,13 @@ void mp_hal_stdout_tx_str(const char *str) {
     mp_hal_stdout_tx_strn(str, strlen(str));
 }
 
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn(const char *str, size_t len) {
     for (; len > 0; --len) {
         uart_tx_char(*str++);
     }
 }
 
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
     for (; len > 0; --len) {
         if (*str == '\n') {
             uart_tx_char('\r');
diff --git a/pic16bit/pic16bit_mphal.h b/pic16bit/pic16bit_mphal.h
index 8dde61f7f..a858f7e0f 100644
--- a/pic16bit/pic16bit_mphal.h
+++ b/pic16bit/pic16bit_mphal.h
@@ -26,19 +26,10 @@
 #ifndef __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__
 #define __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__
 
-#define HAL_GetTick mp_hal_get_milliseconds
-
 #include "py/mpstate.h"
 
 void mp_hal_init(void);
 
-mp_uint_t mp_hal_get_milliseconds(void);
-void mp_hal_milli_delay(mp_uint_t ms);
-
 void mp_hal_set_interrupt_char(int c);
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
 
 #endif // __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__
diff --git a/py/mphal.h b/py/mphal.h
new file mode 100644
index 000000000..a0b642fc9
--- /dev/null
+++ b/py/mphal.h
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef __MICROPY_INCLUDED_PY_MPHAL_H__
+#define __MICROPY_INCLUDED_PY_MPHAL_H__
+
+#include "py/mpconfig.h"
+
+#ifdef MICROPY_MPHALPORT_H
+#include MICROPY_MPHALPORT_H
+#else
+#include <mphalport.h>
+#endif
+
+#ifndef mp_hal_stdin_rx_chr
+int mp_hal_stdin_rx_chr(void);
+#endif
+
+#ifndef mp_hal_stdout_tx_str
+void mp_hal_stdout_tx_str(const char *str);
+#endif
+
+#ifndef mp_hal_stdout_tx_strn
+void mp_hal_stdout_tx_strn(const char *str, size_t len);
+#endif
+
+#ifndef mp_hal_stdout_tx_strn_cooked
+void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len);
+#endif
+
+#ifndef mp_hal_delay_ms
+void mp_hal_delay_ms(mp_uint_t ms);
+#endif
+
+#ifndef mp_hal_ticks_ms
+mp_uint_t mp_hal_ticks_ms(void);
+#endif
+
+#endif // __MICROPY_INCLUDED_PY_MPHAL_H__
diff --git a/py/mpprint.c b/py/mpprint.c
index 6da6614b7..0aecf5c56 100644
--- a/py/mpprint.c
+++ b/py/mpprint.c
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include "py/mphal.h"
 #include "py/mpprint.h"
 #include "py/obj.h"
 #include "py/objint.h"
diff --git a/qemu-arm/mphalport.h b/qemu-arm/mphalport.h
new file mode 100644
index 000000000..4bd8276f3
--- /dev/null
+++ b/qemu-arm/mphalport.h
@@ -0,0 +1 @@
+// empty file
diff --git a/stmhal/Makefile b/stmhal/Makefile
index 222e19b32..8c0cd2175 100644
--- a/stmhal/Makefile
+++ b/stmhal/Makefile
@@ -113,7 +113,7 @@ SRC_C = \
 	usbd_desc.c \
 	usbd_cdc_interface.c \
 	usbd_msc_storage.c \
-	mphal.c \
+	mphalport.c \
 	irq.c \
 	pendsv.c \
 	systick.c  \
diff --git a/stmhal/adc.c b/stmhal/adc.c
index c70d88eaf..d8ce90cb3 100644
--- a/stmhal/adc.c
+++ b/stmhal/adc.c
@@ -25,16 +25,15 @@
  */
 
 #include <stdio.h>
-#include STM32_HAL_H
 #include <string.h>
 
 #include "py/nlr.h"
 #include "py/runtime.h"
 #include "py/binary.h"
+#include "py/mphal.h"
 #include "adc.h"
 #include "pin.h"
 #include "genhdr/pins.h"
-#include "mphal.h"
 #include "timer.h"
 
 /// \moduleref pyb
diff --git a/stmhal/boards/stm32f4xx_prefix.c b/stmhal/boards/stm32f4xx_prefix.c
index 529e0f0c3..f4ffdab68 100644
--- a/stmhal/boards/stm32f4xx_prefix.c
+++ b/stmhal/boards/stm32f4xx_prefix.c
@@ -3,8 +3,8 @@
 #include <stdio.h>
 
 #include "py/obj.h"
+#include "py/mphal.h"
 #include "pin.h"
-#include MICROPY_HAL_H
 
 #define AF(af_idx, af_fn, af_unit, af_type, af_ptr) \
 { \
diff --git a/stmhal/can.c b/stmhal/can.c
index 18fd31eeb..38ddf7448 100644
--- a/stmhal/can.c
+++ b/stmhal/can.c
@@ -33,10 +33,10 @@
 #include "py/objtuple.h"
 #include "py/runtime.h"
 #include "py/gc.h"
+#include "py/mphal.h"
 #include "bufhelper.h"
 #include "can.h"
 #include "pybioctl.h"
-#include MICROPY_HAL_H
 
 #if MICROPY_HW_ENABLE_CAN
 
diff --git a/stmhal/extint.c b/stmhal/extint.c
index ebd9d3e39..1fcf587db 100644
--- a/stmhal/extint.c
+++ b/stmhal/extint.c
@@ -31,7 +31,7 @@
 #include "py/nlr.h"
 #include "py/runtime.h"
 #include "py/gc.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "pin.h"
 #include "extint.h"
 
diff --git a/stmhal/i2c.c b/stmhal/i2c.c
index af37abf44..eb6716ce3 100644
--- a/stmhal/i2c.c
+++ b/stmhal/i2c.c
@@ -29,13 +29,13 @@
 
 #include "py/nlr.h"
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "irq.h"
 #include "pin.h"
 #include "genhdr/pins.h"
 #include "bufhelper.h"
 #include "dma.h"
 #include "i2c.h"
-#include MICROPY_HAL_H
 
 #if !defined(MICROPY_HW_I2C_BAUDRATE_DEFAULT)
 #define MICROPY_HW_I2C_BAUDRATE_DEFAULT 400000
diff --git a/stmhal/irq.c b/stmhal/irq.c
index 7a265a52b..749e4813c 100644
--- a/stmhal/irq.c
+++ b/stmhal/irq.c
@@ -26,10 +26,9 @@
 
 #include "py/nlr.h"
 #include "py/obj.h"
+#include "py/mphal.h"
 #include "irq.h"
 
-#include MICROPY_HAL_H
-
 /// \moduleref pyb
 
 /// \function wfi()
diff --git a/stmhal/led.c b/stmhal/led.c
index e3dbdb594..ca52931e3 100644
--- a/stmhal/led.c
+++ b/stmhal/led.c
@@ -25,15 +25,14 @@
  */
 
 #include <stdio.h>
-#include STM32_HAL_H
 
 #include "py/nlr.h"
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "timer.h"
 #include "led.h"
 #include "pin.h"
 #include "genhdr/pins.h"
-#include "mphal.h"
 
 #if defined(MICROPY_HW_LED1)
 
diff --git a/stmhal/main.c b/stmhal/main.c
index fe4b4c20c..de52cac8f 100644
--- a/stmhal/main.c
+++ b/stmhal/main.c
@@ -34,6 +34,7 @@
 #include "py/runtime.h"
 #include "py/stackctrl.h"
 #include "py/gc.h"
+#include "py/mphal.h"
 
 #include "lib/fatfs/ff.h"
 
@@ -60,7 +61,6 @@
 #include "dac.h"
 #include "can.h"
 #include "modnetwork.h"
-#include MICROPY_HAL_H
 
 void SystemClock_Config(void);
 
diff --git a/stmhal/modmachine.c b/stmhal/modmachine.c
index fa6a1f9dd..6a0c4a9fc 100644
--- a/stmhal/modmachine.c
+++ b/stmhal/modmachine.c
@@ -29,6 +29,7 @@
 #include "modmachine.h"
 #include "py/gc.h"
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "lib/fatfs/ff.h"
 #include "lib/fatfs/diskio.h"
 #include "gccollect.h"
@@ -38,7 +39,6 @@
 #include "pin.h"
 #include "timer.h"
 #include "usb.h"
-#include MICROPY_HAL_H
 
 // machine.info([dump_alloc_table])
 // Print out lots of information about the board.
diff --git a/stmhal/modnwwiznet5k.c b/stmhal/modnwwiznet5k.c
index 48d9be170..2feb9b953 100644
--- a/stmhal/modnwwiznet5k.c
+++ b/stmhal/modnwwiznet5k.c
@@ -32,12 +32,12 @@
 #include "py/nlr.h"
 #include "py/objlist.h"
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "netutils.h"
 #include "modnetwork.h"
 #include "pin.h"
 #include "genhdr/pins.h"
 #include "spi.h"
-#include MICROPY_HAL_H
 
 #include "ethernet/wizchip_conf.h"
 #include "ethernet/socket.h"
diff --git a/stmhal/moduselect.c b/stmhal/moduselect.c
index 0ba595488..232520ec4 100644
--- a/stmhal/moduselect.c
+++ b/stmhal/moduselect.c
@@ -30,8 +30,8 @@
 #include "py/nlr.h"
 #include "py/obj.h"
 #include "py/objlist.h"
+#include "py/mphal.h"
 #include "pybioctl.h"
-#include MICROPY_HAL_H
 
 /// \module select - Provides select function to wait for events on a stream
 ///
diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h
index 52032135c..3848daa8f 100644
--- a/stmhal/mpconfigport.h
+++ b/stmhal/mpconfigport.h
@@ -199,7 +199,6 @@ typedef void *machine_ptr_t; // must be of pointer size
 typedef const void *machine_const_ptr_t; // must be of pointer size
 typedef long mp_off_t;
 
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
 #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
 
 // We have inlined IRQ functions for efficiency (they are generally
@@ -242,7 +241,6 @@ static inline mp_uint_t disable_irq(void) {
 // We need to provide a declaration/definition of alloca()
 #include <alloca.h>
 
-#define MICROPY_HAL_H           "mphal.h"
 #define MICROPY_PIN_DEFS_PORT_H "pin_defs_stmhal.h"
 
 #endif // __INCLUDED_MPCONFIGPORT_H
diff --git a/stmhal/mphal.c b/stmhal/mphalport.c
similarity index 95%
rename from stmhal/mphal.c
rename to stmhal/mphalport.c
index 145ed8a1f..147a8682d 100644
--- a/stmhal/mphal.c
+++ b/stmhal/mphalport.c
@@ -2,9 +2,9 @@
 #include <string.h>
 
 #include "py/mpstate.h"
+#include "py/mphal.h"
 #include "usb.h"
 #include "uart.h"
-#include "mphal.h"
 
 // this table converts from HAL_StatusTypeDef to POSIX errno
 const byte mp_hal_status_to_errno_table[4] = {
@@ -48,7 +48,7 @@ void mp_hal_stdout_tx_str(const char *str) {
     mp_hal_stdout_tx_strn(str, strlen(str));
 }
 
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn(const char *str, size_t len) {
     if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
         uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
     }
@@ -60,7 +60,7 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
     }
 }
 
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
     // send stdout to UART and USB CDC VCP
     if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
         uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
diff --git a/stmhal/mphal.h b/stmhal/mphalport.h
similarity index 79%
rename from stmhal/mphal.h
rename to stmhal/mphalport.h
index bafee7b13..652f1e7be 100644
--- a/stmhal/mphal.h
+++ b/stmhal/mphalport.h
@@ -8,7 +8,7 @@
 #elif defined(MCU_SERIES_F7)
 #define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff0f420)
 #else
-#error mphal.h: Unrecognized MCU_SERIES
+#error mphalport.h: Unrecognized MCU_SERIES
 #endif
 
 // Basic GPIO functions
@@ -24,15 +24,10 @@
 
 void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio);
 
-extern const byte mp_hal_status_to_errno_table[4];
+extern const unsigned char mp_hal_status_to_errno_table[4];
 
 NORETURN void mp_hal_raise(HAL_StatusTypeDef status);
 void mp_hal_set_interrupt_char(int c); // -1 to disable
 
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
-
 #define mp_hal_delay_ms HAL_Delay
 #define mp_hal_ticks_ms HAL_GetTick
diff --git a/stmhal/pin.c b/stmhal/pin.c
index 3aba94975..a0f3994f7 100644
--- a/stmhal/pin.c
+++ b/stmhal/pin.c
@@ -30,7 +30,7 @@
 
 #include "py/nlr.h"
 #include "py/runtime.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "pin.h"
 
 /// \moduleref pyb
diff --git a/stmhal/pin_defs_stmhal.c b/stmhal/pin_defs_stmhal.c
index 6dfefb6bb..0aef5f95f 100644
--- a/stmhal/pin_defs_stmhal.c
+++ b/stmhal/pin_defs_stmhal.c
@@ -1,6 +1,5 @@
 #include "py/obj.h"
 #include "pin.h"
-#include MICROPY_HAL_H
 
 // Returns the pin mode. This value returned by this macro should be one of:
 // GPIO_MODE_INPUT, GPIO_MODE_OUTPUT_PP, GPIO_MODE_OUTPUT_OD,
diff --git a/stmhal/pin_named_pins.c b/stmhal/pin_named_pins.c
index d0cf8adc8..9e5f9593b 100644
--- a/stmhal/pin_named_pins.c
+++ b/stmhal/pin_named_pins.c
@@ -28,7 +28,7 @@
 #include <string.h>
 
 #include "py/runtime.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "pin.h"
 
 STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
diff --git a/stmhal/printf.c b/stmhal/printf.c
index 87cf4f0f9..611ad2df4 100644
--- a/stmhal/printf.c
+++ b/stmhal/printf.c
@@ -29,9 +29,7 @@
 #include <stdarg.h>
 
 #include "py/obj.h"
-#ifdef MICROPY_HAL_H
-#include MICROPY_HAL_H
-#endif
+#include "py/mphal.h"
 
 #if MICROPY_PY_BUILTINS_FLOAT
 #include "py/formatfloat.h"
diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c
index de0a3a0e3..72c164b36 100644
--- a/stmhal/pybstdio.c
+++ b/stmhal/pybstdio.c
@@ -30,7 +30,7 @@
 
 #include "py/obj.h"
 #include "py/stream.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 
 // TODO make stdin, stdout and stderr writable objects so they can
 // be changed by Python code.  This requires some changes, as these
diff --git a/stmhal/pyexec.c b/stmhal/pyexec.c
index f5de90422..116a41d35 100644
--- a/stmhal/pyexec.c
+++ b/stmhal/pyexec.c
@@ -33,9 +33,7 @@
 #include "py/runtime.h"
 #include "py/repl.h"
 #include "py/gc.h"
-#ifdef MICROPY_HAL_H
-#include MICROPY_HAL_H
-#endif
+#include "py/mphal.h"
 #if defined(USE_DEVICE_MODE)
 #include "irq.h"
 #include "usb.h"
diff --git a/stmhal/spi.c b/stmhal/spi.c
index 864463df2..7458da627 100644
--- a/stmhal/spi.c
+++ b/stmhal/spi.c
@@ -29,13 +29,13 @@
 
 #include "py/nlr.h"
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "irq.h"
 #include "pin.h"
 #include "genhdr/pins.h"
 #include "bufhelper.h"
 #include "dma.h"
 #include "spi.h"
-#include MICROPY_HAL_H
 
 // The following defines are for compatability with the '405
 #if !defined(MICROPY_HW_SPI1_NSS)
diff --git a/stmhal/stm32_it.c b/stmhal/stm32_it.c
index dfc33b7c2..1c510d35f 100644
--- a/stmhal/stm32_it.c
+++ b/stmhal/stm32_it.c
@@ -92,7 +92,7 @@ extern PCD_HandleTypeDef pcd_handle;
 
 #if REPORT_HARD_FAULT_REGS
 
-#include "mphal.h"
+#include "py/mphal.h"
 
 char *fmt_hex(uint32_t val, char *buf) {
     const char *hexDig = "0123456789abcdef";
diff --git a/stmhal/timer.c b/stmhal/timer.c
index f88229b8a..18c027cf3 100644
--- a/stmhal/timer.c
+++ b/stmhal/timer.c
@@ -35,7 +35,6 @@
 #include "py/nlr.h"
 #include "py/runtime.h"
 #include "py/gc.h"
-#include MICROPY_HAL_H
 #include "timer.h"
 #include "servo.h"
 #include "pin.h"
diff --git a/stmhal/uart.c b/stmhal/uart.c
index 177318aec..79c272bdb 100644
--- a/stmhal/uart.c
+++ b/stmhal/uart.c
@@ -32,9 +32,9 @@
 #include "py/nlr.h"
 #include "py/runtime.h"
 #include "py/stream.h"
+#include "py/mphal.h"
 #include "uart.h"
 #include "pybioctl.h"
-#include MICROPY_HAL_H
 
 //TODO: Add UART7/8 support for MCU_SERIES_F7
 
diff --git a/stmhal/usbd_desc.c b/stmhal/usbd_desc.c
index 32e4fd043..1ad960b46 100644
--- a/stmhal/usbd_desc.c
+++ b/stmhal/usbd_desc.c
@@ -35,7 +35,7 @@
 
 // need these headers just for MP_HAL_UNIQUE_ID_ADDRESS
 #include "py/misc.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 
 // So we don't clash with existing ST boards, we use the unofficial FOSS VID.
 // This needs a proper solution.
diff --git a/stmhal/usrsw.c b/stmhal/usrsw.c
index 225373ca8..69b0ca9ab 100644
--- a/stmhal/usrsw.c
+++ b/stmhal/usrsw.c
@@ -27,10 +27,10 @@
 #include <stdio.h>
 
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "extint.h"
 #include "pin.h"
 #include "genhdr/pins.h"
-#include "mphal.h"
 #include "usrsw.h"
 
 #if MICROPY_HW_HAS_SWITCH
diff --git a/teensy/led.c b/teensy/led.c
index 500900ffc..5798f537b 100644
--- a/teensy/led.c
+++ b/teensy/led.c
@@ -4,8 +4,8 @@
 
 #include "py/nlr.h"
 #include "py/runtime.h"
+#include "py/mphal.h"
 #include "led.h"
-#include MICROPY_HAL_H
 #include "pin.h"
 #include "genhdr/pins.h"
 
diff --git a/teensy/main.c b/teensy/main.c
index 4fa7aaab3..c31be6e01 100644
--- a/teensy/main.c
+++ b/teensy/main.c
@@ -9,13 +9,13 @@
 #include "py/runtime.h"
 #include "py/stackctrl.h"
 #include "py/gc.h"
+#include "py/mphal.h"
 #include "gccollect.h"
 #include "pyexec.h"
 #include "readline.h"
 #include "lexermemzip.h"
 
 #include "Arduino.h"
-#include MICROPY_HAL_H
 
 #include "servo.h"
 #include "led.h"
diff --git a/teensy/modpyb.c b/teensy/modpyb.c
index aded02263..8429191af 100644
--- a/teensy/modpyb.c
+++ b/teensy/modpyb.c
@@ -31,8 +31,7 @@
 
 #include "py/obj.h"
 #include "py/gc.h"
-
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 
 #include "gccollect.h"
 #include "irq.h"
diff --git a/teensy/mpconfigport.h b/teensy/mpconfigport.h
index d4bfd1cd3..4b2181cdb 100644
--- a/teensy/mpconfigport.h
+++ b/teensy/mpconfigport.h
@@ -66,7 +66,6 @@ typedef void *machine_ptr_t; // must be of pointer size
 typedef const void *machine_const_ptr_t; // must be of pointer size
 typedef long mp_off_t;
 
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
 #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
 
 // We have inlined IRQ functions for efficiency (they are generally
@@ -149,5 +148,5 @@ __attribute__(( always_inline )) static inline mp_uint_t disable_irq(void) {
 
 #define MICROPY_MATH_SQRT_ASM     (1)
 
-#define MICROPY_HAL_H           "teensy_hal.h"
+#define MICROPY_MPHALPORT_H     "teensy_hal.h"
 #define MICROPY_PIN_DEFS_PORT_H "pin_defs_teensy.h"
diff --git a/teensy/pin_defs_teensy.c b/teensy/pin_defs_teensy.c
index fd2476f7b..e7af1e969 100644
--- a/teensy/pin_defs_teensy.c
+++ b/teensy/pin_defs_teensy.c
@@ -1,7 +1,7 @@
 #include <stdint.h>
 #include <mk20dx128.h>
 #include "py/runtime.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "pin.h"
 
 // Returns the pin mode. This value returned by this macro should be one of:
diff --git a/teensy/teensy_hal.c b/teensy/teensy_hal.c
index 099848fb3..8996c27c9 100644
--- a/teensy/teensy_hal.c
+++ b/teensy/teensy_hal.c
@@ -2,16 +2,16 @@
 #include <string.h>
 
 #include "py/mpstate.h"
+#include "py/mphal.h"
 #include "usb.h"
 #include "uart.h"
 #include "Arduino.h"
-#include MICROPY_HAL_H
 
-uint32_t mp_hal_ticks_ms(void) {
+mp_uint_t mp_hal_ticks_ms(void) {
   return millis();
 }
 
-void mp_hal_delay_ms(uint32_t ms) {
+void mp_hal_delay_ms(mp_uint_t ms) {
   delay(ms);
 }
 
@@ -37,7 +37,7 @@ void mp_hal_stdout_tx_str(const char *str) {
     mp_hal_stdout_tx_strn(str, strlen(str));
 }
 
-void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
+void mp_hal_stdout_tx_strn(const char *str, size_t len) {
     if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
         uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
     }
@@ -46,7 +46,7 @@ void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
     }
 }
 
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len) {
+void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
     // send stdout to UART and USB CDC VCP
     if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
         uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
diff --git a/teensy/teensy_hal.h b/teensy/teensy_hal.h
index 24402ee84..b00b6e4ac 100644
--- a/teensy/teensy_hal.h
+++ b/teensy/teensy_hal.h
@@ -112,17 +112,10 @@ __attribute__(( always_inline )) static inline void __WFI(void) {
   __asm volatile ("wfi");
 }
 
-uint32_t mp_hal_ticks_ms(void);
-void mp_hal_delay_ms(uint32_t delay);
 void mp_hal_set_interrupt_char(int c);
 
 void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio);
 
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, uint32_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
-
 void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *init);
 
 #define GPIO_read_pin(gpio, pin)        (((gpio)->PDIR >> (pin)) & 1)
diff --git a/teensy/timer.c b/teensy/timer.c
index 5d6237d00..88583a09b 100644
--- a/teensy/timer.c
+++ b/teensy/timer.c
@@ -32,7 +32,7 @@
 #include "py/nlr.h"
 #include "py/runtime.h"
 #include "py/gc.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 #include "pin.h"
 #include "reg.h"
 #include "timer.h"
diff --git a/teensy/uart.c b/teensy/uart.c
index 1a04bb0d6..81035aed6 100644
--- a/teensy/uart.c
+++ b/teensy/uart.c
@@ -29,7 +29,6 @@
 
 #include "py/nlr.h"
 #include "py/runtime.h"
-#include MICROPY_HAL_H
 #include "bufhelper.h"
 #include "uart.h"
 
diff --git a/unix/input.c b/unix/input.c
index 9baa342b9..a38b63ae3 100644
--- a/unix/input.c
+++ b/unix/input.c
@@ -29,10 +29,10 @@
 #include <string.h>
 
 #include "py/mpstate.h"
+#include "py/mphal.h"
 #include "input.h"
 
 #if MICROPY_USE_READLINE == 1
-#include MICROPY_HAL_H
 #include "lib/mp-readline/readline.h"
 #elif MICROPY_USE_READLINE == 2
 #include <readline/readline.h>
diff --git a/unix/main.c b/unix/main.c
index eed7065bf..1dc54198e 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -44,8 +44,8 @@
 #include "py/repl.h"
 #include "py/gc.h"
 #include "py/stackctrl.h"
+#include "py/mphal.h"
 #include "genhdr/mpversion.h"
-#include MICROPY_HAL_H
 #include "input.h"
 
 // Command line options, with their defaults
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h
index 13cf1e87b..0e1fb6a40 100644
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -223,7 +223,7 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
     mp_obj_t keyboard_interrupt_obj; \
     void *mmap_region_head; \
 
-#define MICROPY_HAL_H "unix_mphal.h"
+#define MICROPY_MPHALPORT_H "unix_mphal.h"
 
 // We need to provide a declaration/definition of alloca()
 #ifdef __FreeBSD__
diff --git a/unix/unix_mphal.c b/unix/unix_mphal.c
index 54a710a3b..308349c60 100644
--- a/unix/unix_mphal.c
+++ b/unix/unix_mphal.c
@@ -30,7 +30,7 @@
 #include <sys/time.h>
 
 #include "py/mpstate.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
 
 #ifndef _WIN32
 #include <signal.h>
@@ -119,7 +119,7 @@ void mp_hal_stdout_tx_str(const char *str) {
     mp_hal_stdout_tx_strn(str, strlen(str));
 }
 
-uint32_t mp_hal_ticks_ms(void) {
+mp_uint_t mp_hal_ticks_ms(void) {
     struct timeval tv;
     gettimeofday(&tv, NULL);
     return tv.tv_sec * 1000 + tv.tv_usec / 1000;
diff --git a/unix/unix_mphal.h b/unix/unix_mphal.h
index 2e10d48a6..8961722db 100644
--- a/unix/unix_mphal.h
+++ b/unix/unix_mphal.h
@@ -33,10 +33,4 @@ void mp_hal_set_interrupt_char(char c);
 void mp_hal_stdio_mode_raw(void);
 void mp_hal_stdio_mode_orig(void);
 
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
-
-#define mp_hal_delay_ms(ms) usleep((ms) * 1000)
-uint32_t mp_hal_ticks_ms(void);
+static inline void mp_hal_delay_ms(mp_uint_t ms) { usleep((ms) * 1000); }
diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h
index ce5783c9c..01e066500 100644
--- a/windows/mpconfigport.h
+++ b/windows/mpconfigport.h
@@ -156,7 +156,7 @@ extern const struct _mp_obj_module_t mp_module_time;
 
 #define MP_STATE_PORT               MP_STATE_VM
 
-#define MICROPY_HAL_H               "windows_mphal.h"
+#define MICROPY_MPHALPORT_H         "windows_mphal.h"
 
 // We need to provide a declaration/definition of alloca()
 #include <malloc.h>
diff --git a/windows/windows_mphal.c b/windows/windows_mphal.c
index 2a803f108..702efa496 100644
--- a/windows/windows_mphal.c
+++ b/windows/windows_mphal.c
@@ -26,8 +26,8 @@
 
 
 #include "py/mpstate.h"
+#include "py/mphal.h"
 
-#include MICROPY_HAL_H
 #include <windows.h>
 #include <unistd.h>
 
@@ -170,11 +170,11 @@ int mp_hal_stdin_rx_chr(void) {
     }
 }
 
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn(const char *str, size_t len) {
     write(1, str, len);
 }
 
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
     mp_hal_stdout_tx_strn(str, len);
 }
 
diff --git a/windows/windows_mphal.h b/windows/windows_mphal.h
index 8173d93ec..c36889dcb 100644
--- a/windows/windows_mphal.h
+++ b/windows/windows_mphal.h
@@ -24,6 +24,7 @@
  * THE SOFTWARE.
  */
 
+#include "sleep.h"
 #include "unix/unix_mphal.h"
 
 #define MICROPY_HAL_HAS_VT100 (0)
-- 
GitLab