You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2018/08/15 10:56:47 UTC

[mynewt-core] branch master updated: Fixed stm32 AF macros and consolidated in single header file.

This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new c07fb4c  Fixed stm32 AF macros and consolidated in single header file.
c07fb4c is described below

commit c07fb4c1971449bac67594ccdfea8f4ac31c6ec0
Author: Markus Lampert <ma...@bibi.ca>
AuthorDate: Tue May 15 22:07:25 2018 -0700

    Fixed stm32 AF macros and consolidated in single header file.
---
 hw/mcu/stm/stm32_common/include/stm32_common/mcu.h | 113 +++++++++++++++++++++
 hw/mcu/stm/stm32_common/src/hal_gpio.c             |  38 ++-----
 hw/mcu/stm/stm32f1xx/include/mcu/mcu.h             |  15 +--
 hw/mcu/stm/stm32f3xx/include/mcu/mcu.h             |  51 +---------
 hw/mcu/stm/stm32f4xx/include/mcu/mcu.h             |  15 +--
 hw/mcu/stm/stm32f7xx/include/mcu/mcu.h             |  50 +--------
 hw/mcu/stm/stm32l1xx/include/mcu/mcu.h             |  15 +--
 hw/mcu/stm/stm32l4xx/include/mcu/mcu.h             |  15 +--
 8 files changed, 135 insertions(+), 177 deletions(-)

diff --git a/hw/mcu/stm/stm32_common/include/stm32_common/mcu.h b/hw/mcu/stm/stm32_common/include/stm32_common/mcu.h
new file mode 100644
index 0000000..52503a6
--- /dev/null
+++ b/hw/mcu/stm/stm32_common/include/stm32_common/mcu.h
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __MCU_STM_MCU_H_
+#define __MCU_STM_MCU_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Note that not all processors have support for all ports.
+ *
+ * GPIO pin mapping
+ *
+ * The stm32 processors have 16 gpio pins per port. The encoding of IO pins
+ * to logical pins has the pattern
+ *
+ *     pin = 0xA.PN
+ *
+ * where
+ *    A .... AF of the pin, see data sheet
+ *    . .... 0, reserved
+ *    P .... Port number GPIOA=0, GPIOB=1, GPIOC=2, ....
+ *    N .... Pin number within port
+ *
+ * A GPIO pin (general purpose IO) is a pin with the AF=0. For readability
+ * we provide macros for GPIO pin mappings and IO pins with enabled alternate
+ * function, called AFIO. There is no conceptual difference between them.
+ */
+
+/*
+ * Defines for naming GPIOs.
+ */
+#define MCU_GPIO_PORTA(pin)	((0 * 16) + (pin))
+#define MCU_GPIO_PORTB(pin)	((1 * 16) + (pin))
+#define MCU_GPIO_PORTC(pin)	((2 * 16) + (pin))
+#define MCU_GPIO_PORTD(pin)	((3 * 16) + (pin))
+#define MCU_GPIO_PORTE(pin)	((4 * 16) + (pin))
+#define MCU_GPIO_PORTF(pin)	((5 * 16) + (pin))
+#define MCU_GPIO_PORTG(pin)	((6 * 16) + (pin))
+#define MCU_GPIO_PORTH(pin)	((7 * 16) + (pin))
+#define MCU_GPIO_PORTI(pin)	((8 * 16) + (pin))
+#define MCU_GPIO_PORTJ(pin)	((9 * 16) + (pin))
+#define MCU_GPIO_PORTK(pin)	((10 * 16) + (pin))
+
+/*
+ * Helper macros to extract components from a pin descriptor.
+ */
+#define MCU_GPIO_PIN_NUM(pin)   (0x000F &  pin)
+#define MCU_GPIO_PIN_PORT(pin)  (0x000F & (pin >> 4))
+#define MCU_GPIO_PIN_PAD(pin)   (0x00FF &  pin)
+
+/*
+ * Use this value for pins that should not be used.
+ */
+#define MCU_GPIO_PIN_NONE       (0xFFFF)
+
+
+/*
+ * Mapping of a GPIO pin to an alternate function.
+ */
+#define MCU_AFIO_GPIO(pin,af)  (((0x0F & af) << 12) | (0x00FF & pin))
+
+/*
+ * Mapping of alternate function pin descriptors.
+ */
+#define MCU_AFIO_PORTA(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTA(pin), af)
+#define MCU_AFIO_PORTB(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTB(pin), af)
+#define MCU_AFIO_PORTC(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTC(pin), af)
+#define MCU_AFIO_PORTD(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTD(pin), af)
+#define MCU_AFIO_PORTE(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTE(pin), af)
+#define MCU_AFIO_PORTF(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTF(pin), af)
+#define MCU_AFIO_PORTG(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTG(pin), af)
+#define MCU_AFIO_PORTH(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTH(pin), af)
+#define MCU_AFIO_PORTI(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTI(pin), af)
+#define MCU_AFIO_PORTJ(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTJ(pin), af)
+#define MCU_AFIO_PORTK(pin, af)   MCU_AFIO_GPIO(MCU_GPIO_PORTK(pin), af)
+
+/*
+ * Helper macros to extract components from a pin descriptor.
+ */
+#define MCU_AFIO_PIN_NUM(pin)   MCU_GPIO_PIN_NUM(pin)
+#define MCU_AFIO_PIN_PORT(pin)  MCU_GPIO_PIN_PORT(pin)
+#define MCU_AFIO_PIN_PAD(pin)   MCU_GPIO_PIN_PAD(pin)
+#define MCU_AFIO_PIN_AF(pin)    (0x000F & (pin >> 12))
+
+/*
+ * Use this value for pins that should not be used.
+ */
+#define MCU_AFIO_PIN_NONE       (0xFFFF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MCU_STM_MCU_H_ */
diff --git a/hw/mcu/stm/stm32_common/src/hal_gpio.c b/hw/mcu/stm/stm32_common/src/hal_gpio.c
index cabead9..872122e 100644
--- a/hw/mcu/stm/stm32_common/src/hal_gpio.c
+++ b/hw/mcu/stm/stm32_common/src/hal_gpio.c
@@ -20,6 +20,7 @@
 #include "hal/hal_gpio.h"
 #include "mcu/cmsis_nvic.h"
 #include "mcu/stm32_hal.h"
