Skip to content

Changes to better support ESP32-S3 and Wiznet 5500 Ethernet chips. #1518

@rmontrosecbw

Description

@rmontrosecbw

Build environment: Windows 11
Moddable SDK version: 5.8.0
Target device: Custom ESP32-S3 device with WizNet 5500 Ethernet MAC/PHY

Description
Changes to better support ESP32-S3 and Wiznet 5500 Ethernet chips.

In "modules\network\ethernet\esp32\ethernet.c", at multiple places, it sets the SPI command bits to 3 and address_bits to 5. The Wiznet 5500 requires command bits set to 0 and address_bits set to 16, and other Ethernet SPI chips may require different settings. I would recommend adding a MODDEF to the Ethernet settings to allow these values to be overridden as needed. (needs to be done in 3 places)

#ifdef MODDEF_ETHERNET_SPI_COMMAND_BITS
		.command_bits = MODDEF_ETHERNET_SPI_COMMAND_BITS,
#else
		.command_bits = 3,		// requires a related change to pins/spi
#endif
#ifdef MODDEF_ETHERNET_SPI_ADDRESS_BITS
		.address_bits = MODDEF_ETHERNET_SPI_ADDRESS_BITS,
#else
		.address_bits = 5,
#endif

In init_spi() when it calls spi_bus_initialize, it sets the DMA channel to 1. This doesn't work on devices like the ESP32-S3, which use SPI DMA channel 1 for the internal Flash and PSRAM; therefore, the user must use DMA channel; 2. A better choice to to allow specifying the DMA channel in the manifest. The value of 3 specifies AUTO SPI_DMA_Channel, that works for all chips except the original ESP32 WROOM chips.

ESP_ERROR_CHECK(spi_bus_initialize(MODDEF_ETHERNET_SPI_PORT, &buscfg, MODDEF_ETHERNET_SPI_DMA_CH));

The SPI_PORT should be a MODDEF variable to allow configuring the appropriate one for the target. The default is HSPI_HOST or VSPI_HOST, and our device uses SPI2_HOST

The Ethernet manifest.json to support this:

	"ethernet": {
		"hz": 16000000,
		"int_pin": 14,
		"power_pin": 8,
		"hostname":"\"Edgetech01\"",
		"spi": {
				"command_bits": 16,
				"address_bits": 8,
				"cs_pin": 10,
				"port": "SPI2_HOST",
				"miso_pin": 13,
				"mosi_pin": 11,
				"sck_pin": 12,
				"polling_ms": 0,
				"dma_ch": 3;
		}
        }

These changes will allow a target device to use Ethernet with the standard Moddable distribution.

To include the Espressif built in Ethernet components I need to add esp_eth esp_netif libraries. These are not in the Espressif Component Registry so the dependency settings cannot be used. I had to modify moddable\build\devices\esp32\xsProj-esp32s3\main\CMakeLists.txt add_prebuilt_library to include these libraries. I don't know a way to add them to our custom target.

add_prebuilt_library(xsesp32 ${CMAKE_BINARY_DIR}/xs_${ESP32_SUBCLASS}.a
			REQUIRES esp_timer esp_wifi spi_flash bt esp_lcd nvs_flash spiffs esp_driver_gpio esp_driver_spi esp_eth esp_netif log ${ESP_COMPONENTS}
		)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions