Light Sleep issues with BTLE & High deep sleep power

User avatar
RalimTEk
Posts: 9
Joined: Wed Oct 10, 2018 12:40 am

Light Sleep issues with BTLE & High deep sleep power

Postby RalimTEk » Thu Nov 22, 2018 3:50 am

Hi,

Two part issue that may be linked together.
I'm running into assert fails when waking from light sleep, and very high current draw when in deep sleep.

These are most likely related, and so figured i'll mention them together.

When I put the ESP32 into light sleep (using timer for wakeup after approx 10 mins), everything wakes up and runs fine until I try and enable the bluetooth again.

I'm using a helper function for BT control (at end) and this works fine without sleep modes being used in the code. However whenever i have the sleep I run into

Code: Select all

ASSERT_PARAM(512 0), in rwble.c at line 222
whenever i try and re-enable the BT after waking up.

The second issue is that entering deep sleep mode appears to work, but it has a very high power consumption (18mA), where as light sleep uses only 2.5mA.

I believe I have the correct sequence for shutting down into deep sleep, but apparently this is not the cause. Would love any help :)

For the BT, is this a known issue of some kind or am I doing a step in the wrong order ?

ESP Module is the WROVER with the 4MB PSRAM

Code for BTLE on/off :

Code: Select all


    printf("TurnBTOnOff State %s \n", on ? "On" : "Off");
    if (on) {
      vTaskDelay(50);
      // Turning on
      ESP_LOGI("BTLE", "Turning On BTLE");
      ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
      if (ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "%s [0] enable controller failed: %s", __func__, esp_err_to_name(ret));
        return;
      }
      ret = esp_bluedroid_init();
      if (ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "%s [1] init bluetooth failed: %s", __func__, esp_err_to_name(ret));
        abort();
        return;
      }

      ret = esp_bluedroid_enable();
      if (ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "%s [2] enable bluetooth failed: %s", __func__, esp_err_to_name(ret));
        return;
      }

      ret = esp_ble_gatts_register_callback(gatts_event_handler);
      if (ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "[3] gatts register error, error code = %x", ret);
        return;
      }

      ret = esp_ble_gap_register_callback(gap_event_handler);
      if (ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "[4] gap register error, error code = %x", ret);
        return;
      }

      ret = esp_ble_gatts_app_register(ESP_APP_ID);
      if (ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "[5] gatts app register error, error code = %x", ret);
        return;
      }

      esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(250);
      if (local_mtu_ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "[6] set local  MTU failed, error code = %x", local_mtu_ret);
      }

      printf("BT On\n");

    } else {
      // Turning off
      ESP_LOGI("BTLE", "Turning Off BTLE");

      ESP_ERROR_CHECK(esp_ble_gatts_app_unregister(ESP_APP_ID));
      ESP_ERROR_CHECK(esp_bluedroid_disable());
      ESP_ERROR_CHECK(esp_bluedroid_deinit());
      ESP_ERROR_CHECK(esp_bt_controller_disable());

      printf("BT Off\n");
      vTaskDelay(100);
    }

Entering deep sleep code :

Code: Select all

printf("PowerState: Critical Shutdown : %d / %dmV\n", getSOC(), batteryVoltage);
          // Go into deep sleep

          if (lastPowerState == PowerStates::Undefined) {
            // First loop has tripped critical, sleep for 60 mins
            esp_sleep_enable_timer_wakeup((uint64_t)60 * (uint64_t)60 * (uint64_t)1000 * (uint64_t)1000);  // 60 min nap
          } else {
            esp_sleep_enable_timer_wakeup(30 * 60 * 1000 * 1000);  // 30 min nap
          }
          // Setup io wakeup
          const uint64_t ext_wakeup_pin_1_mask = 1ULL << PIN_BUTT_WAKE;
          gpio_pad_select_gpio(PIN_BUTT_WAKE);
          gpio_set_direction(PIN_BUTT_WAKE, GPIO_MODE_INPUT);
          ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ESP_EXT1_WAKEUP_ANY_HIGH));
          turnPeriphOnOff(false);
          setBTLE(false); // BTLE control from above ^
          esp_wifi_stop();
          esp_bluedroid_disable();
          esp_bt_controller_disable();
          esp_bt_controller_deinit();
          esp_wifi_deinit();
           esp_deep_sleep_start();
         
--//--
Ralimtek.com

chegewara
Posts: 2362
Joined: Wed Jun 14, 2017 9:00 pm

Re: Light Sleep issues with BTLE & High deep sleep power

Postby chegewara » Thu Nov 22, 2018 7:49 am

About that crash see this
https://github.com/espressif/esp-idf/is ... -336769074

There is few more issues related to rwble.c crash but we have been told it should be fixed.

Who is online

Users browsing this forum: Bing [Bot] and 116 guests