From f3b10eb073c06b2cd426ccc340d5fedb064d1cc6 Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Sun, 9 Apr 2017 11:06:21 -0600
Subject: [PATCH 01/12] net procfs: Some long lines were being generated that
 cause buffer-related problems and corrupted output

---
 net/procfs/netdev_statistics.c | 40 +++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c
index b2b83da801..f4927eab2f 100644
--- a/net/procfs/netdev_statistics.c
+++ b/net/procfs/netdev_statistics.c
@@ -62,7 +62,9 @@
 
 static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile);
 static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile);
-
+#ifdef CONFIG_NET_IPv6
+static int netprocfs_dripaddress(FAR struct netprocfs_file_s *netfile);
+#endif
 #ifdef CONFIG_NETDEV_STATISTICS
 static int netprocfs_rxstatistics_header(FAR struct netprocfs_file_s *netfile);
 static int netprocfs_rxstatistics(FAR struct netprocfs_file_s *netfile);
@@ -83,6 +85,9 @@ static const linegen_t g_linegen[] =
 {
   netprocfs_linklayer,
   netprocfs_ipaddresses
+#ifdef CONFIG_NET_IPv6
+  , netprocfs_dripaddress
+#endif
 #ifdef CONFIG_NETDEV_STATISTICS
   , netprocfs_rxstatistics_header,
   netprocfs_rxstatistics,
@@ -292,7 +297,7 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile)
 
   addr.s_addr = dev->d_netmask;
   len += snprintf(&netfile->line[len], NET_LINELEN - len,
-                  "Mask:%s\n", inet_ntoa(addr));
+                  "Mask:%s\n\n", inet_ntoa(addr));
 #endif
 
 #ifdef CONFIG_NET_IPv6
@@ -307,19 +312,42 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile)
       len += snprintf(&netfile->line[len], NET_LINELEN - len,
                       "\tinet6 addr:%s/%d\n", addrstr, preflen);
     }
+#endif
 
-  /* REVISIT: Show the IPv6 default router address */
+  return len;
+}
+
+/****************************************************************************
+ * Name: netprocfs_dripaddress
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_IPv6
+static int netprocfs_dripaddress(FAR struct netprocfs_file_s *netfile)
+{
+  FAR struct net_driver_s *dev;
+  char addrstr[INET6_ADDRSTRLEN];
+  uint8_t preflen;
+  int len = 0;
+
+  DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
+  dev = netfile->dev;
+
+  /* Convert the 128 network mask to a human friendly prefix length */
+
+  preflen = net_ipv6_mask2pref(dev->d_ipv6netmask);
+
+
+  /* Show the IPv6 default router address */
 
   if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN))
     {
       len += snprintf(&netfile->line[len], NET_LINELEN - len,
-                      "\tinet6 DRaddr:%s/%d\n", addrstr, preflen);
+                      "\tinet6 DRaddr:%s/%d\n\n", addrstr, preflen);
     }
-#endif
 
-  len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n");
   return len;
 }
+#endif
 
 /****************************************************************************
  * Name: netprocfs_rxstatistics_header

From ebd2416f9d5d76b793ffcdbf56c47fce815b021a Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Sun, 9 Apr 2017 11:47:57 -0600
Subject: [PATCH 02/12] stm32 COMP:  Logic in stm32_comp.h must be configured
 on CONFIG_STM32_COMP or otherwise it causes an error via #error on every
 platform without COMP support.

---
 arch/arm/src/stm32/stm32_comp.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/src/stm32/stm32_comp.h b/arch/arm/src/stm32/stm32_comp.h
index 16a0ad6971..ab28cac186 100644
--- a/arch/arm/src/stm32/stm32_comp.h
+++ b/arch/arm/src/stm32/stm32_comp.h
@@ -44,6 +44,8 @@
 
 #include "chip.h"
 
+#ifdef CONFIG_STM32_COMP
+
 #if defined(CONFIG_STM32_STM32F30XX)
 #  error "COMP support for STM32F30XX not implemented yet"
 #elif defined(CONFIG_STM32_STM32F33XX)
@@ -211,4 +213,5 @@ FAR struct comp_dev_s* stm32_compinitialize(int intf);
 #endif
 #endif /* __ASSEMBLY__ */
 
+#endif /* CONFIG_STM23_COMP */
 #endif /* __ARCH_ARM_SRC_STM32_STM32_COMP_H */

From de2c368249f74d719917f002cf696dc0738fd60f Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Sun, 9 Apr 2017 12:13:47 -0600
Subject: [PATCH 03/12] Eliminate a warning about garbage at the end of the
 line.

---
 configs/tm4c123g-launchpad/src/tm4c_ssi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/tm4c123g-launchpad/src/tm4c_ssi.c b/configs/tm4c123g-launchpad/src/tm4c_ssi.c
index 7b295f76aa..ce8ce7021c 100644
--- a/configs/tm4c123g-launchpad/src/tm4c_ssi.c
+++ b/configs/tm4c123g-launchpad/src/tm4c_ssi.c
@@ -59,7 +59,7 @@
  * Pre-processor Definitions
  ************************************************************************************/
 
-#ifdef CONFIG_DEBUG_SPI_INFO)
+#ifdef CONFIG_DEBUG_SPI_INFO
 #  define ssi_dumpgpio(m) tiva_dumpgpio(SDCCS_GPIO, m)
 #else
 #  define ssi_dumpgpio(m)

From 5104eb530f4e48cccb65e71064a9fa8e73ec0a00 Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Sun, 9 Apr 2017 13:46:27 -0600
Subject: [PATCH 04/12] Photon:  Add logic to automatically mount the procfs
 file system on startup.  Fix some LED-related configuration conflicts.

---
 configs/photon/src/stm32_bringup.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/configs/photon/src/stm32_bringup.c b/configs/photon/src/stm32_bringup.c
index d83e0493ed..d55f3bc291 100644
--- a/configs/photon/src/stm32_bringup.c
+++ b/configs/photon/src/stm32_bringup.c
@@ -40,6 +40,7 @@
 #include <nuttx/config.h>
 
 #include <sys/types.h>
+#include <sys/mount.h>
 #include <syslog.h>
 
 #include <nuttx/input/buttons.h>
@@ -70,7 +71,17 @@ int stm32_bringup(void)
 {
   int ret = OK;
 
-#ifdef CONFIG_USERLED
+#ifdef CONFIG_FS_PROCFS
+  /* Mount the procfs file system */
+
+  ret = mount(NULL, "/proc", "procfs", 0, NULL);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret);
+    }
+#endif
+
+#if defined(CONFIG_USERLED) && !defined(CONFIG_ARCH_LEDS)
 #ifdef CONFIG_USERLED_LOWER
   /* Register the LED driver */
 
@@ -81,9 +92,11 @@ int stm32_bringup(void)
       return ret;
     }
 #else
+  /* Enable USER LED support for some other purpose */
+
   board_userled_initialize();
 #endif /* CONFIG_USERLED_LOWER */
-#endif /* CONFIG_USERLED */
+#endif /* CONFIG_USERLED && !CONFIG_ARCH_LEDS */
 
 #ifdef CONFIG_BUTTONS
 #ifdef CONFIG_BUTTONS_LOWER
@@ -96,16 +109,19 @@ int stm32_bringup(void)
       return ret;
     }
 #else
+  /* Enable BUTTON support for some other purpose */
+
   board_button_initialize();
 #endif /* CONFIG_BUTTONS_LOWER */
 #endif /* CONFIG_BUTTONS */
 
 #ifdef CONFIG_STM32_IWDG
