Page 1 of 1

WiFi and BLE cyclical reboot issue

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

Re: WiFi and BLE cyclical reboot issue

Posted: Sun Feb 20, 2022 6:15 am
by ESP_Sprite
Wondering if you could figure out this yourself... look at the file, function and expression that triggers the error, and the name of the error. Then look at your main.c initialization code, and the order in which it does things.