This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 79787882f5c2c52c08590bfdaf8df7ee85d60bfa Author: raiden00pl <[email protected]> AuthorDate: Wed Nov 25 09:17:12 2026 +0100 boards/stm32n6570-dk: Add the IMX335 camera and the camera configuration. Power the MB1854 camera module and register the IMX335 and the DCMIPP at bring-up. The camera configuration shows the preview on the LCD with the camera example. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: raiden00pl <[email protected]> --- .../arm/stm32n6/boards/stm32n6570-dk/index.rst | 16 +++ .../stm32n6/stm32n6570-dk/configs/camera/defconfig | 83 ++++++++++++++++ boards/arm/stm32n6/stm32n6570-dk/include/board.h | 32 +++++- .../arm/stm32n6/stm32n6570-dk/src/CMakeLists.txt | 2 + boards/arm/stm32n6/stm32n6570-dk/src/Make.defs | 2 + .../arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c | 10 ++ .../arm/stm32n6/stm32n6570-dk/src/stm32_camera.c | 107 +++++++++++++++++++++ .../arm/stm32n6/stm32n6570-dk/src/stm32n6570-dk.h | 16 ++- 8 files changed, 266 insertions(+), 2 deletions(-) diff --git a/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst b/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst index 9f457b16868..651ccf07799 100644 --- a/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst +++ b/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst @@ -182,6 +182,16 @@ 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. +Camera module +============= + +The MB1854 module (Sony IMX335) is on the CSI-2 host (two lanes) and I2C1 +(0x1a). PD2 enables the module and PC8 releases the sensor reset. The +DCMIPP converts the raw frames to RGB565 and scales them, with automatic +exposure (``CONFIG_STM32_DCMIPP_AE``) and white balance +(``CONFIG_STM32_DCMIPP_AWB``), switched off with ``V4L2_CID_EXPOSURE_AUTO`` +and ``V4L2_CID_AUTO_WHITE_BALANCE``. + Time-of-flight sensor ===================== @@ -270,6 +280,12 @@ lvgl with ``lvgldemo &``. The image is close to the 511 KiB limit of the boot ROM, so LVGL logging and extra fonts are left out. +camera +------ + +``fb`` plus the IMX335 camera and the ``camera`` example, see `Camera module`_. +``camera 0`` shows a 320x240 preview on the LCD. + jumbo ----- diff --git a/boards/arm/stm32n6/stm32n6570-dk/configs/camera/defconfig b/boards/arm/stm32n6/stm32n6570-dk/configs/camera/defconfig new file mode 100644 index 00000000000..e3f16c59cfd --- /dev/null +++ b/boards/arm/stm32n6/stm32n6570-dk/configs/camera/defconfig @@ -0,0 +1,83 @@ +# +# 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_NXFONTS_DISABLE_16BPP is not set +# CONFIG_NX_DISABLE_16BPP is not set +# CONFIG_STM32_LTDC_L1_CHROMAKEYEN is not set +# CONFIG_STM32_LTDC_L2 is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="stm32n6570-dk" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_STM32N6570_DK=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_CHIP="stm32n6" +CONFIG_ARCH_CHIP_STM32=y +CONFIG_ARCH_CHIP_STM32N657X0=y +CONFIG_ARCH_CHIP_STM32N6=y +CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_ARCH_IRQBUTTONS=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARD_LOOPSPERMSEC=84000 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DRIVERS_VIDEO=y +CONFIG_EXAMPLES_ALARM=y +CONFIG_EXAMPLES_CAMERA=y +CONFIG_EXAMPLES_CAMERA_OUTPUT_LCD=y +CONFIG_EXAMPLES_CAMERA_STACKSIZE=8192 +CONFIG_EXAMPLES_FB=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=4096 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INPUT=y +CONFIG_INPUT_BUTTONS=y +CONFIG_INPUT_BUTTONS_LOWER=y +CONFIG_MQ_MAXMSGSIZE=64 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_NX=y +CONFIG_NXFONT_SANS23X27=y +CONFIG_NX_BLOCKING=y +CONFIG_RAM_SIZE=2620416 +CONFIG_RAM_START=0x34180400 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_RTC_ALARM=y +CONFIG_RTC_DATETIME=y +CONFIG_RTC_DRIVER=y +CONFIG_RTC_NALARMS=2 +CONFIG_RTC_PERIODIC=y +CONFIG_SCHED_WAITPID=y +CONFIG_SPITOOL_MAXBUS=5 +CONFIG_STM32N6_DEBUG=y +CONFIG_STM32_DCMIPP=y +CONFIG_STM32_DMA1=y +CONFIG_STM32_I2C1=y +CONFIG_STM32_I2C2=y +CONFIG_STM32_I2C4=y +CONFIG_STM32_LTDC=y +CONFIG_STM32_LTDC_FB_BASE=0x34080000 +CONFIG_STM32_LTDC_FB_SIZE=768000 +CONFIG_STM32_RNG=y +CONFIG_STM32_RTC=y +CONFIG_STM32_SPI5=y +CONFIG_STM32_USART1=y +CONFIG_STM32_USART2=y +CONFIG_SYSTEM_I2CTOOL=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_SPITOOL=y +CONFIG_USART1_SERIAL_CONSOLE=y +CONFIG_USERLED=y +CONFIG_USERLED_LOWER=y +CONFIG_VIDEO_FB=y +CONFIG_VIDEO_IMX335=y +CONFIG_VIDEO_STREAM=y diff --git a/boards/arm/stm32n6/stm32n6570-dk/include/board.h b/boards/arm/stm32n6/stm32n6570-dk/include/board.h index 648c5336593..ce5d02795db 100644 --- a/boards/arm/stm32n6/stm32n6570-dk/include/board.h +++ b/boards/arm/stm32n6/stm32n6570-dk/include/board.h @@ -59,6 +59,8 @@ * IC11 /6 = 400 MHz / * IC4 /12 = 200 MHz -> SDMMC2 kernel clock * IC16 /96 = 25 MHz -> LTDC pixel clock + * IC17 /8 = 300 MHz -> DCMIPP kernel clock + * IC18 /120 = 20 MHz -> CSI-2 D-PHY configuration clock * PLL2 = HSI / 2 * 48 = 1536 MHz (audio kernel clocks) * PLL3 = HSE / 3 * 125 = 2000 MHz (LTDC) * PLL4 = HSI / 4 * 75 = 1200 MHz (I2C, LTDC) @@ -117,6 +119,15 @@ #define STM32_IC4_SRC RCC_ICCFGR_SEL_PLL1 #define STM32_IC4_DIV 12 +/* IC17 = PLL1 / 8 = 300 MHz -> DCMIPP kernel clock + * IC18 = PLL1 / 120 = 20 MHz -> CSI-2 D-PHY configuration clock + */ + +#define STM32_IC17_SRC RCC_ICCFGR_SEL_PLL1 +#define STM32_IC17_DIV 8 +#define STM32_IC18_SRC RCC_ICCFGR_SEL_PLL1 +#define STM32_IC18_DIV 120 + #define STM32_CPUCLK_FREQUENCY (STM32_PLL1_FREQUENCY / STM32_IC1_DIV) #define STM32_SYSCLK_FREQUENCY (STM32_PLL1_FREQUENCY / STM32_IC2_DIV) #define STM32_RCC_CFGR2_HPRE RCC_CFGR2_HPRE_SYSCLKd2 @@ -133,6 +144,8 @@ * IC6 /12 = 66.7 MHz > SYSCLK components (SYSSW IC2_IC6_IC11) * IC11 /8 = 100 MHz / * IC4 /4 = 200 MHz -> SDMMC2 kernel clock + * IC17 /3 = 267 MHz -> DCMIPP kernel clock + * IC18 /40 = 20 MHz -> CSI-2 D-PHY configuration clock * HPRE /2 = 50 MHz -> HCLK * PPREx /1 = 50 MHz -> PCLK1/2/4/5 * TIMPRE /1 = 100 MHz -> timer kernel clock @@ -164,6 +177,15 @@ #define STM32_IC4_SRC RCC_ICCFGR_SEL_PLL1 #define STM32_IC4_DIV 4 +/* IC17 = PLL1 / 3 = 267 MHz -> DCMIPP kernel clock + * IC18 = PLL1 / 40 = 20 MHz -> CSI-2 D-PHY configuration clock + */ + +#define STM32_IC17_SRC RCC_ICCFGR_SEL_PLL1 +#define STM32_IC17_DIV 3 +#define STM32_IC18_SRC RCC_ICCFGR_SEL_PLL1 +#define STM32_IC18_DIV 40 + #define STM32_CPUCLK_FREQUENCY (STM32_PLL1_FREQUENCY / STM32_IC1_DIV) #define STM32_SYSCLK_FREQUENCY (STM32_PLL1_FREQUENCY / STM32_IC2_DIV) #define STM32_RCC_CFGR2_HPRE RCC_CFGR2_HPRE_SYSCLKd2 @@ -215,6 +237,10 @@ #define STM32_RCC_CCIPR4_LTDCSEL RCC_CCIPR4_LTDCSEL_IC16 +/* DCMIPP kernel clock: IC17 */ + +#define STM32_RCC_CCIPR1_DCMIPPSEL RCC_CCIPR1_DCMIPPSEL_IC17 + /* USB1 and USB2 OTG HS PHY reference clocks: HSE oscillator / 2 = * 24 MHz. Not available with the HSI clock tree. */ @@ -236,7 +262,11 @@ #define BOARD_PWR_VDDIO (PWR_SVMCR3_VDDIO2SV | PWR_SVMCR3_VDDIO3SV | \ PWR_SVMCR3_VDDIO2VRSEL | PWR_SVMCR3_VDDIO3VRSEL) -/* VDDIO5 supplies the microSD pads (SDMMC2) in its 3.3 V range */ +/* VDDIO4 supplies the camera control pads (PC8 NRST) and VDDIO5 the + * microSD pads (SDMMC2), both in their 3.3 V range. + */ + +#define BOARD_PWR_VDDIO4 PWR_SVMCR1_VDDIO4SV #define BOARD_PWR_VDDIO5 PWR_SVMCR2_VDDIO5SV diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/CMakeLists.txt b/boards/arm/stm32n6/stm32n6570-dk/src/CMakeLists.txt index b5c41b524eb..083c3da7a22 100644 --- a/boards/arm/stm32n6/stm32n6570-dk/src/CMakeLists.txt +++ b/boards/arm/stm32n6/stm32n6570-dk/src/CMakeLists.txt @@ -42,6 +42,8 @@ endif() if(CONFIG_VIDEO_VL53L5CX) list(APPEND SRCS stm32_camera.c stm32_tof.c) +elseif(CONFIG_STM32_DCMIPP) + list(APPEND SRCS stm32_camera.c) endif() if(CONFIG_STM32_SDMMC2) diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/Make.defs b/boards/arm/stm32n6/stm32n6570-dk/src/Make.defs index f689931b36a..f643bece32e 100644 --- a/boards/arm/stm32n6/stm32n6570-dk/src/Make.defs +++ b/boards/arm/stm32n6/stm32n6570-dk/src/Make.defs @@ -45,6 +45,8 @@ endif ifeq ($(CONFIG_VIDEO_VL53L5CX),y) CSRCS += stm32_camera.c stm32_tof.c +else ifeq ($(CONFIG_STM32_DCMIPP),y) +CSRCS += stm32_camera.c endif ifeq ($(CONFIG_STM32_SDMMC2),y) diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c index 125693f9879..6562fc5d197 100644 --- a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c +++ b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c @@ -174,6 +174,16 @@ int stm32_bringup(void) } #endif +#if defined(CONFIG_STM32_DCMIPP) && defined(CONFIG_VIDEO_IMX335) + /* Register the IMX335 camera and the DCMIPP */ + + ret = stm32_camera_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_camera_initialize() failed: %d\n", ret); + } +#endif + #ifdef CONFIG_VIDEO_VL53L5CX ret = stm32_tof_initialize(); if (ret < 0) diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_camera.c b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_camera.c index bf7d898f443..6f0f99cc18d 100644 --- a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_camera.c +++ b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_camera.c @@ -27,10 +27,16 @@ #include <nuttx/config.h> #include <stdbool.h> +#include <errno.h> #include <nuttx/signal.h> +#include <nuttx/i2c/i2c_master.h> +#include <nuttx/video/imgsensor.h> +#include <nuttx/video/imx335.h> #include "stm32_gpio.h" +#include "stm32_i2c.h" +#include "stm32_dcmipp.h" #include "stm32n6570-dk.h" /**************************************************************************** @@ -41,12 +47,66 @@ #define CAMERA_POWER_DELAY_US 10000 +#if defined(CONFIG_STM32_DCMIPP) && defined(CONFIG_VIDEO_IMX335) +# define HAVE_IMX335 1 +#endif + +/* IMX335 reset release to the first I2C access */ + +#define CAMERA_RESET_DELAY_US 600 + +/* The MB1854 module has its own 24 MHz oscillator for the IMX335 */ + +#define CAMERA_INCK 24000000 + /**************************************************************************** * Private Data ****************************************************************************/ static bool g_camera_powered; +#ifdef HAVE_IMX335 + +/* IMX335: 2592x1944 RAW10 RGGB on two CSI-2 lanes. The D-PHY receives the + * sensor without errors when set to 800 to 1600 Mbit/s per lane (measured on + * the DK); 1200 is the middle of that range. The black level of 12 (8-bit + * scale) is the dark level measured with the lens covered at the minimum + * gain and exposure. Unity white balance gains and an identity colour + * matrix. The sensor gain has 0.3 dB steps: 20 steps double it. + */ + +static const struct stm32_dcmipp_config_s g_camera_config = +{ + .width = 2592, + .height = 1944, + .pixelformat = IMGSENSOR_PIX_FMT_SRGGB10P, + .lanes = 2, + .bitrate = 1200, + .bpp = 10, + .bayer = STM32_DCMIPP_BAYER_RGGB, + .blacklevel = 12, + .gain = + { + 128, 128, 128 + }, + .ccm = + { + { + 256, 0, 0 + }, + { + 0, 256, 0 + }, + { + 0, 0, 256 + }, + }, + .gamma = true, + .gainsteps = 20, +}; + +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -77,3 +137,50 @@ void stm32_camera_power(void) g_camera_powered = true; } } + +#ifdef HAVE_IMX335 + +/**************************************************************************** + * Name: stm32_camera_initialize + * + * Description: + * Power the camera module, release the IMX335 reset and register the + * sensor and the DCMIPP. + * + * Input Parameters: + * None. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int stm32_camera_initialize(void) +{ + FAR struct i2c_master_s *i2c; + FAR struct imgsensor_s *sensor; + + /* Power the module, then release the sensor reset */ + + stm32_camera_power(); + stm32_gpiowrite(GPIO_CAM_NRST, true); + nxsig_usleep(CAMERA_RESET_DELAY_US); + + i2c = stm32_i2cbus_initialize(CAMERA_I2C_BUS); + if (i2c == NULL) + { + return -ENODEV; + } + + sensor = imx335_initialize(i2c, CAMERA_INCK); + if (sensor == NULL) + { + return -ENODEV; + } + + /* The DCMIPP registers itself in front of the raw sensor */ + + return stm32_dcmipp_initialize(&g_camera_config, sensor); +} + +#endif /* HAVE_IMX335 */ diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/stm32n6570-dk.h b/boards/arm/stm32n6/stm32n6570-dk/src/stm32n6570-dk.h index 27c96f56901..9ad89b08b9d 100644 --- a/boards/arm/stm32n6/stm32n6570-dk/src/stm32n6570-dk.h +++ b/boards/arm/stm32n6/stm32n6570-dk/src/stm32n6570-dk.h @@ -94,6 +94,7 @@ 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) +#define CAMERA_I2C_BUS 1 /* 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 @@ -189,10 +190,23 @@ void stm32_spiregister(void); * ****************************************************************************/ -#ifdef CONFIG_VIDEO_VL53L5CX +#if defined(CONFIG_VIDEO_VL53L5CX) || defined(CONFIG_STM32_DCMIPP) void stm32_camera_power(void); #endif +/**************************************************************************** + * Name: stm32_camera_initialize + * + * Description: + * Power up the camera module and register the IMX335 sensor and the + * DCMIPP capture interface. + * + ****************************************************************************/ + +#if defined(CONFIG_STM32_DCMIPP) && defined(CONFIG_VIDEO_IMX335) +int stm32_camera_initialize(void); +#endif + /**************************************************************************** * Name: stm32_tof_initialize *
