diff --git a/Documentation/platforms/xtensa/esp32/index.rst b/Documentation/platforms/xtensa/esp32/index.rst index 32f698efffaac..c1f8257f810ab 100644 --- a/Documentation/platforms/xtensa/esp32/index.rst +++ b/Documentation/platforms/xtensa/esp32/index.rst @@ -627,25 +627,30 @@ Please check for usage examples using the :doc:`ESP32 DevKitC `__ to build QEMU. +Get or build QEMU from `here `__. Enable the ``ESP32_QEMU_IMAGE`` config found in :menuselection:`Board Selection --> ESP32 binary image for QEMU`. -Download the bootloader and the partition table from https://github.com/espressif/esp-nuttx-bootloader/releases -and place them in a directory, say ``../esp-bins``. +Enable ``ESP32_APP_FORMAT_LEGACY``. Build and generate the QEMU image:: - $ make ESPTOOL_BINDIR=../esp-bins + $ make bootloader + $ make ESPTOOL_BINDIR=. A QEMU-compatible ``nuttx.merged.bin`` binary image will be created. It can be run as:: $ qemu-system-xtensa -nographic -machine esp32 -drive file=nuttx.merged.bin,if=mtd,format=raw +QEMU for ESP32 does not correctly define the chip revision as v3.0 so you have two options: + +- #define ``ESP32_IGNORE_CHIP_REVISION_CHECK`` in ``arch/xtensa/src/esp32/esp32_start.c`` +- Emulate the efuse as described `here `__. + QEMU Networking --------------- -Networking is possible using the openeth MAC driver. Enable ``ESP32_OPENETH`` option and set the nic in QEMU: +Networking is possible using the openeth MAC driver. Enable ``ESP32_OPENETH`` option and set the nic in QEMU:: $ qemu-system-xtensa -nographic -machine esp32 -drive file=nuttx.merged.bin,if=mtd,format=raw -nic user,model=open_eth diff --git a/Documentation/platforms/xtensa/esp32s3/index.rst b/Documentation/platforms/xtensa/esp32s3/index.rst index fef95268ffa83..6ae11d3f6d2c2 100644 --- a/Documentation/platforms/xtensa/esp32s3/index.rst +++ b/Documentation/platforms/xtensa/esp32s3/index.rst @@ -317,6 +317,31 @@ possible to track the root cause of the crash. Saving this output to a file and The above output shows the backtrace of the tasks. By checking it, it is possible to track the functions that were being executed when the crash occurred. +Using QEMU +========== + +Get or build QEMU from `here `__. The minimum supported version is 9.0.0. + +Enable the ``ESP32S3_QEMU_IMAGE`` config found in :menuselection:`Board Selection --> ESP32S3 binary image for QEMU`. + +Enable ``ESP32S3_APP_FORMAT_LEGACY``. + +Build and generate the QEMU image:: + + $ make bootloader + $ make ESPTOOL_BINDIR=. + +A QEMU-compatible ``nuttx.merged.bin`` binary image will be created. It can be run as:: + + $ qemu-system-xtensa -nographic -machine esp32s3 -drive file=nuttx.merged.bin,if=mtd,format=raw + +QEMU Networking +--------------- + +Networking is possible using the openeth MAC driver. Enable ``ESP32S3_OPENETH`` option and set the nic in QEMU: + + $ qemu-system-xtensa -nographic -machine esp32s3 -drive file=nuttx.merged.bin,if=mtd,format=raw -nic user,model=open_eth + Peripheral Support ================== diff --git a/arch/xtensa/src/esp32/esp32_openeth.c b/arch/xtensa/src/common/espressif/esp_openeth.c similarity index 96% rename from arch/xtensa/src/esp32/esp32_openeth.c rename to arch/xtensa/src/common/espressif/esp_openeth.c index a59a7d9af6dc1..8a8c072f9fe3d 100644 --- a/arch/xtensa/src/esp32/esp32_openeth.c +++ b/arch/xtensa/src/common/espressif/esp_openeth.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/xtensa/src/esp32/esp32_openeth.c + * arch/xtensa/src/common/espressif/esp_openeth.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -30,10 +30,7 @@ #include #include -#include "hardware/esp32_soc.h" -#include "esp32_irq.h" - -#ifdef CONFIG_ESP32_OPENETH +#include /**************************************************************************** * Pre-processor Definitions @@ -43,7 +40,7 @@ /* DMA buffers configuration */ #define DMA_BUF_SIZE 1600 -#define RX_BUF_COUNT CONFIG_ESP32_OPENETH_DMA_RX_BUFFER_NUM + /* Only need 1 TX buf because packets are transmitted immediately */ #define TX_BUF_COUNT 1 @@ -439,7 +436,7 @@ static int openeth_set_addr(uint8_t *addr) ****************************************************************************/ /**************************************************************************** - * Name: esp32_openeth_initialize + * Name: esp_openeth_initialize * * Description: * Initialize the openeth driver @@ -452,7 +449,7 @@ static int openeth_set_addr(uint8_t *addr) * ****************************************************************************/ -int esp32_openeth_initialize(void) +int esp_openeth_initialize(void) { int ret; struct openeth_priv_s *priv = &g_openeth; @@ -462,8 +459,9 @@ int esp32_openeth_initialize(void) if (REG_READ(OPENETH_MODER_REG) != OPENETH_MODER_DEFAULT) { - nerr("CONFIG_ESP32_OPENETH should only be used when running in QEMU."); - nerr("When running the app on the ESP32, use ESP32 EMAC instead."); + nerr("Openeth should only be used when running in QEMU."); + nerr("When running the app on the real hardware," + "use the real MAC instead."); abort(); } @@ -512,8 +510,8 @@ int esp32_openeth_initialize(void) /* Setup interrupts */ - priv->cpuint = esp32_setup_irq(0, ESP32_PERIPH_EMAC, - 1, ESP32_CPUINT_LEVEL); + priv->cpuint = OPENETH_SETUP_IRQ(0, OPENETH_PERIPH_MAC, + 1, OPENETH_CPUINT_LEVEL); if (priv->cpuint < 0) { nerr("ERROR: Failed allocate interrupt\n"); @@ -531,7 +529,7 @@ int esp32_openeth_initialize(void) /* Attach the interrupt */ - ret = irq_attach(ESP32_IRQ_EMAC, openeth_isr_handler, priv); + ret = irq_attach(OPENETH_IRQ_MAC, openeth_isr_handler, priv); /* Register the device with the OS so that socket IOCTLs can be * performed. @@ -552,5 +550,3 @@ int esp32_openeth_initialize(void) nerr("Failed initializing ret = %d", ret); abort(); } - -#endif /* CONFIG_ESP32_OPENETH */ diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs index 3e69a2972d979..43990fcde0649 100644 --- a/arch/xtensa/src/esp32/Make.defs +++ b/arch/xtensa/src/esp32/Make.defs @@ -205,7 +205,7 @@ endif endif ifeq ($(CONFIG_ESP32_OPENETH),y) -CHIP_CSRCS += esp32_openeth.c +CHIP_CSRCS += esp_openeth.c endif ############################################################################# diff --git a/arch/xtensa/src/esp32/chip.h b/arch/xtensa/src/esp32/chip.h index 1fd16a250b018..47412cf93aa84 100644 --- a/arch/xtensa/src/esp32/chip.h +++ b/arch/xtensa/src/esp32/chip.h @@ -30,10 +30,23 @@ #include "chip_macros.h" #include "chip_memory.h" +#if defined(CONFIG_ESP32_OPENETH) && !defined(__ASSEMBLY__) +#include "hardware/esp32_soc.h" +#include "esp32_irq.h" +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#if defined(CONFIG_ESP32_OPENETH) +#define OPENETH_PERIPH_MAC ESP32_PERIPH_EMAC +#define OPENETH_CPUINT_LEVEL ESP32_CPUINT_LEVEL +#define OPENETH_IRQ_MAC ESP32_IRQ_EMAC +#define OPENETH_SETUP_IRQ esp32_setup_irq +#define RX_BUF_COUNT CONFIG_ESP32_OPENETH_DMA_RX_BUFFER_NUM +#endif + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/arch/xtensa/src/esp32s3/Kconfig b/arch/xtensa/src/esp32s3/Kconfig index 64968c3d81344..e3793d0abf832 100644 --- a/arch/xtensa/src/esp32s3/Kconfig +++ b/arch/xtensa/src/esp32s3/Kconfig @@ -1658,6 +1658,27 @@ config ESP32S3_WIFI_LISTEN_INTERVAL endmenu # ESP32S3_WIFI +config ESP32S3_OPENETH + bool "Opencores Ethernet MAC" + default n + depends on !ESP32S3_WIFI + select NET + select SCHED_WORKQUEUE + ---help--- + Enable ESP32S3 ethernet opencores support for use with QEMU. + Disable this if you are using the real device. + +if ESP32S3_OPENETH + +config ESP32S3_OPENETH_DMA_RX_BUFFER_NUM + int "Number of Ethernet DMA Rx buffers" + range 1 64 + default 4 + ---help--- + Number of DMA receive buffers, each buffer is 1600 bytes. + +endif # ESP32S3_OPENETH + menu "BLE Configuration" depends on ESP32S3_BLE diff --git a/arch/xtensa/src/esp32s3/Make.defs b/arch/xtensa/src/esp32s3/Make.defs index 608a985129fce..1e5ecdacd7620 100644 --- a/arch/xtensa/src/esp32s3/Make.defs +++ b/arch/xtensa/src/esp32s3/Make.defs @@ -206,6 +206,10 @@ endif CHIP_CSRCS += esp32s3_pm.c endif +ifeq ($(CONFIG_ESP32S3_OPENETH),y) +CHIP_CSRCS += esp_openeth.c +endif + ############################################################################# # Espressif HAL for 3rd Party Platforms ############################################################################# diff --git a/arch/xtensa/src/esp32s3/chip.h b/arch/xtensa/src/esp32s3/chip.h index 725c54dd092b8..de74a17c482a5 100644 --- a/arch/xtensa/src/esp32s3/chip.h +++ b/arch/xtensa/src/esp32s3/chip.h @@ -30,10 +30,23 @@ #include "chip_macros.h" #include "chip_memory.h" +#if defined(CONFIG_ESP32S3_OPENETH) && !defined(__ASSEMBLY__) +#include "hardware/esp32s3_soc.h" +#include "esp32s3_irq.h" +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#if defined(CONFIG_ESP32S3_OPENETH) +#define OPENETH_PERIPH_MAC ESP32S3_PERIPH_MAC +#define OPENETH_CPUINT_LEVEL ESP32S3_CPUINT_LEVEL +#define OPENETH_IRQ_MAC ESP32S3_IRQ_MAC +#define OPENETH_SETUP_IRQ esp32s3_setup_irq +#define RX_BUF_COUNT CONFIG_ESP32S3_OPENETH_DMA_RX_BUFFER_NUM +#endif + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/arch/xtensa/src/esp32s3/hardware/esp32s3_soc.h b/arch/xtensa/src/esp32s3/hardware/esp32s3_soc.h index 35d026f37e801..47ca7321b9a83 100644 --- a/arch/xtensa/src/esp32s3/hardware/esp32s3_soc.h +++ b/arch/xtensa/src/esp32s3/hardware/esp32s3_soc.h @@ -40,7 +40,7 @@ ****************************************************************************/ #define DR_REG_USB_BASE 0x60080000 - +#define DR_REG_EMAC_BASE 0x600CD000 #define DR_REG_ASSIST_DEBUG_BASE 0x600CE000 #define DR_REG_WORLD_CNTL_BASE 0x600D0000 #define DR_REG_DPORT_END 0x600D3FFC diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/qemu-openeth/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/qemu_openeth/defconfig similarity index 98% rename from boards/xtensa/esp32/esp32-devkitc/configs/qemu-openeth/defconfig rename to boards/xtensa/esp32/esp32-devkitc/configs/qemu_openeth/defconfig index 6d0f99d5cf61a..3a91849e46644 100644 --- a/boards/xtensa/esp32/esp32-devkitc/configs/qemu-openeth/defconfig +++ b/boards/xtensa/esp32/esp32-devkitc/configs/qemu_openeth/defconfig @@ -19,6 +19,7 @@ CONFIG_ARCH_STACKDUMP=y CONFIG_ARCH_XTENSA=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y +CONFIG_ESP32_APP_FORMAT_LEGACY=y CONFIG_ESP32_OPENETH=y CONFIG_ESP32_QEMU_IMAGE=y CONFIG_ESP32_UART0=y diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h b/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h index 0e3ad3f7d7f5b..ddce1e7bafea2 100644 --- a/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h +++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h @@ -245,7 +245,7 @@ int board_ws2812_initialize( * ****************************************************************************/ #ifdef CONFIG_ESP32_OPENETH -int esp32_openeth_initialize(void); +int esp_openeth_initialize(void); #endif #endif /* __ASSEMBLY__ */ diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c index e3891007bfa1e..3fca7db59b5f9 100644 --- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c @@ -362,7 +362,7 @@ int esp32_bringup(void) #endif #ifdef CONFIG_ESP32_OPENETH - ret = esp32_openeth_initialize(); + ret = esp_openeth_initialize(); if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to initialize Open ETH ethernet.\n"); diff --git a/boards/xtensa/esp32s3/common/Kconfig b/boards/xtensa/esp32s3/common/Kconfig index 97c7c69bd0c82..47c74d04328bd 100644 --- a/boards/xtensa/esp32s3/common/Kconfig +++ b/boards/xtensa/esp32s3/common/Kconfig @@ -12,6 +12,13 @@ config ESP32S3_MERGE_BINS This is only useful when the path to binary files (e.g. bootloader) is provided via the ESPTOOL_BINDIR variable. +config ESP32S3_QEMU_IMAGE + bool "ESP32S3 binary image for QEMU" + default n + select ESP32S3_MERGE_BINS + ---help--- + Create a binary flash image used for QEMU. + config ESP32S3_SPEED_UP_ISR bool "Speed up ISR" default n diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/qemu_openeth/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/qemu_openeth/defconfig new file mode 100644 index 0000000000000..7748659415b55 --- /dev/null +++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/qemu_openeth/defconfig @@ -0,0 +1,68 @@ +# +# 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_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32s3-devkit" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32S3_DEVKIT=y +CONFIG_ARCH_CHIP="esp32s3" +CONFIG_ARCH_CHIP_ESP32S3=y +CONFIG_ARCH_CHIP_ESP32S3WROOM1N4=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_ESP32S3_APP_FORMAT_LEGACY=y +CONFIG_ESP32S3_OPENETH=y +CONFIG_ESP32S3_QEMU_IMAGE=y +CONFIG_ESP32S3_UART0=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=3072 +CONFIG_INTELHEX_BINARY=y +CONFIG_NETDB_DNSCLIENT=y +CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x0a000203 +CONFIG_NETDEV_LATEINIT=y +CONFIG_NETDEV_WORK_THREAD=y +CONFIG_NETINIT_DRIPADDR=0x0a000202 +CONFIG_NETINIT_IPADDR=0x0a000215 +CONFIG_NET_BINDTODEVICE=y +CONFIG_NET_ICMP_NPOLLWAITERS=4 +CONFIG_NET_ICMP_SOCKET=y +CONFIG_NET_ROUTE=y +CONFIG_NET_TCP=y +CONFIG_NET_TCPBACKLOG=y +CONFIG_NET_TCP_NPOLLWAITERS=8 +CONFIG_NET_TCP_WRITE_BUFFERS=y +CONFIG_NET_UDP=y +CONFIG_NET_UDP_NPOLLWAITERS=8 +CONFIG_NET_UDP_WRITE_BUFFERS=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_LPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSLOG_BUFFER=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_PING=y +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h index cafb03f6fdd0c..0a3fe78785574 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h +++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h @@ -269,5 +269,9 @@ int esp32s3_lan9250_initialize(int port); int esp32s3_lan9250_uninitialize(int port); #endif +#ifdef CONFIG_ESP32S3_OPENETH +int esp_openeth_initialize(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_XTENSA_ESP32S3_ESP32S3_DEVKIT_SRC_ESP32S3_DEVKIT_H */ diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c index 4017a141e04e1..8718a875db1b5 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c +++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c @@ -438,6 +438,14 @@ int esp32s3_bringup(void) #endif +#ifdef CONFIG_ESP32S3_OPENETH + ret = esp_openeth_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize Open ETH ethernet.\n"); + } +#endif + #ifdef CONFIG_DEV_GPIO ret = esp32s3_gpio_init(); if (ret < 0) diff --git a/tools/ci/testlist/xtensa-01.dat b/tools/ci/testlist/xtensa-01.dat index 8d1f5fa4d2a1a..74be477241823 100644 --- a/tools/ci/testlist/xtensa-01.dat +++ b/tools/ci/testlist/xtensa-01.dat @@ -1,4 +1,4 @@ /xtensa/esp32 # We do not set ESPTOOL_BINDIR in this build --esp32-devkitc:qemu-openeth +-esp32-devkitc:qemu_openeth diff --git a/tools/ci/testlist/xtensa-02.dat b/tools/ci/testlist/xtensa-02.dat index 5541451dfbae5..0d325bf303b95 100644 --- a/tools/ci/testlist/xtensa-02.dat +++ b/tools/ci/testlist/xtensa-02.dat @@ -1,3 +1,6 @@ /xtensa/esp32s2 /xtensa/esp32s3 + +# We do not set ESPTOOL_BINDIR in this build +-esp32s3-devkit:qemu_openeth diff --git a/tools/esp32s3/Config.mk b/tools/esp32s3/Config.mk index 3ca37ea260306..8b44cace29333 100644 --- a/tools/esp32s3/Config.mk +++ b/tools/esp32s3/Config.mk @@ -127,7 +127,13 @@ define MERGEBIN echo "Missing Flash memory size configuration for the ESP32-S3 chip."; \ exit 1; \ fi - esptool.py -c esp32s3 merge_bin --output nuttx.merged.bin $(ESPTOOL_FLASH_OPTS) $(ESPTOOL_BINS) + $(eval ESPTOOL_MERGEBIN_OPTS := \ + $(if $(CONFIG_ESP32S3_QEMU_IMAGE), \ + --fill-flash-size $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ), \ + $(ESPTOOL_FLASH_OPTS) \ + ) \ + ) + esptool.py -c esp32s3 merge_bin --output nuttx.merged.bin $(ESPTOOL_MERGEBIN_OPTS) $(ESPTOOL_BINS) $(Q) echo nuttx.merged.bin >> nuttx.manifest $(Q) echo "Generated: nuttx.merged.bin" endef