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 87b63402a75bca35b82ecd39dace3632f0774924 Author: Eren Terzioglu <[email protected]> AuthorDate: Mon Apr 27 10:50:06 2026 +0200 boards/risc-v/esp32p4: Add LPSPI and SPI3 board support Add LPSPI and SPI3 board support for esp32[-p4] Signed-off-by: Eren Terzioglu <[email protected]> --- arch/risc-v/src/common/espressif/Kconfig | 4 +- .../esp32p4/common/include/esp_board_spidev.h | 3 +- boards/risc-v/esp32p4/common/src/esp_board_spi.c | 64 ++++++++++++++++++++++ .../risc-v/esp32p4/common/src/esp_board_spidev.c | 33 +++++++++++ .../src/esp32p4_bringup.c | 27 ++++++++- 5 files changed, 126 insertions(+), 5 deletions(-) diff --git a/arch/risc-v/src/common/espressif/Kconfig b/arch/risc-v/src/common/espressif/Kconfig index 4f32573b044..0eceac8825d 100644 --- a/arch/risc-v/src/common/espressif/Kconfig +++ b/arch/risc-v/src/common/espressif/Kconfig @@ -1783,7 +1783,7 @@ config ESPRESSIF_SPI_SLAVE config ESPRESSIF_SPI_PERIPH bool - depends on ESPRESSIF_SPI2 + depends on ESPRESSIF_SPI2 || ESPRESSIF_SPI3 || ESPRESSIF_LPSPI0 default n config ESPRESSIF_SPI2 @@ -1802,7 +1802,7 @@ config ESPRESSIF_SPI3 select ESPRESSIF_SPI_PERIPH config ESPRESSIF_LPSPI0 - bool "LP SPI" + bool "LP SPI0" depends on ARCH_CHIP_ESP32P4 default n select ESPRESSIF_SPI diff --git a/boards/risc-v/esp32p4/common/include/esp_board_spidev.h b/boards/risc-v/esp32p4/common/include/esp_board_spidev.h index aba55192e52..7fe27cf3999 100644 --- a/boards/risc-v/esp32p4/common/include/esp_board_spidev.h +++ b/boards/risc-v/esp32p4/common/include/esp_board_spidev.h @@ -67,7 +67,8 @@ extern "C" * ****************************************************************************/ -#if defined(CONFIG_ESPRESSIF_SPI2) || defined(CONFIG_ESPRESSIF_SPI_BITBANG) +#if defined(CONFIG_ESPRESSIF_SPI2) || defined(CONFIG_ESPRESSIF_SPI_BITBANG) \ + || defined(CONFIG_ESPRESSIF_SPI3) || defined(CONFIG_ESPRESSIF_LPSPI0) int board_spidev_initialize(int bus); #endif diff --git a/boards/risc-v/esp32p4/common/src/esp_board_spi.c b/boards/risc-v/esp32p4/common/src/esp_board_spi.c index 7614d592db4..057725b5230 100644 --- a/boards/risc-v/esp32p4/common/src/esp_board_spi.c +++ b/boards/risc-v/esp32p4/common/src/esp_board_spi.c @@ -57,6 +57,17 @@ uint8_t esp_spi2_status(struct spi_dev_s *dev, uint32_t devid) #endif +/**************************************************************************** + * Name: esp_spi2_select + ****************************************************************************/ + +#if defined(CONFIG_ESPRESSIF_SPI2) && defined(CONFIG_ESPRESSIF_SPI_UDCS) +void esp_spi2_select(struct spi_dev_s *dev, uint32_t devid, bool select) +{ + esp_gpiowrite(CONFIG_ESPRESSIF_SPI2_CSPIN, !select); +} +#endif + /**************************************************************************** * Name: esp_spi2_cmddata ****************************************************************************/ @@ -83,3 +94,56 @@ int esp_spi2_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) } #endif + +#ifdef CONFIG_ESPRESSIF_SPI3 + +/**************************************************************************** + * Name: esp_spi3_status + ****************************************************************************/ + +uint8_t esp_spi3_status(struct spi_dev_s *dev, uint32_t devid) +{ + uint8_t status = 0; + + return status; +} + +#endif + +/**************************************************************************** + * Name: esp_spi2_select + ****************************************************************************/ + +#if defined(CONFIG_ESPRESSIF_SPI3) && defined(CONFIG_ESPRESSIF_SPI_UDCS) +void esp_spi3_select(struct spi_dev_s *dev, uint32_t devid, bool select) +{ + esp_gpiowrite(CONFIG_ESPRESSIF_SPI3_CSPIN, !select); +} +#endif + +/**************************************************************************** + * Name: esp_spi3_cmddata + ****************************************************************************/ + +#if defined(CONFIG_ESPRESSIF_SPI3) && defined(CONFIG_SPI_CMDDATA) + +int esp_spi3_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + if (devid == SPIDEV_DISPLAY(0)) + { + /* This is the Data/Command control pad which determines whether the + * data bits are data or a command. + */ + + esp_gpiowrite(CONFIG_ESPRESSIF_SPI3_MISOPIN, !cmd); + + return OK; + } + + spiinfo("devid: %" PRIu32 " CMD: %s\n", devid, cmd ? "command" : + "data"); + + return -ENODEV; +} + +#endif diff --git a/boards/risc-v/esp32p4/common/src/esp_board_spidev.c b/boards/risc-v/esp32p4/common/src/esp_board_spidev.c index 5395b9c94e3..633eea93cf8 100644 --- a/boards/risc-v/esp32p4/common/src/esp_board_spidev.c +++ b/boards/risc-v/esp32p4/common/src/esp_board_spidev.c @@ -122,6 +122,15 @@ static int spi_driver_init(int port) return -ENODEV; } +#ifdef CONFIG_ESPRESSIF_LPSPI0 + /* LP SPI cannot be used on HP core due to common layer driver */ + + if (port == ESPRESSIF_LPSPI0) + { + return OK; + } +#endif + ret = spi_register(spi, port); if (ret < 0) { @@ -170,6 +179,18 @@ int board_spidev_initialize(int port) } #endif +#ifdef CONFIG_ESPRESSIF_SPI3 + case ESPRESSIF_SPI3: + { + ret = spi_driver_init(ESPRESSIF_SPI3); + if (ret != OK) + { + return ret; + } + break; + } +#endif + #ifdef CONFIG_ESPRESSIF_SPI_BITBANG case ESPRESSIF_SPI_BITBANG: { @@ -182,6 +203,18 @@ int board_spidev_initialize(int port) } #endif +#ifdef CONFIG_ESPRESSIF_LPSPI0 + case ESPRESSIF_LPSPI0: + { + ret = spi_driver_init(ESPRESSIF_LPSPI0); + if (ret != OK) + { + return ret; + } + break; + } +#endif + default: { wderr("ERROR: unsupported SPI %d\n", port); diff --git a/boards/risc-v/esp32p4/esp32p4-function-ev-board/src/esp32p4_bringup.c b/boards/risc-v/esp32p4/esp32p4-function-ev-board/src/esp32p4_bringup.c index d2d185d3a75..d11a942b726 100644 --- a/boards/risc-v/esp32p4/esp32p4-function-ev-board/src/esp32p4_bringup.c +++ b/boards/risc-v/esp32p4/esp32p4-function-ev-board/src/esp32p4_bringup.c @@ -258,14 +258,14 @@ int esp_bringup(void) #endif #ifdef CONFIG_ESPRESSIF_SPI -# ifdef CONFIG_ESPRESSIF_SPI_SLAVE +# if defined(CONFIG_ESPRESSIF_SPI2_SLAVE) && defined(CONFIG_ESPRESSIF_SPI2) ret = board_spislavedev_initialize(ESPRESSIF_SPI2); if (ret < 0) { syslog(LOG_ERR, "Failed to initialize SPI%d Slave driver: %d\n", ESPRESSIF_SPI2, ret); } -# else +# elif defined(CONFIG_ESPRESSIF_SPI2) ret = board_spidev_initialize(ESPRESSIF_SPI2); if (ret < 0) { @@ -273,6 +273,21 @@ int esp_bringup(void) } # endif +# if defined(CONFIG_ESPRESSIF_SPI3_SLAVE) && defined(CONFIG_ESPRESSIF_SPI3) + ret = board_spislavedev_initialize(ESPRESSIF_SPI3); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize SPI%d Slave driver: %d\n", + ESPRESSIF_SPI3, ret); + } +# elif defined(CONFIG_ESPRESSIF_SPI3) + ret = board_spidev_initialize(ESPRESSIF_SPI3); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to init spidev 3: %d\n", ret); + } +# endif + # ifdef CONFIG_ESPRESSIF_SPI_BITBANG ret = board_spidev_initialize(ESPRESSIF_SPI_BITBANG); if (ret < 0) @@ -280,6 +295,14 @@ int esp_bringup(void) syslog(LOG_ERR, "ERROR: Failed to init spidev 3: %d\n", ret); } # endif /* CONFIG_ESPRESSIF_SPI_BITBANG */ + +# ifdef CONFIG_ESPRESSIF_LPSPI0 + ret = board_spidev_initialize(ESPRESSIF_LPSPI0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to init lpspi: %d\n", ret); + } +# endif #endif /* CONFIG_ESPRESSIF_SPI */ #ifdef CONFIG_ESPRESSIF_SPIFLASH
