Page 1 of 1

SPI half duplex migration issues from ESP-IDF v4 to v5

Posted: Sun Jul 28, 2024 4:53 pm
by fußgänger
I am currently trying to port code from ESP-IDF v4 to v5 (from Arduino-ESP32 v2 to v3), and I am stuck with its SPI part which speaks to the CMT2300a using half duplex SPI.

My ESP32-C6 is crashing with the error

Code: Select all

E (2072) spi_master: check_trans_valid(793): SPI half duplex mode is not supported when both MOSI and MISO phases are enabled.
pointing to the following api call

Code: Select all

file: "lib/CMT2300a/cmt_spi3.c" line 101
func: cmt_spi3_read
expression: spi_device_polling_transmit(spi_reg, &t)
The code can be found here.

I am compiling for the esp32-c6-devkitm-1 and my patched code can be found here.

Has someone an idea what went wrong here, since this code worked on previous versions?

Edit: Corrected mentioned ESP-IDF version.

Re: SPI half duplex issues at ESP-IDF V3

Posted: Mon Jul 29, 2024 2:12 am
by ESP_Sprite
ESP-IDF v3 is old and deprecated by now; we're at 5.3 or something now. Are you sure that's the esp-idf version you're using?

Re: SPI half duplex issues at ESP-IDF V3

Posted: Mon Jul 29, 2024 2:15 pm
by fußgänger
ESP_Sprite wrote:
Mon Jul 29, 2024 2:12 am
ESP-IDF v3 is old and deprecated by now; we're at 5.3 or something now. Are you sure that's the esp-idf version you're using?
Ah, sorry, my bad. I meant ESP-IDF v5.1.4 (which is used by Arduino-ESP32 v3).

Re: SPI half duplex migration issues from ESP-IDF v4 to v5

Posted: Tue Jul 30, 2024 3:07 am
by ESP_Sprite
Hm, this might have been an issue with that specific version: I don't see that error message pop up in the current ESP-IDF master. Easiest way might be to work around it: start two transactions, one for TX and one for RX.

Re: SPI half duplex migration issues from ESP-IDF v4 to v5

Posted: Fri Aug 02, 2024 8:39 pm
by fußgänger
ESP_Sprite wrote:
Tue Jul 30, 2024 3:07 am
Easiest way might be to work around it: start two transactions, one for TX and one for RX.
Thank you for your hint. I need a bit more help from you to tackle this.

So I have looked into the code and SPI documentation a bit deeper.
Do I understand it correctly that a call to spi_device_polling_transmit results in a transaction?
From reading the documentation, I interpret that setting tx_buffer to NULL skips the transmit phase. Is that correct?

Re: SPI half duplex migration issues from ESP-IDF v4 to v5

Posted: Sun Aug 04, 2024 12:51 am
by ESP_Sprite
That is correct.

Re: SPI half duplex migration issues from ESP-IDF v4 to v5

Posted: Thu Aug 29, 2024 1:05 pm
by fußgänger
From reading the documentation spi_transaction_t::length should be the length of bytes that will be transmitted by the SPI driver (and spi_transaction_t::rxlength how many bytes will be received).

In the code which implements SPI reading (cmt_spi3_read) the (tx) length is set to 8 but nothing else is configured for writing. I have set it to 0 and now everything works. Do I understand it correctly that this is a bug in the code and this has been undefined behavior?