From 3f22b633218264db80ac5dd1091f385ae726be55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Rei=C3=9Fnegger?= Date: Tue, 20 Sep 2016 13:24:39 -0700 Subject: [PATCH] SAM3/4: Fix GPIO pull-up/down code. Enabling the pull-down resistor while the pull-up resistor is still enabled is not possible. In this case, the write of PIO_PPDER for the relevant I/O line is discarded. Likewise, enabling the pull-up resistor while the pull-down resistor is still enabled is not possible. In this case, the write of PIO_PUER for the relevant I/O line is discarded. --- arch/arm/src/sam34/sam_gpio.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm/src/sam34/sam_gpio.c b/arch/arm/src/sam34/sam_gpio.c index 5fda366fe0..27a500f07c 100644 --- a/arch/arm/src/sam34/sam_gpio.c +++ b/arch/arm/src/sam34/sam_gpio.c @@ -190,6 +190,12 @@ static inline int sam_configinput(uintptr_t base, uint32_t pin, if ((cfgset & GPIO_CFG_PULLUP) != 0) { + /* The pull-up on a pin can not be enabled if its pull-down is still + * active. Therefore, we need to disable the pull-down first before + * enabling the pull-up. + */ + + putreg32(pin, base + SAM_PIO_PPDDR_OFFSET); putreg32(pin, base + SAM_PIO_PUER_OFFSET); } else @@ -202,6 +208,12 @@ static inline int sam_configinput(uintptr_t base, uint32_t pin, if ((cfgset & GPIO_CFG_PULLDOWN) != 0) { + /* The pull-down on a pin can not be enabled if its pull-up is still + * active. Therefore, we need to disable the pull-up first before + * enabling the pull-down. + */ + + putreg32(pin, base + SAM_PIO_PUDR_OFFSET); putreg32(pin, base + SAM_PIO_PPDER_OFFSET); } else