diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 2412a15acc9..f30278d3ab7 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 2412a15acc9cf250f25f541b21ef0edeb1d22fae +Subproject commit f30278d3ab70d79791243bf329471043b309719c diff --git a/components/bt/porting/nimble/include/nimble/nimble_port.h b/components/bt/porting/nimble/include/nimble/nimble_port.h index 7d531728c00..2b000081eab 100644 --- a/components/bt/porting/nimble/include/nimble/nimble_port.h +++ b/components/bt/porting/nimble/include/nimble/nimble_port.h @@ -35,8 +35,21 @@ extern "C" { #endif -void nimble_port_init(void); -void nimble_port_deinit(void); +/** +* @brief nimble_port_init - Initialize controller and NimBLE host stack +* +* @return esp_err_t - ESP_OK ( if success) +* Error code in case of failure +*/ +esp_err_t nimble_port_init(void); + +/** +* @brief nimble_port_deinit - Deinitialize controller and NimBLE host stack +* +* @return esp_err_t - ESP_OK ( if success) +* Error code in case of failure +*/ +esp_err_t nimble_port_deinit(void); void nimble_port_run(void); int nimble_port_stop(void); diff --git a/components/protocomm/src/transports/protocomm_nimble.c b/components/protocomm/src/transports/protocomm_nimble.c index d92b98a13b4..806b8775ad2 100644 --- a/components/protocomm/src/transports/protocomm_nimble.c +++ b/components/protocomm/src/transports/protocomm_nimble.c @@ -494,7 +494,11 @@ static int simple_ble_start(const simple_ble_cfg_t *cfg) int rc; ESP_LOGD(TAG, "Free memory at start of simple_ble_init %" PRIu32, esp_get_free_heap_size()); - nimble_port_init(); + rc = nimble_port_init(); + if (rc != ESP_OK) { + ESP_LOGE(TAG, "Failed to init nimble %d ", rc); + return rc; + } /* Initialize the NimBLE host configuration. */ ble_hs_cfg.reset_cb = simple_ble_on_reset; diff --git a/examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c b/examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c index 4d402d10a4c..93155523e15 100644 --- a/examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c +++ b/examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c @@ -132,13 +132,20 @@ void mesh_host_task(void *param) esp_err_t bluetooth_init(void) { + esp_err_t ret; + mesh_sem = xSemaphoreCreateBinary(); if (mesh_sem == NULL) { ESP_LOGE(TAG, "Failed to create mesh semaphore"); return ESP_FAIL; } - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to init nimble %d ", ret); + return ret; + } + /* Initialize the NimBLE host configuration. */ ble_hs_cfg.reset_cb = mesh_on_reset; ble_hs_cfg.sync_cb = mesh_on_sync; diff --git a/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c b/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c index 04811fd0364..1d6496d0c0b 100644 --- a/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c +++ b/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c @@ -506,7 +506,9 @@ app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + assert(ret == 0); + /* Configure the host. */ ble_hs_cfg.reset_cb = blecent_on_reset; ble_hs_cfg.sync_cb = blecent_on_sync; diff --git a/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c b/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c index 166b490a4d5..986382f8af5 100644 --- a/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c +++ b/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c @@ -435,7 +435,12 @@ app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(tag, "Failed to init nimble %d ", ret); + return; + } + /* Initialize the NimBLE host configuration. */ ble_hs_cfg.reset_cb = bleprph_on_reset; ble_hs_cfg.sync_cb = bleprph_on_sync; diff --git a/examples/bluetooth/nimble/ble_periodic_adv/main/main.c b/examples/bluetooth/nimble/ble_periodic_adv/main/main.c index 04cb6a727d8..e0beed995f4 100644 --- a/examples/bluetooth/nimble/ble_periodic_adv/main/main.c +++ b/examples/bluetooth/nimble/ble_periodic_adv/main/main.c @@ -188,7 +188,13 @@ app_main(void) ret = nvs_flash_init(); } ESP_ERROR_CHECK(ret); - nimble_port_init(); + + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(tag, "Failed to init nimble %d ", ret); + return; + } + /* Initialize the NimBLE host configuration. */ ble_hs_cfg.reset_cb = periodic_adv_on_reset; ble_hs_cfg.sync_cb = periodic_adv_on_sync; diff --git a/examples/bluetooth/nimble/ble_periodic_sync/main/main.c b/examples/bluetooth/nimble/ble_periodic_sync/main/main.c index 8d7cb555318..2f0bbc750f2 100644 --- a/examples/bluetooth/nimble/ble_periodic_sync/main/main.c +++ b/examples/bluetooth/nimble/ble_periodic_sync/main/main.c @@ -184,7 +184,12 @@ app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret); + return; + } + /* Configure the host. */ ble_hs_cfg.reset_cb = periodic_sync_on_reset; ble_hs_cfg.sync_cb = periodic_sync_on_sync; diff --git a/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c b/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c index 95d7184f5c5..76810c3aa90 100644 --- a/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c @@ -477,7 +477,12 @@ app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret); + return; + } + /* Configure the host. */ ble_hs_cfg.reset_cb = blecent_on_reset; ble_hs_cfg.sync_cb = blecent_on_sync; diff --git a/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c b/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c index 2b34bdd16ed..03bc446be6b 100644 --- a/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c @@ -396,7 +396,12 @@ app_main(void) //ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init()); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret); + return; + } + /* Initialize the NimBLE host configuration. */ ble_hs_cfg.reset_cb = bleprph_on_reset; ble_hs_cfg.sync_cb = bleprph_on_sync; diff --git a/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c b/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c index 73cd4683444..f88702aff10 100644 --- a/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c +++ b/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c @@ -414,7 +414,11 @@ app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret); + return; + } /* Initialize UART driver and start uart task */ ble_spp_uart_init(); diff --git a/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c b/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c index 1c2b4272e3f..622a8188ec1 100644 --- a/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c +++ b/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c @@ -406,7 +406,11 @@ app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret); + return; + } /* Initialize connection_handle array */ for (int i = 0; i <= CONFIG_BT_NIMBLE_MAX_CONNECTIONS; i++) { diff --git a/examples/bluetooth/nimble/blecent/main/main.c b/examples/bluetooth/nimble/blecent/main/main.c index 8e4efe6095c..eec81d0b059 100644 --- a/examples/bluetooth/nimble/blecent/main/main.c +++ b/examples/bluetooth/nimble/blecent/main/main.c @@ -615,7 +615,12 @@ static void stack_init_deinit(void) ESP_LOGI(tag, "Init host"); - nimble_port_init(); + rc = nimble_port_init(); + if (rc != ESP_OK) { + ESP_LOGI(tag, "Failed to init nimble %d ", rc); + break; + } + nimble_port_freertos_init(blecent_host_task); ESP_LOGI(tag, "Waiting for 1 second"); @@ -635,7 +640,12 @@ app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(tag, "Failed to init nimble %d ", ret); + return; + } + /* Configure the host. */ ble_hs_cfg.reset_cb = blecent_on_reset; ble_hs_cfg.sync_cb = blecent_on_sync; diff --git a/examples/bluetooth/nimble/blehr/main/main.c b/examples/bluetooth/nimble/blehr/main/main.c index 77eef26ca74..b9c7ea991f9 100644 --- a/examples/bluetooth/nimble/blehr/main/main.c +++ b/examples/bluetooth/nimble/blehr/main/main.c @@ -280,7 +280,12 @@ void app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret); + return; + } + /* Initialize the NimBLE host configuration */ ble_hs_cfg.sync_cb = blehr_on_sync; ble_hs_cfg.reset_cb = blehr_on_reset; diff --git a/examples/bluetooth/nimble/blemesh/main/app_mesh.c b/examples/bluetooth/nimble/blemesh/main/app_mesh.c index 9d9defa3daf..30329724c2b 100644 --- a/examples/bluetooth/nimble/blemesh/main/app_mesh.c +++ b/examples/bluetooth/nimble/blemesh/main/app_mesh.c @@ -451,7 +451,11 @@ void app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(tag, "Failed to init nimble %d ", ret); + return; + } ble_svc_gap_init(); ble_svc_gatt_init(); diff --git a/examples/bluetooth/nimble/bleprph/main/main.c b/examples/bluetooth/nimble/bleprph/main/main.c index 036df6993ad..4c35fcb4732 100644 --- a/examples/bluetooth/nimble/bleprph/main/main.c +++ b/examples/bluetooth/nimble/bleprph/main/main.c @@ -496,7 +496,11 @@ app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(tag, "Failed to init nimble %d ", ret); + return; + } /* Initialize the NimBLE host configuration. */ ble_hs_cfg.reset_cb = bleprph_on_reset; ble_hs_cfg.sync_cb = bleprph_on_sync; diff --git a/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c b/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c index 70b647189dc..c4eac37c50c 100644 --- a/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c +++ b/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c @@ -539,7 +539,11 @@ app_main(void) wifi_init_sta(); do_ping_cmd(); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to init nimble %d ", ret); + return; + } /* Initialize the NimBLE host configuration. */ ble_hs_cfg.reset_cb = bleprph_on_reset; ble_hs_cfg.sync_cb = bleprph_on_sync; diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c index c6566788438..7edd712e295 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c @@ -723,7 +723,11 @@ app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(tag, "Failed to init nimble %d ", ret); + return; + } /* Configure the host. */ ble_hs_cfg.reset_cb = blecent_on_reset; diff --git a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c index 3a29f94eb47..0d66133220c 100644 --- a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c +++ b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c @@ -371,7 +371,12 @@ void app_main(void) } ESP_ERROR_CHECK(ret); - nimble_port_init(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(tag, "Failed to init nimble %d ", ret); + return; + } + /* Initialize the NimBLE host configuration */ ble_hs_cfg.sync_cb = gatts_on_sync; ble_hs_cfg.reset_cb = gatts_on_reset; diff --git a/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c b/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c index efd181558b9..52b70bff0e9 100644 --- a/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c +++ b/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c @@ -273,7 +273,7 @@ void app_main(void) #endif // CONFIG_EXAMPLE_CONNECT_WIFI #if CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED - esp_ble_helper_init(); + ESP_ERROR_CHECK(esp_ble_helper_init()); #endif xTaskCreate(&advanced_ota_example_task, "advanced_ota_example_task", 1024 * 8, NULL, 5, NULL); diff --git a/examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c b/examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c index d6b2cf93985..ce78fe5dfbb 100644 --- a/examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c +++ b/examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c @@ -16,13 +16,11 @@ #include "bluedroid_gatts.h" #endif -#if CONFIG_BT_BLE_ENABLED static const char *TAG = "BLE_API"; -#endif -void esp_ble_helper_init(void) +esp_err_t esp_ble_helper_init(void) { - esp_err_t err; + esp_err_t err = ESP_OK; #if CONFIG_BT_BLE_ENABLED ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT)); @@ -30,48 +28,54 @@ void esp_ble_helper_init(void) err = esp_bt_controller_init(&bt_cfg); if (err) { ESP_LOGE(TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(err)); - return; + return err; } err = esp_bt_controller_enable(ESP_BT_MODE_BLE); if (err) { ESP_LOGE(TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(err)); - return; + return err; } err = esp_bluedroid_init(); if (err) { ESP_LOGE(TAG, "%s init bluetooth failed: %s\n", __func__, esp_err_to_name(err)); - return; + return err; } err = esp_bluedroid_enable(); if (err) { ESP_LOGE(TAG, "%s enable bluetooth failed: %s\n", __func__, esp_err_to_name(err)); - return; + return err; } err = esp_ble_gatts_register_callback(gatts_event_handler); if (err) { ESP_LOGE(TAG, "gatts register error, error code = %x", err); - return; + return err; } err = esp_ble_gap_register_callback(gap_event_handler); if (err) { ESP_LOGE(TAG, "gap register error, error code = %x", err); - return; + return err; } err = esp_ble_gatts_app_register(PROFILE_A_APP_ID); if (err) { ESP_LOGE(TAG, "gatts app register error, error code = %x", err); - return; + return err; } esp_err_t local_mtu_err = esp_ble_gatt_set_local_mtu(500); if (local_mtu_err) { ESP_LOGE(TAG, "set local MTU failed, error code = %x", local_mtu_err); + return local_mtu_err; } #elif CONFIG_BT_NIMBLE_ENABLED - nimble_port_init(); + err = nimble_port_init(); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to init nimble %d ", err); + return err; + } + /* Initialize the NimBLE host configuration. */ ble_hs_cfg.reset_cb = bleprph_on_reset; ble_hs_cfg.sync_cb = bleprph_on_sync; @@ -90,6 +94,8 @@ void esp_ble_helper_init(void) nimble_port_freertos_init(bleprph_host_task); #endif + + return ESP_OK; } #endif diff --git a/examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h b/examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h index e315114a6bb..740355c1e26 100644 --- a/examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h +++ b/examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h @@ -1,25 +1,19 @@ -// Copyright 2021 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once +#include "esp_err.h" + #ifdef __cplusplus extern "C" { #endif #if CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED -void esp_ble_helper_init(void); +esp_err_t esp_ble_helper_init(void); #endif diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 0eba6d561c2..83412b2855d 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1608,7 +1608,6 @@ examples/system/ipc/ipc_isr/main/main.c examples/system/light_sleep/example_test.py examples/system/ota/advanced_https_ota/example_test.py examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c -examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h examples/system/ota/native_ota_example/example_test.py examples/system/ota/native_ota_example/main/native_ota_example.c examples/system/ota/otatool/example_test.py