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 ee643a53ea28e6c74bd28aac7114ddfb5f033f3a
Author: Hoa Bui <[email protected]>
AuthorDate: Fri Nov 20 10:38:23 2026 +0000

    boards/arm/rzv2h: Add QSPI flash support for RZV2H-EVK and RZV2H-RDK
    
    Add the xSPI0 pin definitions to board.h, configure the pins at boot,
    register the on-board Micron MT25QU512ABB QSPI NOR flash as an MTD device
    during board bring-up, and add the nsh-xspi defconfig. The board Kconfig
    selects the chip select, the read protocol, flash partitioning and an
    optional syslog file on the flash.
    
    Signed-off-by: Hoa Bui <[email protected]>
---
 boards/arm/rzv2h/rzv2h-evk/Kconfig                 | 134 +++++++
 .../arm/rzv2h/rzv2h-evk/configs/nsh-xspi/defconfig |  52 +++
 boards/arm/rzv2h/rzv2h-evk/include/board.h         |  27 ++
 boards/arm/rzv2h/rzv2h-evk/src/CMakeLists.txt      |   4 +
 boards/arm/rzv2h/rzv2h-evk/src/Makefile            |   4 +
 boards/arm/rzv2h/rzv2h-evk/src/rzv2h-evk.h         |  28 ++
 boards/arm/rzv2h/rzv2h-evk/src/rzv2h_boot.c        |   6 +
 boards/arm/rzv2h/rzv2h-evk/src/rzv2h_bringup.c     |  10 +
 boards/arm/rzv2h/rzv2h-evk/src/rzv2h_qspi.c        | 391 +++++++++++++++++++++
 boards/arm/rzv2h/rzv2h-rdk/Kconfig                 | 134 +++++++
 .../arm/rzv2h/rzv2h-rdk/configs/nsh-xspi/defconfig |  52 +++
 boards/arm/rzv2h/rzv2h-rdk/include/board.h         |  27 ++
 boards/arm/rzv2h/rzv2h-rdk/src/CMakeLists.txt      |   4 +
 boards/arm/rzv2h/rzv2h-rdk/src/Makefile            |   4 +
 boards/arm/rzv2h/rzv2h-rdk/src/rzv2h-rdk.h         |  28 ++
 boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_boot.c        |   6 +
 boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_bringup.c     |  10 +
 boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_qspi.c        | 391 +++++++++++++++++++++
 18 files changed, 1312 insertions(+)

diff --git a/boards/arm/rzv2h/rzv2h-evk/Kconfig 
b/boards/arm/rzv2h/rzv2h-evk/Kconfig
index 9a0bed133ce..ba3ebe8aeb1 100644
--- a/boards/arm/rzv2h/rzv2h-evk/Kconfig
+++ b/boards/arm/rzv2h/rzv2h-evk/Kconfig
@@ -27,6 +27,140 @@ config BOARD_RZV2H_EVK
        ---help---
                Enable support for the RZV2H-EVK board based on the RZV2H MPU.
 
+if RZV2H_QSPI
+
+config RZV2H_EVK_QSPI_MT25QU512ABB
+       bool
+       default y
+       select MTD
+       select MTD_N25QXXX
+       ---help---
+               The RZV2H-EVK and RZV2H-RDK are fitted with a Micron
+               MT25QU512ABB8E12-0SIT 512Mbit (64MB) QSPI NOR FLASH.  This
+               part shares the same command set as the Micron N25Q/MT25Q
+               family, so it is supported by the n25qxxx MTD driver
+               (auto-detected at runtime via its JEDEC ID: manufacturer
+               0x20, device type 0xbb, capacity 0x20).
+
+choice
+       prompt "QSPI flash chip select"
+       default RZV2H_EVK_QSPI_CHIP_SELECT_0
+       ---help---
+               Which xSPI0 chip select the QSPI NOR flash is wired to.
+               Both RZV2H-EVK and RZV2H-RDK fit the flash on CS0 by
+               default, and both boards' rzv2h_qspi_setup() also pin-mux
+               CS1 (xSPI0_CS1N, P1_0/Func15) when this is set to CS1.
+
+config RZV2H_EVK_QSPI_CHIP_SELECT_0
+       bool "CS0"
+
+config RZV2H_EVK_QSPI_CHIP_SELECT_1
+       bool "CS1"
+
+endchoice
+
+choice
+       prompt "N25QXXX read protocol"
+       default RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_1S4S4S
+       ---help---
+               SPI protocol width used for reads from the on-board
+               MT25QU512ABB.  The n25qxxx MTD driver itself always issues
+               its stock Quad I/O Fast Read (0xEB, 1S-4S-4S); board-specific
+               rzv2h_qspi_memory() transparently re-encodes that request
+               onto the wire in whichever protocol is selected here,
+               entering/exiting the flash's persistent Quad SPI mode as
+               needed.  Program, erase, and status/config-register commands
+               are unaffected and always use plain 1S-1S-1S.
+
+config RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_1S1S1S
+       bool "1S-1S-1S (standard SPI Read, 0x03)"
+
+config RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_1S2S2S
+       bool "1S-2S-2S (Dual I/O Fast Read, 0xBB)"
+
+config RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_1S4S4S
+       bool "1S-4S-4S (Quad I/O Fast Read, 0xEB)"
+
+config RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_4S4S4S
+       bool "4S-4S-4S (persistent Quad SPI / QPI mode)"
+       ---help---
+               Switches the flash into its persistent Quad SPI mode (Micron
+               N25Q/MT25Q: ENTER QUAD I/O MODE, 0x35) around each read and
+               back out (RESET QUAD I/O MODE, 0xF5) afterward.  Requires the
+               xSPI controller to honor a quad-wide instruction phase on
+               demand, which rzv2h_qspi_command()/rzv2h_qspi_memory() do --
+               if that ever changes, the RESET command will not reach the
+               chip and every following operation will fail until the chip
+               is power-cycled.
+
+config RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_4S4D4D
+       bool "4S-4D-4D (persistent Quad SPI / QPI mode, DTR read)"
+       ---help---
+               Like the 4S-4S-4S option, this switches the flash into its
+               persistent Quad SPI mode (ENTER QUAD I/O MODE, 0x35) around
+               each read and back out (RESET QUAD I/O MODE, 0xF5)
+               afterward, but issues DTR FAST READ (0x0D) instead of plain
+               FAST READ, doubling data throughput by sampling on both
+               clock edges. Same power-cycle caveat as 4S-4S-4S if the RESET
+               command is ever lost.
+
+endchoice
+
+endif # RZV2H_QSPI
+
+config RZV2H_EVK_QSPI_SYSLOG_FILE
+       bool "Redirect syslog output to a file on the QSPI flash"
+       default n
+       depends on RZV2H_QSPI && FS_LITTLEFS && SYSLOG_FILE
+       help
+               Once the QSPI flash is mounted, switch the SYSLOG output channel
+               to a file on it via syslog_file_channel(), so log messages
+               persist across resets.
+
+config RZV2H_EVK_QSPI_SYSLOG_FILE_PATH
+       string "SYSLOG file path"
+       default "/mnt/qspi/syslog.txt"
+       depends on RZV2H_EVK_QSPI_SYSLOG_FILE
+
+config RZV2H_EVK_QSPI_FW_PART_SIZE
+       int "Firmware image partition size (KiB)"
+       default 4096
+       range 0 65536
+       depends on RZV2H_QSPI && MTD_PARTITION
+       help
+               Size, in KiB, of the QSPI partition reserved for the firmware
+               image.  Rounded down to a multiple of the flash erase size.
+
+               When CONFIG_MTD_PARTITION is enabled, the QSPI flash is split
+               into three MTD partitions instead of exposing it as a single
+               flat filesystem, so that firmware, parameters, and logging
+               cannot corrupt one another:
+
+                 - a firmware-image partition (raw MTD, no filesystem),
+                   intended to hold a flight-stack (e.g. PX4) firmware image
+                   at a fixed offset;
+                 - a parameter/configuration partition, registered as
+                   /dev/config via mtdconfig_register() (requires
+                   CONFIG_MTD_CONFIG or CONFIG_MTD_CONFIG_NVS);
+                 - a mission-data/flight-log partition, formatted with
+                   LittleFS and mounted at /mnt/qspi as before.
+
+               When CONFIG_MTD_PARTITION is disabled, the QSPI flash is used
+               as a single flat LittleFS volume, as before, and this setting
+               has no effect.
+
+config RZV2H_EVK_QSPI_PARAM_PART_SIZE
+       int "Parameter/configuration partition size (KiB)"
+       default 256
+       range 0 65536
+       depends on RZV2H_QSPI && MTD_PARTITION
+       help
+               Size, in KiB, of the QSPI partition reserved for the
+               parameter/configuration store.  Rounded down to a multiple of
+               the flash erase size.  The remainder of the flash, after the
+               firmware and parameter partitions, is used for mission data
+               and flight logs.
+
 endif
 
 config RZV2H_EXAMPLE_SUPPORT
