[HAL][STM32] Incorrect if check in pal_lld.c Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
thor.thau
Posts: 17
Joined: Thu Jul 07, 2016 12:37 pm
Has thanked: 2 times
Been thanked: 7 times

[HAL][STM32] Incorrect if check in pal_lld.c

Post by thor.thau »

It seems like an if check implemented in function _pal_lld_setgroupmode for STM32/LLD/GPIO version 2 and version 3 is incorrect. The if check can only become true when the input ioportmask_t mask equals 0x01.

ChibiOS: 16.1.6
SVN: branches/stable_16.1.x@10005

Code: Select all

diff --git a/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.c b/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.c
index b4545f094..dc1f1d71e 100644
--- a/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.c
+++ b/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.c
@@ -177,7 +177,7 @@ void _pal_lld_setgroupmode(ioportid_t port,
       port->OTYPER  = (port->OTYPER & ~m1) | otyper;
       port->OSPEEDR = (port->OSPEEDR & ~m2) | ospeedr;
       port->PUPDR   = (port->PUPDR & ~m2) | pupdr;
-      if (moder == PAL_STM32_MODE_ALTERNATE) {
+      if ((mode & PAL_STM32_MODE_MASK) == PAL_STM32_MODE_ALTERNATE) {
         /* If going in alternate mode then the alternate number is set
            before switching mode in order to avoid glitches.*/
         if (bit < 8)
diff --git a/os/hal/ports/STM32/LLD/GPIOv3/pal_lld.c b/os/hal/ports/STM32/LLD/GPIOv3/pal_lld.c
index b45f7fe15..11969863a 100644
--- a/os/hal/ports/STM32/LLD/GPIOv3/pal_lld.c
+++ b/os/hal/ports/STM32/LLD/GPIOv3/pal_lld.c
@@ -163,7 +163,7 @@ void _pal_lld_setgroupmode(ioportid_t port,
       port->ASCR    = (port->ASCR & ~m1) | ascr;
       port->OSPEEDR = (port->OSPEEDR & ~m2) | ospeedr;
       port->PUPDR   = (port->PUPDR & ~m2) | pupdr;
-       if (moder == PAL_STM32_MODE_ALTERNATE) {
+      if ((mode & PAL_STM32_MODE_MASK) == PAL_STM32_MODE_ALTERNATE) {
         /* If going in alternate mode then the alternate number is set
            before switching mode in order to avoid glitches.*/
         if (bit < 8)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [HAL][STM32] Incorrect if check in pal_lld.c

Post by Giovanni »

Thanks, it is probably worth an immediate 16.1.7 release.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [HAL][STM32] Incorrect if check in pal_lld.c

Post by Giovanni »

Hi,

Fixed as bug #813.

Giovanni
Post Reply