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

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

commit 58c07d00d15fb94a4480926f5f96040a0d056272
Author: ImBonkers <[email protected]>
AuthorDate: Tue May 19 01:33:26 2026 +0200

    boards/arm/stm32n6/nucleo-n657x0-q: Add autoleds support.
    
    Add the autoleds driver for the three on-board user LEDs (LD5 red
    PG10, LD6 green PG0, LD7 blue PG8; all active-low).  Structure
    mirrors boards/arm/stm32h5/nucleo-h563zi with the polarity and
    initial-OFF state corrected for the active-low wiring.
    
    * boards/Kconfig: ARCH_BOARD_NUCLEO_N657X0_Q selects ARCH_HAVE_LEDS
      so the ARCH_LEDS prompt becomes available.
    * arch/arm/src/stm32n6/stm32_idle.c: include <arch/board/board.h>
      so LED_IDLE is defined and up_idle() actually calls into the
      autoleds driver around WFI.
    
    The existing nsh and ostest defconfigs do not pin CONFIG_ARCH_LEDS
    and therefore inherit its Kconfig default (y when ARCH_HAVE_LEDS is
    selected), so after this patch they include the autoleds driver by
    default.  This matches the convention on the comparable H5 and H7
    Nucleo defconfigs, which also leave ARCH_LEDS at its default.
    
    Tested on Nucleo-N657X0-Q: nsh and ostest still build, flash and
    run.  With CONFIG_ARCH_LEDS=y, green is steady at the NSH idle
    prompt; red pulses on each IRQ but the on-time is too brief to be
    clearly visible to the eye.
    
    Signed-off-by: ImBonkers <[email protected]>
---
 arch/arm/src/stm32n6/stm32_idle.c                  |   2 +
 boards/Kconfig                                     |   1 +
 boards/arm/stm32n6/nucleo-n657x0-q/include/board.h |  51 ++++++
 .../arm/stm32n6/nucleo-n657x0-q/src/CMakeLists.txt |   4 +
 boards/arm/stm32n6/nucleo-n657x0-q/src/Makefile    |   4 +
 .../stm32n6/nucleo-n657x0-q/src/nucleo-n657x0-q.h  |  25 +++
 .../stm32n6/nucleo-n657x0-q/src/stm32_autoleds.c   | 188 +++++++++++++++++++++
 .../arm/stm32n6/nucleo-n657x0-q/src/stm32_boot.c   |   5 +
 8 files changed, 280 insertions(+)

diff --git a/arch/arm/src/stm32n6/stm32_idle.c 
b/arch/arm/src/stm32n6/stm32_idle.c
index 9cfee2870a5..dfbd263ba31 100644
--- a/arch/arm/src/stm32n6/stm32_idle.c
+++ b/arch/arm/src/stm32n6/stm32_idle.c
@@ -29,6 +29,8 @@
 #include <nuttx/arch.h>
 #include <nuttx/board.h>
 
+#include <arch/board/board.h>
+
 #include "nvic.h"
 #include "arm_internal.h"
 
diff --git a/boards/Kconfig b/boards/Kconfig
index 2f4e6e9cb44..65d6d76cc97 100644
--- a/boards/Kconfig
+++ b/boards/Kconfig
@@ -3165,6 +3165,7 @@ config ARCH_BOARD_NUCLEO_H563ZI
 config ARCH_BOARD_NUCLEO_N657X0_Q
        bool "NUCLEO_N657X0_Q"
        depends on ARCH_CHIP_STM32N657X0
+       select ARCH_HAVE_LEDS
        ---help---
                STMicro Nucleo-N657X0-Q development board based on the STMicro
                STM32N657X0 MCU (Cortex-M55).  Boots in DEV mode by loading
diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/include/board.h 
b/boards/arm/stm32n6/nucleo-n657x0-q/include/board.h
index 0dfe61e2af1..997a4137f55 100644
--- a/boards/arm/stm32n6/nucleo-n657x0-q/include/board.h
+++ b/boards/arm/stm32n6/nucleo-n657x0-q/include/board.h
@@ -81,6 +81,57 @@
 #define BOARD_PWR_VDDIO  (PWR_SVMCR3_VDDIO2SV    | PWR_SVMCR3_VDDIO3SV | \
                           PWR_SVMCR3_VDDIO2VRSEL | PWR_SVMCR3_VDDIO3VRSEL)
 
