From 50dd1c5725c2ebdc6c189950fc9aaaaefa68ee38 Mon Sep 17 00:00:00 2001 From: Michael Spieler Date: Wed, 16 Jul 2014 12:58:36 +0200 Subject: [PATCH] stm32: gpio_toggle: ensure correct state of non-toggled pins. --- lib/stm32/common/gpio_common_all.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/stm32/common/gpio_common_all.c b/lib/stm32/common/gpio_common_all.c index 38219280..f75491d9 100644 --- a/lib/stm32/common/gpio_common_all.c +++ b/lib/stm32/common/gpio_common_all.c @@ -77,7 +77,8 @@ uint16_t gpio_get(uint32_t gpioport, uint16_t gpios) /*---------------------------------------------------------------------------*/ /** @brief Toggle a Group of Pins -Toggle one or more pins of the given GPIO port. This is not an atomic operation. +Toggle one or more pins of the given GPIO port. The toggling is not atomic, but +the non-toggled pins are not affected. @param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id @param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id @@ -86,7 +87,8 @@ Toggle one or more pins of the given GPIO port. This is not an atomic operation. */ void gpio_toggle(uint32_t gpioport, uint16_t gpios) { - GPIO_ODR(gpioport) ^= gpios; + uint32_t port = GPIO_ODR(gpioport); + GPIO_BSRR(gpioport) = ((port & gpios) << 16) | (~port & gpios); } /*---------------------------------------------------------------------------*/