+  /* Initialize the watchdog timer */
+
   stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY);
 #endif
 
 #ifdef CONFIG_PHOTON_WDG
-
   /* Start WDG kicker thread */
 
   ret = photon_watchdog_initialize();
@@ -117,7 +133,6 @@ int stm32_bringup(void)
 #endif
 
 #ifdef CONFIG_PHOTON_WLAN
-
   /* Initialize wlan driver and hardware */
 
   ret = photon_wlan_initialize();

From 77f980e676c11c1cb2303d28d73f4c5f5dcfd682 Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Sun, 9 Apr 2017 14:44:49 -0600
Subject: [PATCH 05/12] Buttons:  Correct some comments left after last
 button-related change:  32- vs 8-bit bit set.

---
 configs/avr32dev1/src/avr32_buttons.c                | 2 +-
 configs/clicker2-stm32/src/stm32_buttons.c           | 2 +-
 configs/cloudctrl/src/stm32_buttons.c                | 2 +-
 configs/dk-tm4c129x/src/tm4c_buttons.c               | 2 +-
 configs/fire-stm32v2/src/stm32_buttons.c             | 2 +-
 configs/freedom-k64f/src/k64_buttons.c               | 2 +-
 configs/freedom-k66f/src/k66_buttons.c               | 2 +-
 configs/hymini-stm32v/src/stm32_buttons.c            | 2 +-
 configs/kwikstik-k40/src/k40_buttons.c               | 2 +-
 configs/launchxl-tms57004/src/tms570_buttons.c       | 2 +-
 configs/nucleo-144/src/stm32_buttons.c               | 2 +-
 configs/nucleo-f303re/src/stm32_buttons.c            | 2 +-
 configs/nucleo-f4x1re/src/stm32_buttons.c            | 2 +-
 configs/nucleo-l476rg/src/stm32_buttons.c            | 2 +-
 configs/olimex-efm32g880f128-stk/src/efm32_buttons.c | 2 +-
 configs/olimex-stm32-e407/src/stm32_buttons.c        | 2 +-
 configs/olimex-stm32-h405/src/stm32_buttons.c        | 2 +-
 configs/olimex-stm32-h407/src/stm32_buttons.c        | 2 +-
 configs/olimex-stm32-p207/src/stm32_buttons.c        | 2 +-
 configs/olimex-stm32-p407/src/stm32_buttons.c        | 2 +-
 configs/olimexino-stm32/src/stm32_buttons.c          | 4 ++--
 configs/pcduino-a10/src/a1x_buttons.c                | 2 +-
 configs/pic32mz-starterkit/src/pic32mz_buttons.c     | 2 +-
 configs/sam3u-ek/src/sam_buttons.c                   | 2 +-
 configs/sam4e-ek/src/sam_buttons.c                   | 2 +-
 configs/sam4l-xplained/src/sam_buttons.c             | 2 +-
 configs/sam4s-xplained-pro/src/sam_buttons.c         | 2 +-
 configs/sam4s-xplained/src/sam_buttons.c             | 2 +-
 configs/sama5d2-xult/src/sam_buttons.c               | 2 +-
 configs/sama5d3-xplained/src/sam_buttons.c           | 2 +-
 configs/sama5d3x-ek/src/sam_buttons.c                | 2 +-
 configs/sama5d4-ek/src/sam_buttons.c                 | 2 +-
 configs/samd20-xplained/src/sam_buttons.c            | 2 +-
 configs/samd21-xplained/src/sam_buttons.c            | 2 +-
 configs/same70-xplained/src/sam_buttons.c            | 2 +-
 configs/saml21-xplained/src/sam_buttons.c            | 2 +-
 configs/samv71-xult/src/sam_buttons.c                | 2 +-
 configs/shenzhou/src/stm32_buttons.c                 | 2 +-
 configs/spark/src/stm32_buttons.c                    | 2 +-
 configs/stm3210e-eval/src/stm32_buttons.c            | 2 +-
 configs/stm3220g-eval/src/stm32_buttons.c            | 2 +-
 configs/stm3240g-eval/src/stm32_buttons.c            | 2 +-
 configs/stm32f103-minimum/src/stm32_buttons.c        | 2 +-
 configs/stm32f3discovery/src/stm32_buttons.c         | 2 +-
 configs/stm32f429i-disco/src/stm32_buttons.c         | 2 +-
 configs/stm32f4discovery/src/stm32_buttons.c         | 2 +-
 configs/stm32f746g-disco/src/stm32_buttons.c         | 2 +-
 configs/stm32l476-mdk/src/stm32_buttons.c            | 2 +-
 configs/stm32l476vg-disco/src/stm32_buttons.c        | 2 +-
 configs/stm32ldiscovery/src/stm32_buttons.c          | 2 +-
 configs/stm32vldiscovery/src/stm32_buttons.c         | 2 +-
 configs/sure-pic32mx/src/pic32mx_buttons.c           | 2 +-
 configs/tm4c123g-launchpad/src/tm4c_buttons.c        | 2 +-
 configs/twr-k60n512/src/k60_buttons.c                | 2 +-
 configs/ubw32/src/pic32_buttons.c                    | 2 +-
 configs/viewtool-stm32f107/src/stm32_buttons.c       | 2 +-
 configs/zkit-arm-1769/src/lpc17_buttons.c            | 2 +-
 include/nuttx/board.h                                | 2 +-
 58 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/configs/avr32dev1/src/avr32_buttons.c b/configs/avr32dev1/src/avr32_buttons.c
index 427a19d835..4514a800a5 100644
--- a/configs/avr32dev1/src/avr32_buttons.c
+++ b/configs/avr32dev1/src/avr32_buttons.c
@@ -120,7 +120,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions in the board.h header file for the meaning of each bit in
  *   the returned value.
  *
diff --git a/configs/clicker2-stm32/src/stm32_buttons.c b/configs/clicker2-stm32/src/stm32_buttons.c
index 922007dcf6..00a571c817 100644
--- a/configs/clicker2-stm32/src/stm32_buttons.c
+++ b/configs/clicker2-stm32/src/stm32_buttons.c
@@ -110,7 +110,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/cloudctrl/src/stm32_buttons.c b/configs/cloudctrl/src/stm32_buttons.c
index 6603ce1d07..574e6a1581 100644
--- a/configs/cloudctrl/src/stm32_buttons.c
+++ b/configs/cloudctrl/src/stm32_buttons.c
@@ -145,7 +145,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to  collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the
+ *   32-bit bit set with each bit associated with a button.  See the
  *   BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning
  *   of each bit.
  *
diff --git a/configs/dk-tm4c129x/src/tm4c_buttons.c b/configs/dk-tm4c129x/src/tm4c_buttons.c
index 7ef91a768b..7a85cda8e8 100644
--- a/configs/dk-tm4c129x/src/tm4c_buttons.c
+++ b/configs/dk-tm4c129x/src/tm4c_buttons.c
@@ -137,7 +137,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT and JOYSTICK_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/fire-stm32v2/src/stm32_buttons.c b/configs/fire-stm32v2/src/stm32_buttons.c
index 5c041230f9..d1fcbda183 100644
--- a/configs/fire-stm32v2/src/stm32_buttons.c
+++ b/configs/fire-stm32v2/src/stm32_buttons.c
@@ -121,7 +121,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the
+ *   32-bit bit set with each bit associated with a button.  See the
  *   BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning
  *   of each bit.
  *