+/* LED definitions **********************************************************/
+
+/* The Nucleo-N657X0-Q has three user LEDs (UM3417 silkscreen):
+ *
+ *   LD5  PG10  Red
+ *   LD6  PG0   Green
+ *   LD7  PG8   Blue
+ *
+ * They are not used by the board port unless CONFIG_ARCH_LEDS is defined.
+ * In that case the usage by the board port is defined in include/board.h
+ * and src/stm32_autoleds.c.  The LEDs are used to encode OS-related events
+ * as follows.
+ *
+ * The following definitions are used to access individual LEDs.
+ */
+
+/* LED index values for use with board_userled() */
+
+#define BOARD_LED1        0
+#define BOARD_LED2        1
+#define BOARD_LED3        2
+#define BOARD_NLEDS       3
+
+#define BOARD_LED_RED     BOARD_LED1
+#define BOARD_LED_GREEN   BOARD_LED2
+#define BOARD_LED_BLUE    BOARD_LED3
+
+/* LED bits for use with board_userled_all() */
+
+#define BOARD_LED1_BIT    (1 << BOARD_LED1)
+#define BOARD_LED2_BIT    (1 << BOARD_LED2)
+#define BOARD_LED3_BIT    (1 << BOARD_LED3)
+
+/* If CONFIG_ARCH_LEDS is defined, the LEDs are used to encode OS-related
+ * events as follows:
+ *
+ *   SYMBOL                     Meaning                      LED state
+ *                                                        Red   Green Blue
+ *   ----------------------  --------------------------  ------ ------ ----
+ */
+
+#define LED_STARTED        0 /* NuttX has been started   OFF    OFF   OFF  */
+#define LED_HEAPALLOCATE   1 /* Heap has been allocated  OFF    OFF   ON   */
+#define LED_IRQSENABLED    2 /* Interrupts enabled       OFF    ON    OFF  */
+#define LED_STACKCREATED   3 /* Idle stack created       OFF    ON    ON   */
+#define LED_INIRQ          4 /* In an interrupt          N/C    N/C   GLOW */
+#define LED_SIGNAL         5 /* In a signal handler      N/C    GLOW  N/C  */
+#define LED_ASSERTION      6 /* An assertion failed      GLOW   N/C   GLOW */
+#define LED_PANIC          7 /* The system has crashed   Blink  OFF   N/C  */
+#define LED_IDLE           8 /* MCU is in sleep mode     ON     OFF   OFF  */
+
 /* Alternate function pin selections ****************************************/
 
 /* USART1 GPIOs *************************************************************/
diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/src/CMakeLists.txt 
b/boards/arm/stm32n6/nucleo-n657x0-q/src/CMakeLists.txt
index 0146628e33d..b623947359b 100644
--- a/boards/arm/stm32n6/nucleo-n657x0-q/src/CMakeLists.txt
+++ b/boards/arm/stm32n6/nucleo-n657x0-q/src/CMakeLists.txt
@@ -22,6 +22,10 @@
 
 set(SRCS stm32_boot.c stm32_bringup.c)
 
+if(CONFIG_ARCH_LEDS)
+  list(APPEND SRCS stm32_autoleds.c)
+endif()
+
 target_sources(board PRIVATE ${SRCS})
 
 set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")
diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/src/Makefile 
b/boards/arm/stm32n6/nucleo-n657x0-q/src/Makefile
index 6bcfb95b605..61f4b292f16 100644
--- a/boards/arm/stm32n6/nucleo-n657x0-q/src/Makefile
+++ b/boards/arm/stm32n6/nucleo-n657x0-q/src/Makefile
@@ -25,4 +25,8 @@
 ASRCS =
 CSRCS = stm32_boot.c stm32_bringup.c
 
+ifeq ($(CONFIG_ARCH_LEDS),y)
+CSRCS += stm32_autoleds.c
+endif
+
 include $(TOPDIR)/boards/Board.mk
diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/src/nucleo-n657x0-q.h 
b/boards/arm/stm32n6/nucleo-n657x0-q/src/nucleo-n657x0-q.h
index 99c6e3e5476..af0f6bfb374 100644
--- a/boards/arm/stm32n6/nucleo-n657x0-q/src/nucleo-n657x0-q.h
+++ b/boards/arm/stm32n6/nucleo-n657x0-q/src/nucleo-n657x0-q.h
@@ -31,6 +31,31 @@
 #include <nuttx/compiler.h>
 #include <stdint.h>
 
+#include "stm32_gpio.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* LED definitions **********************************************************/
+
+/* The Nucleo-N657X0-Q has three user LEDs (UM3417 silkscreen):
+ *
+ *   LD5  PG10  Red
+ *   LD6  PG0   Green
+ *   LD7  PG8   Blue
+ *
+ * - When the I/O is LOW,  the LED is on.
+ * - When the I/O is HIGH, the LED is off.
+ */
+
+#define GPIO_LD5       (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHZ | \
+                        GPIO_OUTPUT_SET | GPIO_PORTG | GPIO_PIN10)
+#define GPIO_LD6       (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHZ | \
+                        GPIO_OUTPUT_SET | GPIO_PORTG | GPIO_PIN0)
+#define GPIO_LD7       (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHZ | \
+                        GPIO_OUTPUT_SET | GPIO_PORTG | GPIO_PIN8)
+
 /****************************************************************************
  * Public Types
  ****************************************************************************/
diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_autoleds.c 
b/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_autoleds.c
new file mode 100644
index 00000000000..ae709119698
--- /dev/null
+++ b/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_autoleds.c
@@ -0,0 +1,188 @@
+/****************************************************************************
+ * boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_autoleds.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <nuttx/debug.h>
+
+#include <sys/param.h>
+
+#include <nuttx/board.h>
+
+#include "chip.h"
+#include "arm_internal.h"
+#include "stm32_gpio.h"
+#include "nucleo-n657x0-q.h"
+
+#include <arch/board/board.h>
+
+#ifdef CONFIG_ARCH_LEDS
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Indexed by BOARD_LED_<color> */
+
+static const uint32_t g_ledmap[BOARD_NLEDS] =
+{
+  GPIO_LD5,
+  GPIO_LD6,
+  GPIO_LD7,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void phy_set_led(int led, bool state)
+{
+  /* Active Low */
+
+  stm32_gpiowrite(g_ledmap[led], !state);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_autoled_initialize
+ ****************************************************************************/
+
+void board_autoled_initialize(void)
+{
+  int i;
+
+  /* Configure the LD5, LD6, and LD7 GPIOs for output. Initial state is OFF */
+
+  for (i = 0; i < nitems(g_ledmap); i++)
+    {
+      stm32_configgpio(g_ledmap[i]);
+      stm32_gpiowrite(g_ledmap[i], true);
+    }
+}
+
+/****************************************************************************
+ * Name: board_autoled_on
+ ****************************************************************************/
+
+void board_autoled_on(int led)
+{
+  switch (led)
+    {
+    case LED_HEAPALLOCATE:
+      phy_set_led(BOARD_LED_GREEN, false);
+      phy_set_led(BOARD_LED_BLUE,  false);
+      phy_set_led(BOARD_LED_RED,   false);
+      break;
+
+    case LED_IDLE:
+      phy_set_led(BOARD_LED_GREEN, true);
+      phy_set_led(BOARD_LED_BLUE,  false);
+      phy_set_led(BOARD_LED_RED,   false);
+     break;
+
+    case LED_IRQSENABLED:
+      phy_set_led(BOARD_LED_GREEN, false);
+      phy_set_led(BOARD_LED_BLUE,  true);
+      phy_set_led(BOARD_LED_RED,   false);
+      break;
+
+    case LED_STACKCREATED:
+      phy_set_led(BOARD_LED_GREEN, true);
+      phy_set_led(BOARD_LED_BLUE,  true);
+      phy_set_led(BOARD_LED_RED,   false);
+     break;
+
+    case LED_INIRQ:
+      phy_set_led(BOARD_LED_GREEN, false);
+      phy_set_led(BOARD_LED_BLUE,  false);
+      phy_set_led(BOARD_LED_RED,   true);
+      break;
+
+    case LED_SIGNAL:
+      phy_set_led(BOARD_LED_GREEN, true);
+      phy_set_led(BOARD_LED_BLUE,  false);
+      phy_set_led(BOARD_LED_RED,   true);
+      break;
+
+    case LED_ASSERTION:
+      phy_set_led(BOARD_LED_GREEN, false);
+      phy_set_led(BOARD_LED_BLUE,  true);
+      phy_set_led(BOARD_LED_RED,   true);
+      break;
+
+    case LED_PANIC:
+      phy_set_led(BOARD_LED_GREEN, true);
+      phy_set_led(BOARD_LED_BLUE,  true);
+      phy_set_led(BOARD_LED_RED,   true);
+      break;
+
+    default:
+      break;
+    }
+}
+
+/****************************************************************************
+ * Name: board_autoled_off
+ ****************************************************************************/
+
+void board_autoled_off(int led)
+{
+  switch (led)
+    {
+    case LED_SIGNAL:
+      phy_set_led(BOARD_LED_RED,   false);
+      phy_set_led(BOARD_LED_GREEN, false);
+      break;
+
+    case LED_INIRQ:
+      phy_set_led(BOARD_LED_RED,   false);
+      break;
+
+    case LED_ASSERTION:
+      phy_set_led(BOARD_LED_BLUE,  false);
+      break;
+
+    case LED_PANIC:
+      phy_set_led(BOARD_LED_GREEN, false);
+      phy_set_led(BOARD_LED_RED,   false);
+      phy_set_led(BOARD_LED_BLUE,  false);
+      break;
+
+    case LED_IDLE:
+      phy_set_led(BOARD_LED_GREEN, false);
+      break;
+
+    default:
+      break;
+    }
+}
+
+#endif /* CONFIG_ARCH_LEDS */
diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_boot.c 
b/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_boot.c
index 6bb40b35dc5..206317b2364 100644
--- a/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_boot.c
+++ b/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_boot.c
@@ -52,6 +52,11 @@
 
 void stm32_board_initialize(void)
 {
+#ifdef CONFIG_ARCH_LEDS
+  /* Configure on-board LEDs if LED support has been selected. */
+
+  board_autoled_initialize();
+#endif
 }
 
 /****************************************************************************

Reply via email to