diff --git a/boards/arm/rzv2h/rzv2h-evk/configs/nsh-xspi/defconfig 
b/boards/arm/rzv2h/rzv2h-evk/configs/nsh-xspi/defconfig
new file mode 100644
index 00000000000..cb896e9d1c8
--- /dev/null
+++ b/boards/arm/rzv2h/rzv2h-evk/configs/nsh-xspi/defconfig
@@ -0,0 +1,52 @@
+#
+# 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="arm"
+CONFIG_ARCH_BOARD="rzv2h-evk"
+CONFIG_ARCH_BOARD_RZV2H_EVK=y
+CONFIG_ARCH_CHIP="rzv2h"
+CONFIG_ARCH_CHIP_R9A09G057=y
+CONFIG_ARCH_CHIP_RZV2H=y
+CONFIG_ARCH_INTERRUPTSTACK=2048
+CONFIG_ARCH_LOWVECTORS=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7R_DCACHE_DISABLE=y
+CONFIG_ARMV7R_ICACHE_DISABLE=y
+CONFIG_ARM_MPU=y
+CONFIG_ARM_MPU_NREGIONS=6
+CONFIG_ARM_THUMB=y
+CONFIG_BINFMT_DISABLE=y
+CONFIG_BOARD_LOOPSPERMSEC=4241
+CONFIG_BUILTIN=y
+CONFIG_DEV_GPIO=y
+CONFIG_EXAMPLES_GPIO=y
+CONFIG_FS_LITTLEFS=y
+CONFIG_IDLETHREAD_STACKSIZE=2048
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INTELHEX_BINARY=y
+CONFIG_N25QXXX_QSPI_FREQUENCY=50000000
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_READLINE=y
+CONFIG_RAM_SIZE=262144
+CONFIG_RAM_START=0x08180000
+CONFIG_RAW_BINARY=y
+CONFIG_RZV2H_CORTEXR8_0=y
+CONFIG_RZV2H_QSPI=y
+CONFIG_RZV2H_SCI_B_UART0=y
+CONFIG_SCHED_WAITPID=y
+CONFIG_SCI0_SERIAL_CONSOLE=y
+CONFIG_SERIAL_TERMIOS=y
+CONFIG_SERIAL_TIOCGICOUNT=y
+CONFIG_SIG_DEFAULT=y
+CONFIG_START_DAY=29
+CONFIG_START_MONTH=7
+CONFIG_START_YEAR=2026
+CONFIG_SYSLOG_FILE=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TTY_SIGINT=y
+CONFIG_USEC_PER_TICK=1000
diff --git a/boards/arm/rzv2h/rzv2h-evk/include/board.h 
b/boards/arm/rzv2h/rzv2h-evk/include/board.h
index bcb10095859..9e025202bad 100644
--- a/boards/arm/rzv2h/rzv2h-evk/include/board.h
+++ b/boards/arm/rzv2h/rzv2h-evk/include/board.h
@@ -109,6 +109,21 @@
 #define BOARD_SCI9_TXD_GPIO   GPIO_TXD9_MOSI9_SDA9_P8_2_M6
 #define BOARD_SCI9_RXD_GPIO   GPIO_RXD9_MISO9_SCL9_P8_3_M6
 
+/* xSPI0 (QSPI NOR flash) pins.
+ *
+ */
+
+#define BOARD_QSPI0_CKN_GPIO     GPIO_XSPI0_CKN
+#define BOARD_QSPI0_CKP_GPIO     GPIO_XSPI0_CKP
+#define BOARD_QSPI0_CS0N_GPIO    GPIO_XSPI0_CS0N
+#define BOARD_QSPI0_CS1N_GPIO    GPIO_XSPI0_CS1N
+#define BOARD_QSPI0_RESET0N_GPIO GPIO_XSPI0_RESET0N
+#define BOARD_QSPI0_IO0_GPIO     GPIO_XSPI0_IO0
+#define BOARD_QSPI0_IO1_GPIO     GPIO_XSPI0_IO1
+#define BOARD_QSPI0_IO2_GPIO     GPIO_XSPI0_IO2
+#define BOARD_QSPI0_IO3_GPIO     GPIO_XSPI0_IO3
+#define BOARD_QSPI0_DS_GPIO      GPIO_XSPI0_DS
+
 /****************************************************************************
  * Public Function Prototypes
  ****************************************************************************/
@@ -143,6 +158,18 @@ void rzv2h_board_initialize(void);
 
 void rzv2h_serial_setup(void);
 
+/****************************************************************************
+ * Name: rzv2h_qspi_setup
+ *
+ * Description:
+ *   Configure the xSPI0 pins (SPCLK/IO0-3/CS0) for QSPI operation.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RZV2H_QSPI
+void rzv2h_qspi_setup(void);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/boards/arm/rzv2h/rzv2h-evk/src/CMakeLists.txt 
b/boards/arm/rzv2h/rzv2h-evk/src/CMakeLists.txt
index a14522415cc..426ba2da1cc 100644
--- a/boards/arm/rzv2h/rzv2h-evk/src/CMakeLists.txt
+++ b/boards/arm/rzv2h/rzv2h-evk/src/CMakeLists.txt
@@ -47,6 +47,10 @@ if(CONFIG_DEV_GPIO)
   list(APPEND SRCS rzv2h_gpio.c)
 endif()
 
+if(CONFIG_RZV2H_QSPI)
+  list(APPEND SRCS rzv2h_qspi.c)
+endif()
+
 # Peripheral driver initialization
 
 target_sources(board PRIVATE ${SRCS})
diff --git a/boards/arm/rzv2h/rzv2h-evk/src/Makefile 
b/boards/arm/rzv2h/rzv2h-evk/src/Makefile
index c2c6b1484af..424d5e1f6e2 100644
--- a/boards/arm/rzv2h/rzv2h-evk/src/Makefile
+++ b/boards/arm/rzv2h/rzv2h-evk/src/Makefile
@@ -58,6 +58,10 @@ ifeq ($(CONFIG_DEV_GPIO),y)
 CSRCS += rzv2h_gpio.c
 endif
 
+ifeq ($(CONFIG_RZV2H_QSPI),y)
+CSRCS += rzv2h_qspi.c
+endif
+
 ############################################################################
 # Peripheral driver initialization
 ############################################################################
diff --git a/boards/arm/rzv2h/rzv2h-evk/src/rzv2h-evk.h 
b/boards/arm/rzv2h/rzv2h-evk/src/rzv2h-evk.h
index 07a73aeed21..4b387bcbd9e 100644
--- a/boards/arm/rzv2h/rzv2h-evk/src/rzv2h-evk.h
+++ b/boards/arm/rzv2h/rzv2h-evk/src/rzv2h-evk.h
@@ -91,6 +91,22 @@ void board_button_initialize(void);
  *
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: rzv2h_qspi_initialize
+ *
+ * Description:
+ *   Initialize the xSPI bus in QSPI mode and register the attached SPI
+ *   NOR flash as an MTD device, optionally mounted with a filesystem.
+ *
+ * Return Value:
+ *   OK on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RZV2H_QSPI
+int rzv2h_qspi_initialize(void);
+#endif
+
 /****************************************************************************
  * Name: rzv2h_serial_setup
  *
@@ -101,6 +117,18 @@ void board_button_initialize(void);
 
 void rzv2h_serial_setup(void);
 
+/****************************************************************************
+ * Name: rzv2h_qspi_setup
+ *
+ * Description:
+ *   Configure the xSPI0 pins (SPCLK/IO0-3/CS0) for QSPI operation.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RZV2H_QSPI
+void rzv2h_qspi_setup(void);
+#endif
+
 #ifdef CONFIG_RZV2H_EXAMPLE_SUPPORT
 int rzv2h_appexamples(void);
 #endif
diff --git a/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_boot.c 
b/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_boot.c
index 924ebbc43df..9ef04c3278b 100644
--- a/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_boot.c
+++ b/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_boot.c
@@ -121,6 +121,12 @@ void rzv2h_board_initialize(void)
   rzv2h_serial_setup();
 #endif
 
+  /* Configure the xSPI0 pins for QSPI operation */
+
+#ifdef CONFIG_RZV2H_QSPI
+  rzv2h_qspi_setup();
+#endif
+
   /* Configure on-board LEDs if LED support has been selected */
 
 #ifdef CONFIG_ARCH_LEDS