diff --git a/configs/freedom-k64f/src/k64_buttons.c b/configs/freedom-k64f/src/k64_buttons.c
index d6f6ea44d6..53caa760b8 100644
--- a/configs/freedom-k64f/src/k64_buttons.c
+++ b/configs/freedom-k64f/src/k64_buttons.c
@@ -120,7 +120,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may
  *   be called to collect the state of all buttons.  board_buttons() returns
- *   an 8-bit bit set with each bit associated with a button.  See the
+ *   an 32-bit bit set with each bit associated with a button.  See the
  *   BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning
  *   of each bit.
  *
diff --git a/configs/freedom-k66f/src/k66_buttons.c b/configs/freedom-k66f/src/k66_buttons.c
index ce63345c85..b186d40b41 100644
--- a/configs/freedom-k66f/src/k66_buttons.c
+++ b/configs/freedom-k66f/src/k66_buttons.c
@@ -124,7 +124,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may
  *   be called to collect the state of all buttons.  board_buttons() returns
- *   an 8-bit bit set with each bit associated with a button.  See the
+ *   an 32-bit bit set with each bit associated with a button.  See the
  *   BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning
  *   of each bit.
  *
diff --git a/configs/hymini-stm32v/src/stm32_buttons.c b/configs/hymini-stm32v/src/stm32_buttons.c
index 757f159af7..4dac6fc8f4 100644
--- a/configs/hymini-stm32v/src/stm32_buttons.c
+++ b/configs/hymini-stm32v/src/stm32_buttons.c
@@ -120,7 +120,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the
+ *   32-bit bit set with each bit associated with a button.  See the
  *   BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning
  *  of each bit.
  *
diff --git a/configs/kwikstik-k40/src/k40_buttons.c b/configs/kwikstik-k40/src/k40_buttons.c
index 35f673d0ea..c66c2d858c 100644
--- a/configs/kwikstik-k40/src/k40_buttons.c
+++ b/configs/kwikstik-k40/src/k40_buttons.c
@@ -92,7 +92,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the
+ *   32-bit bit set with each bit associated with a button.  See the
  *   BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning
  *   of each bit.
  *
diff --git a/configs/launchxl-tms57004/src/tms570_buttons.c b/configs/launchxl-tms57004/src/tms570_buttons.c
index 3ee9e0eb31..d84de8f63a 100644
--- a/configs/launchxl-tms57004/src/tms570_buttons.c
+++ b/configs/launchxl-tms57004/src/tms570_buttons.c
@@ -154,7 +154,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/nucleo-144/src/stm32_buttons.c b/configs/nucleo-144/src/stm32_buttons.c
index 5d47aa30bd..a8783b4e20 100644
--- a/configs/nucleo-144/src/stm32_buttons.c
+++ b/configs/nucleo-144/src/stm32_buttons.c
@@ -92,7 +92,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/nucleo-f303re/src/stm32_buttons.c b/configs/nucleo-f303re/src/stm32_buttons.c
index 8ae6081f48..e40db64c28 100644
--- a/configs/nucleo-f303re/src/stm32_buttons.c
+++ b/configs/nucleo-f303re/src/stm32_buttons.c
@@ -83,7 +83,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit unsigned integer with each bit associated with a button.  See the
+ *   32-bit unsigned integer with each bit associated with a button.  See the
  *   BUTTON_*_BIT definitions in board.h for the meaning of each bit.
  *
  ****************************************************************************/
diff --git a/configs/nucleo-f4x1re/src/stm32_buttons.c b/configs/nucleo-f4x1re/src/stm32_buttons.c
index 30fd294fc5..fe18b0b216 100644
--- a/configs/nucleo-f4x1re/src/stm32_buttons.c
+++ b/configs/nucleo-f4x1re/src/stm32_buttons.c
@@ -98,7 +98,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/nucleo-l476rg/src/stm32_buttons.c b/configs/nucleo-l476rg/src/stm32_buttons.c
index 55f99e8192..456795c304 100644
--- a/configs/nucleo-l476rg/src/stm32_buttons.c
+++ b/configs/nucleo-l476rg/src/stm32_buttons.c
@@ -98,7 +98,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c
index 9637b12555..2863a332c1 100644
--- a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c
+++ b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c
@@ -120,7 +120,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/olimex-stm32-e407/src/stm32_buttons.c b/configs/olimex-stm32-e407/src/stm32_buttons.c
index c57c54f42d..e52d296079 100644
--- a/configs/olimex-stm32-e407/src/stm32_buttons.c
+++ b/configs/olimex-stm32-e407/src/stm32_buttons.c
@@ -121,7 +121,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON_*_BIT
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
  *   board_button_irq() may be called to register an interrupt handler that
diff --git a/configs/olimex-stm32-h405/src/stm32_buttons.c b/configs/olimex-stm32-h405/src/stm32_buttons.c
index e7bd98cf23..abcac85c80 100644
--- a/configs/olimex-stm32-h405/src/stm32_buttons.c
+++ b/configs/olimex-stm32-h405/src/stm32_buttons.c
@@ -120,7 +120,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/olimex-stm32-h407/src/stm32_buttons.c b/configs/olimex-stm32-h407/src/stm32_buttons.c
index 976157d117..1155069e5e 100644
--- a/configs/olimex-stm32-h407/src/stm32_buttons.c
+++ b/configs/olimex-stm32-h407/src/stm32_buttons.c
@@ -121,7 +121,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON_*_BIT
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
  *   board_button_irq() may be called to register an interrupt handler that
diff --git a/configs/olimex-stm32-p207/src/stm32_buttons.c b/configs/olimex-stm32-p207/src/stm32_buttons.c
index 9400b7456c..bde278810b 100644
--- a/configs/olimex-stm32-p207/src/stm32_buttons.c
+++ b/configs/olimex-stm32-p207/src/stm32_buttons.c
@@ -156,7 +156,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/olimex-stm32-p407/src/stm32_buttons.c b/configs/olimex-stm32-p407/src/stm32_buttons.c
index 3d98c9eab7..a7bf89714d 100644
--- a/configs/olimex-stm32-p407/src/stm32_buttons.c
+++ b/configs/olimex-stm32-p407/src/stm32_buttons.c
@@ -158,7 +158,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/olimexino-stm32/src/stm32_buttons.c b/configs/olimexino-stm32/src/stm32_buttons.c
index cc6ea25509..092383cade 100644
--- a/configs/olimexino-stm32/src/stm32_buttons.c
+++ b/configs/olimexino-stm32/src/stm32_buttons.c
@@ -63,7 +63,7 @@
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.
+ *   32-bit bit set with each bit associated with a button.
  *   See the BUTTON_*_BIT definitions in board.h for the meaning of each bit.
  *
  *   board_button_irq() may be called to register an interrupt handler that
