Closed ghost closed 2 years ago
An update: spi: spi_bus_initialize(628): SPI bus already initialized.␛[0
this is possibly related to not using the right bus (I do not know yet how to force use of software SPI bus).
We might want to use VSPI_HOST for LORA, and HSPI_HOST for the sdcard.
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
SDSPI_HOST_DEFAULT is here. https://github.com/espressif/esp-idf/blob/master/components/driver/include/driver/sdspi_host.h
SDSPI_HOST_DEFAULT () has the following contents.
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
#define SDSPI_DEFAULT_HOST HSPI_HOST
#define SDSPI_DEFAULT_DMA SDSPI_DEFAULT_HOST
#else
#define SDSPI_DEFAULT_HOST SPI2_HOST
#define SDSPI_DEFAULT_DMA SPI_DMA_CH_AUTO
#endif
/**
* @brief Default sdmmc_host_t structure initializer for SD over SPI driver
*
* Uses SPI mode and max frequency set to 20MHz
*
* 'slot' should be set to an sdspi device initialized by `sdspi_host_init_device()`.
*/
#define SDSPI_HOST_DEFAULT() {\
.flags = SDMMC_HOST_FLAG_SPI | SDMMC_HOST_FLAG_DEINIT_ARG, \
.slot = SDSPI_DEFAULT_HOST, \
.max_freq_khz = SDMMC_FREQ_DEFAULT, \
.io_voltage = 3.3f, \
.init = &sdspi_host_init, \
.set_bus_width = NULL, \
.get_bus_width = NULL, \
.set_bus_ddr_mode = NULL, \
.set_card_clk = &sdspi_host_set_card_clk, \
.do_transaction = &sdspi_host_do_transaction, \
.deinit_p = &sdspi_host_remove_device, \
.io_int_enable = &sdspi_host_io_int_enable, \
.io_int_wait = &sdspi_host_io_int_wait, \
.command_timeout_ms = 0, \
}
HSPI_HOST / SPI2_HOST cannot be used on other devices. Conflicts when using HSPI_HOST / SPI2_HOST on other devices..
#ifdef USE_SDCARD
spi_bus_config_t bus_cfg = {
.mosi_io_num = SDCARD_MOSI,
.miso_io_num = SDCARD_MISO,
.sclk_io_num = SDCARD_SCK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 4000,
};
ret = spi_bus_initialize(host.slot, &bus_cfg, SDSPI_DEFAULT_HOST); ---> host.slot is HSPI_HOST/SPI2_HOST
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize bus.");
return ret;
}
#endif
When using SDSPI, HSPI_HOST / SPI2_HOST cannot be used for SPI_HOST_ID.
#ifdef CONFIG_IDF_TARGET_ESP32
#define SPI_HOST_ID HSPI_HOST --> Must be change
#elif defined CONFIG_IDF_TARGET_ESP32S2
#define SPI_HOST_ID SPI2_HOST --> Must be change
#elif defined CONFIG_IDF_TARGET_ESP32S3
#define SPI_HOST_ID SPI2_HOST --> Must be change
#elif defined CONFIG_IDF_TARGET_ESP32C3
#define SPI_HOST_ID SPI2_HOST --> Must be change
#endif
ret = spi_bus_initialize(SPI_HOST_ID, &bus, SPI_DMA_CH_AUTO);
if (ret != ESP_OK)
return ret;
I've ported part of the IRQ handling code from https://github.com/bkgoodman/esp-idf-lora, to your implementation.
I want to know more details.
I found this code no longer meaningful: ESP32 has SPI2_HOST/SPI3_HOST.
#ifdef CONFIG_IDF_TARGET_ESP32
#define LCD_HOST HSPI_HOST
#elif defined CONFIG_IDF_TARGET_ESP32S2
#define LCD_HOST SPI2_HOST
#elif defined CONFIG_IDF_TARGET_ESP32S3
#define LCD_HOST SPI2_HOST
#elif defined CONFIG_IDF_TARGET_ESP32C3
#define LCD_HOST SPI2_HOST
#endif
I am considering making it possible to select SPI2_HOST / SPI3_HOST.
You can now select SPI2_HOST / SPI3_HOST.
Set to SPI3_HOST when using with SDSPI.
We might want to use VSPI_HOST for LORA, and HSPI_HOST for the sdcard.
ESP32S2 / S3 / C3 / H2 / C2 does not have VSPI_HOST.
In ESP32S2 / S3 / C3 / H2 / C2, VSPI_HOST has changed to SPI3_HOST.
I've ported part of the IRQ handling code from https://github.com/bkgoodman/esp-idf-lora, to your implementation. However, I'm seeing a conflict with both the IRQ handling and the SPI bus initialization:
My SD card code is identical to:
https://raw.githubusercontent.com/espressif/esp-idf/a82e6e63d98bb051d4c59cb3d440c537ab9f74b0/examples/storage/sd_card/sdspi/main/sd_card_example_main.c
My TTGO LORA32 board configuration:
LORA setup:
I've been trying to follow the steps described here: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdspi_share.html
I'm happy to send you the entire lora.c file. Thank you for your excellent work again, your repositories are an absolute time saver and great reference.