diff --git a/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_bringup.c 
b/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_bringup.c
index 622ea33148a..b1ad025d9ef 100644
--- a/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_bringup.c
+++ b/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_bringup.c
@@ -74,6 +74,16 @@ int rzv2h_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_RZV2H_QSPI
+  ret = rzv2h_qspi_initialize();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR,
+             "ERROR: rzv2h_qspi_initialize() failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
 #if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER)
   /* Register the user LED driver.  The generic lower half calls
    * board_userled_initialize() before registering /dev/userleds.
diff --git a/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_qspi.c 
b/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_qspi.c
new file mode 100644
index 00000000000..92097409e06
--- /dev/null
+++ b/boards/arm/rzv2h/rzv2h-evk/src/rzv2h_qspi.c
@@ -0,0 +1,391 @@
+/****************************************************************************
+ * boards/arm/rzv2h/rzv2h-evk/src/rzv2h_qspi.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 <stdio.h>
+#include <syslog.h>
+#include <errno.h>
+
+#include <arch/barriers.h>
+#include <nuttx/arch.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/mtd/mtd.h>
+#include <nuttx/mtd/configdata.h>
+#include <nuttx/spi/qspi.h>
+#include <nuttx/syslog/syslog.h>
+
+#include "chip.h"
+#include "rzv2h_gpio.h"
+#include "rzv2h_qspi.h"
+#include "rzv2h-evk.h"
+
+#include <arch/board/board.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#if defined(CONFIG_MTD_PARTITION) && \
+    !defined(CONFIG_MTD_CONFIG) && !defined(CONFIG_MTD_CONFIG_NVS)
+#  error "CONFIG_MTD_PARTITION on this board requires CONFIG_MTD_CONFIG " \
+         "or CONFIG_MTD_CONFIG_NVS"
+#endif
+
+#ifdef CONFIG_RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_4S4D4D
+#  error "4S-4D-4D not supported: XSPI0_DS is not connected to the " \
+         "flash chip on this board"
+#endif
+
+/* Micron N25Q/MT25Q command set, as used by the n25qxxx MTD driver.  These
+ * mirror n25qxxx.c's own (private) command macros; they are standard
+ * across the Micron N25Q/MT25Q family fitted on this board.
+ */
+
+#define N25QXXX_CMD_FAST_READ_QUADIO   0xeb
+#define N25QXXX_CMD_READ               0x03
+#define N25QXXX_CMD_FAST_READ_DUALIO   0xbb
+#define N25QXXX_CMD_FAST_READ          0x0b
+#define N25QXXX_CMD_FAST_READ_DTR      0x0d
+#define N25QXXX_CMD_ENTER_QPI          0x35
+#define N25QXXX_CMD_RESET_QPI          0xf5
+#define N25QXXX_CMD_PAGE_PROGRAM       0x02
+#define N25QXXX_CMD_WRITE_ENABLE       0x06
+#define N25QXXX_CMD_READ_STATUS        0x05
+
+/* Bit position (not mask) within the status register read via
+ * N25QXXX_CMD_READ_STATUS -- bit 0 flags write/erase in progress, bit 1
+ * flags the write-enable latch.
+ */
+
+#define N25QXXX_STATUS_WIP_BIT         0
+#define N25QXXX_STATUS_WEL_BIT         1
+
+#define N25QXXX_PAGE_SIZE_BYTES        256
+#define N25QXXX_MEMORY_MB              64
+
+/* The datasheet's command table lists "factory default" dummy-clock
+ * counts per command (10 for FAST READ 0Bh's Quad SPI column, 8 for
+ * DTR FAST READ 0Dh's) -- but per that table's Note 5, those are only
+ * shipped defaults: the flash's actual dummy count is whatever is
+ * programmed into its volatile/nonvolatile configuration register,
+ * uniformly across FAST READ variants.  n25qxxx_initialize() programs the
+ * VCR to CONFIG_N25QXXX_DUMMIES (default 6) via n25qxxx_write_volcfg(), so
+ * 6 -- not the per-command table default -- is what the flash actually
+ * expects here, confirmed on hardware for 0Bh/4S-4S-4S.
+ */
+
+#define N25QXXX_QPI_READ_DUMMIES       6
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* The n25qxxx MTD driver always issues Quad I/O Fast Read (0xEB, 1S-4S-4S).
+ * Depending on the selected read protocol, the xSPI driver re-encodes it
+ * onto the wire; 1S-4S-4S needs no translation.  Program, erase, and
+ * status/config-register commands are unaffected and always use 1S-1S-1S.
+ */
+
+static const struct rzv2h_qspi_flash_s g_qspi_flash =
+{
+#ifdef CONFIG_RZV2H_EVK_QSPI_CHIP_SELECT_1
+  .chip_select      = 1,
+#else
+  .chip_select      = 0,
+#endif
+  .memory_mb        = N25QXXX_MEMORY_MB,
+  .page_size        = N25QXXX_PAGE_SIZE_BYTES,
+  .page_program_cmd = N25QXXX_CMD_PAGE_PROGRAM,
+  .write_enable_cmd = N25QXXX_CMD_WRITE_ENABLE,
+  .status_cmd       = N25QXXX_CMD_READ_STATUS,
+  .read_cmd         = N25QXXX_CMD_READ,
+  .write_status_bit = N25QXXX_STATUS_WIP_BIT,
+  .write_enable_bit = N25QXXX_STATUS_WEL_BIT,
+
+#if defined(CONFIG_RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_1S1S1S)
+  .read_xlate_from  = N25QXXX_CMD_FAST_READ_QUADIO,
+  .read_xlate_to    = N25QXXX_CMD_READ,
+  .read_protocol    = RZV2H_QSPI_PROTOCOL_1S1S1S,
+  .read_dummies     = 0,
+#elif defined(CONFIG_RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_1S2S2S)
+  .read_xlate_from  = N25QXXX_CMD_FAST_READ_QUADIO,
+  .read_xlate_to    = N25QXXX_CMD_FAST_READ_DUALIO,
+  .read_protocol    = RZV2H_QSPI_PROTOCOL_1S2S2S,
+  .read_dummies     = -1,
+#elif defined(CONFIG_RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_4S4S4S)
+  .read_xlate_from  = N25QXXX_CMD_FAST_READ_QUADIO,
+  .read_xlate_to    = N25QXXX_CMD_FAST_READ,
+  .read_protocol    = RZV2H_QSPI_PROTOCOL_4S4S4S,
+  .read_dummies     = N25QXXX_QPI_READ_DUMMIES,
+  .qpi_enter_cmd    = N25QXXX_CMD_ENTER_QPI,
+  .qpi_exit_cmd     = N25QXXX_CMD_RESET_QPI,
+#elif defined(CONFIG_RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_4S4D4D)
+  .read_xlate_from  = N25QXXX_CMD_FAST_READ_QUADIO,
+  .read_xlate_to    = N25QXXX_CMD_FAST_READ_DTR,
+  .read_protocol    = RZV2H_QSPI_PROTOCOL_4S4D4D,
+  .read_dummies     = N25QXXX_QPI_READ_DUMMIES,
+  .qpi_enter_cmd    = N25QXXX_CMD_ENTER_QPI,
+  .qpi_exit_cmd     = N25QXXX_CMD_RESET_QPI,
+#else /* CONFIG_RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_1S4S4S */
+  .read_protocol    = RZV2H_QSPI_PROTOCOL_1S4S4S,
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rzv2h_qspi_partition
+ *
+ * Description:
+ *   Split the raw QSPI MTD device into three regions so that firmware,
+ *   parameters/configuration, and mission-data/flight-logs cannot
+ *   corrupt one another on the same chip:
+ *
+ *     - a firmware-image partition (raw MTD, no filesystem);
+ *     - a parameter/configuration partition, exposed as /dev/config via
+ *       mtdconfig_register();
+ *     - the remaining flash, formatted with LittleFS and mounted at
+ *       /mnt/qspi for mission data and flight logs.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_MTD_PARTITION
+static int rzv2h_qspi_partition(struct mtd_dev_s *mtd,
+                                       struct mtd_dev_s **data_mtd)
+{
+  struct mtd_geometry_s geo;
+  struct mtd_dev_s *mtd_fw;
+  struct mtd_dev_s *mtd_param;
+  off_t fw_blocks;
+  off_t param_blocks;
+  int ret;
+
+  ret = mtd->ioctl(mtd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo));
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: MTDIOC_GEOMETRY failed: %d\n", ret);
+      return ret;
+    }
+
+  fw_blocks    = (CONFIG_RZV2H_EVK_QSPI_FW_PART_SIZE * 1024) /
+                 geo.erasesize;
+  param_blocks = (CONFIG_RZV2H_EVK_QSPI_PARAM_PART_SIZE * 1024) /
+                 geo.erasesize;
+
+  if (fw_blocks + param_blocks >= geo.neraseblocks)
+    {
+      syslog(LOG_ERR,
+             "ERROR: QSPI firmware/param partitions (%lu+%lu blocks) do "
+             "not fit in %lu erase blocks\n",
+             (unsigned long)fw_blocks, (unsigned long)param_blocks,
+             (unsigned long)geo.neraseblocks);
+      return -EINVAL;
+    }
+
+  mtd_fw = mtd_partition(mtd, 0, fw_blocks);
+  if (mtd_fw == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: failed to create QSPI firmware partition\n");
+      return -EIO;
+    }
+
+  ret = register_mtddriver("/dev/mtdfw0", mtd_fw, 0755, NULL);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR,
+             "ERROR: register_mtddriver(/dev/mtdfw0) failed: %d\n", ret);
+      return ret;
+    }
+
+  mtd_param = mtd_partition(mtd, fw_blocks, param_blocks);
+  if (mtd_param == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: failed to create QSPI parameter partition\n");
+      return -EIO;
+    }
+
+  ret = mtdconfig_register(mtd_param);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: mtdconfig_register() failed: %d\n", ret);
+      return ret;
+    }
+
+  *data_mtd = mtd_partition(mtd, fw_blocks + param_blocks,
+                             geo.neraseblocks - fw_blocks - param_blocks);
+  if (*data_mtd == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: failed to create QSPI data partition\n");
+      return -EIO;
+    }
+
+  return OK;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rzv2h_qspi_setup
+ *
+ * Description:
+ *   Configure the xSPI0 pins (CKP/CS0N or CS1N/RESET0N/IO0-3, plus DS
+ *   when a DDR protocol is selected) for QSPI
+ *   operation.  Must run before rzv2h_qspibus_initialize().
+ *
+ *   R_BSP_XSPIOutputEnableCfg() is required besides the per-pin config:
+ *   PFC_OEN.OEN2-5 is a separate group-level output-enable gate for the
+ *   xSPI0 pads, defaults disabled, and R_XSPI_QSPI_Open() never touches
+ *   it. Without it the pins never drive, reading back as a fixed
+ *   all-zero response from the flash.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RZV2H_QSPI
+void rzv2h_qspi_setup(void)
+{
+  R_BSP_XSPIOutputEnableCfg();
+  UP_DSB();
+
+  rzv2h_configgpio(BOARD_QSPI0_CKP_GPIO);
+  UP_DSB();
+#ifdef CONFIG_RZV2H_EVK_QSPI_CHIP_SELECT_1
+  rzv2h_configgpio(BOARD_QSPI0_CS1N_GPIO);
+#else
+  rzv2h_configgpio(BOARD_QSPI0_CS0N_GPIO);
+#endif
+  UP_DSB();
+  rzv2h_configgpio(BOARD_QSPI0_RESET0N_GPIO);
+  UP_DSB();
+  rzv2h_configgpio(BOARD_QSPI0_IO0_GPIO);
+  UP_DSB();
+  rzv2h_configgpio(BOARD_QSPI0_IO1_GPIO);
+  UP_DSB();
+  rzv2h_configgpio(BOARD_QSPI0_IO2_GPIO);
+  UP_DSB();
+  rzv2h_configgpio(BOARD_QSPI0_IO3_GPIO);
+  UP_DSB();
+#ifdef CONFIG_RZV2H_EVK_QSPI_N25QXXX_PROTOCOL_4S4D4D
+  rzv2h_configgpio(BOARD_QSPI0_DS_GPIO);
+  UP_DSB();
+#endif
+}
+#endif
+
+/****************************************************************************
+ * Name: rzv2h_qspi_initialize
+ *
+ * Description:
+ *   Initialize the xSPI bus in QSPI mode, register the attached SPI NOR
+ *   MTD device selected via Kconfig, and mount LittleFS if configured.
+ *
+ *   Fitted part: Micron MT25QU512ABB8E12-0SIT 512Mbit (64MB), supported
+ *   by the n25qxxx MTD driver (CONFIG_MTD_N25QXXX), auto-selected via
+ *   CONFIG_RZV2H_EVK_QSPI_MT25QU512ABB.  The other CONFIG_MTD_* branches
+ *   only support derivative boards fitted with a different QSPI NOR part.
+ *
+ *   With CONFIG_MTD_PARTITION, the flash is split into firmware/
+ *   parameter/data partitions (rzv2h_qspi_partition()); otherwise it's
+ *   one flat LittleFS volume.
+ *
+ ****************************************************************************/
+
+int rzv2h_qspi_initialize(void)
+{
+  struct qspi_dev_s *qspi;
+  struct mtd_dev_s *mtd;
+  struct mtd_dev_s *data_mtd;
+  char blockdev[32];
+  int ret;
+
+  qspi = rzv2h_qspibus_initialize(0, &g_qspi_flash);
+  if (qspi == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: rzv2h_qspibus_initialize() failed\n");
+      return -ENODEV;
+    }
+
+#if defined(CONFIG_MTD_N25QXXX)
+  mtd = n25qxxx_initialize(qspi, true);
+#else
+  syslog(LOG_ERR,
+         "ERROR: no CONFIG_MTD_* QSPI driver selected for xSPI\n");
+  return -ENOSYS;
+#endif
+
+  if (mtd == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: QSPI initialize() failed\n");
+      return -ENODEV;
+    }
+
+#ifdef CONFIG_MTD_PARTITION
+  ret = rzv2h_qspi_partition(mtd, &data_mtd);
+  if (ret < 0)
+    {
+      return ret;
+    }
+#else
+  data_mtd = mtd;
+#endif
+
+  snprintf(blockdev, sizeof(blockdev), "/dev/mtdqspi0");
+
+  ret = register_mtddriver(blockdev, data_mtd, 0755, NULL);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: register_mtddriver() failed: %d\n", ret);
+      return ret;
+    }
+
+#ifdef CONFIG_FS_LITTLEFS
+  ret = nx_mount(blockdev, "/mnt/qspi", "littlefs", 0, NULL);
+  if (ret < 0)
+    {
+      ret = nx_mount(blockdev, "/mnt/qspi", "littlefs", 0, "forceformat");
+      if (ret < 0)
+        {
+          syslog(LOG_ERR, "ERROR: nx_mount() failed: %d\n", ret);
+          return ret;
+        }
+    }
+
+#ifdef CONFIG_RZV2H_EVK_QSPI_SYSLOG_FILE
+  if (syslog_file_channel(CONFIG_RZV2H_EVK_QSPI_SYSLOG_FILE_PATH) == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: syslog_file_channel() failed\n");
+    }
+#endif
+#endif
+
+  return OK;
+}
diff --git a/boards/arm/rzv2h/rzv2h-rdk/Kconfig 
b/boards/arm/rzv2h/rzv2h-rdk/Kconfig
index 194933d2eae..edfbf2a5d44 100644
--- a/boards/arm/rzv2h/rzv2h-rdk/Kconfig
+++ b/boards/arm/rzv2h/rzv2h-rdk/Kconfig
@@ -27,6 +27,140 @@ config BOARD_RZV2H_RDK
        ---help---
                Enable support for the RZV2H-RDK board based on the RZV2H MPU.
 