@@ -97,7 +97,7 @@ void board_button_initialize(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.
+ *   32-bit bit set with each bit associated with a button.
  *   See the BUTTON_*_BIT definitions in board.h for the meaning of each bit.
  *
  ****************************************************************************/
diff --git a/configs/pcduino-a10/src/a1x_buttons.c b/configs/pcduino-a10/src/a1x_buttons.c
index c7d1089135..4d4feccc0f 100644
--- a/configs/pcduino-a10/src/a1x_buttons.c
+++ b/configs/pcduino-a10/src/a1x_buttons.c
@@ -78,7 +78,7 @@ void board_button_initialize(void)
  *
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON* definitions
  *   above for the meaning of each bit in the returned value.
  *
diff --git a/configs/pic32mz-starterkit/src/pic32mz_buttons.c b/configs/pic32mz-starterkit/src/pic32mz_buttons.c
index 206be294c3..639844a953 100644
--- a/configs/pic32mz-starterkit/src/pic32mz_buttons.c
+++ b/configs/pic32mz-starterkit/src/pic32mz_buttons.c
@@ -140,7 +140,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the
+ *   32-bit bit set with each bit associated with a button.  See the
  *   BUTTON_*_BIT definitions in board.h for the meaning of each bit.
  *
  *   board_button_irq() may be called to register an interrupt handler that
diff --git a/configs/sam3u-ek/src/sam_buttons.c b/configs/sam3u-ek/src/sam_buttons.c
index 107c7036a6..19a00d97ec 100644
--- a/configs/sam3u-ek/src/sam_buttons.c
+++ b/configs/sam3u-ek/src/sam_buttons.c
@@ -127,7 +127,7 @@ void board_button_initialize(void)
  *
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be called to collect
- *   the state of all buttons.  board_buttons() returns an 8-bit bit set with each bit
+ *   the state of all buttons.  board_buttons() returns an 32-bit bit set with each bit
  *   associated with a button.  See the BUTTON* definitions above for the meaning of
  *   each bit in the returned value.
  *
diff --git a/configs/sam4e-ek/src/sam_buttons.c b/configs/sam4e-ek/src/sam_buttons.c
index 53626290b7..ed3690782a 100644
--- a/configs/sam4e-ek/src/sam_buttons.c
+++ b/configs/sam4e-ek/src/sam_buttons.c
@@ -130,7 +130,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/sam4l-xplained/src/sam_buttons.c b/configs/sam4l-xplained/src/sam_buttons.c
index 8d306bb311..78949a1cde 100644
--- a/configs/sam4l-xplained/src/sam_buttons.c
+++ b/configs/sam4l-xplained/src/sam_buttons.c
@@ -79,7 +79,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/sam4s-xplained-pro/src/sam_buttons.c b/configs/sam4s-xplained-pro/src/sam_buttons.c
index 3b9b4fe359..f19f29894e 100644
--- a/configs/sam4s-xplained-pro/src/sam_buttons.c
+++ b/configs/sam4s-xplained-pro/src/sam_buttons.c
@@ -81,7 +81,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/sam4s-xplained/src/sam_buttons.c b/configs/sam4s-xplained/src/sam_buttons.c
index 314e8e1818..5b979a1aa9 100644
--- a/configs/sam4s-xplained/src/sam_buttons.c
+++ b/configs/sam4s-xplained/src/sam_buttons.c
@@ -80,7 +80,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/sama5d2-xult/src/sam_buttons.c b/configs/sama5d2-xult/src/sam_buttons.c
index 0939ddaa11..56548f3480 100644
--- a/configs/sama5d2-xult/src/sam_buttons.c
+++ b/configs/sama5d2-xult/src/sam_buttons.c
@@ -91,7 +91,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/sama5d3-xplained/src/sam_buttons.c b/configs/sama5d3-xplained/src/sam_buttons.c
index 43794b374d..768b7b5db7 100644
--- a/configs/sama5d3-xplained/src/sam_buttons.c
+++ b/configs/sama5d3-xplained/src/sam_buttons.c
@@ -95,7 +95,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/sama5d3x-ek/src/sam_buttons.c b/configs/sama5d3x-ek/src/sam_buttons.c
index dbdaa310f6..e76fcd2a0a 100644
--- a/configs/sama5d3x-ek/src/sam_buttons.c
+++ b/configs/sama5d3x-ek/src/sam_buttons.c
@@ -95,7 +95,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/sama5d4-ek/src/sam_buttons.c b/configs/sama5d4-ek/src/sam_buttons.c
index 4ccae619f6..90dff73b16 100644
--- a/configs/sama5d4-ek/src/sam_buttons.c
+++ b/configs/sama5d4-ek/src/sam_buttons.c
@@ -91,7 +91,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/samd20-xplained/src/sam_buttons.c b/configs/samd20-xplained/src/sam_buttons.c
index fc8f14bd0c..334bf8b403 100644
--- a/configs/samd20-xplained/src/sam_buttons.c
+++ b/configs/samd20-xplained/src/sam_buttons.c
@@ -79,7 +79,7 @@ void board_button_initialize(void)
  *
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be called to collect
- *   the state of all buttons.  board_buttons() returns an 8-bit bit set with each bit
+ *   the state of all buttons.  board_buttons() returns an 32-bit bit set with each bit
  *   associated with a button.  See the BUTTON* definitions above for the meaning of
  *   each bit in the returned value.
  *
diff --git a/configs/samd21-xplained/src/sam_buttons.c b/configs/samd21-xplained/src/sam_buttons.c
index e4c31aa941..8e1789d1c9 100644
--- a/configs/samd21-xplained/src/sam_buttons.c
+++ b/configs/samd21-xplained/src/sam_buttons.c
@@ -79,7 +79,7 @@ void board_button_initialize(void)
  *
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be called to collect
- *   the state of all buttons.  board_buttons() returns an 8-bit bit set with each bit
+ *   the state of all buttons.  board_buttons() returns an 32-bit bit set with each bit
  *   associated with a button.  See the BUTTON* definitions above for the meaning of
  *   each bit in the returned value.
  *
diff --git a/configs/same70-xplained/src/sam_buttons.c b/configs/same70-xplained/src/sam_buttons.c
index 7e66905c8a..ab7dfeb8cf 100644
--- a/configs/same70-xplained/src/sam_buttons.c
+++ b/configs/same70-xplained/src/sam_buttons.c
@@ -142,7 +142,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/saml21-xplained/src/sam_buttons.c b/configs/saml21-xplained/src/sam_buttons.c
index 909fa58a7a..407b24bb4d 100644
--- a/configs/saml21-xplained/src/sam_buttons.c
+++ b/configs/saml21-xplained/src/sam_buttons.c
@@ -79,7 +79,7 @@ void board_button_initialize(void)
  *
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be called to collect
- *   the state of all buttons.  board_buttons() returns an 8-bit bit set with each bit
+ *   the state of all buttons.  board_buttons() returns an 32-bit bit set with each bit
  *   associated with a button.  See the BUTTON* definitions above for the meaning of
  *   each bit in the returned value.
  *
diff --git a/configs/samv71-xult/src/sam_buttons.c b/configs/samv71-xult/src/sam_buttons.c
index 1a06c84034..adcd280d73 100644
--- a/configs/samv71-xult/src/sam_buttons.c
+++ b/configs/samv71-xult/src/sam_buttons.c
@@ -158,7 +158,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/shenzhou/src/stm32_buttons.c b/configs/shenzhou/src/stm32_buttons.c
index 139d517956..57053359b8 100644
--- a/configs/shenzhou/src/stm32_buttons.c
+++ b/configs/shenzhou/src/stm32_buttons.c
@@ -136,7 +136,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT and JOYSTICK_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/spark/src/stm32_buttons.c b/configs/spark/src/stm32_buttons.c
index 3ab2f3c854..3534eeeb6a 100644
--- a/configs/spark/src/stm32_buttons.c
+++ b/configs/spark/src/stm32_buttons.c
@@ -95,7 +95,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/stm3210e-eval/src/stm32_buttons.c b/configs/stm3210e-eval/src/stm32_buttons.c
index b9f4822814..f6a8575881 100644
--- a/configs/stm3210e-eval/src/stm32_buttons.c
+++ b/configs/stm3210e-eval/src/stm32_buttons.c
@@ -148,7 +148,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT and JOYSTICK_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/stm3220g-eval/src/stm32_buttons.c b/configs/stm3220g-eval/src/stm32_buttons.c
index 669b460b03..9bec8f3c10 100644
--- a/configs/stm3220g-eval/src/stm32_buttons.c
+++ b/configs/stm3220g-eval/src/stm32_buttons.c
@@ -136,7 +136,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/stm3240g-eval/src/stm32_buttons.c b/configs/stm3240g-eval/src/stm32_buttons.c
index 4682ffb1a9..c543a0b6ac 100644
--- a/configs/stm3240g-eval/src/stm32_buttons.c
+++ b/configs/stm3240g-eval/src/stm32_buttons.c
@@ -144,7 +144,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/stm32f103-minimum/src/stm32_buttons.c b/configs/stm32f103-minimum/src/stm32_buttons.c
index 6891b3db0a..154f24225e 100644
--- a/configs/stm32f103-minimum/src/stm32_buttons.c
+++ b/configs/stm32f103-minimum/src/stm32_buttons.c
@@ -140,7 +140,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns
- *   an 8-bit bit set with each bit associated with a button.  See the
+ *   an 32-bit bit set with each bit associated with a button.  See the
  *   BUTTON_*_BIT definitions in board.h for the meaning of each bit.
  *
  *   board_button_irq() may be called to register an interrupt handler that
diff --git a/configs/stm32f3discovery/src/stm32_buttons.c b/configs/stm32f3discovery/src/stm32_buttons.c
index a0ecada6a5..a17912bdbd 100644
--- a/configs/stm32f3discovery/src/stm32_buttons.c
+++ b/configs/stm32f3discovery/src/stm32_buttons.c
@@ -131,7 +131,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/stm32f429i-disco/src/stm32_buttons.c b/configs/stm32f429i-disco/src/stm32_buttons.c
index d2e9ba2e09..c5ce618d0c 100644
--- a/configs/stm32f429i-disco/src/stm32_buttons.c
+++ b/configs/stm32f429i-disco/src/stm32_buttons.c
@@ -131,7 +131,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/stm32f4discovery/src/stm32_buttons.c b/configs/stm32f4discovery/src/stm32_buttons.c
index 2d86ea80cf..2b805075e0 100644
--- a/configs/stm32f4discovery/src/stm32_buttons.c
+++ b/configs/stm32f4discovery/src/stm32_buttons.c
@@ -131,7 +131,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/stm32f746g-disco/src/stm32_buttons.c b/configs/stm32f746g-disco/src/stm32_buttons.c
index b8a46a8dac..42faf1d90f 100644
--- a/configs/stm32f746g-disco/src/stm32_buttons.c
+++ b/configs/stm32f746g-disco/src/stm32_buttons.c
@@ -92,7 +92,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/stm32l476-mdk/src/stm32_buttons.c b/configs/stm32l476-mdk/src/stm32_buttons.c
index 7debe3c597..58e9079153 100644
--- a/configs/stm32l476-mdk/src/stm32_buttons.c
+++ b/configs/stm32l476-mdk/src/stm32_buttons.c
@@ -138,7 +138,7 @@ uint32_t board_buttons(void)
  *
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the
+ *   32-bit bit set with each bit associated with a button.  See the
  *   BUTTON_*_BIT definitions in board.h for the meaning of each bit.
  *
  *   board_button_irq() may be called to register an interrupt handler that
diff --git a/configs/stm32l476vg-disco/src/stm32_buttons.c b/configs/stm32l476vg-disco/src/stm32_buttons.c
index f3c4d50c9c..18b984d2c1 100644
--- a/configs/stm32l476vg-disco/src/stm32_buttons.c
+++ b/configs/stm32l476vg-disco/src/stm32_buttons.c
@@ -306,7 +306,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/stm32ldiscovery/src/stm32_buttons.c b/configs/stm32ldiscovery/src/stm32_buttons.c
index f766017d15..d985c9f4d3 100644
--- a/configs/stm32ldiscovery/src/stm32_buttons.c
+++ b/configs/stm32ldiscovery/src/stm32_buttons.c
@@ -131,7 +131,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/stm32vldiscovery/src/stm32_buttons.c b/configs/stm32vldiscovery/src/stm32_buttons.c
index 9784b19d77..95d9f1590c 100644
--- a/configs/stm32vldiscovery/src/stm32_buttons.c
+++ b/configs/stm32vldiscovery/src/stm32_buttons.c
@@ -94,7 +94,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT and JOYSTICK_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/sure-pic32mx/src/pic32mx_buttons.c b/configs/sure-pic32mx/src/pic32mx_buttons.c
index bf5ca03429..e2ee0ac219 100644
--- a/configs/sure-pic32mx/src/pic32mx_buttons.c
+++ b/configs/sure-pic32mx/src/pic32mx_buttons.c
@@ -185,7 +185,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT and JOYSTICK_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/tm4c123g-launchpad/src/tm4c_buttons.c b/configs/tm4c123g-launchpad/src/tm4c_buttons.c
index 96370046f4..24eb21ea04 100644
--- a/configs/tm4c123g-launchpad/src/tm4c_buttons.c
+++ b/configs/tm4c123g-launchpad/src/tm4c_buttons.c
@@ -113,7 +113,7 @@ void board_button_initialize(void)
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  See the BUTTON*
+ *   32-bit bit set with each bit associated with a button.  See the BUTTON*
  *   definitions above for the meaning of each bit in the returned value.
  *
  ****************************************************************************/
diff --git a/configs/twr-k60n512/src/k60_buttons.c b/configs/twr-k60n512/src/k60_buttons.c
index d9206f2c71..99bee75910 100644
--- a/configs/twr-k60n512/src/k60_buttons.c
+++ b/configs/twr-k60n512/src/k60_buttons.c
@@ -121,7 +121,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT and JOYSTICK_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/ubw32/src/pic32_buttons.c b/configs/ubw32/src/pic32_buttons.c
index 69b1deeb44..469167f137 100644
--- a/configs/ubw32/src/pic32_buttons.c
+++ b/configs/ubw32/src/pic32_buttons.c
@@ -160,7 +160,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT  definitions in
  *   board.h for the meaning of each bit.
  *
diff --git a/configs/viewtool-stm32f107/src/stm32_buttons.c b/configs/viewtool-stm32f107/src/stm32_buttons.c
index 9e39a2d72c..086a321755 100644
--- a/configs/viewtool-stm32f107/src/stm32_buttons.c
+++ b/configs/viewtool-stm32f107/src/stm32_buttons.c
@@ -132,7 +132,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT and JOYSTICK_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/configs/zkit-arm-1769/src/lpc17_buttons.c b/configs/zkit-arm-1769/src/lpc17_buttons.c
index ffa7646686..e93f27734f 100644
--- a/configs/zkit-arm-1769/src/lpc17_buttons.c
+++ b/configs/zkit-arm-1769/src/lpc17_buttons.c
@@ -142,7 +142,7 @@ uint32_t board_buttons(void)
  *   handlers.
  *
  *   After board_button_initialize() has been called, board_buttons() may be called to
- *   collect the state of all buttons.  board_buttons() returns an 8-bit bit set
+ *   collect the state of all buttons.  board_buttons() returns an 32-bit bit set
  *   with each bit associated with a button.  See the BUTTON_*_BIT and JOYSTICK_*_BIT
  *   definitions in board.h for the meaning of each bit.
  *
diff --git a/include/nuttx/board.h b/include/nuttx/board.h
index 310a973c34..c00d09ce3c 100644
--- a/include/nuttx/board.h
+++ b/include/nuttx/board.h
@@ -581,7 +581,7 @@ void board_button_initialize(void);
  * Description:
  *   After board_button_initialize() has been called, board_buttons() may be
  *   called to collect the state of all buttons.  board_buttons() returns an
- *   8-bit bit set with each bit associated with a button.  A bit set to
+ *   32-bit bit set with each bit associated with a button.  A bit set to
  *   "1" means that the button is depressed; a bit set to "0" means that
  *   the button is released.  The correspondence of the each button bit
  *   and physical buttons is board-specific.

From 755e9312b51f8a03f38d9287e1e2bfbae285cfbe Mon Sep 17 00:00:00 2001
From: Juha Niskanen <juha.niskanen@haltian.com>
Date: Mon, 10 Apr 2017 07:18:16 -0600
Subject: [PATCH 06/12] pthread: use cancel cleanup handlers in rwlock

---
 libc/pthread/pthread_rwlock_rdlock.c | 17 ++++++++++++++++-
 libc/pthread/pthread_rwlock_wrlock.c | 27 +++++++++++++++++++++++----
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c
index 9fd461a758..19979f79bb 100644
--- a/libc/pthread/pthread_rwlock_rdlock.c
+++ b/libc/pthread/pthread_rwlock_rdlock.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * libc/pthread/pthread_rwlockread.c
+ * libc/pthread/pthread_rwlock_rdlock.c
  *
  *   Copyright (C) 2017 Mark Schulte. All rights reserved.
  *   Author: Mark Schulte <mark@mjs.pw>
@@ -50,6 +50,15 @@
  * Private Functions
  ****************************************************************************/
 
+#ifdef CONFIG_PTHREAD_CLEANUP
+static void rdlock_cleanup(FAR void *arg)
+{
+  FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg;
+
+  pthread_mutex_unlock(&rw_lock->lock);
+}
+#endif
+
 static int tryrdlock(FAR pthread_rwlock_t *rw_lock)
 {
   int err;
@@ -116,6 +125,9 @@ int pthread_rwlock_timedrdlock(FAR pthread_rwlock_t *rw_lock,
       return err;
     }
 
+#ifdef CONFIG_PTHREAD_CLEANUP
+  pthread_cleanup_push(&rdlock_cleanup, rw_lock);
+#endif
   while ((err = tryrdlock(rw_lock)) == EBUSY)
     {
       if (ts != NULL)
@@ -132,6 +144,9 @@ int pthread_rwlock_timedrdlock(FAR pthread_rwlock_t *rw_lock,
           break;
         }
     }
+#ifdef CONFIG_PTHREAD_CLEANUP
+  pthread_cleanup_pop(0);
+#endif
 
   pthread_mutex_unlock(&rw_lock->lock);
   return err;
diff --git a/libc/pthread/pthread_rwlock_wrlock.c b/libc/pthread/pthread_rwlock_wrlock.c
index ecda4cb25b..fcda35cb4f 100644
--- a/libc/pthread/pthread_rwlock_wrlock.c
+++ b/libc/pthread/pthread_rwlock_wrlock.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * libc/pthread/pthread_rwlockwrite.c
+ * libc/pthread/pthread_rwlock_wrlock.c
  *
  *   Copyright (C) 2017 Mark Schulte. All rights reserved.
  *   Author: Mark Schulte <mark@mjs.pw>
@@ -46,15 +46,29 @@
 
 #include <nuttx/semaphore.h>
 
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_PTHREAD_CLEANUP
+static void wrlock_cleanup(FAR void *arg)
+{
+  FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg;
+
+  rw_lock->num_writers--;
+  pthread_mutex_unlock(&rw_lock->lock);
+}
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: pthread_rwlock_rdlock
+ * Name: pthread_rwlock_wrlock
  *
  * Description:
- *   Locks a read/write lock for reading
+ *   Locks a read/write lock for writing
  *
  * Parameters:
  *   None
@@ -106,6 +120,9 @@ int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *rw_lock,
 
   rw_lock->num_writers++;
 
+#ifdef CONFIG_PTHREAD_CLEANUP
+  pthread_cleanup_push(&wrlock_cleanup, rw_lock);
+#endif
   while (rw_lock->write_in_progress || rw_lock->num_readers > 0)
     {
       if (ts != NULL)
@@ -122,12 +139,14 @@ int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *rw_lock,
           break;
         }
     }
+#ifdef CONFIG_PTHREAD_CLEANUP
+  pthread_cleanup_pop(0);
+#endif
 
   if (err == 0)
     {
       rw_lock->write_in_progress = true;
     }
-
   else
     {
       /* In case of error, notify any blocked readers. */

From b51b72b2dba6dc7350cddfa40ca93203ebbc6932 Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Mon, 10 Apr 2017 08:11:16 -0600
Subject: [PATCH 07/12] pthreads: Re-order some operations so that mutexes are
 placed in the inconsistent state BEFORE the clean-up callbacks are called.

---
 sched/Kconfig                           |  4 ++--
 sched/pthread/pthread_cancel.c          | 12 ++++++------
 sched/pthread/pthread_exit.c            | 12 ++++++------
 sched/pthread/pthread_mutexconsistent.c |  4 +++-
 4 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/sched/Kconfig b/sched/Kconfig
index 50613fb44d..6cefe0e121 100644
--- a/sched/Kconfig
+++ b/sched/Kconfig
@@ -601,8 +601,6 @@ config PTHREAD_CLEANUP_STACKSIZE
 		8 for a CPU with 32-bit addressing and 4 for a CPU with 16-bit
 		addressing.
 
-endmenu # Pthread Options
-
 config CANCELLATION_POINTS
 	bool "Cancellation points"
 	default n
@@ -611,6 +609,8 @@ config CANCELLATION_POINTS
 		cancellation points will also used with the () task_delete() API even if
 		pthreads are not enabled.
 
+endmenu # Pthread Options
+
 menu "Performance Monitoring"
 
 config SCHED_CPULOAD
diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c
index e2cad60ebb..f68d272e03 100644
--- a/sched/pthread/pthread_cancel.c
+++ b/sched/pthread/pthread_cancel.c
@@ -145,6 +145,12 @@ int pthread_cancel(pthread_t thread)
       pthread_exit(PTHREAD_CANCELED);
     }
 
+#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
+  /* Recover any mutexes still held by the canceled thread */
+
+  pthread_mutex_inconsistent(tcb);
+#endif
+
 #ifdef CONFIG_PTHREAD_CLEANUP
   /* Perform any stack pthread clean-up callbacks.
    *
@@ -162,12 +168,6 @@ int pthread_cancel(pthread_t thread)
 
   (void)pthread_completejoin((pid_t)thread, PTHREAD_CANCELED);
 
-#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
-  /* Recover any mutexes still held by the canceled thread */
-
-  pthread_mutex_inconsistent(tcb);
-#endif
-
   /* Then let task_terminate do the real work */
 
   return task_terminate((pid_t)thread, false);
diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c
index bcc8e79c85..4929db94cb 100644
--- a/sched/pthread/pthread_exit.c
+++ b/sched/pthread/pthread_exit.c
@@ -105,6 +105,12 @@ void pthread_exit(FAR void *exit_value)
    tcb->cpcount = 0;
 #endif
 
+#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
+  /* Recover any mutexes still held by the canceled thread */
+
+  pthread_mutex_inconsistent((FAR struct pthread_tcb_s *)tcb);
+#endif
+
 #ifdef CONFIG_PTHREAD_CLEANUP
    /* Perform any stack pthread clean-up callbacks */
 
@@ -123,12 +129,6 @@ void pthread_exit(FAR void *exit_value)
       exit(EXIT_FAILURE);
     }
 
