-
Notifications
You must be signed in to change notification settings - Fork 94
Fix NimBLEDevice::init() to check the return value from nimble_port_init(). #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -983,7 +983,15 @@ bool NimBLEDevice::init(const std::string& deviceName) { | |
| # endif | ||
| # endif | ||
| # endif | ||
| # ifdef ESP_PLATFORM | ||
| esp_err_t rc = nimble_port_init(); | ||
| NIMBLE_LOGE(LOG_TAG, "nimble_port_init rc=%d, npl_funcs=%p", rc, npl_funcs); | ||
| if (rc != ESP_OK) { | ||
| return false; | ||
|
Comment on lines
+988
to
+990
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Do not log successful initialization as an error, arr.
🤖 Prompt for AI AgentsSource: MCP tools |
||
| } | ||
| # else | ||
| nimble_port_init(); | ||
| # endif | ||
|
|
||
| // Setup callbacks for host events | ||
| ble_hs_cfg.reset_cb = NimBLEDevice::onReset; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: h2zero/esp-nimble-cpp
Length of output: 229
🏁 Script executed:
Repository: h2zero/esp-nimble-cpp
Length of output: 4225
🏁 Script executed:
Repository: h2zero/esp-nimble-cpp
Length of output: 12032
🌐 Web query:
h2zero NimBLE-Arduino nimble_npl_os.h CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT npl_funcs💡 Result:
In the context of the h2zero/NimBLE-Arduino library and the underlying NimBLE stack, the elements you mentioned relate to the porting and configuration of the Bluetooth Low Energy (BLE) host stack for specific hardware environments (primarily ESP32 and Nordic chips) [1][2][3]. nimble_npl_os.h This header file is part of the NimBLE Porting Layer (NPL). It defines the interfaces (often as a struct of function pointers called npl_funcs_t) that the NimBLE host stack uses to interact with the underlying Operating System (such as FreeRTOS) for tasks like memory management, event queues, mutexes, semaphores, and timing [4][5]. Because NimBLE is designed to be OS-agnostic, this layer allows it to run on different platforms by providing a standard set of OS-specific implementations [4]. CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT This is a configuration flag (typically found in ESP-IDF or related build systems) that enables the support for the NPL porting layer within the BLE controller [3][6]. When enabled, it signals the build system to include the necessary source files and drivers required to bridge the NimBLE stack with the hardware's OS and controller interfaces [3]. npl_funcs This variable typically holds an instance of the npl_funcs_t structure (defined in nimble_npl_os.h) [4][5]. It contains the set of function pointers used by the NimBLE stack to make OS-specific calls [4][5]. During initialization (e.g., in npl_freertos_funcs_init), this structure is allocated and populated with functions corresponding to the current OS (e.g., FreeRTOS), and it is deinitialized by freeing the memory during stack teardown [4][7]. These components together ensure that the NimBLE host stack can communicate correctly with the specific hardware and RTOS environment of your target device [3][4]. You generally do not need to interact with these files directly unless you are porting the library to a new platform or debugging low-level stack initialization/deinitialization issues [1][8].
Citations:
🏁 Script executed:
Repository: h2zero/esp-nimble-cpp
Length of output: 10155
🌐 Web query:
site:raw.githubusercontent.com/h2zero/NimBLE-Arduino nimble_npl_os.h "CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT"💡 Result:
No exact match was found on
raw.githubusercontent.com/h2zero/NimBLE-Arduinofor:The symbol does appear in Espressif ESP-IDF configuration output, not in NimBLE-Arduino’s
nimble_npl_os.h. (github.com)NimBLE-Arduino’s header is referenced in compatibility/build issues, but the searched configuration symbol was not found there. (github.com)
Citations:
🏁 Script executed:
Repository: h2zero/esp-nimble-cpp
Length of output: 22042
🌐 Web query:
ESP-IDF nimble_npl_os.h npl_funcs CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT include💡 Result:
In ESP-IDF, nimble_npl_os.h provides the NimBLE Porting Layer (NPL), which abstracts OS-specific functions—such as task management, event queues, mutexes, and timers—to allow the NimBLE host stack to run on FreeRTOS [1][2]. The
npl_funcssymbol is a global variable of typestruct npl_funcs_tthat acts as a jump table for these porting functions [1][3][4]. It is initialized within the ESP-IDF Bluetooth controller stack (typically vianpl_freertos_funcs_init()andesp_register_npl_funcs()) to link the generic NimBLE stack to the specific ESP-IDF FreeRTOS implementation [3][5]. The Kconfig optionCONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORTcontrols whether this NPL porting support is compiled into the Bluetooth controller component [6][7][8]. When enabled (default 'y' for supported chips), it ensures the necessary porting source files (e.g., npl_os_freertos.c) and include directories are included in the build, allowing the controller to interface correctly with the host stack's requirements for OS-level services [6][5][8]. Key points: - nimble_npl_os.h: Defines the API interface for the NimBLE Porting Layer [1][2]. - npl_funcs: A function pointer table that allows the NimBLE stack to call OS-specific functions (e.g., p_ble_npl_eventq_init) without being tightly coupled to FreeRTOS [1][4][9]. - CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT: A build-time configuration setting that enables the inclusion of the NPL glue code required for the BLE controller to function within the ESP-IDF environment [6][5][8].Citations:
🏁 Script executed:
Repository: h2zero/esp-nimble-cpp
Length of output: 13005
🏁 Script executed:
Repository: h2zero/esp-nimble-cpp
Length of output: 12849
🌐 Web query:
site:github.com/espressif/esp-idf "extern struct npl_funcs_t *npl_funcs" "CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT"💡 Result:
The variable extern struct npl_funcs_t *npl_funcs is part of the NimBLE Porting Layer (NPL) architecture within the Espressif IoT Development Framework (ESP-IDF) [1][2]. It is used to store function pointers that provide the Bluetooth LE controller with essential Operating System (OS) services, such as task creation, mutexes, semaphores, and memory management [1][3]. The configuration option CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT acts as a conditional compilation flag in the ESP-IDF build system [4][5]. When enabled (set to y), the build system includes the necessary source files—specifically those located in the porting/npl/freertos/ directory—to provide the OS-specific implementations required by the Bluetooth controller [6]. In typical usage: 1. The system initializes the NPL functions (e.g., via npl_freertos_funcs_init) [1][7]. 2. A pointer to these initialized functions is retrieved and subsequently registered with the controller using a call to esp_register_npl_funcs [1]. 3. This mechanism allows the controller, which is often provided as a binary blob, to remain OS-agnostic by interacting with the provided struct npl_funcs_t to perform port-specific operations [1][6]. If this configuration is disabled, the controller cannot access the required OS services, which typically results in build errors if the controller component is included in the project [6].
Citations:
Guard
npl_funcsfor disabled NPL OS porting support, arr. WhenCONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORTis disabled,nimble_npl_os.homits thenpl_funcsdeclaration. ThisESP_PLATFORM-only log can fail to compile. Guard the diagnostic with the same configuration macro.🤖 Prompt for AI Agents
Source: MCP tools