+if RZV2H_QSPI
+
+config RZV2H_RDK_QSPI_MT25QU512ABB
+       bool
+       default y
+       select MTD
+       select MTD_N25QXXX
+       ---help---
+               The RZV2H-EVK and RZV2H-RDK are fitted with a Micron
+               MT25QU512ABB8E12-0SIT 512Mbit (64MB) QSPI NOR FLASH.  This
+               part shares the same command set as the Micron N25Q/MT25Q
+               family, so it is supported by the n25qxxx MTD driver
+               (auto-detected at runtime via its JEDEC ID: manufacturer
+               0x20, device type 0xbb, capacity 0x20).
+
+choice
+       prompt "QSPI flash chip select"
+       default RZV2H_RDK_QSPI_CHIP_SELECT_0
+       ---help---
+               Which xSPI0 chip select the QSPI NOR flash is wired to.
+               Both RZV2H-EVK and RZV2H-RDK fit the flash on CS0 by
+               default, and both boards' rzv2h_qspi_setup() also pin-mux
+               CS1 (xSPI0_CS1N, P1_0/Func15) when this is set to CS1.
+
+config RZV2H_RDK_QSPI_CHIP_SELECT_0
+       bool "CS0"
+
+config RZV2H_RDK_QSPI_CHIP_SELECT_1
+       bool "CS1"
+
+endchoice
+
+choice
+       prompt "N25QXXX read protocol"
+       default RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_1S4S4S
+       ---help---
+               SPI protocol width used for reads from the on-board
+               MT25QU512ABB.  The n25qxxx MTD driver itself always issues
+               its stock Quad I/O Fast Read (0xEB, 1S-4S-4S); board-specific
+               rzv2h_qspi_memory() transparently re-encodes that request
+               onto the wire in whichever protocol is selected here,
+               entering/exiting the flash's persistent Quad SPI mode as
+               needed.  Program, erase, and status/config-register commands
+               are unaffected and always use plain 1S-1S-1S.
+
+config RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_1S1S1S
+       bool "1S-1S-1S (standard SPI Read, 0x03)"
+
+config RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_1S2S2S
+       bool "1S-2S-2S (Dual I/O Fast Read, 0xBB)"
+
+config RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_1S4S4S
+       bool "1S-4S-4S (Quad I/O Fast Read, 0xEB)"
+
+config RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_4S4S4S
+       bool "4S-4S-4S (persistent Quad SPI / QPI mode)"
+       ---help---
+               Switches the flash into its persistent Quad SPI mode (Micron
+               N25Q/MT25Q: ENTER QUAD I/O MODE, 0x35) around each read and
+               back out (RESET QUAD I/O MODE, 0xF5) afterward.  Requires the
+               xSPI controller to honor a quad-wide instruction phase on
+               demand, which rzv2h_qspi_command()/rzv2h_qspi_memory() do --
+               if that ever changes, the RESET command will not reach the
+               chip and every following operation will fail until the chip
+               is power-cycled.
+
+config RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_4S4D4D
+       bool "4S-4D-4D (persistent Quad SPI / QPI mode, DTR read)"
+       ---help---
+               Like the 4S-4S-4S option, this switches the flash into its
+               persistent Quad SPI mode (ENTER QUAD I/O MODE, 0x35) around
+               each read and back out (RESET QUAD I/O MODE, 0xF5)
+               afterward, but issues DTR FAST READ (0x0D) instead of plain
+               FAST READ, doubling data throughput by sampling on both
+               clock edges. Same power-cycle caveat as 4S-4S-4S if the RESET
+               command is ever lost.
+
+endchoice
+
+endif # RZV2H_QSPI
+
+config RZV2H_RDK_QSPI_SYSLOG_FILE
+       bool "Redirect syslog output to a file on the QSPI flash"
+       default n
+       depends on RZV2H_QSPI && FS_LITTLEFS && SYSLOG_FILE
+       help
+               Once the QSPI flash is mounted, switch the SYSLOG output channel
+               to a file on it via syslog_file_channel(), so log messages
+               persist across resets.
+
+config RZV2H_RDK_QSPI_SYSLOG_FILE_PATH
+       string "SYSLOG file path"
+       default "/mnt/qspi/syslog.txt"
+       depends on RZV2H_RDK_QSPI_SYSLOG_FILE
+
+config RZV2H_RDK_QSPI_FW_PART_SIZE
+       int "Firmware image partition size (KiB)"
+       default 4096
+       range 0 65536
+       depends on RZV2H_QSPI && MTD_PARTITION
+       help
+               Size, in KiB, of the QSPI partition reserved for the firmware
+               image.  Rounded down to a multiple of the flash erase size.
+
+               When CONFIG_MTD_PARTITION is enabled, the QSPI flash is split
+               into three MTD partitions instead of exposing it as a single
+               flat filesystem, so that firmware, parameters, and logging
+               cannot corrupt one another:
+
+                 - a firmware-image partition (raw MTD, no filesystem),
+                   intended to hold a flight-stack (e.g. PX4) firmware image
+                   at a fixed offset;
+                 - a parameter/configuration partition, registered as
+                   /dev/config via mtdconfig_register() (requires
+                   CONFIG_MTD_CONFIG or CONFIG_MTD_CONFIG_NVS);
+                 - a mission-data/flight-log partition, formatted with
+                   LittleFS and mounted at /mnt/qspi as before.
+
+               When CONFIG_MTD_PARTITION is disabled, the QSPI flash is used
+               as a single flat LittleFS volume, as before, and this setting
+               has no effect.
+
+config RZV2H_RDK_QSPI_PARAM_PART_SIZE
+       int "Parameter/configuration partition size (KiB)"
+       default 256
+       range 0 65536
+       depends on RZV2H_QSPI && MTD_PARTITION
+       help
+               Size, in KiB, of the QSPI partition reserved for the
+               parameter/configuration store.  Rounded down to a multiple of
+               the flash erase size.  The remainder of the flash, after the
+               firmware and parameter partitions, is used for mission data
+               and flight logs.
+
 endif
 
 config RZV2H_EXAMPLE_SUPPORT
