ESP32-S2 SPI flash CS only low during clock pulse

tobi_ffm
Posts: 2
Joined: Sun Mar 12, 2023 11:00 am

ESP32-S2 SPI flash CS only low during clock pulse

Postby tobi_ffm » Sun Mar 12, 2023 11:34 am

Hi all,
We are having some strange behaviour of the CS line with ESP32-S2 and SPI flash. I would expect the CS line to be low for the whole transaction. But it is only low for very short periods and during clock pulses.

Writing to and reading from the flash works fine. But we have flash corruption from time to time. So I started to check the signals.

I tried with SPI2_HOST and SPI3_HOST and also with different CS pins and several ESP32s.
CS is pulled up with a 4K7 resistor.
Flash: S25FL256SAGNFI000

Can anyone help me with this?

Thanks in advance.
Tobi

Code: Select all

esp_flash_t* example_init_ext_flash(void)
{
  spi_bus_config_t bus_config = {
	.mosi_io_num = GPIO_NUM_12,
	.miso_io_num = GPIO_NUM_13,
	.sclk_io_num = GPIO_NUM_15,
	.quadwp_io_num = -1,
	.quadhd_io_num = -1
    };

    const esp_flash_spi_device_config_t device_config = {
        .host_id = SPI2_HOST,
        .cs_io_num = GPIO_NUM_5,
        .io_mode = SPI_FLASH_SLOWRD,
        .speed = ESP_FLASH_40MHZ,
        .input_delay_ns = 0,
        .cs_id = 0,
        .freq_mhz = 40,
    };

    ESP_LOGI(API_TAG_IO, "Initializing external SPI Module");
    ESP_LOGI(API_TAG_IO, "Pin assignments:");
    ESP_LOGI(API_TAG_IO, "MOSI: %2d   MISO: %2d   SCLK: %2d   CS: %2d",
        bus_config.mosi_io_num, bus_config.miso_io_num,
        bus_config.sclk_io_num, device_config.cs_io_num
    );

    // Initialize the SPI bus
    ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &bus_config, SPI2_HOST));

    // Add device to the SPI bus
    esp_flash_t* ext_flash;
    ESP_ERROR_CHECK(spi_bus_add_flash_device(&ext_flash, &device_config));
	
    // Probe the Flash chip and initialize it
    // ERASE DOES NOT WORK WITH THIS
    ext_flash->chip_drv = &esp_flash_chip_winbond;
    esp_err_t err = esp_flash_init(ext_flash);
    if (err != ESP_OK) {
        ESP_LOGE(API_TAG_IO, "Failed to initialize external Flash: %s (0x%x)", esp_err_to_name(err), err);
        return NULL;
    }

    ext_flash->size = 32*1024*1024;
    esp_flash_set_chip_write_protect(ext_flash,false);

    return ext_flash;
}
ESP32-S2_SPI_Flash.PNG
ESP32-S2_SPI_Flash.PNG (196.04 KiB) Viewed 1011 times

ESP_Sprite
Posts: 9769
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S2 SPI flash CS only low during clock pulse

Postby ESP_Sprite » Mon Mar 13, 2023 12:24 am

Your scope is set to 20uS/div and SPI runs at 40MHz, meaning one clock cycle is 1/800th div. Are you sure you're not just zoomed out too much on your scope?

tobi_ffm
Posts: 2
Joined: Sun Mar 12, 2023 11:00 am

Re: ESP32-S2 SPI flash CS only low during clock pulse

Postby tobi_ffm » Mon Mar 13, 2023 8:15 am

You are absolutely right. Oh boy :lol:
Thank you so much!

Who is online

Users browsing this forum: No registered users and 102 guests