Skip to content
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

Fixed bluetooth initialization crash on espressif esp32 boards. #345

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/utility/HCIVirtualTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ HCIVirtualTransportClass::~HCIVirtualTransportClass()

int HCIVirtualTransportClass::begin()
{
#ifdef ARDUINO_ARCH_ESP32
if (!btStart()) {
return 0;
}
#else
btStarted(); // this somehow stops the arduino ide from initializing bluedroid

rec_buffer = xStreamBufferCreate(258, 1);
send_buffer = xStreamBufferCreate(258, 1);

esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
Expand All @@ -86,17 +88,26 @@ int HCIVirtualTransportClass::begin()
esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
esp_bt_controller_init(&bt_cfg);
esp_bt_controller_enable(ESP_BT_MODE_BLE);
#endif

rec_buffer = xStreamBufferCreate(258, 1);
send_buffer = xStreamBufferCreate(258, 1);

xTaskCreatePinnedToCore(&bleTask, "bleTask", 2048, NULL, 5, &bleHandle, 0);
return 1;
}

void HCIVirtualTransportClass::end()
{
vTaskDelete(bleHandle);
vStreamBufferDelete(rec_buffer);
vStreamBufferDelete(send_buffer);
#ifdef ARDUINO_ARCH_ESP32
btStop();
#else
esp_bt_controller_disable();
esp_bt_controller_deinit();
vTaskDelete(bleHandle);
#endif
}

void HCIVirtualTransportClass::wait(unsigned long timeout)
Expand Down
Loading