WiFi and BLE cyclical reboot issue
Posted: Sat Feb 19, 2022 5:39 am
Hi all,
I am trying to use both the BLE and WiFi stacks in my application. I am basing my code on the example 'ble_mesh_wifi_coexist', but I am getting a cyclical reboot and I have been stuck on this problem for a while now. I am hoping to get some help here.
I copied over the 'sdkconfig' and 'partition.csv' from the example. Below are my application code.
Thanks in advance,
Ed
WiFi and BLE code here.
My terminal log session - Cyclical reboot.
I am trying to use both the BLE and WiFi stacks in my application. I am basing my code on the example 'ble_mesh_wifi_coexist', but I am getting a cyclical reboot and I have been stuck on this problem for a while now. I am hoping to get some help here.
I copied over the 'sdkconfig' and 'partition.csv' from the example. Below are my application code.
Thanks in advance,
Ed
- void app_main(void)
- {
- uint32_t level = 1;
- nvs_flash_init();
- xQueue_wifi_ble = xQueueCreate(8, sizeof(uint8_t) );
- xTaskCreatePinnedToCore(sm_wifi, "WIFI_CONNECTION_TASK",
- 4096, NULL, WIFI_TASK_PRIO, NULL, tskNO_AFFINITY);
- xTaskCreatePinnedToCore(sm_ble, "BLE_CONNECTION_TASK",
- 4096, NULL, BLE_TASK_PRIO, NULL, tskNO_AFFINITY);
- while (true) {
- gpio_set_level(GPIO_NUM_4, level);
- level = !level;
- vTaskDelay(300 / portTICK_PERIOD_MS);
- }
- }
- // WiFi state machine and initialisation function.
- void sm_wifi() {
- static uint8_t tx_msg;
- const TickType_t xDelay = 5000 / portTICK_PERIOD_MS;
- init_wifi();
- for(;;) {
- xQueueReceive( xQueue_wifi, &state, ( TickType_t ) portMAX_DELAY);
- printf("app_wifi:New message received: %d\n", state);
- switch(state) {
- // Ommitted to keep it concise.
- }
- previous_state = state;
- vTaskDelay(xDelay);
- }
- }
- //Handlers not included to keep it concise.
- void init_wifi() {
- xQueue_wifi = xQueueCreate(XQWIFI_SIZE_BYTES, sizeof(uint8_t));
- wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
- ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
- ESP_ERROR_CHECK( esp_wifi_start() );
- ESP_ERROR_CHECK(esp_netif_init());
- ESP_ERROR_CHECK(esp_event_loop_create_default());
- ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
- ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL));
- ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
- ESP_ERROR_CHECK( esp_wifi_set_ps(WIFI_PS_MIN_MODEM) ); //must call this
- ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
- ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
- }
- // BLE state machine and BLE stack initialisation function.
- void sm_ble() {
- uint8_t wifi_state;
- const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
- init_ble();
- for(;;) {
- xQueueReceive( xQueue_wifi_ble, &wifi_state, ( TickType_t ) portMAX_DELAY);
- switch(wifi_state) {
- //Omitted to keep it concise.
- }
- vTaskDelay( xDelay );
- }
- }
- void init_ble() {
- ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
- esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
- esp_bt_controller_init(&bt_cfg);
- esp_bt_controller_enable(ESP_BT_MODE_BLE);
- esp_bluedroid_init();
- esp_bluedroid_enable();
- ble_ibeacon_appRegister();
- esp_ble_gap_set_scan_params(&ble_scan_params);
- }
- ELF file SHA256: a359d48b9e23aa19
- Rebooting...
- ets Jul 29 2019 12:21:46
- rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
- configsip: 0, SPIWP:0xee
- clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
- mode:DIO, clock div:2
- load:0x3fff0030,len:7872
- load:0x40078000,len:15576
- load:0x40080400,len:4392
- 0x40080400: _init at ??:?
- entry 0x4008069c
- I (27) boot: ESP-IDF v4.3.2-dirty 2nd stage bootloader
- I (27) boot: compile time 10:41:24
- I (27) boot: chip revision: 3
- I (30) boot_comm: chip revision: 3, min. bootloader chip revision: 0
- I (38) qio_mode: Enabling default flash chip QIO
- I (43) boot.esp32: SPI Speed : 40MHz
- I (47) boot.esp32: SPI Mode : QIO
- I (52) boot.esp32: SPI Flash Size : 4MB
- I (57) boot: Enabling RNG early entropy source...
- I (62) boot: Partition Table:
- I (66) boot: ## Label Usage Type ST Offset Length
- I (73) boot: 0 nvs WiFi data 01 02 00009000 00004000
- I (80) boot: 1 otadata OTA data 01 00 0000d000 00002000
- I (88) boot: 2 phy_init RF data 01 01 0000f000 00001000
- I (95) boot: 3 factory factory app 00 00 00010000 00200000
- I (103) boot: End of partition table
- I (107) boot: Defaulting to factory image
- I (112) boot_comm: chip revision: 3, min. application chip revision: 0
- I (119) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=32c94h (208020) map
- I (192) esp_image: segment 1: paddr=00042cbc vaddr=3ffbdb60 size=05628h ( 22056) load
- I (199) esp_image: segment 2: paddr=000482ec vaddr=40080000 size=07d2ch ( 32044) load
- I (211) esp_image: segment 3: paddr=00050020 vaddr=400d0020 size=ed8ach (972972) map
- I (512) esp_image: segment 4: paddr=0013d8d4 vaddr=40087d2c size=12868h ( 75880) load
- I (539) esp_image: segment 5: paddr=00150144 vaddr=50000000 size=00010h ( 16) load
- I (552) boot: Loaded app from partition at offset 0x10000
- I (553) boot: Disabling RNG early entropy source...
- I (564) cpu_start: Pro cpu up.
- I (564) cpu_start: Starting app cpu, entry point is 0x40081214
- 0x40081214: call_start_cpu1 at /home/ed/Work/Gardens/eclipse/esp-idf-v4.3.2/components/esp_system/port/cpu_start.c:150
- I (551) cpu_start: App cpu up.
- I (581) cpu_start: Pro cpu start user code
- I (581) cpu_start: cpu freq: 240000000
- I (581) cpu_start: Application information:
- I (585) cpu_start: Project name: app-template
- I (591) cpu_start: App version: 1
- I (595) cpu_start: Compile time: Feb 19 2022 13:02:22
- I (601) cpu_start: ELF file SHA256: a359d48b9e23aa19...
- I (607) cpu_start: ESP-IDF: v4.3.2-dirty
- I (613) heap_init: Initializing. RAM available for dynamic allocation:
- I (620) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
- I (626) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
- I (632) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
- I (638) heap_init: At 3FFD0378 len 0000FC88 (63 KiB): DRAM
- I (644) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
- I (651) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
- I (657) heap_init: At 4009A594 len 00005A6C (22 KiB): IRAM
- I (664) spi_flash: detected chip: generic
- I (668) spi_flash: flash io: qio
- I (673) cpu_start: Starting scheduler on PRO CPU.
- I (0) cpu_start: Starting scheduler on APP CPU.
- ESP_ERROR_CHECK failed: esp_err_t 0x3001 (ESP_ERR_WIFI_NOT_INIT) at 0x4008ee90
- 0x4008ee90: _esp_error_check_failed at /home/ed/Work/Gardens/eclipse/esp-idf-v4.3.2/components/esp_common/src/esp_err.c:41
- file: "../main/app_wifi.c" line 114
- func: init_wifi
- expression: esp_wifi_set_config(WIFI_IF_STA, &sta_config)
- abort() was called at PC 0x4008ee93 on core 1
- 0x4008ee93: _esp_error_check_failed at /home/ed/Work/Gardens/eclipse/esp-idf-v4.3.2/components/esp_common/src/esp_err.c:42
- Backtrace:0x4008154f:0x3ffd2590 0x400905c5:0x3ffd25b0 0x400966d6:0x3ffd25d0 0x4008ee93:0x3ffd2640 0x400d7bec:0x3ffd2660 0x400d7ce3:0x3ffd2740 0x40093ae5:0x3ffd2760
- 0x4008154f: panic_abort at /home/ed/Work/Gardens/eclipse/esp-idf-v4.3.2/components/esp_system/panic.c:393
- 0x400905c5: esp_system_abort at /home/ed/Work/Gardens/eclipse/esp-idf-v4.3.2/components/esp_system/system_api.c:112
- 0x400966d6: abort at /home/ed/Work/Gardens/eclipse/esp-idf-v4.3.2/components/newlib/abort.c:46
- 0x4008ee93: _esp_error_check_failed at /home/ed/Work/Gardens/eclipse/esp-idf-v4.3.2/components/esp_common/src/esp_err.c:42
- 0x400d7bec: init_wifi at /home/ed/Work/Gardens/gardens_esp32/build/../main/app_wifi.c:114 (discriminator 1)
- 0x400d7ce3: sm_wifi at /home/ed/Work/Gardens/gardens_esp32/build/../main/app_wifi.c:38
- 0x40093ae5: vPortTaskWrapper at /home/ed/Work/Gardens/eclipse/esp-idf-v4.3.2/components/freertos/port/xtensa/port.c:168