-#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
-  /* Recover any mutexes still held by the canceled thread */
-
-  pthread_mutex_inconsistent((FAR struct pthread_tcb_s *)tcb);
-#endif
-
   /* Perform common task termination logic.  This will get called again later
    * through logic kicked off by _exit().  However, we need to call it before
    * calling _exit() in order certain operations if this is the last thread
diff --git a/sched/pthread/pthread_mutexconsistent.c b/sched/pthread/pthread_mutexconsistent.c
index 77d9bede3e..e374083021 100644
--- a/sched/pthread/pthread_mutexconsistent.c
+++ b/sched/pthread/pthread_mutexconsistent.c
@@ -119,7 +119,6 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex)
               /* The thread associated with the PID no longer exists */
 
               mutex->pid    = -1;
-              mutex->flags &= _PTHREAD_MFLAGS_ROBUST;
 #ifdef CONFIG_PTHREAD_MUTEX_TYPES
               mutex->nlocks = 0;
 #endif
@@ -132,6 +131,9 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex)
             }
         }
 
+      /* Clear the inconsistent flag in any case */
+
+      mutex->flags &= _PTHREAD_MFLAGS_ROBUST;
       sched_unlock();
       ret = OK;
     }

From 84849cfc5ec7b74bab3c7a21b2babed14c89e37d Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Mon, 10 Apr 2017 08:44:08 -0600
Subject: [PATCH 08/12] examples/ostest:  pthread rwlock cleanup handlers must
 call pthread_consistent, not pthread_mutex_unlock() on cancellation if robust
 mutexes are enabled.