+#include "stm32_common/mcu.h"
 #include <assert.h>
 
  /* XXX: Notes
@@ -43,26 +44,7 @@
  * 5) Possibly add access to HAL_GPIO_DeInit.
  */
 
-/*
- * GPIO pin mapping
- *
- * The stm32Fxxx processors have 16 gpio pins per port. We map the logical pin
- * numbers (from 0 to N) in the following manner:
- *      Port A: PA0-PA15 map to pins 0 - 15.
- *      Port B: PB0-PB15 map to pins 16 - 31.
- *      Port C: PC0-PC15 map to pins 32 - 47.
- *
- *      To convert a gpio to pin number, do the following:
- *          - Convert port label to its numeric value (A=0, B=1, C=2, etc).
- *          - Multiply by 16.
- *          - Add port pin number.
- *
- *      Ex: PD11 = (3 * 16) + 11 = 59.
- *          PA0 = (0 * 16) + 0 = 0
- */
-#define GPIO_INDEX(pin)     ((pin) & 0x0F)
-#define GPIO_PORT(pin)      (((pin) >> 4) & 0x0F)
-#define GPIO_MASK(pin)      (1 << GPIO_INDEX(pin))
+#define GPIO_MASK(pin)      (1 << MCU_GPIO_PIN_NUM(pin))
 
 #ifndef GPIOA
 #   define GPIOA    0
@@ -350,7 +332,7 @@ hal_gpio_pin_to_irq(int pin)
     int index;
     IRQn_Type irqn;
 
