From 6472ce964dba986907ee4b1a0250c8e27658a492 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Fri, 21 Feb 2014 16:59:58 -0800 Subject: stm32: add analog GPIO configuration Allow to setup a GPIO pin in analog mode on STM32 chips. Signed-off-by: Vincent Palatin BRANCH=none BUG=none TEST=run comparators with GPIOs in analog mode on STM32L151 and STM32F072. Change-Id: Ie11dd8711e39ab191c96478c6d8c7b7e0dfa7ea4 Reviewed-on: https://chromium-review.googlesource.com/189863 Reviewed-by: Vic Yang Commit-Queue: Vincent Palatin Tested-by: Vincent Palatin --- chip/stm32/gpio-stm32f.c | 5 ++++- chip/stm32/gpio-stm32f0.c | 4 ++++ chip/stm32/gpio-stm32l.c | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/chip/stm32/gpio-stm32f.c b/chip/stm32/gpio-stm32f.c index 9e6c6799b6..e9f7944354 100644 --- a/chip/stm32/gpio-stm32f.c +++ b/chip/stm32/gpio-stm32f.c @@ -81,7 +81,10 @@ void gpio_set_flags_by_mask(uint32_t port, uint32_t pmask, uint32_t flags) * GPIOx_ODR determines which resistor to activate in * input mode, see Table 16 (datasheet rm0041) */ - if (flags & GPIO_PULL_UP) { + if (flags & GPIO_ANALOG) { + /* Analog input, MODE=00 CNF=00 */ + /* the 4 bits in mask are already reset above */ + } else if (flags & GPIO_PULL_UP) { mask |= 0x88888888 & cnf; STM32_GPIO_BSRR(port) = pmask; } else if (flags & GPIO_PULL_DOWN) { diff --git a/chip/stm32/gpio-stm32f0.c b/chip/stm32/gpio-stm32f0.c index 6933697c46..8e756ab183 100644 --- a/chip/stm32/gpio-stm32f0.c +++ b/chip/stm32/gpio-stm32f0.c @@ -67,6 +67,10 @@ void gpio_set_flags_by_mask(uint32_t port, uint32_t mask, uint32_t flags) val |= 0x55555555 & mask2; STM32_GPIO_MODER(port) = val; + } else if (flags & GPIO_ANALOG) { + /* Analog, MODE=11 */ + val |= 0xFFFFFFFF & mask2; + STM32_GPIO_MODER(port) = val; } else if (flags & GPIO_INPUT) { /* Input, MODE=00 */ STM32_GPIO_MODER(port) = val; diff --git a/chip/stm32/gpio-stm32l.c b/chip/stm32/gpio-stm32l.c index 7283526d89..ca627dd701 100644 --- a/chip/stm32/gpio-stm32l.c +++ b/chip/stm32/gpio-stm32l.c @@ -67,6 +67,10 @@ void gpio_set_flags_by_mask(uint32_t port, uint32_t mask, uint32_t flags) val |= 0x55555555 & mask2; STM32_GPIO_MODER(port) = val; + } else if (flags & GPIO_ANALOG) { + /* Analog, MODE=11 */ + val |= 0xFFFFFFFF & mask2; + STM32_GPIO_MODER(port) = val; } else if (flags & GPIO_INPUT) { /* Input, MODE=00 */ STM32_GPIO_MODER(port) = val; -- cgit v1.2.1