Set CONFIG_BT_ENABLED + re-add double-init patch
Without CONFIG_BT_ENABLED in sdkconfig.h, NimBLEDevice.cpp lines are excluded by #if defined(CONFIG_BT_ENABLED) preprocessor guard, making NimBLEDevice::init() a no-op. No BT controller init ever occurs -> no RF calibration -> invisible BLE advertising. With CONFIG_BT_ENABLED: Arduino framework pre-inits BT controller, then NimBLEDevice::init() double-inits -> ESP_ERROR_CHECK abort. Fix: patch NimBLEDevice.cpp to check return code and skip init if already running.
This commit is contained in:
+50
-1
@@ -70,6 +70,7 @@ def patch_sdkconfig_bt():
|
||||
content = f.read()
|
||||
|
||||
defines = {
|
||||
"CONFIG_BT_ENABLED": 1,
|
||||
"CONFIG_BTDM_CTRL_MODE_BLE_ONLY": 1,
|
||||
"CONFIG_BT_NIMBLE_MAX_CONNECTIONS": 1,
|
||||
"CONFIG_BT_NIMBLE_TASK_STACK_SIZE": 6144,
|
||||
@@ -158,6 +159,54 @@ def patch_nimconfig():
|
||||
print("nimconfig.h patched successfully")
|
||||
|
||||
|
||||
def patch_nimble_device():
|
||||
search_dirs = [
|
||||
os.path.join(os.getcwd(), ".pio", "libdeps"),
|
||||
os.path.expanduser("~/.platformio/lib"),
|
||||
]
|
||||
dev_path = None
|
||||
for base in search_dirs:
|
||||
if not os.path.exists(base):
|
||||
continue
|
||||
for root, _dirs, files in os.walk(base):
|
||||
if "NimBLEDevice.cpp" in files:
|
||||
dev_path = os.path.join(root, "NimBLEDevice.cpp")
|
||||
break
|
||||
if dev_path:
|
||||
break
|
||||
|
||||
if not dev_path:
|
||||
print("WARNING: NimBLEDevice.cpp not found, skipping controller init patch")
|
||||
return
|
||||
|
||||
print(f"Patching {dev_path} to handle double BT controller init")
|
||||
|
||||
with open(dev_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# v1.4.3 code has ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));
|
||||
old_block = (
|
||||
'ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));\n'
|
||||
' ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));\n'
|
||||
' ESP_ERROR_CHECK(esp_nimble_hci_init());'
|
||||
)
|
||||
new_block = (
|
||||
'if (esp_bt_controller_init(&bt_cfg) == ESP_OK) {\n'
|
||||
' ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));\n'
|
||||
' }\n'
|
||||
' ESP_ERROR_CHECK(esp_nimble_hci_init());'
|
||||
)
|
||||
|
||||
if old_block in content:
|
||||
content = content.replace(old_block, new_block)
|
||||
with open(dev_path, 'w') as f:
|
||||
f.write(content)
|
||||
print(" Patched esp_bt_controller_init to skip if already initialized")
|
||||
else:
|
||||
print(" WARNING: Could not find init pattern in NimBLEDevice.cpp (may already be patched)")
|
||||
|
||||
|
||||
patch_usb_ids()
|
||||
patch_sdkconfig_bt()
|
||||
patch_nimconfig()
|
||||
patch_nimconfig()
|
||||
patch_nimble_device()
|
||||
Reference in New Issue
Block a user