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 709fcc1dce937ca7ebef81feb973ddb648cafe14
Author: raiden00pl <[email protected]>
AuthorDate: Wed Nov 18 14:18:43 2026 +0100

    boards/stm32n6570-dk: Add the VL53L5CX ToF sensor.
    
    The camera module carries a VL53L5CX on I2C1, with INT on PQ0 and LPn on
    PQ5.  The board powers the module with the IMX335 held in reset and
    registers the sensor as /dev/video1.  INT takes EXTI0, so the TAMP
    button has no interrupt when the sensor is enabled.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 .../arm/stm32n6/boards/stm32n6570-dk/index.rst     |   9 ++
 .../arm/stm32n6/stm32n6570-dk/src/CMakeLists.txt   |   4 +
 boards/arm/stm32n6/stm32n6570-dk/src/Make.defs     |   4 +
 .../arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c  |   8 ++
 .../arm/stm32n6/stm32n6570-dk/src/stm32_buttons.c  |   9 ++
 .../arm/stm32n6/stm32n6570-dk/src/stm32_camera.c   |  79 ++++++++++++
 boards/arm/stm32n6/stm32n6570-dk/src/stm32_tof.c   | 137 +++++++++++++++++++++
 .../arm/stm32n6/stm32n6570-dk/src/stm32n6570-dk.h  |  47 +++++++
 8 files changed, 297 insertions(+)

diff --git a/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst 
b/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst
index ed95a297c47..9d67906bf76 100644
--- a/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst
+++ b/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst
@@ -182,6 +182,15 @@ The GT911 touch controller on I2C2 (interrupt on PQ4) is 
reset at bring-up
 with PQ4 held low, which selects address 0x5d, and registered as
 ``/dev/input0``; ``tc`` prints the touch coordinates.
 
+Time-of-flight sensor
+=====================
+
+The VL53L5CX on the camera module (MB1854) is on I2C1 at 0x29, with INT on
+PQ0 and LPn on PQ5.  The board powers the module through PD2 with the
+IMX335 held in reset (PC8) and registers the sensor as the V4L2 depth
+camera ``/dev/video1`` (Z16, 8x8 or 4x4).  INT uses EXTI0, so the TAMP
+button has no interrupt when the sensor is enabled.
+
 Clocking
 ========
 
diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/CMakeLists.txt 
b/boards/arm/stm32n6/stm32n6570-dk/src/CMakeLists.txt
index 426a98b5728..57d7d13e2b1 100644
--- a/boards/arm/stm32n6/stm32n6570-dk/src/CMakeLists.txt
+++ b/boards/arm/stm32n6/stm32n6570-dk/src/CMakeLists.txt
@@ -40,6 +40,10 @@ if(CONFIG_STM32_LTDC)
   list(APPEND SRCS stm32_lcd.c)
 endif()
 
+if(CONFIG_VIDEO_VL53L5CX)
+  list(APPEND SRCS stm32_camera.c stm32_tof.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/stm32n6570-dk/src/Make.defs 
b/boards/arm/stm32n6/stm32n6570-dk/src/Make.defs
index 519e85a8e2b..0a450b2c9db 100644
--- a/boards/arm/stm32n6/stm32n6570-dk/src/Make.defs
+++ b/boards/arm/stm32n6/stm32n6570-dk/src/Make.defs
@@ -43,6 +43,10 @@ ifeq ($(CONFIG_STM32_LTDC),y)
 CSRCS += stm32_lcd.c
 endif
 
+ifeq ($(CONFIG_VIDEO_VL53L5CX),y)
+CSRCS += stm32_camera.c stm32_tof.c
+endif
+
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c 
b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c
index 59bc463ca88..5ddfd8ebfc0 100644
--- a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c
+++ b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c
@@ -153,6 +153,14 @@ int stm32_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_VIDEO_VL53L5CX
+  ret = stm32_tof_initialize();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: stm32_tof_initialize() failed: %d\n", ret);
+    }
+#endif
+
   UNUSED(ret);
   return OK;
 }
diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_buttons.c 
b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_buttons.c
index a665e5d1bbb..444c3a29c37 100644
--- a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_buttons.c
+++ b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_buttons.c
@@ -124,6 +124,15 @@ int board_button_irq(int id, xcpt_t irqhandler, void *arg)
       return -EINVAL;
     }
 
+#ifdef CONFIG_VIDEO_VL53L5CX
+  /* EXTI0 serves the ToF INT on PQ0 */
+
+  if (id == BUTTON_TAMP)
+    {
+      return -EBUSY;
+    }
+#endif
+
   return stm32_gpiosetevent(g_buttons[id], true, true, true,
                             irqhandler, arg);
 }
diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_camera.c 
b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_camera.c
new file mode 100644
index 00000000000..bf7d898f443
--- /dev/null
+++ b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_camera.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * boards/arm/stm32n6/stm32n6570-dk/src/stm32_camera.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/signal.h>
+
+#include "stm32_gpio.h"
+#include "stm32n6570-dk.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Module supply settling time after enable, with the sensor in reset */
+
+#define CAMERA_POWER_DELAY_US  10000
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static bool g_camera_powered;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_camera_power
+ *
+ * Description:
+ *   Power the camera module with the IMX335 held in reset.  Only the first
+ *   call powers the module.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   None.
+ *
+ ****************************************************************************/
+
+void stm32_camera_power(void)
+{
+  if (!g_camera_powered)
+    {
+      stm32_configgpio(GPIO_CAM_NRST);
+      stm32_configgpio(GPIO_CAM_EN);
+      stm32_gpiowrite(GPIO_CAM_EN, true);
+      nxsig_usleep(CAMERA_POWER_DELAY_US);
+      g_camera_powered = true;
+    }
+}
diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_tof.c 
b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_tof.c
new file mode 100644
index 00000000000..261b9414db3
--- /dev/null
+++ b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_tof.c
@@ -0,0 +1,137 @@
+/****************************************************************************
+ * boards/arm/stm32n6/stm32n6570-dk/src/stm32_tof.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 <errno.h>
+
+#include <nuttx/signal.h>
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/video/vl53l5cx.h>
+
+#include "stm32_exti.h"
+#include "stm32_gpio.h"
+#include "stm32_i2c.h"
+#include "stm32n6570-dk.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* I2C interface start-up after LPn goes high */
+
+#define TOF_LPN_DELAY_US  10000
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int stm32_tof_attach(FAR const struct vl53l5cx_config_s *config,
+                            xcpt_t isr, FAR void *arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct vl53l5cx_config_s g_tof_config =
+{
+  .addr   = TOF_I2C_ADDR,
+  .attach = stm32_tof_attach,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_tof_attach
+ *
+ * Description:
+ *   Attach and enable the INT handler, or disable it with isr NULL.  INT
+ *   falls when a frame is ready.
+ *
+ * Input Parameters:
+ *   config - The sensor configuration
+ *   isr    - The INT handler, or NULL to disable INT
+ *   arg    - The handler argument
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int stm32_tof_attach(FAR const struct vl53l5cx_config_s *config,
+                            xcpt_t isr, FAR void *arg)
+{
+  return stm32_gpiosetevent(GPIO_TOF_INT, false, true, false, isr, arg);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_tof_initialize
+ *
+ * Description:
+ *   Power the camera module, enable the VL53L5CX I2C interface (LPn) and
+ *   register the sensor as a V4L2 depth camera.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int stm32_tof_initialize(void)
+{
+  FAR struct i2c_master_s *i2c;
+  int ret;
+
+  /* Power the module with LPn low, then enable the sensor I2C interface */
+
+  stm32_configgpio(GPIO_TOF_INT);
+  stm32_configgpio(GPIO_TOF_LPN);
+  stm32_camera_power();
+  stm32_gpiowrite(GPIO_TOF_LPN, true);
+  nxsig_usleep(TOF_LPN_DELAY_US);
+
+  ret = -ENODEV;
+  i2c = stm32_i2cbus_initialize(TOF_I2C_BUS);
+  if (i2c != NULL)
+    {
+      ret = vl53l5cx_register(TOF_DEVPATH, i2c, &g_tof_config);
+    }
+
+  if (ret < 0)
+    {
+      stm32_gpiowrite(GPIO_TOF_LPN, false);
+    }
+
+  return ret;
+}
diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/stm32n6570-dk.h 
b/boards/arm/stm32n6/stm32n6570-dk/src/stm32n6570-dk.h
index 8a78676e3ff..a6de5e0ba8b 100644
--- a/boards/arm/stm32n6/stm32n6570-dk/src/stm32n6570-dk.h
+++ b/boards/arm/stm32n6/stm32n6570-dk/src/stm32n6570-dk.h
@@ -86,6 +86,29 @@
                         GPIO_PORTQ | GPIO_PIN4)
 #define TOUCH_I2C_BUS  2
 
+/* Camera connector (MB1854 module): IMX335 NRST on PC8 (active low) and
+ * module enable on PD2 (active high).  The module devices are on I2C1.
+ */
+
+#define GPIO_CAM_NRST  (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHZ | \
+                        GPIO_OUTPUT_CLEAR | GPIO_PORTC | GPIO_PIN8)
+#define GPIO_CAM_EN    (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHZ | \
+                        GPIO_OUTPUT_CLEAR | GPIO_PORTD | GPIO_PIN2)
+
+/* VL53L5CX time-of-flight sensor on the camera module, I2C1 (0x29):
+ * INT on PQ0 (open drain, active low, EXTI0 like the TAMP button) and LPn
+ * on PQ5 (low disables the I2C interface).
+ */
+
+#define GPIO_TOF_INT   (GPIO_INPUT | GPIO_PULLUP | GPIO_EXTI | \
+                        GPIO_PORTQ | GPIO_PIN0)
+#define GPIO_TOF_LPN   (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHZ | \
+                        GPIO_OUTPUT_CLEAR | GPIO_PORTQ | GPIO_PIN5)
+
+#define TOF_I2C_BUS    1
+#define TOF_I2C_ADDR   0x29
+#define TOF_DEVPATH    "/dev/video1"
+
 #ifndef __ASSEMBLY__
 
 /****************************************************************************
@@ -132,5 +155,29 @@ void stm32_spiinitialize(void);
 void stm32_spiregister(void);
 #endif
 
+/****************************************************************************
+ * Name: stm32_camera_power
+ *
+ * Description:
+ *   Power the camera module with the IMX335 held in reset.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_VIDEO_VL53L5CX
+void stm32_camera_power(void);
+#endif
+
+/****************************************************************************
+ * Name: stm32_tof_initialize
+ *
+ * Description:
+ *   Power the VL53L5CX and register it as a V4L2 depth camera.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_VIDEO_VL53L5CX
+int stm32_tof_initialize(void);
+#endif
+
 #endif /* __ASSEMBLY__ */
 #endif /* __BOARDS_ARM_STM32N6_STM32N6570_DK_SRC_STM32N6570_DK_H */

Reply via email to