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

fußgänger
Posts: 4
Joined: Sun Jul 28, 2024 3:59 pm

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

Postby fußgänger » Sun Jul 28, 2024 4:53 pm

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.
Last edited by fußgänger on Mon Jul 29, 2024 2:20 pm, edited 1 time in total.

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

Re: SPI half duplex issues at ESP-IDF V3

Postby ESP_Sprite » 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?

fußgänger
Posts: 4
Joined: Sun Jul 28, 2024 3:59 pm

Re: SPI half duplex issues at ESP-IDF V3

Postby fußgänger » Mon Jul 29, 2024 2:15 pm

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).

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

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

Postby ESP_Sprite » Tue Jul 30, 2024 3:07 am

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.

fußgänger
Posts: 4
Joined: Sun Jul 28, 2024 3:59 pm

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

Postby fußgänger » Fri Aug 02, 2024 8:39 pm

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?

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

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

Postby ESP_Sprite » Sun Aug 04, 2024 12:51 am

That is correct.

fußgänger
Posts: 4
Joined: Sun Jul 28, 2024 3:59 pm

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

Postby fußgänger » Thu Aug 29, 2024 1:05 pm

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?

Who is online

Users browsing this forum: No registered users and 144 guests