zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10k stars 6.15k forks source link

Add Support for Adafruit ESP32-S3 and ESP32-S2 Feather Boards #68512

Open zpm1066 opened 4 months ago

zpm1066 commented 4 months ago

Is your feature request related to a problem? Please describe. This is a request to add support for the very popular family of Adafruit ESP32-S3 Feather and ESP32-S2 Feather boards.

As we already have support for the Xtensa ESP32-S3 and ESP32-S2 SoCs, I'm hoping it would be relatively less effort to add support for the Adafruit ESP32-S3 & ESP32-S2 Feather boards.

Describe the solution you'd like I'd like to see a common board definition to support these Adafruit ESP32-S3 & ESP32-S2 Feather boards. Folks can then add their own overlays to support the board variants that come with on-board TFT, fuel gauge, sensors, or Flash/PSRAM.

Describe alternatives you've considered Currently there isn't any support for the Adafruit ESP32-S3 & ESP32-S2 Feather boards.

Additional context Here is a list of the current Adafruit ESP3-S3 & ESP32-S2 Feather boards that this request will be able to support.

zpm1066 commented 4 months ago

Hello,

I’ve been looking to see if I can leverage board xiao_esp32s3 or esp32s3_devkitm, as the Adafruit esp32s3 Feather also uses ESP32-S3-Mini-1 SoC.

If so, I expect the changes to add support for the Adafruit esp32s3 boards may be relatively small.

I’ll be available for any testing if needed.

zpm1066 commented 4 months ago

Just ran a few quick tests. It looks like I’ll be able use board xiao_esp32s3 for some initial tests with the Adafruit ESP32S3 Feather boards.

I expected esp32s3_devkitm boards to work with the Adafruit esp32s3 boards as both are ESP32-S3-Mini-1 but no. Perhaps some mismatch flash in the Flash partitions.

Anyway, for now I’ll override GPIOs and I2C in an overlay to conduct some tests using xiao_esp32s3 and provide some updates.

sylvioalves commented 4 months ago

You should be able to get that working adding overlays and necessary configs. You are welcome to submit a PR to bring support to this boards.

zpm1066 commented 4 months ago

Yes - xiaoesp32s3 board works! Build using esp32s3 devkitm did’t work though it is ESP32-S3-Mini-1.

@sylvioalves - Any reason why esp32s3_ devkitm didn’t work? The esp32s3 TFT Feather is 4MB Flash and 2MB PSRAM.

zpm1066 commented 4 months ago

I've setup a new board Adafruit_esp32s3_tft_feather locally.

Added and tested:

Items remaining to configure & test

I've run some test with the regulator binding, see below.

There is 3.26V at the I2C STEMMA connector, SDA and SCK pins also have valid signal levels. This means that the firmware is sending I2C data correctly continuously to the display, as expected.

Given that the first 2 errors are I2C transfer error and ssd1306: Failed to initialize device! before the “*** Booting Zephyr …”, it appears that I2C and SSD1306 initialization occurs before the regulator power comes on.

How do I check and modify the order of I2C, SSD1306, Regulator priorities in Zephyr? I think once this is done, the display will work.

Thanks.

Regulator binding in adafruit_esp32s3_tft_feather.overlay:

    reg_tft_power: reg-tft-power {
        compatible = "regulator-fixed";
        regulator-name = "reg-adafruit";
        enable-gpios = <&gpio0 21 GPIO_ACTIVE_HIGH>;
        regulator-boot-on;
    };

Code snippet for output below:

void oled_display(void)
{    
    char os_ver[32];
    int err;

    uint32_t ver = sys_kernel_version_get();
    snprintf(os_ver,sizeof(os_ver),"Zephyr v%d.%d.%d",SYS_KERNEL_VER_MAJOR(ver), \
        SYS_KERNEL_VER_MINOR(ver),SYS_KERNEL_VER_PATCHLEVEL(ver));

    LOG_INF("%s\n",os_ver);
    LOG_INF(CONFIG_BOARD);
    while (1) {
        cfb_print(dev,CONFIG_BOARD, 0, 2*ppt);
        cfb_print(dev, "", 0, 1*ppt);
        cfb_print(dev, "OLED SSD1306 128x64", 0, 0);
        cfb_print(dev, "", 0, 3*ppt);
        cfb_print(dev, "", 0, 4*ppt);
        cfb_print(dev, "", 0, 5*ppt);
        cfb_print(dev, os_ver, 0, 6*ppt);

        err = cfb_framebuffer_finalize(dev);
        if (err) {
            printk("Could not finalize framebuffer (err %d)\n", err);
        }
        k_sleep(K_MSEC(500));
    }
}

espressif monitor output:

[00:00:00.228,000] <err> i2c_esp32: I2C transfer error: -14
[00:00:00.228,000] <err> ssd1306: Failed to initialize device!
*** Booting Zephyr OS build zephyr-v3.5.0-4872-gcf14d4f1fd6d ***
[00:00:00.228,000] <inf> main: main_thread
Display device not ready
[00:00:00.228,000] <dbg> cfb: cfb_framebuffer_init: number of fonts 2
[00:00:00.317,000] <inf> display: Index[0] font dimensions  5x8
[00:00:00.317,000] <inf> display: Index[1] font dimensions  8x8
[00:00:00.317,000] <inf> display: Selected font: index[3]
[00:00:00.317,000] <inf> display: x_res 128, y_res 64, ppt 8, rows 8, cols 128
[00:00:00.317,000] <inf> display: Zephyr v3.5.99

[00:00:00.317,000] <inf> display: adafruit_esp32s3_tft_feather
uart:~$ device list
devices:
- rtc@60021000 (READY)
- gpio@60004800 (READY)
- gpio@60004000 (READY)
- trng@6003507c (READY)
- uart@60000000 (READY)
- uart@60038000 (READY)
- i2c@60013000 (READY)
- reg-tft-power (READY)
- ssd1306@3c (DISABLED)
uart:~$ 

Output on regulator disable. Re-enabling the regulator stops the the I2C transfer errors.

uart:~$ regulator disable reg-tft-power
[00:26:06.518,000] <err> i2c_esp32: I2C transfer error: -116
[00:26:06.518,000] <err> ssd1306: Failed to write command
Could not finalize framebuffer (err -1)
[00:26:07.519,000] <err> i2c_esp32: I2C transfer error: -116
[00:26:07.519,000] <err> ssd1306: Failed to write command
Could not finalize framebuffer (err -1)
[00:26:08.519,000] <err> i2c_esp32: I2C transfer error: -116
[00:26:08.519,000] <err> ssd1306: Failed to write command
Could not finalize framebuffer (err -1)
uart:~$ 
zpm1066 commented 4 months ago

The I2C STEMMA connector on the ESP32-S3 TFT Feather already has pull-up resistors.

With Arduino, only I2C and SSD1306 requires initialization as Arduino already raises GPIO 21 HIGH prior to Arduino setup().

Screen Shot 2024-02-13 at 11 39 39 PM