Wireless stick lite -> SPI bus already initialized Error

Hello, I’m using a C library that sends raw LoRa data esp32-lora-library , the library works fine when i use it with an ESP32 dev board + SX127X , but when i include it inside the wireless stick lite project, it keeps throwing “E (313) spi: spi_bus_initialize(628): SPI bus already initialized.”

i’m using ESP-IDF and this is the pin configurations for the Heltech board:

#define CONFIG_CS_GPIO 18
#define CONFIG_RST_GPIO 14
#define CONFIG_MISO_GPIO 19
#define CONFIG_MOSI_GPIO 27
#define CONFIG_SCK_GPIO 5

The error comes from the initialization function’s lines which try to initialize the spi and register it.

int lora_init(void)

{
esp_err_t ret;

/*
* Configure CPU hardware to communicate with the radio chip
*/
gpio_pad_select_gpio(CONFIG_RST_GPIO);
gpio_set_direction(CONFIG_RST_GPIO, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(CONFIG_CS_GPIO);
gpio_set_direction(CONFIG_CS_GPIO, GPIO_MODE_OUTPUT);

spi_bus_config_t bus = {
.miso_io_num = CONFIG_MISO_GPIO,
.mosi_io_num = CONFIG_MOSI_GPIO,
.sclk_io_num = CONFIG_SCK_GPIO,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 0
};

ret = spi_bus_initialize(VSPI_HOST, &bus, 0);
assert(ret == ESP_OK);

spi_device_interface_config_t dev = {
.clock_speed_hz = 9000000,
.mode = 0,
.spics_io_num = -1,
.queue_size = 1,
.flags = 0,
.pre_cb = NULL
};
ret = spi_bus_add_device(VSPI_HOST, &dev, &__spi);
assert(ret == ESP_OK);

/*
* Perform hardware reset.
*/
lora_reset();

/*
* Check version.
*/
uint8_t version;
uint8_t i = 0;
while(i++ < TIMEOUT_RESET) {
version = lora_read_reg(REG_VERSION);
if(version == 0x12) break;
vTaskDelay(2);
}
assert(i <= TIMEOUT_RESET + 1); // at the end of the loop above, the max value i can reach is TIMEOUT_RESET + 1

/*
* Default configuration.
*/
lora_sleep();
lora_write_reg(REG_FIFO_RX_BASE_ADDR, 0);
lora_write_reg(REG_FIFO_TX_BASE_ADDR, 0);
lora_write_reg(REG_LNA, lora_read_reg(REG_LNA) | 0x03);
lora_write_reg(REG_MODEM_CONFIG_3, 0x04);
lora_set_tx_power(17);

lora_idle();
return 1;
}

I’ve no idea where else the spi get initialized, and the library is working with other boards!!

Total Error Message:

ELF file SHA256: 4c0154bd6b478d2a

Rebooting…
I (13) boot: ESP-IDF v4.3.2-dirty 2nd stage bootloader
I (13) boot: compile time 11:23:07
I (13) boot: chip revision: 1
I (15) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (22) boot.esp32: SPI Speed : 40MHz
I (27) boot.esp32: SPI Mode : DIO
I (31) boot.esp32: SPI Flash Size : 4MB
I (36) boot: Enabling RNG early entropy source…
I (41) boot: Partition Table:
I (45) boot: ## Label Usage Type ST Offset Length
I (52) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (59) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (67) boot: 2 factory factory app 00 00 00010000 00100000
I (74) boot: End of partition table
I (79) boot_comm: chip revision: 1, min. application chip revision: 0
I (86) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=08718h ( 34584) map
I (107) esp_image: segment 1: paddr=00018740 vaddr=3ffb0000 size=02a04h ( 10756) load
I (111) esp_image: segment 2: paddr=0001b14c vaddr=40080000 size=04ecch ( 20172) load
I (122) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=160fch ( 90364) map
I (155) esp_image: segment 4: paddr=00036124 vaddr=40084ecc size=079d4h ( 31188) load
I (168) esp_image: segment 5: paddr=0003db00 vaddr=50000000 size=00010h ( 16) load
I (174) boot: Loaded app from partition at offset 0x10000
I (174) boot: Disabling RNG early entropy source…
I (188) cpu_start: Pro cpu up.
I (188) cpu_start: Starting app cpu, entry point is 0x400810e8
0x400810e8: call_start_cpu1 at C:/ESP/esp/esp-idf/components/esp_system/port/cpu_start.c:150

I (182) cpu_start: App cpu up.
I (202) cpu_start: Pro cpu start user code
I (202) cpu_start: cpu freq: 80000000
I (202) cpu_start: Application information:
I (207) cpu_start: Project name: WSL_Cork_RTOS
I (212) cpu_start: App version: d7438e2-dirty
I (218) cpu_start: Compile time: Feb 1 2022 11:22:48
I (224) cpu_start: ELF file SHA256: 4c0154bd6b478d2a…
I (230) cpu_start: ESP-IDF: v4.3.2-dirty
I (235) heap_init: Initializing. RAM available for dynamic allocation:
I (242) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (248) heap_init: At 3FFB3318 len 0002CCE8 (179 KiB): DRAM
I (255) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (261) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (267) heap_init: At 4008C8A0 len 00013760 (77 KiB): IRAM
I (275) spi_flash: detected chip: gd
I (278) spi_flash: flash io: dio
I (283) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (293) TEST_1: Starting the Raw LoRa Test
E (313) spi: spi_bus_initialize(628): SPI bus already initialized.

assert failed: lora_init lora.c:336 (ret == ESP_OK)

Backtrace:0x400813f3:0x3ffb5de0 0x40085fdd:0x3ffb5e00 0x4008b791:0x3ffb5e20 0x400d513e:0x3ffb5f40 0x400d4f81:0x3ffb5fb0 0x400e5f34:0x3ffb5fe0 0x40088aa1:0x3ffb6000
0x400813f3: panic_abort at C:/ESP/esp/esp-idf/components/esp_system/panic.c:393

0x40085fdd: esp_system_abort at C:/ESP/esp/esp-idf/components/esp_system/system_api.c:112

0x4008b791: __assert_func at C:/ESP/esp/esp-idf/components/newlib/assert.c:85

0x400d513e: lora_init at C:\ESP\ESP-IDF_Firmwares\WSL_Cork_RTOS\build/…/components/Cork_LoRa/lora.c:336 (discriminator 1)

0x400d4f81: app_main at C:\ESP\ESP-IDF_Firmwares\WSL_Cork_RTOS\build/…/main/main.c:44 (discriminator 1)

0x400e5f34: main_task at C:/ESP/esp/esp-idf/components/freertos/port/port_common.c:133 (discriminator 2)

0x40088aa1: vPortTaskWrapper at C:/ESP/esp/esp-idf/components/freertos/port/xtensa/port.c:168