From fa2c7a694fbe76dfedf58935d9582afcfba2caa1 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Fri, 9 Jun 2017 15:09:03 -0600 Subject: [PATCH] stm32f103-minimum: Fix a small BUG when reading from output pin. We need a different read_ops to read from output pin. This patch fixes the issue: nsh> gpio -o 0 /dev/gpout1 Driver: /dev/gpout1 Output pin: Value=1 Writing: Value=0 Verify: Value=1 Now: nsh> gpio -o 0 /dev/gpout1 Driver: /dev/gpout1 Output pin: Value=1 Writing: Value=0 Verify: Value=0 --- configs/stm32f103-minimum/src/stm32_gpio.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/configs/stm32f103-minimum/src/stm32_gpio.c b/configs/stm32f103-minimum/src/stm32_gpio.c index 6335acc4a3..854b84a793 100644 --- a/configs/stm32f103-minimum/src/stm32_gpio.c +++ b/configs/stm32f103-minimum/src/stm32_gpio.c @@ -67,7 +67,6 @@ struct stm32gpio_dev_s { struct gpio_dev_s gpio; uint8_t id; - bool value; }; struct stm32gpint_dev_s @@ -81,6 +80,7 @@ struct stm32gpint_dev_s ****************************************************************************/ static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value); +static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value); static int gpout_write(FAR struct gpio_dev_s *dev, bool value); static int gpint_attach(FAR struct gpio_dev_s *dev, pin_interrupt_t callback); @@ -100,7 +100,7 @@ static const struct gpio_operations_s gpin_ops = static const struct gpio_operations_s gpout_ops = { - .go_read = gpin_read, + .go_read = gpout_read, .go_write = gpout_write, .go_attach = NULL, .go_enable = NULL, @@ -167,17 +167,31 @@ static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value) FAR struct stm32gpio_dev_s *stm32gpio = (FAR struct stm32gpio_dev_s *)dev; DEBUGASSERT(stm32gpio != NULL && value != NULL); + DEBUGASSERT(stm32gpio->id < BOARD_NGPIOIN); gpioinfo("Reading...\n"); *value = stm32_gpioread(g_gpioinputs[stm32gpio->id]); return OK; } +static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value) +{ + FAR struct stm32gpio_dev_s *stm32gpio = (FAR struct stm32gpio_dev_s *)dev; + + DEBUGASSERT(stm32gpio != NULL && value != NULL); + DEBUGASSERT(stm32gpio->id < BOARD_NGPIOOUT); + gpioinfo("Reading...\n"); + + *value = stm32_gpioread(g_gpiooutputs[stm32gpio->id]); + return OK; +} + static int gpout_write(FAR struct gpio_dev_s *dev, bool value) { FAR struct stm32gpio_dev_s *stm32gpio = (FAR struct stm32gpio_dev_s *)dev; DEBUGASSERT(stm32gpio != NULL); + DEBUGASSERT(stm32gpio->id < BOARD_NGPIOOUT); gpioinfo("Writing %d\n", (int)value); stm32_gpiowrite(g_gpiooutputs[stm32gpio->id], value);