Skip to content

Commit

Permalink
ESP32: Wait till NimBLE host-cotroller is synced (#9565)
Browse files Browse the repository at this point in the history
* Use RTC memory as heap in unicore mode and readme fixes

Signed-off-by: Shubham Patil <shubham.patil@espressif.com>

* Wait till NimBLE host-controller is synced

Signed-off-by: Shubham Patil <shubham.patil@espressif.com>
  • Loading branch information
shubhamdp authored and pull[bot] committed Sep 27, 2021
1 parent bcc736e commit 586ee80
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
10 changes: 9 additions & 1 deletion examples/temperature-measurement-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,13 @@ Optimization related to WiFi, BLuetooth, Asserts etc are the part of this
example by default. To enable this option set is_debug=false from command-line.

```
idf.py -p /dev/tty.SLAB_USBtoUART -Dis_debug=false build flash monitor
# Reconfigure the project for additional optimizations
rm -rf sdkconfig build/
idf.py -Dis_debug=false reconfigure
# Set additional configurations if required
idf.py menuconfig
# Build, flash, and monitor the device
idf.py -p /dev/tty.SLAB_USBtoUART build flash monitor
```
3 changes: 3 additions & 0 deletions examples/temperature-measurement-app/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=16
# FreeRTOS
CONFIG_FREERTOS_UNICORE=y

# Add RTC memory to system heap
CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP=y

# LWIP
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=16
# FreeRTOS
CONFIG_FREERTOS_UNICORE=y

# Add RTC memory to system heap
CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP=y

# Log output
CONFIG_LOG_DEFAULT_LEVEL_NONE=y

Expand Down
20 changes: 18 additions & 2 deletions src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const ble_uuid128_t UUID_CHIPoBLEChar_TX = {
{ BLE_UUID_TYPE_128 }, { 0x12, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18 }
};

SemaphoreHandle_t semaphoreHandle = NULL;

} // unnamed namespace

BLEManagerImpl BLEManagerImpl::sInstance;
Expand Down Expand Up @@ -595,9 +597,8 @@ void BLEManagerImpl::bleprph_on_reset(int reason)

void BLEManagerImpl::bleprph_on_sync(void)
{
sInstance.mFlags.Set(Flags::kESPBLELayerInitialized);
sInstance.mFlags.Set(Flags::kGATTServiceStarted);
ESP_LOGI(TAG, "BLE host-controller synced");
xSemaphoreGive(semaphoreHandle);
}

void BLEManagerImpl::bleprph_host_task(void * param)
Expand All @@ -614,6 +615,14 @@ CHIP_ERROR BLEManagerImpl::InitESPBleLayer(void)

VerifyOrExit(!mFlags.Has(Flags::kESPBLELayerInitialized), /* */);

semaphoreHandle = xSemaphoreCreateBinary();
if (semaphoreHandle == NULL)
{
err = CHIP_ERROR_NO_MEMORY;
ESP_LOGE(TAG, "Failed to create semaphore");
ExitNow();
}

for (int i = 0; i < kMaxConnections; i++)
{
mSubscribedConIds[i] = BLE_CONNECTION_UNINITIALIZED;
Expand Down Expand Up @@ -655,6 +664,13 @@ CHIP_ERROR BLEManagerImpl::InitESPBleLayer(void)

nimble_port_freertos_init(bleprph_host_task);

xSemaphoreTake(semaphoreHandle, portMAX_DELAY);
vSemaphoreDelete(semaphoreHandle);
semaphoreHandle = NULL;

sInstance.mFlags.Set(Flags::kESPBLELayerInitialized);
sInstance.mFlags.Set(Flags::kGATTServiceStarted);

exit:
return err;
}
Expand Down

0 comments on commit 586ee80

Please sign in to comment.