ESP32-S3 freeze in spi_device_transmit() when transaction length is 1 bit (ESP-IDF v5.4.1)

zwer97
Posts: 14
Joined: Wed Dec 25, 2019 5:43 pm

ESP32-S3 freeze in spi_device_transmit() when transaction length is 1 bit (ESP-IDF v5.4.1)

Postby zwer97 » Wed May 28, 2025 5:22 pm

I'm trying to run libswd-esp32 on esp32-s3 and it freezes at the first SPI transaction, which has length of 1 bit.

Here is a code I used to reproduce it separately, it works on ESP32, but freezes on ESP32-S3.
It only freezes when the transaction length is set to 1.

Code: Select all


static spi_device_handle_t deviceSPI;

spi_bus_config_t buscfg = {
        .mosi_io_num     = GPIO_NUM_2, // SWD I/O
        .miso_io_num     = -1, // not connected
        .sclk_io_num     = GPIO_NUM_1, // SWD CLK
        .quadwp_io_num   = -1,
        .quadhd_io_num   = -1,
        .max_transfer_sz = 0
};
    
spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_DISABLED);

spi_device_interface_config_t devcfg = {
        .command_bits        = 0,
        .address_bits        = 0,
        .dummy_bits          = 0,
        .mode                = 0,
        .duty_cycle_pos      = 0,
        .cs_ena_pretrans     = 0,
        .cs_ena_posttrans    = 0,
        .clock_speed_hz      = 100000,
        .spics_io_num        = -1,
        .flags               = SPI_DEVICE_3WIRE | SPI_DEVICE_HALFDUPLEX | SPI_DEVICE_BIT_LSBFIRST,
        .queue_size          = 24,
        .pre_cb              = NULL,
        .post_cb             = NULL
};

spi_bus_add_device(SPI2_HOST, &devcfg, &deviceSPI)

spi_transaction_t transSPI;
memset(&transSPI, 0, sizeof(spi_transaction_t));

// simulated transaction from libswd
transSPI.flags = SPI_TRANS_USE_TXDATA;
transSPI.cmd = 0;
transSPI.addr = 0;
transSPI.length = 1;
transSPI.rxlength = 0;
transSPI.tx_data[0] = 0;
transSPI.tx_data[1] = 0;
transSPI.tx_data[2] = 0;
transSPI.tx_data[3] = 0;

spi_device_transmit(deviceSPI, &transSPI); // <=== FREEZE HERE



I stepped deeper into the ESP-IDF code and the processor is freezing here in spi_device_get_trans_result():

Code: Select all

r = xQueueReceive(handle->ret_queue, (void*)&trans_buf, ticks_to_wait);

Is this a bug and how could I bypass it?

zwer97
Posts: 14
Joined: Wed Dec 25, 2019 5:43 pm

Re: ESP32-S3 freeze in spi_device_transmit() when transaction length is 1 bit (ESP-IDF v5.4.1)

Postby zwer97 » Wed May 28, 2025 8:12 pm

I checked the clock pin with a probe and it never outputs that pulse with length set to 1, but with length set to 2 it works.
Any ideas?

Screenshot from 2025-05-28 23-08-42.png
Screenshot from 2025-05-28 23-08-42.png (37.49 KiB) Viewed 68 times

Who is online

Users browsing this forum: PerplexityBot and 19 guests