---
 libc/pthread/pthread_rwlock_rdlock.c | 13 ++++++++++++-
 libc/pthread/pthread_rwlock_wrlock.c | 14 +++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c
index 19979f79bb..29dcf7daae 100644
--- a/libc/pthread/pthread_rwlock_rdlock.c
+++ b/libc/pthread/pthread_rwlock_rdlock.c
@@ -55,7 +55,18 @@ static void rdlock_cleanup(FAR void *arg)
 {
   FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg;
 
-  pthread_mutex_unlock(&rw_lock->lock);
+#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
+  /* Check if this is a robust mutex in an inconsistent state */
+
+  if ((rw_lock->lock.flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0)
+    {
+      (void)pthread_mutex_consistent(&rw_lock->lock);
+    }
+  else
+#endif
+    {
+      (void)pthread_mutex_unlock(&rw_lock->lock);
+    }
 }
 #endif
 
diff --git a/libc/pthread/pthread_rwlock_wrlock.c b/libc/pthread/pthread_rwlock_wrlock.c
index fcda35cb4f..93a6a23858 100644
--- a/libc/pthread/pthread_rwlock_wrlock.c
+++ b/libc/pthread/pthread_rwlock_wrlock.c
@@ -56,7 +56,19 @@ static void wrlock_cleanup(FAR void *arg)
   FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg;
 
   rw_lock->num_writers--;
-  pthread_mutex_unlock(&rw_lock->lock);
+
+#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
+  /* Check if this is a robust mutex in an inconsistent state */
+
+  if ((rw_lock->lock.flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0)
+    {
+      (void)pthread_mutex_consistent(&rw_lock->lock);
+    }
+  else
+#endif
+    {
+      (void)pthread_mutex_unlock(&rw_lock->lock);
+    }
 }
 #endif
 

From 948332ca343f596acf7af0b434812a2bb7f90079 Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Mon, 10 Apr 2017 09:51:03 -0600
Subject: [PATCH 09/12] pthreads:  Backed most of last pthread changes.  Found
 the 'real' root poblem.  A one like error in pthread_mutex.c.

---
 libc/pthread/pthread_rwlock_rdlock.c | 13 +------------
 libc/pthread/pthread_rwlock_wrlock.c | 14 +-------------
 sched/pthread/pthread_cancel.c       | 12 ++++++------
 sched/pthread/pthread_exit.c         | 12 ++++++------
 sched/pthread/pthread_mutex.c        |  6 ++++--
 5 files changed, 18 insertions(+), 39 deletions(-)

diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c
index 29dcf7daae..4eadfedccb 100644
--- a/libc/pthread/pthread_rwlock_rdlock.c
+++ b/libc/pthread/pthread_rwlock_rdlock.c
@@ -55,18 +55,7 @@ static void rdlock_cleanup(FAR void *arg)
 {
   FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg;
 
-#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
-  /* Check if this is a robust mutex in an inconsistent state */
-
-  if ((rw_lock->lock.flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0)
-    {
-      (void)pthread_mutex_consistent(&rw_lock->lock);
-    }
-  else
-#endif
-    {
-      (void)pthread_mutex_unlock(&rw_lock->lock);
-    }
+  (void)pthread_mutex_unlock(&rw_lock->lock);
 }
 #endif
 
diff --git a/libc/pthread/pthread_rwlock_wrlock.c b/libc/pthread/pthread_rwlock_wrlock.c
index 93a6a23858..c9f4f3a7c5 100644
--- a/libc/pthread/pthread_rwlock_wrlock.c
+++ b/libc/pthread/pthread_rwlock_wrlock.c
@@ -56,19 +56,7 @@ static void wrlock_cleanup(FAR void *arg)
   FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg;
 
   rw_lock->num_writers--;
-
-#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
-  /* Check if this is a robust mutex in an inconsistent state */
-
-  if ((rw_lock->lock.flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0)
-    {
-      (void)pthread_mutex_consistent(&rw_lock->lock);
-    }
-  else
-#endif
-    {
-      (void)pthread_mutex_unlock(&rw_lock->lock);
-    }
+  (void)pthread_mutex_unlock(&rw_lock->lock);
 }
 #endif
 
diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c
index f68d272e03..e2cad60ebb 100644
--- a/sched/pthread/pthread_cancel.c
+++ b/sched/pthread/pthread_cancel.c
@@ -145,12 +145,6 @@ int pthread_cancel(pthread_t thread)
       pthread_exit(PTHREAD_CANCELED);
     }
 
-#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
-  /* Recover any mutexes still held by the canceled thread */
-
-  pthread_mutex_inconsistent(tcb);
-#endif
-
 #ifdef CONFIG_PTHREAD_CLEANUP
   /* Perform any stack pthread clean-up callbacks.
    *
@@ -168,6 +162,12 @@ int pthread_cancel(pthread_t thread)
 
   (void)pthread_completejoin((pid_t)thread, PTHREAD_CANCELED);
 
+#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
+  /* Recover any mutexes still held by the canceled thread */
+
+  pthread_mutex_inconsistent(tcb);
+#endif
+
   /* Then let task_terminate do the real work */
 
   return task_terminate((pid_t)thread, false);
diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c
index 4929db94cb..bcc8e79c85 100644
--- a/sched/pthread/pthread_exit.c
+++ b/sched/pthread/pthread_exit.c
@@ -105,12 +105,6 @@ void pthread_exit(FAR void *exit_value)
    tcb->cpcount = 0;
 #endif
 
-#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
-  /* Recover any mutexes still held by the canceled thread */
-
-  pthread_mutex_inconsistent((FAR struct pthread_tcb_s *)tcb);
-#endif
-
 #ifdef CONFIG_PTHREAD_CLEANUP
    /* Perform any stack pthread clean-up callbacks */
 
@@ -129,6 +123,12 @@ void pthread_exit(FAR void *exit_value)
       exit(EXIT_FAILURE);
     }
 
