diff --git a/cpu/sam0_common/include/periph_cpu_common.h b/cpu/sam0_common/include/periph_cpu_common.h index 2f3203515b..927e7d6460 100644 --- a/cpu/sam0_common/include/periph_cpu_common.h +++ b/cpu/sam0_common/include/periph_cpu_common.h @@ -73,12 +73,18 @@ typedef uint32_t gpio_t; * @brief Macro for accessing GPIO pins * @{ */ -#ifdef CPU_FAM_SAML11 -#define GPIO_PIN(x, y) (((gpio_t)(&PORT_SEC->Group[x])) | y) -#elif defined(PORT_IOBUS) /* Use IOBUS access when available */ +#ifdef MODULE_PERIPH_GPIO_FAST_READ +#ifdef PORT_IOBUS_SEC +#define GPIO_PIN(x, y) (((gpio_t)(&PORT_IOBUS_SEC->Group[x])) | y) +#else /* Use IOBUS access when available */ #define GPIO_PIN(x, y) (((gpio_t)(&PORT_IOBUS->Group[x])) | y) +#endif /* PORT_IOBUS_SEC */ +#else +#ifdef PORT_SEC +#define GPIO_PIN(x, y) (((gpio_t)(&PORT_SEC->Group[x])) | y) #else #define GPIO_PIN(x, y) (((gpio_t)(&PORT->Group[x])) | y) +#endif /* PORT_IOBUS_SEC */ #endif /** diff --git a/cpu/sam0_common/periph/gpio.c b/cpu/sam0_common/periph/gpio.c index 2479fe6d76..ce453fcbd1 100644 --- a/cpu/sam0_common/periph/gpio.c +++ b/cpu/sam0_common/periph/gpio.c @@ -109,12 +109,17 @@ static inline PortGroup *_port_iobus(gpio_t pin) static inline PortGroup *_port(gpio_t pin) { -#ifdef PORT_IOBUS +#ifdef MODULE_PERIPH_GPIO_FAST_READ /* Shift the PortGroup address back from the IOBUS region to the peripheral * region */ +#ifdef PORT_IOBUS_SEC + return (PortGroup *)((uintptr_t)_port_iobus(pin) - + (uintptr_t)PORT_IOBUS_SEC + (uintptr_t)PORT_SEC); +#else return (PortGroup *)((uintptr_t)_port_iobus(pin) - (uintptr_t)PORT_IOBUS + (uintptr_t)PORT); +#endif /* PORT_IOBUS_SEC */ #else return _port_iobus(pin); #endif