Closed ghost closed 11 months ago
Hi @brahmajit ,
You are attempting to use the sample application code as it is, but it seems certain points are not considered while calling the relevant APIs . The crash appears to be due to half-way deinitialization of host when 2 standalone applications are combined.
The thing happening here while combining two standalone applications is:
The provided sample applications in IDF are reference applications showcasing scenario for standalone use cases. If your use case needs merging the two applications, then please make sure you are taking care of correctly deinitalizing the stack before you initialize again. Your application needs to ensure all stack cleanup happens correctly before an attempt of initializing it is done again. Since IDF code is open source, you can refer to code / documentation to get more information about how stack initialization happens.
Thanks, Isha
@IshaESP thank you. Unfortunately I'm new to IDF. Any resources (which part of the official doc should I check) where I could read how to deinitalize the stack.
I was looking at the nimble docs, but deinitializing nimble before begining provisioning example just stops the provisioning too.
Hi @brahmajit ,
ESP-IDF has nimble stack which is from upstream mynewt-nimble code - https://mynewt.apache.org/latest/network/ .The major changes done in IDF is for the porting layer ,rest of the code is picked from open source as it is.
The API documentation you can start referring to understand is - https://github.com/espressif/esp-idf/blob/master/components/bt/host/nimble/esp-hci/include/esp_nimble_hci.h#L89
@IshaESP 2nd link is invalid at this moment.
Hi @KaeLL, I have updated the link, please check it now.
Thank you @IshaESP
On Fri, Mar 11, 2022 at 5:53 PM IshaESP @.***> wrote:
Hi @brahmajit https://github.com/brahmajit ,
ESP-IDF has nimble stack which is from upstream mynewt-nimble code - https://mynewt.apache.org/latest/network/ http://url .The major changes done in IDF is for the porting layer ,rest of the code is picked from open source as it is.
The API documentation you can start referring to understand is - https://github.com/espressif/esp-idf/blob/a8ba5a0264d50f9aadd79838e2672a2828704770/components/bt/host/nimble/esp-hci/include/esp_nimble_hci.h#L117 http://url
— Reply to this email directly, view it on GitHub https://github.com/espressif/esp-idf/issues/8502#issuecomment-1065065826, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVQVTSN2M6XP2LKUYA7A54DU7M3LTANCNFSM5P7HD5DQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>
-- Regards Brahmajit
Hi @IshaESP,
I too am facing a similar kind of issue. I took a look at the links you posted and using sample code from there as well as the code I found on the espressif doc. Basically I'm first deinitializing the NimBLE stack using the following code snippet and I've also tried nimble_port_freertos_deinit();
and then I'm calling the provisioning function.
int ret = nimble_port_stop();
if (ret == 0) {
nimble_port_deinit();
ret = esp_nimble_hci_and_controller_deinit();
if (ret != ESP_OK) {
ESP_LOGE(TAG, "esp_nimble_hci_and_controller_deinit() failed with error: %d", ret);
}
}
I also took a look at the esp-nimble-cpp repo and saw that they too are deinitializing the nimBLE stack in a similar way. So what am I missing?
And then starting the provisioning function and it results with the following error code
I (8159) wifi_init: rx ba win: 6
I (8159) wifi_init: tcpip mbox: 32
I (8159) wifi_init: udp mbox: 6
I (8169) wifi_init: tcp mbox: 6
I (8169) wifi_init: tcp tx win: 5744
I (8179) wifi_init: tcp rx win: 5744
I (8179) wifi_init: tcp mss: 1440
I (8179) wifi_init: WiFi IRAM OP enabled
I (8189) wifi_init: WiFi RX IRAM OP enabled
I (8229) ble prov: Starting provisioning
I (8239) wifi:mode : sta (24:62:ab:c3:ad:d0)
I (8239) wifi:enable tsf
ESP_ERROR_CHECK failed: esp_err_t 0x103 (ESP_ERR_INVALID_STATE) at 0x40090774
0x40090774: _esp_error_check_failed at /home/listout/esp/esp-idf/components/esp_system/esp_err.c:42
file: "/IDF/components/protocomm/src/transports/protocomm_nimble.c" line 482
func: simple_ble_start
expression: esp_nimble_hci_and_controller_init()
abort() was called at PC 0x40090777 on core 1
0x40090777: _esp_error_check_failed at /home/listout/esp/esp-idf/components/esp_system/esp_err.c:43
I was able get the code to not panic reboot. Before starting the provisioning process I called these functions
nimble_port_deinit();
esp_nimble_hci_and_controller_deinit();
nimble_port_freertos_deinit();
But now the device cannot be connected from the provisioning app and disappears after first scan.
Is there an update on proper deinitialization of the nimble stack. Can someone provide an example for this? I have been struggling with this quite a while now.
I'm in the master branch, but this work for now:
nimble_port_stop();
nimble_port_deinit();
my provision function looks like
void
provision_start()
{
nimble_port_stop();
nimble_port_deinit();
/* Initialize TCP/IP */
ESP_ERROR_CHECK(esp_netif_init());
/* Initialize the event loop */
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_event_group = xEventGroupCreate();
...
}
EDIT
Full code is at https://github.com/listout/provisoning_nimble.
It's a merge of nimble spp and provision example from master. Connect it to your spp client (mobile or something), send prov, provisioning should start.
Output log: https://gist.github.com/listout/910786ad26de5e73ceb9a727c3ca0857
Environment
git describe --tags
to find it): v5.0-dev-1766-g84f9aa13c9xtensa-esp32-elf-gcc --version
to find it): 8.4.0Problem Description
Cannot provision wifi when another NimBLE application is running. I've the NimBLE SPP example running, if I get an input (say 'prov'), I'm de-initializing the nimble hci and controller host with the API
esp_nimble_hci_and_controller_deinit()
and then calling the wifi provisioning function. But once the provisioning completes successfully, my device reboots with guru meditation error. I'm guessing the it's something to do with incorrect initializing or de-initializing the NimBLE, since provisioning too uses NimBLE. It would be great if someone could help.Expected Behavior
Run as usual without reboot
Actual Behavior
Device reboots
Steps to reproduce
Code to reproduce this issue
SPP Example:
Provisioning Example:
init_provision()
// If your code is longer than 30 lines, GIST is preferred.
Debug Logs