diff --git a/boards/arm/rzv2h/rzv2h-rdk/configs/nsh-xspi/defconfig 
b/boards/arm/rzv2h/rzv2h-rdk/configs/nsh-xspi/defconfig
new file mode 100644
index 00000000000..043ee5ad687
--- /dev/null
+++ b/boards/arm/rzv2h/rzv2h-rdk/configs/nsh-xspi/defconfig
@@ -0,0 +1,52 @@
+#
+# 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="arm"
+CONFIG_ARCH_BOARD="rzv2h-rdk"
+CONFIG_ARCH_BOARD_RZV2H_RDK=y
+CONFIG_ARCH_CHIP="rzv2h"
+CONFIG_ARCH_CHIP_R9A09G057=y
+CONFIG_ARCH_CHIP_RZV2H=y
+CONFIG_ARCH_INTERRUPTSTACK=2048
+CONFIG_ARCH_LOWVECTORS=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7R_DCACHE_DISABLE=y
+CONFIG_ARMV7R_ICACHE_DISABLE=y
+CONFIG_ARM_MPU=y
+CONFIG_ARM_MPU_NREGIONS=6
+CONFIG_ARM_THUMB=y
+CONFIG_BINFMT_DISABLE=y
+CONFIG_BOARD_LOOPSPERMSEC=4241
+CONFIG_BUILTIN=y
+CONFIG_DEV_GPIO=y
+CONFIG_EXAMPLES_GPIO=y
+CONFIG_FS_LITTLEFS=y
+CONFIG_IDLETHREAD_STACKSIZE=2048
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INTELHEX_BINARY=y
+CONFIG_N25QXXX_QSPI_FREQUENCY=50000000
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_READLINE=y
+CONFIG_RAM_SIZE=262144
+CONFIG_RAM_START=0x08180000
+CONFIG_RAW_BINARY=y
+CONFIG_RZV2H_CORTEXR8_0=y
+CONFIG_RZV2H_QSPI=y
+CONFIG_RZV2H_SCI_B_UART0=y
+CONFIG_SCHED_WAITPID=y
+CONFIG_SCI0_SERIAL_CONSOLE=y
+CONFIG_SERIAL_TERMIOS=y
+CONFIG_SERIAL_TIOCGICOUNT=y
+CONFIG_SIG_DEFAULT=y
+CONFIG_START_DAY=29
+CONFIG_START_MONTH=7
+CONFIG_START_YEAR=2026
+CONFIG_SYSLOG_FILE=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TTY_SIGINT=y
+CONFIG_USEC_PER_TICK=1000
diff --git a/boards/arm/rzv2h/rzv2h-rdk/include/board.h 
b/boards/arm/rzv2h/rzv2h-rdk/include/board.h
index 0a34e0462d4..8a4d195b39a 100644
--- a/boards/arm/rzv2h/rzv2h-rdk/include/board.h
+++ b/boards/arm/rzv2h/rzv2h-rdk/include/board.h
@@ -109,6 +109,21 @@
 #define BOARD_SCI9_TXD_GPIO   GPIO_TXD9_MOSI9_SDA9_P8_2_M6
 #define BOARD_SCI9_RXD_GPIO   GPIO_RXD9_MISO9_SCL9_P8_3_M6
 