+#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
+  /* Recover any mutexes still held by the canceled thread */
+
+  pthread_mutex_inconsistent((FAR struct pthread_tcb_s *)tcb);
+#endif
+
   /* Perform common task termination logic.  This will get called again later
    * through logic kicked off by _exit().  However, we need to call it before
    * calling _exit() in order certain operations if this is the last thread
diff --git a/sched/pthread/pthread_mutex.c b/sched/pthread/pthread_mutex.c
index f11a5b01f6..afd296407e 100644
--- a/sched/pthread/pthread_mutex.c
+++ b/sched/pthread/pthread_mutex.c
@@ -125,10 +125,12 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex, bool intr)
         }
       else
         {
-          /* Take semaphore underlying the mutex */
+          /* Take semaphore underlying the mutex.  pthread_takesemaphore
+           * returns zero on success and a positive errno value on failue.
+           */
 
           ret = pthread_takesemaphore(&mutex->sem, intr);
-          if (ret < OK)
+          if (ret != OK)
             {
               ret = get_errno();
             }

From 6935d44405284ee9d680a79b8669143dd96faca3 Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Mon, 10 Apr 2017 09:58:34 -0600
Subject: [PATCH 10/12] Update TODO list

---
 TODO | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/TODO b/TODO
index d19ac0f067..8998fb1a46 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-NuttX TODO List (Last updated March 26, 2017)
+NuttX TODO List (Last updated April 10, 2017)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 This file summarizes known NuttX bugs, limitations, inconsistencies with
@@ -108,9 +108,10 @@ o Task/Scheduler (sched/)
                2. They run in supervisor mode (if applicable), and
                3. They do not obey any setup of PIC or address
                   environments. Do they need to?