-    index = GPIO_INDEX(pin);
+    index = MCU_GPIO_PIN_NUM(pin);
     if (index <= 4) {
         irqn = EXTI0_IRQn + index;
     } else if (index <=  9) {
@@ -422,7 +404,7 @@ hal_gpio_init_stm(int pin, GPIO_InitTypeDef *cfg)
     uint32_t mcu_pin_mask;
 
     /* Is this a valid pin? */
-    port = GPIO_PORT(pin);
+    port = MCU_GPIO_PIN_PORT(pin);
     if (port >= HAL_GPIO_PORT_COUNT) {
         return -1;
     }
@@ -456,7 +438,7 @@ hal_gpio_deinit_stm(int pin, GPIO_InitTypeDef *cfg)
     uint32_t mcu_pin_mask;
 
     /* Is this a valid pin? */
-    port = GPIO_PORT(pin);
+    port = MCU_GPIO_PIN_PORT(pin);
     if (port >= HAL_GPIO_PORT_COUNT) {
         return -1;
     }
@@ -510,7 +492,7 @@ int hal_gpio_init_out(int pin, int val)
     int port;
 
     /* Is this a valid pin? */
-    port = GPIO_PORT(pin);
+    port = MCU_GPIO_PIN_PORT(pin);
     if (port >= HAL_GPIO_PORT_COUNT) {
         return -1;
     }
@@ -585,7 +567,7 @@ void hal_gpio_write(int pin, int val)
     uint32_t mcu_pin_mask;
     GPIO_PinState state;
 
-    port = GPIO_PORT(pin);
+    port = MCU_GPIO_PIN_PORT(pin);
     mcu_pin_mask = GPIO_MASK(pin);
 
     if (val) {
@@ -611,7 +593,7 @@ int hal_gpio_read(int pin)
     int port;
     uint32_t mcu_pin_mask;
 
-    port = GPIO_PORT(pin);
+    port = MCU_GPIO_PIN_PORT(pin);
     mcu_pin_mask = GPIO_MASK(pin);
     return HAL_GPIO_ReadPin(portmap[port], mcu_pin_mask);
 }
@@ -690,7 +672,7 @@ hal_gpio_irq_init(int pin, hal_gpio_irq_handler_t handler, void *arg,
         __HAL_GPIO_EXTI_CLEAR_FLAG(pin_mask);
 
         /* Set the gpio irq handler */
-        index = GPIO_INDEX(pin);
+        index = MCU_GPIO_PIN_NUM(pin);
         gpio_irq_handlers[index].isr = handler;
         gpio_irq_handlers[index].arg = arg;
 
@@ -732,7 +714,7 @@ hal_gpio_irq_release(int pin)
     __HAL_GPIO_EXTI_CLEAR_FLAG(pin_mask);
 
     /* Clear out the irq handler */
-    index = GPIO_INDEX(pin);
+    index = MCU_GPIO_PIN_NUM(pin);
     gpio_irq_handlers[index].arg = NULL;
     gpio_irq_handlers[index].isr = NULL;
 }
diff --git a/hw/mcu/stm/stm32f1xx/include/mcu/mcu.h b/hw/mcu/stm/stm32f1xx/include/mcu/mcu.h
index 0458b28..3f707ac 100644
--- a/hw/mcu/stm/stm32f1xx/include/mcu/mcu.h
+++ b/hw/mcu/stm/stm32f1xx/include/mcu/mcu.h
@@ -20,25 +20,14 @@
 #ifndef __MCU_MCU_H_
 #define __MCU_MCU_H_
 
+#include <stm32_common/mcu.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #define SVC_IRQ_NUMBER SVCall_IRQn
 
-/*
- * Defines for naming GPIOs.
- */
-#define MCU_GPIO_PORTA(pin)	((0 * 16) + (pin))
-#define MCU_GPIO_PORTB(pin)	((1 * 16) + (pin))
-#define MCU_GPIO_PORTC(pin)	((2 * 16) + (pin))
-#define MCU_GPIO_PORTD(pin)	((3 * 16) + (pin))
-#define MCU_GPIO_PORTE(pin)	((4 * 16) + (pin))
-#define MCU_GPIO_PORTF(pin)	((5 * 16) + (pin))
-#define MCU_GPIO_PORTG(pin)	((6 * 16) + (pin))
-#define MCU_GPIO_PORTH(pin)	((7 * 16) + (pin))
-#define MCU_GPIO_PORTI(pin)	((8 * 16) + (pin))
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32f3xx/include/mcu/mcu.h b/hw/mcu/stm/stm32f3xx/include/mcu/mcu.h
index bd5a29e..f68848c 100644
--- a/hw/mcu/stm/stm32f3xx/include/mcu/mcu.h
+++ b/hw/mcu/stm/stm32f3xx/include/mcu/mcu.h
@@ -20,59 +20,12 @@
 #ifndef __MCU_MCU_H_
 #define __MCU_MCU_H_
 
+#include <stm32_common/mcu.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-/*
- * Defines for naming GPIOs.
- */
-#define MCU_GPIO_PORTA(pin)	((0 * 16) + (pin))
-#define MCU_GPIO_PORTB(pin)	((1 * 16) + (pin))
-#define MCU_GPIO_PORTC(pin)	((2 * 16) + (pin))
-#define MCU_GPIO_PORTD(pin)	((3 * 16) + (pin))
-#define MCU_GPIO_PORTE(pin)	((4 * 16) + (pin))
-#define MCU_GPIO_PORTF(pin)	((5 * 16) + (pin))
-#define MCU_GPIO_PORTG(pin)	((6 * 16) + (pin))
-#define MCU_GPIO_PORTH(pin)	((7 * 16) + (pin))
-#define MCU_GPIO_PORTI(pin)	((8 * 16) + (pin))
-#define MCU_GPIO_PORTJ(pin)	((9 * 16) + (pin))
-/* NOTE: PORTK only have pins 0, 1, 3, 4, 5, 6, 7 available */
-#define MCU_GPIO_PORTK(pin)	((10 * 16) + (pin))
-
-/*
- * Mapping of a GPIO pin to an alternate function.
- */
-#define MCU_AFIO_GPIO(pin,af)  (((0x0F & af) << 12) | (0x00FF & pin))
-
-/*
- * Mapping of alternate function pin descriptors.
- */
-#define MCU_AFIO_PORTA(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTA(pin))
-#define MCU_AFIO_PORTB(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTB(pin))
-#define MCU_AFIO_PORTC(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTC(pin))
-#define MCU_AFIO_PORTD(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTD(pin))
-#define MCU_AFIO_PORTE(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTE(pin))
-#define MCU_AFIO_PORTF(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTF(pin))
-#define MCU_AFIO_PORTG(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTG(pin))
-#define MCU_AFIO_PORTH(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTH(pin))
-#define MCU_AFIO_PORTI(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTI(pin))
-#define MCU_AFIO_PORTJ(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTJ(pin))
-#define MCU_AFIO_PORTK(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTK(pin))
-
-/*
- * Helper macros to extract components from a pin descriptor.
- */
-#define MCU_AFIO_PIN_NUM(pin)    (0x000F & pin)
-#define MCU_AFIO_PIN_PORT(pin)  ((0x00F0 & pin) >> 4)
-#define MCU_AFIO_PIN_PAD(pin)    (0x00FF & pin)
-#define MCU_AFIO_PIN_AF(pin)    ((0xF000 & pin) >> 12)
-
-/*
- * Use this value for pins that should not be used.
- */
-#define MCU_AFIO_PIN_NONE       (0xFFFF)
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32f4xx/include/mcu/mcu.h b/hw/mcu/stm/stm32f4xx/include/mcu/mcu.h
index 8975146..f68848c 100644
--- a/hw/mcu/stm/stm32f4xx/include/mcu/mcu.h
+++ b/hw/mcu/stm/stm32f4xx/include/mcu/mcu.h
@@ -20,23 +20,12 @@
 #ifndef __MCU_MCU_H_
 #define __MCU_MCU_H_
 
+#include <stm32_common/mcu.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-/*
- * Defines for naming GPIOs.
- */
-#define MCU_GPIO_PORTA(pin)	((0 * 16) + (pin))
-#define MCU_GPIO_PORTB(pin)	((1 * 16) + (pin))
-#define MCU_GPIO_PORTC(pin)	((2 * 16) + (pin))
-#define MCU_GPIO_PORTD(pin)	((3 * 16) + (pin))
-#define MCU_GPIO_PORTE(pin)	((4 * 16) + (pin))
-#define MCU_GPIO_PORTF(pin)	((5 * 16) + (pin))
-#define MCU_GPIO_PORTG(pin)	((6 * 16) + (pin))
-#define MCU_GPIO_PORTH(pin)	((7 * 16) + (pin))
-#define MCU_GPIO_PORTI(pin)	((8 * 16) + (pin))
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32f7xx/include/mcu/mcu.h b/hw/mcu/stm/stm32f7xx/include/mcu/mcu.h
index bd5a29e..d844326 100644
--- a/hw/mcu/stm/stm32f7xx/include/mcu/mcu.h
+++ b/hw/mcu/stm/stm32f7xx/include/mcu/mcu.h
@@ -20,58 +20,12 @@
 #ifndef __MCU_MCU_H_
 #define __MCU_MCU_H_
 
+#include <stm32_common/mcu.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-/*
- * Defines for naming GPIOs.
- */
-#define MCU_GPIO_PORTA(pin)	((0 * 16) + (pin))
-#define MCU_GPIO_PORTB(pin)	((1 * 16) + (pin))
-#define MCU_GPIO_PORTC(pin)	((2 * 16) + (pin))
-#define MCU_GPIO_PORTD(pin)	((3 * 16) + (pin))
-#define MCU_GPIO_PORTE(pin)	((4 * 16) + (pin))
-#define MCU_GPIO_PORTF(pin)	((5 * 16) + (pin))
-#define MCU_GPIO_PORTG(pin)	((6 * 16) + (pin))
-#define MCU_GPIO_PORTH(pin)	((7 * 16) + (pin))
-#define MCU_GPIO_PORTI(pin)	((8 * 16) + (pin))
-#define MCU_GPIO_PORTJ(pin)	((9 * 16) + (pin))
-/* NOTE: PORTK only have pins 0, 1, 3, 4, 5, 6, 7 available */
-#define MCU_GPIO_PORTK(pin)	((10 * 16) + (pin))
-
-/*
- * Mapping of a GPIO pin to an alternate function.
- */
-#define MCU_AFIO_GPIO(pin,af)  (((0x0F & af) << 12) | (0x00FF & pin))
-
-/*
- * Mapping of alternate function pin descriptors.
- */
-#define MCU_AFIO_PORTA(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTA(pin))
-#define MCU_AFIO_PORTB(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTB(pin))
-#define MCU_AFIO_PORTC(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTC(pin))
-#define MCU_AFIO_PORTD(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTD(pin))
-#define MCU_AFIO_PORTE(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTE(pin))
-#define MCU_AFIO_PORTF(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTF(pin))
-#define MCU_AFIO_PORTG(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTG(pin))
-#define MCU_AFIO_PORTH(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTH(pin))
-#define MCU_AFIO_PORTI(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTI(pin))
-#define MCU_AFIO_PORTJ(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTJ(pin))
-#define MCU_AFIO_PORTK(pin, af)   MCU_AFIO_GPIO(af, MCU_GPIO_PORTK(pin))
-
-/*
- * Helper macros to extract components from a pin descriptor.
- */
-#define MCU_AFIO_PIN_NUM(pin)    (0x000F & pin)
-#define MCU_AFIO_PIN_PORT(pin)  ((0x00F0 & pin) >> 4)
-#define MCU_AFIO_PIN_PAD(pin)    (0x00FF & pin)
-#define MCU_AFIO_PIN_AF(pin)    ((0xF000 & pin) >> 12)
-
-/*
- * Use this value for pins that should not be used.
- */
-#define MCU_AFIO_PIN_NONE       (0xFFFF)
 
 #ifdef __cplusplus
 }