+/* xSPI0 (QSPI NOR flash) pins.
+ *
+ */
+
+#define BOARD_QSPI0_CKN_GPIO     GPIO_XSPI0_CKN
+#define BOARD_QSPI0_CKP_GPIO     GPIO_XSPI0_CKP
+#define BOARD_QSPI0_CS0N_GPIO    GPIO_XSPI0_CS0N
+#define BOARD_QSPI0_CS1N_GPIO    GPIO_XSPI0_CS1N
+#define BOARD_QSPI0_RESET0N_GPIO GPIO_XSPI0_RESET0N
+#define BOARD_QSPI0_IO0_GPIO     GPIO_XSPI0_IO0
+#define BOARD_QSPI0_IO1_GPIO     GPIO_XSPI0_IO1
+#define BOARD_QSPI0_IO2_GPIO     GPIO_XSPI0_IO2
+#define BOARD_QSPI0_IO3_GPIO     GPIO_XSPI0_IO3
+#define BOARD_QSPI0_DS_GPIO      GPIO_XSPI0_DS
+
 /****************************************************************************
  * Public Function Prototypes
  ****************************************************************************/
@@ -143,6 +158,18 @@ void rzv2h_board_initialize(void);
 
 void rzv2h_serial_setup(void);
 
+/****************************************************************************
+ * Name: rzv2h_qspi_setup
+ *
+ * Description:
+ *   Configure the xSPI0 pins (SPCLK/IO0-3/CS0) for QSPI operation.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RZV2H_QSPI
+void rzv2h_qspi_setup(void);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/boards/arm/rzv2h/rzv2h-rdk/src/CMakeLists.txt 
b/boards/arm/rzv2h/rzv2h-rdk/src/CMakeLists.txt
index 24497a91e4b..aa712b59664 100644
--- a/boards/arm/rzv2h/rzv2h-rdk/src/CMakeLists.txt
+++ b/boards/arm/rzv2h/rzv2h-rdk/src/CMakeLists.txt
@@ -47,6 +47,10 @@ if(CONFIG_DEV_GPIO)
   list(APPEND SRCS rzv2h_gpio.c)
 endif()
 
+if(CONFIG_RZV2H_QSPI)
+  list(APPEND SRCS rzv2h_qspi.c)
+endif()
+
 # Peripheral driver initialization
 
 target_sources(board PRIVATE ${SRCS})
diff --git a/boards/arm/rzv2h/rzv2h-rdk/src/Makefile 
b/boards/arm/rzv2h/rzv2h-rdk/src/Makefile
index 5d1115d19b3..8831ca6e8a4 100644
--- a/boards/arm/rzv2h/rzv2h-rdk/src/Makefile
+++ b/boards/arm/rzv2h/rzv2h-rdk/src/Makefile
@@ -58,6 +58,10 @@ ifeq ($(CONFIG_DEV_GPIO),y)
 CSRCS += rzv2h_gpio.c
 endif
 
+ifeq ($(CONFIG_RZV2H_QSPI),y)
+CSRCS += rzv2h_qspi.c
+endif
+
 ############################################################################
 # Peripheral driver initialization
 ############################################################################
diff --git a/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h-rdk.h 
b/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h-rdk.h
index 2304ee389b7..26c0c7e4ae2 100644
--- a/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h-rdk.h
+++ b/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h-rdk.h
@@ -91,6 +91,22 @@ void board_button_initialize(void);
  *
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: rzv2h_qspi_initialize
+ *
+ * Description:
+ *   Initialize the xSPI bus in QSPI mode and register the attached SPI
+ *   NOR flash as an MTD device, optionally mounted with a filesystem.
+ *
+ * Return Value:
+ *   OK on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RZV2H_QSPI
+int rzv2h_qspi_initialize(void);
+#endif
+
 /****************************************************************************
  * Name: rzv2h_serial_setup
  *
@@ -101,6 +117,18 @@ void board_button_initialize(void);
 
 void rzv2h_serial_setup(void);
 
+/****************************************************************************
+ * Name: rzv2h_qspi_setup
+ *
+ * Description:
+ *   Configure the xSPI0 pins (SPCLK/IO0-3/CS0) for QSPI operation.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RZV2H_QSPI
+void rzv2h_qspi_setup(void);
+#endif
+
 #ifdef CONFIG_RZV2H_EXAMPLE_SUPPORT
 int rzv2h_appexamples(void);
 #endif
diff --git a/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_boot.c 
b/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_boot.c
index 042309f1f75..79b0461850e 100644
--- a/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_boot.c
+++ b/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_boot.c
@@ -121,6 +121,12 @@ void rzv2h_board_initialize(void)
   rzv2h_serial_setup();
 #endif
 
+  /* Configure the xSPI0 pins for QSPI operation */
+
+#ifdef CONFIG_RZV2H_QSPI
+  rzv2h_qspi_setup();
+#endif
+
   /* Configure on-board LEDs if LED support has been selected */
 
 #ifdef CONFIG_ARCH_LEDS
