Page 1 of 1

ESP32-C3 SPI3_HOST not recognized

Posted: Fri Aug 13, 2021 8:56 am
by bernardbru
Hi,

Environment:
board ESP32-C3-DevKitC-02
ESP-IDF V4.3
chip revision 3

Issue
I have an issue with SPI master.
ret = spi_bus_initialize(SPI2_HOST, &buscfg, DMA_CHAN); this is OK
but
ret = spi_bus_initialize(SPI3_HOST, &buscfg, DMA_CHAN); this is not OK
During execution, it fails with the error message:
spi_bus_initialize(627): invalid host_id
But SPI3_HOST should be recognized as illustrated hereunder.

in spi_types.h
SPI_EV_BUF_TXtypedef enum {
//SPI1 can be used as GPSPI only on ESP32
SPI1_HOST=0, ///< SPI1
SPI2_HOST=1, ///< SPI2
SPI3_HOST=2, ///< SPI3
} spi_host_device_t;


I did some search and found that in spi_common.c line 102
static inline bool is_valid_host(spi_host_device_t host)
{
#if (SOC_SPI_PERIPH_NUM == 2)
return host >= SPI1_HOST && host <= SPI2_HOST;
#elif (SOC_SPI_PERIPH_NUM == 3)
return host >= SPI1_HOST && host <= SPI3_HOST;
#endif
}
looking at socs_caps.h line 175
#define SOC_SPI_PERIPH_NUM 2
So why it is 2 instead or 3, ESP32-C3 has 3 SPI interface and SPI3_HOST is for general purpose ???

Re: ESP32-C3 SPI3_HOST not recognized

Posted: Fri Aug 13, 2021 3:03 pm
by ESP_Sprite
The ESP32C3 only has SPI0 (unusable by software as it is controlled by the flash cache) SPI1 (which is kinda hard to use as it's also connected to the flash) and SPI2; the hardware does not contain SPI3.

Re: ESP32-C3 SPI3_HOST not recognized

Posted: Fri Aug 13, 2021 3:41 pm
by bernardbru
You are correct there are only 3 SPI interface but SPI3_HOST exist .
or to simplify SPI0, SPI1, SP2
What I see is using the value 2, it doesn't work : error message "invalid host_id"
So on my side, I can't access the third SPI interface.
Could you ?

spi_types.h
SPI_EV_BUF_TXtypedef enum {
//SPI1 can be used as GPSPI only on ESP32
SPI1_HOST=0, ///< SPI1
SPI2_HOST=1, ///< SPI2
SPI3_HOST=2, ///< SPI3
} spi_host_device_t;

Re: ESP32-C3 SPI3_HOST not recognized

Posted: Sat Aug 14, 2021 1:36 am
by ESP_Sprite
SPI3 (or SPI3_HOST) does *not* exist in the -C3. From the datasheet: "ESP32-C3 family features three SPI interfaces (SPI0, SPI1, and SPI2). SPI0 and SPI1 can only be configured to operate in SPI memory mode, while SPI2 can be configured to operate in both SPI memory and general-purpose SPI modes." The define is in there because other ESP32s have a fourth SPI interface called SPI3 (note we start counting from SPI0, so SPI3 is the fourth SPI interface) but the -C3 does not. The header file you see does not mention SPI0 (and does not have an enum value for it) as it's special in all ESP32 chips and never usable by software, so there's no need to have an identifier for it.

Re: ESP32-C3 SPI3_HOST not recognized

Posted: Sun Aug 15, 2021 6:37 pm
by bernardbru
Thank you ESP_Sprite, using SPI1 it works