diff --git a/hw/mcu/stm/stm32l1xx/include/mcu/mcu.h b/hw/mcu/stm/stm32l1xx/include/mcu/mcu.h
index f468816..2ac5e96 100644
--- a/hw/mcu/stm/stm32l1xx/include/mcu/mcu.h
+++ b/hw/mcu/stm/stm32l1xx/include/mcu/mcu.h
@@ -20,25 +20,14 @@
 #ifndef __MCU_MCU_H_
 #define __MCU_MCU_H_
 
+#include <stm32_common/mcu.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #define SVC_IRQ_NUMBER SVC_IRQn
 
-/*
- * Defines for naming GPIOs.
- */
-#define MCU_GPIO_PORTA(pin)	((0 * 16) + (pin))
-#define MCU_GPIO_PORTB(pin)	((1 * 16) + (pin))
-#define MCU_GPIO_PORTC(pin)	((2 * 16) + (pin))
-#define MCU_GPIO_PORTD(pin)	((3 * 16) + (pin))
-#define MCU_GPIO_PORTE(pin)	((4 * 16) + (pin))
-#define MCU_GPIO_PORTF(pin)	((5 * 16) + (pin))
-#define MCU_GPIO_PORTG(pin)	((6 * 16) + (pin))
-#define MCU_GPIO_PORTH(pin)	((7 * 16) + (pin))
-#define MCU_GPIO_PORTI(pin)	((8 * 16) + (pin))
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32l4xx/include/mcu/mcu.h b/hw/mcu/stm/stm32l4xx/include/mcu/mcu.h
index f468816..2ac5e96 100644
--- a/hw/mcu/stm/stm32l4xx/include/mcu/mcu.h
+++ b/hw/mcu/stm/stm32l4xx/include/mcu/mcu.h
@@ -20,25 +20,14 @@
 #ifndef __MCU_MCU_H_
 #define __MCU_MCU_H_
 
+#include <stm32_common/mcu.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #define SVC_IRQ_NUMBER SVC_IRQn
 
-/*
- * Defines for naming GPIOs.
- */
-#define MCU_GPIO_PORTA(pin)	((0 * 16) + (pin))
-#define MCU_GPIO_PORTB(pin)	((1 * 16) + (pin))
-#define MCU_GPIO_PORTC(pin)	((2 * 16) + (pin))
-#define MCU_GPIO_PORTD(pin)	((3 * 16) + (pin))
-#define MCU_GPIO_PORTE(pin)	((4 * 16) + (pin))
-#define MCU_GPIO_PORTF(pin)	((5 * 16) + (pin))
-#define MCU_GPIO_PORTG(pin)	((6 * 16) + (pin))
-#define MCU_GPIO_PORTH(pin)	((7 * 16) + (pin))
-#define MCU_GPIO_PORTI(pin)	((8 * 16) + (pin))
-
 #ifdef __cplusplus
 }
 #endif