diff --git a/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_bringup.c 
b/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_bringup.c
index 20734a82d0d..54b7b71c1d9 100644
--- a/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_bringup.c
+++ b/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_bringup.c
@@ -70,6 +70,16 @@ int rzv2h_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_RZV2H_QSPI
+  ret = rzv2h_qspi_initialize();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR,
+             "ERROR: rzv2h_qspi_initialize() failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
 #if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER)
   /* Register the user LED driver.  The generic lower half calls
    * board_userled_initialize() before registering /dev/userleds.
diff --git a/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_qspi.c 
b/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_qspi.c
new file mode 100644
index 00000000000..231452089bc
--- /dev/null
+++ b/boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_qspi.c
@@ -0,0 +1,391 @@
+/****************************************************************************
+ * boards/arm/rzv2h/rzv2h-rdk/src/rzv2h_qspi.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 <stdio.h>
+#include <syslog.h>
+#include <errno.h>
+
+#include <arch/barriers.h>
+#include <nuttx/arch.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/mtd/mtd.h>
+#include <nuttx/mtd/configdata.h>
+#include <nuttx/spi/qspi.h>
+#include <nuttx/syslog/syslog.h>
+
+#include "chip.h"
+#include "rzv2h_gpio.h"
+#include "rzv2h_qspi.h"
+#include "rzv2h-rdk.h"
+
+#include <arch/board/board.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#if defined(CONFIG_MTD_PARTITION) && \
+    !defined(CONFIG_MTD_CONFIG) && !defined(CONFIG_MTD_CONFIG_NVS)
+#  error "CONFIG_MTD_PARTITION on this board requires CONFIG_MTD_CONFIG " \
+         "or CONFIG_MTD_CONFIG_NVS"
+#endif
+
+#ifdef CONFIG_RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_4S4D4D
+#  error "4S-4D-4D not supported: XSPI0_DS is not connected to the " \
+         "flash chip on this board"
+#endif
+
+/* Micron N25Q/MT25Q command set, as used by the n25qxxx MTD driver.  These
+ * mirror n25qxxx.c's own (private) command macros; they are standard
+ * across the Micron N25Q/MT25Q family fitted on this board.
+ */
+
+#define N25QXXX_CMD_FAST_READ_QUADIO   0xeb
+#define N25QXXX_CMD_READ               0x03
+#define N25QXXX_CMD_FAST_READ_DUALIO   0xbb
+#define N25QXXX_CMD_FAST_READ          0x0b
+#define N25QXXX_CMD_FAST_READ_DTR      0x0d
+#define N25QXXX_CMD_ENTER_QPI          0x35
+#define N25QXXX_CMD_RESET_QPI          0xf5
+#define N25QXXX_CMD_PAGE_PROGRAM       0x02
+#define N25QXXX_CMD_WRITE_ENABLE       0x06
+#define N25QXXX_CMD_READ_STATUS        0x05
+
+/* Bit position (not mask) within the status register read via
+ * N25QXXX_CMD_READ_STATUS -- bit 0 flags write/erase in progress, bit 1
+ * flags the write-enable latch.
+ */
+
+#define N25QXXX_STATUS_WIP_BIT         0
+#define N25QXXX_STATUS_WEL_BIT         1
+
+#define N25QXXX_PAGE_SIZE_BYTES        256
+#define N25QXXX_MEMORY_MB              64
+
+/* The datasheet's command table lists "factory default" dummy-clock
+ * counts per command (10 for FAST READ 0Bh's Quad SPI column, 8 for
+ * DTR FAST READ 0Dh's) -- but per that table's Note 5, those are only
+ * shipped defaults: the flash's actual dummy count is whatever is
+ * programmed into its volatile/nonvolatile configuration register,
+ * uniformly across FAST READ variants.  n25qxxx_initialize() programs the
+ * VCR to CONFIG_N25QXXX_DUMMIES (default 6) via n25qxxx_write_volcfg(), so
+ * 6 -- not the per-command table default -- is what the flash actually
+ * expects here, confirmed on hardware for 0Bh/4S-4S-4S.
+ */
+
+#define N25QXXX_QPI_READ_DUMMIES       6
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* The n25qxxx MTD driver always issues Quad I/O Fast Read (0xEB, 1S-4S-4S).
+ * Depending on the selected read protocol, the xSPI driver re-encodes it
+ * onto the wire; 1S-4S-4S needs no translation.  Program, erase, and
+ * status/config-register commands are unaffected and always use 1S-1S-1S.
+ */
+
+static const struct rzv2h_qspi_flash_s g_qspi_flash =
+{
+#ifdef CONFIG_RZV2H_RDK_QSPI_CHIP_SELECT_1
+  .chip_select      = 1,
+#else
+  .chip_select      = 0,
+#endif
+  .memory_mb        = N25QXXX_MEMORY_MB,
+  .page_size        = N25QXXX_PAGE_SIZE_BYTES,
+  .page_program_cmd = N25QXXX_CMD_PAGE_PROGRAM,
+  .write_enable_cmd = N25QXXX_CMD_WRITE_ENABLE,
+  .status_cmd       = N25QXXX_CMD_READ_STATUS,
+  .read_cmd         = N25QXXX_CMD_READ,
+  .write_status_bit = N25QXXX_STATUS_WIP_BIT,
+  .write_enable_bit = N25QXXX_STATUS_WEL_BIT,
+
+#if defined(CONFIG_RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_1S1S1S)
+  .read_xlate_from  = N25QXXX_CMD_FAST_READ_QUADIO,
+  .read_xlate_to    = N25QXXX_CMD_READ,
+  .read_protocol    = RZV2H_QSPI_PROTOCOL_1S1S1S,
+  .read_dummies     = 0,
+#elif defined(CONFIG_RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_1S2S2S)
+  .read_xlate_from  = N25QXXX_CMD_FAST_READ_QUADIO,
+  .read_xlate_to    = N25QXXX_CMD_FAST_READ_DUALIO,
+  .read_protocol    = RZV2H_QSPI_PROTOCOL_1S2S2S,
+  .read_dummies     = -1,
+#elif defined(CONFIG_RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_4S4S4S)
+  .read_xlate_from  = N25QXXX_CMD_FAST_READ_QUADIO,
+  .read_xlate_to    = N25QXXX_CMD_FAST_READ,
+  .read_protocol    = RZV2H_QSPI_PROTOCOL_4S4S4S,
+  .read_dummies     = N25QXXX_QPI_READ_DUMMIES,
+  .qpi_enter_cmd    = N25QXXX_CMD_ENTER_QPI,
+  .qpi_exit_cmd     = N25QXXX_CMD_RESET_QPI,
+#elif defined(CONFIG_RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_4S4D4D)
+  .read_xlate_from  = N25QXXX_CMD_FAST_READ_QUADIO,
+  .read_xlate_to    = N25QXXX_CMD_FAST_READ_DTR,
+  .read_protocol    = RZV2H_QSPI_PROTOCOL_4S4D4D,
+  .read_dummies     = N25QXXX_QPI_READ_DUMMIES,
+  .qpi_enter_cmd    = N25QXXX_CMD_ENTER_QPI,
+  .qpi_exit_cmd     = N25QXXX_CMD_RESET_QPI,
+#else /* CONFIG_RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_1S4S4S */
+  .read_protocol    = RZV2H_QSPI_PROTOCOL_1S4S4S,
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rzv2h_qspi_partition
+ *
+ * Description:
+ *   Split the raw QSPI MTD device into three regions so that firmware,
+ *   parameters/configuration, and mission-data/flight-logs cannot
+ *   corrupt one another on the same chip:
+ *
+ *     - a firmware-image partition (raw MTD, no filesystem);
+ *     - a parameter/configuration partition, exposed as /dev/config via
+ *       mtdconfig_register();
+ *     - the remaining flash, formatted with LittleFS and mounted at
+ *       /mnt/qspi for mission data and flight logs.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_MTD_PARTITION
+static int rzv2h_qspi_partition(struct mtd_dev_s *mtd,
+                                       struct mtd_dev_s **data_mtd)
+{
+  struct mtd_geometry_s geo;
+  struct mtd_dev_s *mtd_fw;
+  struct mtd_dev_s *mtd_param;
+  off_t fw_blocks;
+  off_t param_blocks;
+  int ret;
+
+  ret = mtd->ioctl(mtd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo));
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: MTDIOC_GEOMETRY failed: %d\n", ret);
+      return ret;
+    }
+
+  fw_blocks    = (CONFIG_RZV2H_RDK_QSPI_FW_PART_SIZE * 1024) /
+                 geo.erasesize;
+  param_blocks = (CONFIG_RZV2H_RDK_QSPI_PARAM_PART_SIZE * 1024) /
+                 geo.erasesize;
+
+  if (fw_blocks + param_blocks >= geo.neraseblocks)
+    {
+      syslog(LOG_ERR,
+             "ERROR: QSPI firmware/param partitions (%lu+%lu blocks) do "
+             "not fit in %lu erase blocks\n",
+             (unsigned long)fw_blocks, (unsigned long)param_blocks,
+             (unsigned long)geo.neraseblocks);
+      return -EINVAL;
+    }
+
+  mtd_fw = mtd_partition(mtd, 0, fw_blocks);
+  if (mtd_fw == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: failed to create QSPI firmware partition\n");
+      return -EIO;
+    }
+
+  ret = register_mtddriver("/dev/mtdfw0", mtd_fw, 0755, NULL);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR,
+             "ERROR: register_mtddriver(/dev/mtdfw0) failed: %d\n", ret);
+      return ret;
+    }
+
+  mtd_param = mtd_partition(mtd, fw_blocks, param_blocks);
+  if (mtd_param == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: failed to create QSPI parameter partition\n");
+      return -EIO;
+    }
+
+  ret = mtdconfig_register(mtd_param);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: mtdconfig_register() failed: %d\n", ret);
+      return ret;
+    }
+
+  *data_mtd = mtd_partition(mtd, fw_blocks + param_blocks,
+                             geo.neraseblocks - fw_blocks - param_blocks);
+  if (*data_mtd == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: failed to create QSPI data partition\n");
+      return -EIO;
+    }
+
+  return OK;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rzv2h_qspi_setup
+ *
+ * Description:
+ *   Configure the xSPI0 pins (CKP/CS0N or CS1N/RESET0N/IO0-3, plus DS
+ *   when a DDR protocol is selected) for QSPI
+ *   operation.  Must run before rzv2h_qspibus_initialize().
+ *
+ *   R_BSP_XSPIOutputEnableCfg() is required besides the per-pin config:
+ *   PFC_OEN.OEN2-5 is a separate group-level output-enable gate for the
+ *   xSPI0 pads, defaults disabled, and R_XSPI_QSPI_Open() never touches
+ *   it. Without it the pins never drive, reading back as a fixed
+ *   all-zero response from the flash.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RZV2H_QSPI
+void rzv2h_qspi_setup(void)
+{
+  R_BSP_XSPIOutputEnableCfg();
+  UP_DSB();
+
+  rzv2h_configgpio(BOARD_QSPI0_CKP_GPIO);
+  UP_DSB();
+#ifdef CONFIG_RZV2H_RDK_QSPI_CHIP_SELECT_1
+  rzv2h_configgpio(BOARD_QSPI0_CS1N_GPIO);
+#else
+  rzv2h_configgpio(BOARD_QSPI0_CS0N_GPIO);
+#endif
+  UP_DSB();
+  rzv2h_configgpio(BOARD_QSPI0_RESET0N_GPIO);
+  UP_DSB();
+  rzv2h_configgpio(BOARD_QSPI0_IO0_GPIO);
+  UP_DSB();
+  rzv2h_configgpio(BOARD_QSPI0_IO1_GPIO);
+  UP_DSB();
+  rzv2h_configgpio(BOARD_QSPI0_IO2_GPIO);
+  UP_DSB();
+  rzv2h_configgpio(BOARD_QSPI0_IO3_GPIO);
+  UP_DSB();
+#ifdef CONFIG_RZV2H_RDK_QSPI_N25QXXX_PROTOCOL_4S4D4D
+  rzv2h_configgpio(BOARD_QSPI0_DS_GPIO);
+  UP_DSB();
+#endif
+}
+#endif
+
+/****************************************************************************
+ * Name: rzv2h_qspi_initialize
+ *
+ * Description:
+ *   Initialize the xSPI bus in QSPI mode, register the attached SPI NOR
+ *   MTD device selected via Kconfig, and mount LittleFS if configured.
+ *
+ *   Fitted part: Micron MT25QU512ABB8E12-0SIT 512Mbit (64MB), supported
+ *   by the n25qxxx MTD driver (CONFIG_MTD_N25QXXX), auto-selected via
+ *   CONFIG_RZV2H_RDK_QSPI_MT25QU512ABB.  The other CONFIG_MTD_* branches
+ *   only support derivative boards fitted with a different QSPI NOR part.
+ *
+ *   With CONFIG_MTD_PARTITION, the flash is split into firmware/
+ *   parameter/data partitions (rzv2h_qspi_partition()); otherwise it's
+ *   one flat LittleFS volume.
+ *
+ ****************************************************************************/
+
+int rzv2h_qspi_initialize(void)
+{
+  struct qspi_dev_s *qspi;
+  struct mtd_dev_s *mtd;
+  struct mtd_dev_s *data_mtd;
+  char blockdev[32];
+  int ret;
+
+  qspi = rzv2h_qspibus_initialize(0, &g_qspi_flash);
+  if (qspi == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: rzv2h_qspibus_initialize() failed\n");
+      return -ENODEV;
+    }
+
+#if defined(CONFIG_MTD_N25QXXX)
+  mtd = n25qxxx_initialize(qspi, true);
+#else
+  syslog(LOG_ERR,
+         "ERROR: no CONFIG_MTD_* QSPI driver selected for xSPI\n");
+  return -ENOSYS;
+#endif
+
+  if (mtd == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: QSPI initialize() failed\n");
+      return -ENODEV;
+    }
+
+#ifdef CONFIG_MTD_PARTITION
+  ret = rzv2h_qspi_partition(mtd, &data_mtd);
+  if (ret < 0)
+    {
+      return ret;
+    }
+#else
+  data_mtd = mtd;
+#endif
+
+  snprintf(blockdev, sizeof(blockdev), "/dev/mtdqspi0");
+
+  ret = register_mtddriver(blockdev, data_mtd, 0755, NULL);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: register_mtddriver() failed: %d\n", ret);
+      return ret;
+    }
+
+#ifdef CONFIG_FS_LITTLEFS
+  ret = nx_mount(blockdev, "/mnt/qspi", "littlefs", 0, NULL);
+  if (ret < 0)
+    {
+      ret = nx_mount(blockdev, "/mnt/qspi", "littlefs", 0, "forceformat");
+      if (ret < 0)
+        {
+          syslog(LOG_ERR, "ERROR: nx_mount() failed: %d\n", ret);
+          return ret;
+        }
+    }
+
+#ifdef CONFIG_RZV2H_RDK_QSPI_SYSLOG_FILE
+  if (syslog_file_channel(CONFIG_RZV2H_RDK_QSPI_SYSLOG_FILE_PATH) == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: syslog_file_channel() failed\n");
+    }
+#endif
+#endif
+
+  return OK;
+}

Reply via email to