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 921c9d1c2fe79e73950dc368fc6638c636a267c6 Author: ImBonkers <[email protected]> AuthorDate: Tue May 19 01:30:59 2026 +0200 boards/arm/stm32n6/nucleo-n657x0-q: Add userleds support. Add the userleds driver and register the /dev/userleds device so the three on-board LEDs (LD5/LD6/LD7) can be driven from userspace when CONFIG_ARCH_LEDS is disabled. Structure mirrors boards/arm/stm32h5/nucleo-h563zi with one adjustment: GPIO writes invert state for the active-low wiring. ARCH_LEDS / USERLED remain mutually exclusive per the H5/H7 convention. stm32_bringup.c now calls userled_lower_initialize("/dev/userleds") when CONFIG_USERLED_LOWER is set; mirrors the H5 bringup hook. Ship a nucleo-n657x0-q:leds defconfig that bundles ARCH_LEDS=n + USERLED + USERLED_LOWER + EXAMPLES_LEDS (LEDSET=0x07) so the userled path is reproducible with one configure step. Tested on Nucleo-N657X0-Q with arm-none-eabi-gcc. Configured with nucleo-n657x0-q:leds, built and flashed: /dev/userleds appears and the 'leds' NSH command cycles Red, Green and Blue independently as expected. Signed-off-by: ImBonkers <[email protected]> --- .../stm32n6/nucleo-n657x0-q/configs/leds/defconfig | 37 ++++++ .../arm/stm32n6/nucleo-n657x0-q/src/CMakeLists.txt | 2 + boards/arm/stm32n6/nucleo-n657x0-q/src/Makefile | 2 + .../stm32n6/nucleo-n657x0-q/src/stm32_bringup.c | 15 +++ .../stm32n6/nucleo-n657x0-q/src/stm32_userleds.c | 128 +++++++++++++++++++++ 5 files changed, 184 insertions(+) diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/configs/leds/defconfig b/boards/arm/stm32n6/nucleo-n657x0-q/configs/leds/defconfig new file mode 100644 index 00000000000..c5fb9d9dcbd --- /dev/null +++ b/boards/arm/stm32n6/nucleo-n657x0-q/configs/leds/defconfig @@ -0,0 +1,37 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="nucleo-n657x0-q" +CONFIG_ARCH_BOARD_NUCLEO_N657X0_Q=y +CONFIG_ARCH_CHIP="stm32n6" +CONFIG_ARCH_CHIP_STM32N657X0=y +CONFIG_ARCH_CHIP_STM32N6=y +CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARD_LOOPSPERMSEC=21000 +CONFIG_BUILTIN=y +CONFIG_EXAMPLES_LEDS=y +CONFIG_EXAMPLES_LEDS_LEDSET=0x07 +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=4096 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_RAM_SIZE=4193280 +CONFIG_RAM_START=0x34000400 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_STM32N6_USART1=y +CONFIG_SYSTEM_NSH=y +CONFIG_USART1_SERIAL_CONSOLE=y +CONFIG_USERLED=y +CONFIG_USERLED_LOWER=y diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/src/CMakeLists.txt b/boards/arm/stm32n6/nucleo-n657x0-q/src/CMakeLists.txt index b623947359b..6e7cc10972e 100644 --- a/boards/arm/stm32n6/nucleo-n657x0-q/src/CMakeLists.txt +++ b/boards/arm/stm32n6/nucleo-n657x0-q/src/CMakeLists.txt @@ -24,6 +24,8 @@ set(SRCS stm32_boot.c stm32_bringup.c) if(CONFIG_ARCH_LEDS) list(APPEND SRCS stm32_autoleds.c) +else() + list(APPEND SRCS stm32_userleds.c) endif() target_sources(board PRIVATE ${SRCS}) diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/src/Makefile b/boards/arm/stm32n6/nucleo-n657x0-q/src/Makefile index 61f4b292f16..74f826721e4 100644 --- a/boards/arm/stm32n6/nucleo-n657x0-q/src/Makefile +++ b/boards/arm/stm32n6/nucleo-n657x0-q/src/Makefile @@ -27,6 +27,8 @@ CSRCS = stm32_boot.c stm32_bringup.c ifeq ($(CONFIG_ARCH_LEDS),y) CSRCS += stm32_autoleds.c +else +CSRCS += stm32_userleds.c endif include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_bringup.c b/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_bringup.c index fb6f9999957..db9bca1a415 100644 --- a/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_bringup.c +++ b/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_bringup.c @@ -26,9 +26,12 @@ #include <nuttx/config.h> +#include <sys/types.h> +#include <syslog.h> #include <debug.h> #include <nuttx/board.h> +#include <nuttx/leds/userled.h> #include "nucleo-n657x0-q.h" @@ -54,5 +57,17 @@ int stm32_bringup(void) { +#if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER) + int ret; + + /* 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 OK; } diff --git a/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_userleds.c b/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_userleds.c new file mode 100644 index 00000000000..a01ffd828eb --- /dev/null +++ b/boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_userleds.c @@ -0,0 +1,128 @@ +/**************************************************************************** + * boards/arm/stm32n6/nucleo-n657x0-q/src/stm32_userleds.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 <stdbool.h> +#include <nuttx/debug.h> + +#include <sys/param.h> + +#include <nuttx/board.h> +#include <arch/board/board.h> + +#include "stm32_gpio.h" +#include "nucleo-n657x0-q.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This array maps an LED number to GPIO pin configuration and is indexed by + * BOARD_LED_<color> + */ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LD5, + GPIO_LD6, + GPIO_LD7, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then the + * board_userled_initialize() is available to initialize the LEDs from user + * application logic. + * + ****************************************************************************/ + +uint32_t board_userled_initialize(void) +{ + int i; + + /* Configure LD5, LD6, and LD7 GPIOs for output */ + + for (i = 0; i < nitems(g_ledcfg); i++) + { + stm32_configgpio(g_ledcfg[i]); + } + + return BOARD_NLEDS; +} + +/**************************************************************************** + * Name: board_userled + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled() is + * available to control the LEDs from user application logic. + * + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if ((unsigned)led < nitems(g_ledcfg)) + { + /* Active Low */ + + stm32_gpiowrite(g_ledcfg[led], !ledon); + } +} + +/**************************************************************************** + * Name: board_userled_all + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled_all() + * is available to control the LED from user application logic. + * + ****************************************************************************/ + +void board_userled_all(uint32_t ledset) +{ + int i; + + /* Configure LD5, LD6, and LD7 GPIOs. Active Low: pin LOW = LED on. */ + + for (i = 0; i < nitems(g_ledcfg); i++) + { + stm32_gpiowrite(g_ledcfg[i], !(ledset & (1 << i))); + } +} + +#endif /* !CONFIG_ARCH_LEDS */