-               4. In the case of task_delete() and pthread_cancel(), these
-                  callbacks will run on the thread of execution and address
-                  context of the caller of task.  That is very bad!
+               4. In the case of task_delete() and pthread_cancel() without
+                  defferred cancellation, these callbacks will run on the
+                  thread of execution and address context of the caller of
+                  task_delete() or pthread_cancel().  That is very bad!
 
                The fix for all of these issues it to have the callbacks
                run on the caller's thread as is currently done with

From c36bf090f09c50be36022a4678e4ce4d8f9eb7ee Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Mon, 10 Apr 2017 10:10:41 -0600
Subject: [PATCH 11/12] pthread: Minor logic fix in pthread_mutex_consistent. 
 Updat some comments.

---
 sched/pthread/pthread_mutexconsistent.c | 30 ++++++++++++++++++-------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/sched/pthread/pthread_mutexconsistent.c b/sched/pthread/pthread_mutexconsistent.c
index e374083021..dac4fcf043 100644
--- a/sched/pthread/pthread_mutexconsistent.c
+++ b/sched/pthread/pthread_mutexconsistent.c
@@ -104,13 +104,14 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex)
       DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */
       if (mutex->pid >= 0)
         {
-          /* No.. Verify that the PID still exists.  We may be destroying
-           * the mutex after cancelling a pthread and the mutex may have
-           * been in a bad state owned by the dead pthread.  NOTE: The
-           * folling is unspecified behavior (see pthread_mutex_consistent()).
+          /* No.. Verify that the thread associated with the PID still
+           * exists.  We may be destroying the mutex after cancelling a
+           * pthread and the mutex may have been in a bad state owned by
+           * the dead pthread.  NOTE: The following is unspecified behavior
+           * (see pthread_mutex_consistent()).
            *
            * If the holding thread is still valid, then we should be able to
-           * map its PID to the underlying TCB. That is what sched_gettcb()
+           * map its PID to the underlying TCB.  That is what sched_gettcb()
            * does.
            */
 
@@ -119,6 +120,7 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex)
               /* The thread associated with the PID no longer exists */
 
               mutex->pid    = -1;
+              mutex->flags &= _PTHREAD_MFLAGS_ROBUST;
 #ifdef CONFIG_PTHREAD_MUTEX_TYPES
               mutex->nlocks = 0;
 #endif
@@ -129,11 +131,23 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex)
               status = sem_reset((FAR sem_t *)&mutex->sem, 1);
               ret = (status != OK) ? get_errno() : OK;
             }
+
+          /* Otherwise the mutex is held by some active thread.  Let's not
+           * touch anything!
+           */
+        }
+      else
+        {
+          /* There is no holder of the mutex.  Just make sure the
+           * inconsistent flag is cleared and the number of locks is zero.
+           */
+
+          mutex->flags &= _PTHREAD_MFLAGS_ROBUST;
+#ifdef CONFIG_PTHREAD_MUTEX_TYPES
+          mutex->nlocks = 0;
+#endif
         }
 
-      /* Clear the inconsistent flag in any case */
-
-      mutex->flags &= _PTHREAD_MFLAGS_ROBUST;
       sched_unlock();
       ret = OK;
     }

From c08ba10d325c0d01c5985cd613ab3cc9404e19b6 Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Mon, 10 Apr 2017 14:56:23 -0600
Subject: [PATCH 12/12] include/: Add some definitions needed by
 apps/wireless/wapi

---
 include/nuttx/wireless/wireless.h | 20 ++++++++++++++++++--
 sched/pthread/pthread_cancel.c    |  6 +++---
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/include/nuttx/wireless/wireless.h b/include/nuttx/wireless/wireless.h
index 6ab0b0b3d1..74908e7350 100644
--- a/include/nuttx/wireless/wireless.h
+++ b/include/nuttx/wireless/wireless.h
@@ -203,6 +203,22 @@
 
 #define IW_ESSID_MAX_SIZE   32
 
+/* Modes of operation */
+
+#define IW_MODE_AUTO        0    /* Let the driver decides */
+#define IW_MODE_ADHOC       1    /* Single cell network */
+#define IW_MODE_INFRA       2    /* Multi cell network, roaming, ... */
+#define IW_MODE_MASTER      3    /* Synchronisation master or Access Point */
+#define IW_MODE_REPEAT      4    /* Wireless Repeater (forwarder) */
+#define IW_MODE_SECOND      5    /* Secondary master/repeater (backup) */
+#define IW_MODE_MONITOR     6    /* Passive monitor (listen only) */
+#define IW_MODE_MESH        7    /* Mesh (IEEE 802.11s) network */
+
+/* Frequency flags */
+
+#define IW_FREQ_AUTO        0x00 /* Let the driver decides */
+#define IW_FREQ_FIXED       0x01 /* Force a specific value */
+
 /************************************************************************************
  * Public Types
  ************************************************************************************/
@@ -303,8 +319,8 @@ union iwreq_data
 
 struct iwreq
 {
-  char ifrn_name[IFNAMSIZ];    /* Interface name, e.g. "eth0" */
-  union iwreq_data u;          /* Data payload */
+  char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "eth0" */
+  union iwreq_data u;       /* Data payload */
 };
 
 #endif /* CONFIG_DRIVERS_WIRELESS */
diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c
index e2cad60ebb..20e6f838b7 100644
--- a/sched/pthread/pthread_cancel.c
+++ b/sched/pthread/pthread_cancel.c
@@ -150,9 +150,9 @@ int pthread_cancel(pthread_t thread)
    *
    * REVISIT: In this case, the clean-up callback will execute on the
    * thread of the caller of pthread cancel, not on the thread of
-   * the thread-to-be-canceled.  Is that an issue?  Presumably they
-   * are both within the same group and within the same process address
-   * space.
+   * the thread-to-be-canceled.  This is a problem when deferred
+   * cancellation is not supported because, for example, the clean-up
+   * function will be unable to unlock its own mutexes.
    */
 
   pthread_cleanup_popall(tcb);