From edf3cc55a5829ded2744c3ef700cfcb4731023f3 Mon Sep 17 00:00:00 2001 From: Michal Lenc Date: Thu, 27 Nov 2025 10:42:15 +0100 Subject: [PATCH] drivers/mtd/w25: support custom SPI transfers delay This commit adds SPI_SETDELAY interface if CONFIG_SPI_DELAY_CONTROL option is set. This allows to set custom delay between SPI transfers, chip selects and so on. Default values are set to 0. W25 SPI NOR flash works with them and I haven't found any other values in the datasheet. Signed-off-by: Michal Lenc --- drivers/mtd/Kconfig | 32 ++++++++++++++++++++++++++++++++ drivers/mtd/w25.c | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 0104ae2177f..0a70ccbd313 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -1352,6 +1352,38 @@ config W25_SPIFREQUENCY int "W25 SPI Frequency" default 20000000 +config W25_START_DELAY + int "W25 SPI start delay" + depends on SPI_DELAY_CONTROL + range 0 1000000 + default 0 + ---help--- + The delay between CS active and first CLK. In ns. + +config W25_STOP_DELAY + int "W25 SPI stop delay" + depends on SPI_DELAY_CONTROL + range 0 1000000 + default 0 + ---help--- + The delay between last CLK and CS inactive. In ns. + +config W25_CS_DELAY + int "W25 SPI chip select delay" + depends on SPI_DELAY_CONTROL + range 0 1000000 + default 0 + ---help--- + The delay between CS inactive and CS active again. In ns. + +config W25_IFDELAY + int "W25 SPI frames delay" + depends on SPI_DELAY_CONTROL + range 0 1000000 + default 0 + ---help--- + The delay between consecutive frames. In ns. + config W25_READONLY bool "W25 Read-Only FLASH" default n diff --git a/drivers/mtd/w25.c b/drivers/mtd/w25.c index a5ef7b560cd..0a025183c7d 100644 --- a/drivers/mtd/w25.c +++ b/drivers/mtd/w25.c @@ -354,6 +354,11 @@ static void w25_lock(FAR struct spi_dev_s *spi) SPI_SETBITS(spi, 8); SPI_HWFEATURES(spi, 0); SPI_SETFREQUENCY(spi, CONFIG_W25_SPIFREQUENCY); +#ifdef CONFIG_SPI_DELAY_CONTROL + SPI_SETDELAY(spi, CONFIG_W25_START_DELAY, + CONFIG_W25_STOP_DELAY, CONFIG_W25_CS_DELAY, + CONFIG_W25_IFDELAY); +#endif } /****************************************************************************