You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/09/07 17:31:01 UTC

[nuttx] branch master updated: Add userleds and autoleds to the stm32f411e-disco board

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 153137a258 Add userleds and autoleds to the stm32f411e-disco board
153137a258 is described below

commit 153137a2584ce0dcadb6c62ffc2fec64fdb05443
Author: trns1997 <th...@mail.polimi.it>
AuthorDate: Fri Aug 11 09:24:51 2023 +0200

    Add userleds and autoleds to the stm32f411e-disco board
---
 .../stm32/stm32f103-minimum/src/stm32_userleds.c   |   4 +-
 boards/arm/stm32/stm32f411e-disco/include/board.h  |  38 ++++++--
 boards/arm/stm32/stm32f411e-disco/src/Make.defs    |   6 ++
 .../src/stm32_autoleds.c}                          | 108 +++++++++++++--------
 .../arm/stm32/stm32f411e-disco/src/stm32_bringup.c |  10 ++
 .../src/stm32_userleds.c                           |  13 ++-
 .../stm32/stm32f411e-disco/src/stm32f411e-disco.h  |  22 ++++-
 7 files changed, 146 insertions(+), 55 deletions(-)

diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c
index befd887061..fd2c21e022 100644
--- a/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c
+++ b/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c
@@ -59,7 +59,7 @@ uint32_t board_userled_initialize(void)
 {
   int i;
 
-  /* Configure LED1-8 GPIOs for output */
+  /* Configure LED GPIOs for output */
 
   for (i = 0; i < BOARD_NLEDS; i++)
     {
@@ -89,7 +89,7 @@ void board_userled_all(uint32_t ledset)
 {
   int i;
 
-  /* Configure LED1-8 GPIOs for output */
+  /* Configure LED GPIOs for output */
 
   for (i = 0; i < BOARD_NLEDS; i++)
     {
diff --git a/boards/arm/stm32/stm32f411e-disco/include/board.h b/boards/arm/stm32/stm32f411e-disco/include/board.h
index 434549f726..0e24099526 100644
--- a/boards/arm/stm32/stm32f411e-disco/include/board.h
+++ b/boards/arm/stm32/stm32f411e-disco/include/board.h
@@ -297,19 +297,45 @@
 
 /* LEDs
  *
- * The STM32F411E Discovery board has four user leds but only one is
- * configured so far.
- * LD2 connected to PD12.
+ * The STM32F411E Discovery board has four user leds
+ * LD3 connected to PD13.
+ * LD4 connected to PD12.
+ * LD5 connected to PD14.
+ * LD6 connected to PD15.
  */
 
 /* LED index values for use with board_userled() */
 
-#define BOARD_LD2         0
-#define BOARD_NLEDS       1
+#define BOARD_LD3         0
+#define BOARD_LD4         1
+#define BOARD_LD5         2
+#define BOARD_LD6         3
+#define BOARD_NLEDS       4
 
 /* LED bits for use with board_userled_all() */
 
-#define BOARD_LD2_BIT     (1 << BOARD_LD2)
+#define BOARD_LD3_BIT     (1 << BOARD_LD3)
+#define BOARD_LD4_BIT     (1 << BOARD_LD4)
+#define BOARD_LD5_BIT     (1 << BOARD_LD5)
+#define BOARD_LD6_BIT     (1 << BOARD_LD6)
+
+/* If CONFIG_ARCH_LEDs is defined, then NuttX will control the LED on board.
+ * The following definitions describe how NuttX controls
+ * the LEDs:
+ *
+ *   SYMBOL                Meaning                      LED
+ *   -------------------  ----------------------------  --------------------
+ */
+
+#define LED_STARTED       0 /* NuttX has been started    None  */
+#define LED_HEAPALLOCATE  1 /* Heap has been allocated   ON(1),  OFF(2) */
+#define LED_IRQSENABLED   2 /* Interrupts enabled        OFF(1), ON(2)  */
+#define LED_STACKCREATED  3 /* Idle stack created        ON(1), ON(2) */
+#define LED_INIRQ         4 /* In an interrupt          (no change) */
+#define LED_SIGNAL        5 /* In a signal handler      (no change) */
+#define LED_ASSERTION     6 /* An assertion failed       ON(3) */
+#define LED_PANIC         7 /* The system has crashed    FLASH(1,2) */
+#define LED_IDLE          8 /* idle loop                 FLASH(4) */
 
 /* Buttons
  *
diff --git a/boards/arm/stm32/stm32f411e-disco/src/Make.defs b/boards/arm/stm32/stm32f411e-disco/src/Make.defs
index 877b62860c..416fe63646 100644
--- a/boards/arm/stm32/stm32f411e-disco/src/Make.defs
+++ b/boards/arm/stm32/stm32f411e-disco/src/Make.defs
@@ -26,6 +26,12 @@ ifeq ($(CONFIG_NSH_LIBRARY),y)
 CSRCS += stm32_appinit.c
 endif
 
+ifeq ($(CONFIG_ARCH_LEDS),y)
+  CSRCS += stm32_autoleds.c
+else
+  CSRCS += stm32_userleds.c
+endif
+
 ifeq ($(CONFIG_STM32_OTGFS),y)
 CSRCS += stm32_usb.c
 endif
diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c b/boards/arm/stm32/stm32f411e-disco/src/stm32_autoleds.c
similarity index 55%
copy from boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c
copy to boards/arm/stm32/stm32f411e-disco/src/stm32_autoleds.c
index befd887061..abd6b23ce5 100644
--- a/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c
+++ b/boards/arm/stm32/stm32f411e-disco/src/stm32_autoleds.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c
+ * boards/arm/stm32/stm32f411e-disco/src/stm32_autoleds.c
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -28,73 +28,105 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <nuttx/board.h>
 #include <arch/board/board.h>
 
 #include "chip.h"
+#include "arm_internal.h"
 #include "stm32.h"
-#include "stm32f103_minimum.h"
+#include "stm32f411e-disco.h"
 
-#ifndef CONFIG_ARCH_LEDS
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/* This array maps an LED number to GPIO pin configuration */
-
-static const uint32_t g_ledcfg[BOARD_NLEDS] =
-{
-  GPIO_LED1,
-};
+#ifdef CONFIG_ARCH_LEDS
 
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: board_userled_initialize
+ * Name: board_autoled_initialize
  ****************************************************************************/
 
-uint32_t board_userled_initialize(void)
+void board_autoled_initialize(void)
 {
-  int i;
+  /* Configure LED GPIO for output */
 
-  /* Configure LED1-8 GPIOs for output */
-
-  for (i = 0; i < BOARD_NLEDS; i++)
-    {
-      stm32_configgpio(g_ledcfg[i]);
-    }
-
-  return BOARD_NLEDS;
+  stm32_configgpio(GPIO_LD3);
+  stm32_configgpio(GPIO_LD4);
+  stm32_configgpio(GPIO_LD5);
+  stm32_configgpio(GPIO_LD6);
 }
 
 /****************************************************************************
- * Name: board_userled
+ * Name: board_autoled_on
  ****************************************************************************/
 
-void board_userled(int led, bool ledon)
+void board_autoled_on(int led)
 {
-  if ((unsigned)led < BOARD_NLEDS)
+    switch (led)
     {
-      stm32_gpiowrite(g_ledcfg[led], ledon);
+      case LED_HEAPALLOCATE:
+        {
+          stm32_gpiowrite(GPIO_LD3, true);
+          stm32_gpiowrite(GPIO_LD4, false);
+        }
+        break;
+
+      case LED_IRQSENABLED:
+        {
+          stm32_gpiowrite(GPIO_LD3, false);
+          stm32_gpiowrite(GPIO_LD4, true);
+        }
+        break;
+
+      case LED_STACKCREATED:
+        {
+          stm32_gpiowrite(GPIO_LD3, true);
+          stm32_gpiowrite(GPIO_LD4, true);
+        }
+        break;
+
+      case LED_ASSERTION:
+        {
+          stm32_gpiowrite(GPIO_LD5, true);
+        }
+        break;
+
+      case LED_PANIC:
+        {
+          stm32_gpiowrite(GPIO_LD3, true);
+          stm32_gpiowrite(GPIO_LD4, true);
+        }
+        break;
+
+      case LED_IDLE:
+        {
+          stm32_gpiowrite(GPIO_LD6, true);
+        }
+        break;
     }
 }
 
 /****************************************************************************
- * Name: board_userled_all
+ * Name: board_autoled_off
  ****************************************************************************/
 
-void board_userled_all(uint32_t ledset)
+void board_autoled_off(int led)
 {
-  int i;
-
-  /* Configure LED1-8 GPIOs for output */
-
-  for (i = 0; i < BOARD_NLEDS; i++)
+  switch (led)
     {
-      stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
+      case LED_PANIC:
+        {
+          stm32_gpiowrite(GPIO_LD3, false);
+          stm32_gpiowrite(GPIO_LD4, false);
+        }
+        break;
+
+      case LED_IDLE:
+        {
+          stm32_gpiowrite(GPIO_LD6, false);
+        }
+        break;
     }
 }
 
-#endif /* !CONFIG_ARCH_LEDS */
+#endif /* CONFIG_ARCH_LEDS */
diff --git a/boards/arm/stm32/stm32f411e-disco/src/stm32_bringup.c b/boards/arm/stm32/stm32f411e-disco/src/stm32_bringup.c
index 7aefa12e23..62ed147709 100644
--- a/boards/arm/stm32/stm32f411e-disco/src/stm32_bringup.c
+++ b/boards/arm/stm32/stm32f411e-disco/src/stm32_bringup.c
@@ -82,5 +82,15 @@ int stm32_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_USERLED
+  /* Register the LED driver */
+
+  ret = userled_lower_initialize("/dev/userleds");
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret);
+    }
+#endif
+
   return ret;
 }
diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c b/boards/arm/stm32/stm32f411e-disco/src/stm32_userleds.c
similarity index 92%
copy from boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c
copy to boards/arm/stm32/stm32f411e-disco/src/stm32_userleds.c
index befd887061..644208aea6 100644
--- a/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c
+++ b/boards/arm/stm32/stm32f411e-disco/src/stm32_userleds.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c
+ * boards/arm/stm32/stm32f411e-disco/src/stm32_userleds.c
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -32,7 +32,7 @@
 
 #include "chip.h"
 #include "stm32.h"
-#include "stm32f103_minimum.h"
+#include "stm32f411e-disco.h"
 
 #ifndef CONFIG_ARCH_LEDS
 
@@ -44,7 +44,10 @@
 
 static const uint32_t g_ledcfg[BOARD_NLEDS] =
 {
-  GPIO_LED1,
+  GPIO_LD3,
+  GPIO_LD4,
+  GPIO_LD5,
+  GPIO_LD6,
 };
 
 /****************************************************************************
@@ -59,7 +62,7 @@ uint32_t board_userled_initialize(void)
 {
   int i;
 
-  /* Configure LED1-8 GPIOs for output */
+  /* Configure LED GPIOs for output */
 
   for (i = 0; i < BOARD_NLEDS; i++)
     {
@@ -89,7 +92,7 @@ void board_userled_all(uint32_t ledset)
 {
   int i;
 
-  /* Configure LED1-8 GPIOs for output */
+  /* Configure LED GPIOs for output */
 
   for (i = 0; i < BOARD_NLEDS; i++)
     {
diff --git a/boards/arm/stm32/stm32f411e-disco/src/stm32f411e-disco.h b/boards/arm/stm32/stm32f411e-disco/src/stm32f411e-disco.h
index a2dc009f44..daec169d24 100644
--- a/boards/arm/stm32/stm32f411e-disco/src/stm32f411e-disco.h
+++ b/boards/arm/stm32/stm32f411e-disco/src/stm32f411e-disco.h
@@ -36,18 +36,32 @@
 
 /* Configuration ************************************************************/
 
-/* LED.  User LD2: the green LED is a user LED connected to Arduino signal
- * D13 corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on
- * the STM32 target.
+/* User LED.
  *
  * - When the I/O is HIGH value, the LED is on.
  * - When the I/O is LOW, the LED is off.
  */
 
-#define GPIO_LD2 \
+/* User LD3: The orange LED is a user LED connected to the I/O PD13 */
+#define GPIO_LD3 \
+  (GPIO_PORTD | GPIO_PIN13 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | \
+   GPIO_SPEED_50MHz)
+
+/* User LD4: The green LED is a user LED connected to the I/O PD12 */
+#define GPIO_LD4 \
   (GPIO_PORTD | GPIO_PIN12 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | \
    GPIO_SPEED_50MHz)
 
+/* User LD5: The red LED is a user LED connected to the I/O PD14 */
+#define GPIO_LD5 \
+  (GPIO_PORTD | GPIO_PIN14 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | \
+   GPIO_SPEED_50MHz)
+
+/* User LD6: The blue LED is a user LED connected to the I/O PD15 */
+#define GPIO_LD6 \
+  (GPIO_PORTD | GPIO_PIN15 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | \
+   GPIO_SPEED_50MHz)
+
 /* Buttons
  *
  * B1 USER: the user button is connected to the I/O PA0 of the STM32