diff --git a/stmhal/Makefile b/stmhal/Makefile
index 4931ebf80c0c816272cb021680ec61a1602e3259..b1424a61ef24e428117695b91c3b4c3bd9033966 100644
--- a/stmhal/Makefile
+++ b/stmhal/Makefile
@@ -47,6 +47,7 @@ INC += -I../lib/timeutils
 CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
 CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_MOD) $(CFLAGS_CORTEX_M4) $(COPT)
 CFLAGS += -Iboards/$(BOARD)
+CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES)xx_hal.h>'
 
 LDFLAGS = -nostdlib -T $(LD_FILE) -Map=$(@:.elf=.map) --cref
 LIBS =
diff --git a/stmhal/accel.c b/stmhal/accel.c
index a61e8ef3eef9a2884eac4fd69b8b2da57294e04a..64ac852664db94f9376a86449f4a0f93f5720d42 100644
--- a/stmhal/accel.c
+++ b/stmhal/accel.c
@@ -27,7 +27,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 #include "py/nlr.h"
 #include "py/runtime.h"
diff --git a/stmhal/adc.c b/stmhal/adc.c
index 9ec8eac72594dc1e62592a9d7d8414aa0d1372e3..7431a356d56b5f6b16528e85bea0459a971712ab 100644
--- a/stmhal/adc.c
+++ b/stmhal/adc.c
@@ -25,7 +25,7 @@
  */
 
 #include <stdio.h>
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 #include <string.h>
 
 #include "py/nlr.h"
diff --git a/stmhal/dac.c b/stmhal/dac.c
index b1e688442a42fc1dc3bb9f105400adc023619ba0..178017e222f7a857b070c96126659ea15e9b5818 100644
--- a/stmhal/dac.c
+++ b/stmhal/dac.c
@@ -28,7 +28,7 @@
 #include <stdint.h>
 #include <string.h>
 
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 #include "py/nlr.h"
 #include "py/runtime.h"
diff --git a/stmhal/diskio.c b/stmhal/diskio.c
index abad2f41ab922e69db611631a138867ab02bc0fe..3fd83ec90d7be58f2ec4945e300f7d2dfc65012f 100644
--- a/stmhal/diskio.c
+++ b/stmhal/diskio.c
@@ -30,7 +30,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 #include "py/runtime.h"
 #include "lib/fatfs/ff.h"        /* FatFs lower layer API */
diff --git a/stmhal/dma.c b/stmhal/dma.c
index 77474b767611a03e4e616735987b08ce234b4c79..674e4a93724a610f1dd766faa29aabe21337c467 100644
--- a/stmhal/dma.c
+++ b/stmhal/dma.c
@@ -27,7 +27,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 
 #include "dma.h"
 
diff --git a/stmhal/flash.c b/stmhal/flash.c
index f576f927a2f1c8966b1b297e8c80e9c495f74b54..7eef9b979626ec1aa0b9088f16edb4720ad759b2 100644
--- a/stmhal/flash.c
+++ b/stmhal/flash.c
@@ -24,7 +24,7 @@
  * THE SOFTWARE.
  */
 
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 
 #include "flash.h"
 
diff --git a/stmhal/lcd.c b/stmhal/lcd.c
index f0f7ae90f2fa2082beab12d233ac98032d27539d..12d96e699635f8742905ec5a265d906bf167e161 100644
--- a/stmhal/lcd.c
+++ b/stmhal/lcd.c
@@ -26,7 +26,7 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 
 #include "py/nlr.h"
 #include "py/runtime.h"
diff --git a/stmhal/led.c b/stmhal/led.c
index 5c538eee188f6a8609440663f5aea558a181d3cf..11a2ec4317639f2d52b6a6830b6221b328b205df 100644
--- a/stmhal/led.c
+++ b/stmhal/led.c
@@ -25,7 +25,7 @@
  */
 
 #include <stdio.h>
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 
 #include "py/nlr.h"
 #include "py/runtime.h"
diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c
index 2c5c19903ecf626a12c28233ba316bfb7aecf8f5..2f2e0399645271b09594be4b3e84b718cfb99428 100644
--- a/stmhal/modpyb.c
+++ b/stmhal/modpyb.c
@@ -27,7 +27,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 #include "py/mpstate.h"
 #include "py/nlr.h"
diff --git a/stmhal/modstm.c b/stmhal/modstm.c
index b795d296b4e045800be7140fc9d2cbf742a9eb5a..cedc8948120a96d0e275937cd38ccc98a459a5d4 100644
--- a/stmhal/modstm.c
+++ b/stmhal/modstm.c
@@ -27,7 +27,7 @@
 #include <stdio.h>
 #include <stdint.h>
 
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 #include "py/nlr.h"
 #include "py/obj.h"
diff --git a/stmhal/modutime.c b/stmhal/modutime.c
index 75605a37c3cbd0c79d12411054cb6d8385917a91..72ed4d2518bf33047d0f3e89eab2ebbc1bb745dd 100644
--- a/stmhal/modutime.c
+++ b/stmhal/modutime.c
@@ -26,7 +26,7 @@
 
 #include <stdio.h>
 #include <string.h>
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 #include "py/nlr.h"
 #include "py/obj.h"
diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h
index 67efd091bfa9f7945eb920de378011088bea0b5e..0ed8c21893b8e8834bbb470fe0495fff19c8ca5d 100644
--- a/stmhal/mpconfigport.h
+++ b/stmhal/mpconfigport.h
@@ -200,7 +200,7 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
 // value from disable_irq back to enable_irq.  If you really need
 // to know the machine-specific values, see irq.h.
 
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 
 static inline void enable_irq(mp_uint_t state) {
     __set_PRIMASK(state);
diff --git a/stmhal/mphal.h b/stmhal/mphal.h
index b705facc4308b2ef8e218ba2c7c8e88cf97ffcda..e211cc02f31f560fc5155840b9156ad7c088c6a9 100644
--- a/stmhal/mphal.h
+++ b/stmhal/mphal.h
@@ -1,5 +1,5 @@
 // We use the ST Cube HAL library for most hardware peripherals
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 
 // Basic GPIO functions
 #define GPIO_read_pin(gpio, pin)        (((gpio)->IDR >> (pin)) & 1)
diff --git a/stmhal/pendsv.c b/stmhal/pendsv.c
index 5f5603f35be74925597ded8bea5d0b3df1ee63e0..f374e06fdf6b36aa0faae6a7e22d1e03cbc85698 100644
--- a/stmhal/pendsv.c
+++ b/stmhal/pendsv.c
@@ -25,7 +25,7 @@
  */
 
 #include <stdlib.h>
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 
 #include "py/mpstate.h"
 #include "py/runtime.h"
diff --git a/stmhal/rng.c b/stmhal/rng.c
index c2685ce2be92149758f1f65b99131cdc744e5980..2571bc3a01ffc40972451c2d5befbca264e3d690 100644
--- a/stmhal/rng.c
+++ b/stmhal/rng.c
@@ -26,7 +26,7 @@
 
 #include <string.h>
 
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 #include "py/obj.h"
 #include "rng.h"
diff --git a/stmhal/rtc.c b/stmhal/rtc.c
index 8b21c6ee507773f6e722085141d2c8f0dd3363d0..00821cabb3488b45e8fc75d06e874579ff186b57 100644
--- a/stmhal/rtc.c
+++ b/stmhal/rtc.c
@@ -26,7 +26,7 @@
 
 #include <stdio.h>
 
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 #include "py/runtime.h"
 #include "rtc.h"
diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c
index 0eac1615c8d148f3056964ab5f1a36511bedd8a3..2e98f73c1542862c3e7dffad2ce778e1c70b1edb 100644
--- a/stmhal/sdcard.c
+++ b/stmhal/sdcard.c
@@ -26,7 +26,7 @@
 
 // TODO make it work with DMA
 
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 
 #include "py/nlr.h"
 #include "py/runtime.h"
diff --git a/stmhal/servo.c b/stmhal/servo.c
index 4c4f95da4f58d4df1fa2816c5ebd4139709ec27a..7f5a09f7778a79908590a935945d432a7274c3d4 100644
--- a/stmhal/servo.c
+++ b/stmhal/servo.c
@@ -26,7 +26,7 @@
 
 #include <stdio.h>
 
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 #include "py/nlr.h"
 #include "py/runtime.h"
diff --git a/stmhal/stm32f4xx_it.c b/stmhal/stm32f4xx_it.c
index 26c914da6240fc167241bc59db9b1e7cccc119fa..7be5af30f64300d78d6c8ca255d56a71b23480be 100644
--- a/stmhal/stm32f4xx_it.c
+++ b/stmhal/stm32f4xx_it.c
@@ -68,7 +68,7 @@
 #include <stdio.h>
 
 #include "stm32f4xx_it.h"
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 #include "py/obj.h"
 #include "pendsv.h"
diff --git a/stmhal/storage.c b/stmhal/storage.c
index da3541c587664b4084bfa07657f96e44dc8de716..97dfc74b2becc8fe50fa59690243149ea53d0845 100644
--- a/stmhal/storage.c
+++ b/stmhal/storage.c
@@ -26,7 +26,7 @@
 
 #include <stdint.h>
 #include <string.h>
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 
 #include "py/obj.h"
 #include "systick.h"
diff --git a/stmhal/system_stm32f4xx.c b/stmhal/system_stm32f4xx.c
index 207fb528b638370d23b0122cfb102ea91c7a7807..f6dbf70db1aad98ff6b656848d66b3e5f31bcfd2 100644
--- a/stmhal/system_stm32f4xx.c
+++ b/stmhal/system_stm32f4xx.c
@@ -92,7 +92,7 @@
   */
 
 #include "mpconfigboard.h"
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 
 void __fatal_error(const char *msg);
 
diff --git a/stmhal/systick.c b/stmhal/systick.c
index 027e72a4143783f0ccf959c46f7650867e8d59ef..aed5b96901754ec9092025333f201bea0a54a3cf 100644
--- a/stmhal/systick.c
+++ b/stmhal/systick.c
@@ -24,7 +24,7 @@
  * THE SOFTWARE.
  */
 
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 
 #include "py/obj.h"
 #include "irq.h"
diff --git a/stmhal/timer.c b/stmhal/timer.c
index 002e6b4296f876237fbdf4b8de4ff426776e0325..f88229b8ace6a74c448f8d66eb496d7c1077ebc6 100644
--- a/stmhal/timer.c
+++ b/stmhal/timer.c
@@ -28,7 +28,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <stm32f4xx_hal.h>
+#include STM32_HAL_H
 #include "usbd_cdc_msc_hid.h"
 #include "usbd_cdc_interface.h"
 
diff --git a/stmhal/usbd_conf.c b/stmhal/usbd_conf.c
index c55db33c9610f3a8dea311517f321ae02670b855..600c17a41daea137a91fdfbdb20a8a2346a9f8d5 100644
--- a/stmhal/usbd_conf.c
+++ b/stmhal/usbd_conf.c
@@ -30,7 +30,7 @@
   */
 
 /* Includes ------------------------------------------------------------------*/
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 #include "usbd_core.h"
 
 /* Private typedef -----------------------------------------------------------*/
diff --git a/stmhal/usbd_conf.h b/stmhal/usbd_conf.h
index fc8015f318550bdc1fec41851f2f4ab71e7201c6..5415eb10b4944e51ad02e9a535dc0bb14e607b66 100644
--- a/stmhal/usbd_conf.h
+++ b/stmhal/usbd_conf.h
@@ -34,7 +34,7 @@
 #define __USBD_CONF_H
 
 /* Includes ------------------------------------------------------------------*/
-#include "stm32f4xx_hal.h"
+#include STM32_HAL_H
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>