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

Memory leak in Blue tooth serial with bluedroid #1798

Closed
usrdes opened this issue Aug 25, 2018 · 30 comments
Closed

Memory leak in Blue tooth serial with bluedroid #1798

usrdes opened this issue Aug 25, 2018 · 30 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck) Type: Bug 🐛 All bugs

Comments

@usrdes
Copy link

usrdes commented Aug 25, 2018

Hardware:

Board: ESP32-PICO-KIT Dev. Board
Core Installation/update date: 1 Aug 2018
IDE name: Arduino 1.8.5
Flash Frequency: 80MHz
Upload Speed: 921600

Description:

Blue tooth serial (Bluedroid) has memory leak. The sketch below is modified from serial to serial BT example.
The modification is as follows:

  1. set up timer for 1 sec timeout
  2. every sec turn on or off the bloe tooth serial.
  3. every time BTSerial is turned on or off print heap size
  4. observe that the heap size keeps diminishing, and eventually the core crashes.

Sketch: Modified serial to serial blue tooth example as follows:

//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

volatile int switch_off_Bluetooth = 0;

// Timer set up
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
#define PRESCALER 50000
#define NUM_TO_COUNT_UP_TO_1_SEC  1600
#define COUNT_OF_SECS 1  
#define TIME_OUT COUNT_OF_SECS*NUM_TO_COUNT_UP_TO_1_SEC
volatile int timeout_occured=0;

void IRAM_ATTR onTimer() {
  portENTER_CRITICAL_ISR(&timerMux);
  timeout_occured = 1;
  portEXIT_CRITICAL_ISR(&timerMux);
}

void setup_timer() {
  timer = timerBegin(0, PRESCALER, true);
  timerAttachInterrupt(timer, &onTimer, true);
  timerAlarmWrite(timer, TIME_OUT, true);
  timerAlarmEnable(timer);
}

void reset_timeout() {
    portENTER_CRITICAL(&timerMux);
    timeout_occured = 0;
    portEXIT_CRITICAL(&timerMux);
}

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
  setup_timer();
  Serial.printf("Timer for a count of %d seconds of BTserial ON/OFF started",COUNT_OF_SECS);
  Serial.println(" --> ");
}

void loop() {

    if(timeout_occured) { // Turn on or off blue tooth based on timer time-out of COUNT_OF_SECS
      reset_timeout(); // first reset time out flag
      if (switch_off_Bluetooth) { // check if the BT serial needs to be turned off
        switch_off_Bluetooth = 0;
        SerialBT.flush();
        SerialBT.end(); 
        Serial.print("@ ");
        Serial.print(millis()/1000);
        Serial.printf(" secs > BTserial OFF Heap Size: %d ",ESP.getFreeHeap());
        Serial.println(" "); 
      } else { // else switch on Bluetooth serial
        switch_off_Bluetooth = 1;
        SerialBT.begin("ESP32test"); //Bluetooth device name
        Serial.print("@ ");
        Serial.print(millis()/1000);
        Serial.printf(" secs > BTserial ON  Heap Size: %d ",ESP.getFreeHeap());
        Serial.println(" "); 
      }
      
    }
    
}

Debug Messages:

The device started, now you can pair it with bluetooth!
Timer for a count of 1 seconds of BTserial ON/OFF started -->
@ 1 secs > BTserial ON Heap Size: 100308
@ 2 secs > BTserial OFF Heap Size: 169984
@ 3 secs > BTserial ON Heap Size: 95212
@ 4 secs > BTserial OFF Heap Size: 165340
@ 5 secs > BTserial ON Heap Size: 90616
@ 6 secs > BTserial OFF Heap Size: 160696
@ 7 secs > BTserial ON Heap Size: 86028
@ 8 secs > BTserial OFF Heap Size: 156060
@ 9 secs > BTserial ON Heap Size: 81340
@ 10 secs > BTserial OFF Heap Size: 152332
@ 11 secs > BTserial ON Heap Size: 77612
@ 12 secs > BTserial OFF Heap Size: 148608
@ 13 secs > BTserial ON Heap Size: 73912
@ 14 secs > BTserial OFF Heap Size: 144884
@ 15 secs > BTserial ON Heap Size: 70180
@ 16 secs > BTserial OFF Heap Size: 141160
@ 17 secs > BTserial ON Heap Size: 66508
@ 18 secs > BTserial OFF Heap Size: 137436
@ 19 secs > BTserial ON Heap Size: 62740
@ 20 secs > BTserial OFF Heap Size: 133708
@ 21 secs > BTserial ON Heap Size: 59036
@ 22 secs > BTserial OFF Heap Size: 129984
@ 23 secs > BTserial ON Heap Size: 55296
@ 24 secs > BTserial OFF Heap Size: 126264
@ 25 secs > BTserial ON Heap Size: 51552
@ 26 secs > BTserial OFF Heap Size: 122536
@ 27 secs > BTserial ON Heap Size: 47884
@ 28 secs > BTserial OFF Heap Size: 118816
@ 29 secs > BTserial ON Heap Size: 44172
@ 30 secs > BTserial OFF Heap Size: 115092
@ 31 secs > BTserial ON Heap Size: 40404
@ 32 secs > BTserial OFF Heap Size: 111368
@ 33 secs > BTserial ON Heap Size: 36664
@ 34 secs > BTserial OFF Heap Size: 107644
@ 35 secs > BTserial ON Heap Size: 32948
@ 36 secs > BTserial OFF Heap Size: 103920
@ 37 secs > BTserial ON Heap Size: 29224
@ 38 secs > BTserial OFF Heap Size: 100196
@ 39 secs > BTserial ON Heap Size: 25504
@ 40 secs > BTserial OFF Heap Size: 96472
@ 41 secs > BTserial ON Heap Size: 21804
@ 42 secs > BTserial OFF Heap Size: 92748
@ 43 secs > BTserial ON Heap Size: 18076
@ 44 secs > BTserial OFF Heap Size: 89024
@ 45 secs > BTserial ON Heap Size: 14384
@ 46 secs > BTserial OFF Heap Size: 85300
@ 47 secs > BTserial ON Heap Size: 10696
@ 48 secs > BTserial OFF Heap Size: 81576
@ 49 secs > BTserial ON Heap Size: 6928
@ 50 secs > BTserial OFF Heap Size: 77852
@ 53 secs > BTserial ON Heap Size: 3112
@ 53 secs > BTserial OFF Heap Size: 74132
Guru Meditation Error: Core 0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x4000c46c PS : 0x00060e30 A0 : 0x801139de A1 : 0x3ffdaf90
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x0000001c A5 : 0x00000000
A6 : 0x40179f3c A7 : 0x00000001 A8 : 0x800d70bd A9 : 0x3ffdaf50
A10 : 0x3ffe8ca8 A11 : 0x00000000 A12 : 0x00000001 A13 : 0x3ffe7370
A14 : 0x3ffe15f4 A15 : 0x00000084 SAR : 0x00000008 EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000
Backtrace: 0x4000c46c:0x3ffdaf90 0x401139db:0x3ffdafa0 0x401142b1:0x3ffdafc0
0x400ef8f5:0x3ffdafe0 0x400ef92f:0x3ffdb000
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:808
load:0x40078000,len:6084
load:0x40080000,len:6696
entry 0x400802e4

@stickbreaker
Copy link
Contributor

@usrdes please edit your message, add the Markdown symbols for code ( three back ticks then c++ on a line before your code example, and three back ticks on a separate line after your code). You code should look like this:

void setup(){
// important stuff here
}

@copercini
Copy link
Contributor

I can confirm it

Test code:

#include "BluetoothSerial.h"

BluetoothSerial SerialBT;
volatile int switch_off_Bluetooth = 0;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
  Serial.println(" --> ");
  delay(1000);
}

void loop() {
  if (switch_off_Bluetooth) { // check if the BT serial needs to be turned off
    switch_off_Bluetooth = 0;
    SerialBT.flush();
    SerialBT.end();
    Serial.print("@ ");
    Serial.print(millis() / 1000);
    Serial.printf(" secs > BTserial OFF Heap Size: %d ", ESP.getFreeHeap());
    Serial.println(" ");
  } else { // else switch on Bluetooth serial
    switch_off_Bluetooth = 1;
    SerialBT.begin("ESP32test"); //Bluetooth device name
    Serial.print("@ ");
    Serial.print(millis() / 1000);
    Serial.printf(" secs > BTserial ON  Heap Size: %d ", ESP.getFreeHeap());
    Serial.println(" ");
  }
  delay(1000);
}

LOGS:

The device started, now you can pair it with bluetooth!
 --> 
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
@ 1 secs > BTserial ON  Heap Size: 127336  
�[0;31mE (2766) BT_APPL: JVenable fails�[0m
@ 2 secs > BTserial OFF Heap Size: 152544  
@ 3 secs > BTserial ON  Heap Size: 126448  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
@ 4 secs > BTserial OFF Heap Size: 151192  
@ 5 secs > BTserial ON  Heap Size: 125104  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
@ 7 secs > BTserial OFF Heap Size: 149844  
@ 8 secs > BTserial ON  Heap Size: 123716  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
@ 9 secs > BTserial OFF Heap Size: 148492  
@ 10 secs > BTserial ON  Heap Size: 122364  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (11730) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 11 secs > BTserial OFF Heap Size: 148040  
@ 12 secs > BTserial ON  Heap Size: 121968  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (13971) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 13 secs > BTserial OFF Heap Size: 147440  
@ 14 secs > BTserial ON  Heap Size: 121368  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (16213) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 16 secs > BTserial OFF Heap Size: 146988  
@ 17 secs > BTserial ON  Heap Size: 120924  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (18454) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 18 secs > BTserial OFF Heap Size: 146536  
@ 19 secs > BTserial ON  Heap Size: 120416  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (20695) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 20 secs > BTserial OFF Heap Size: 146088  
@ 21 secs > BTserial ON  Heap Size: 119968  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (22936) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 22 secs > BTserial OFF Heap Size: 145640  
@ 23 secs > BTserial ON  Heap Size: 119520  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (25177) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 25 secs > BTserial OFF Heap Size: 145044  
@ 26 secs > BTserial ON  Heap Size: 118980  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (27419) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 27 secs > BTserial OFF Heap Size: 144596  
@ 28 secs > BTserial ON  Heap Size: 118476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (29661) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 29 secs > BTserial OFF Heap Size: 144148  
@ 30 secs > BTserial ON  Heap Size: 118028  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (31902) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 31 secs > BTserial OFF Heap Size: 143696  
@ 32 secs > BTserial ON  Heap Size: 117584  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (34142) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 33 secs > BTserial OFF Heap Size: 143248  
@ 35 secs > BTserial ON  Heap Size: 117136  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (36384) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 36 secs > BTserial OFF Heap Size: 142796  
@ 37 secs > BTserial ON  Heap Size: 116696  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (38715) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 38 secs > BTserial OFF Heap Size: 142348  
@ 39 secs > BTserial ON  Heap Size: 116296  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (40956) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 40 secs > BTserial OFF Heap Size: 141900  
@ 41 secs > BTserial ON  Heap Size: 115800  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (43197) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 43 secs > BTserial OFF Heap Size: 141452  
@ 44 secs > BTserial ON  Heap Size: 115352  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (45438) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 45 secs > BTserial OFF Heap Size: 141004  
@ 46 secs > BTserial ON  Heap Size: 114904  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (47679) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 47 secs > BTserial OFF Heap Size: 140552  
@ 48 secs > BTserial ON  Heap Size: 114448  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (49966) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 49 secs > BTserial OFF Heap Size: 140104  
@ 50 secs > BTserial ON  Heap Size: 114000  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (52207) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 52 secs > BTserial OFF Heap Size: 139656  
@ 53 secs > BTserial ON  Heap Size: 113544  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (54449) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 54 secs > BTserial OFF Heap Size: 139208  
@ 55 secs > BTserial ON  Heap Size: 113096  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (56690) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 56 secs > BTserial OFF Heap Size: 138760  
@ 57 secs > BTserial ON  Heap Size: 112648  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (58930) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 58 secs > BTserial OFF Heap Size: 138312  
@ 59 secs > BTserial ON  Heap Size: 112200  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (61213) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 61 secs > BTserial OFF Heap Size: 137864  
@ 62 secs > BTserial ON  Heap Size: 111752  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (63455) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 63 secs > BTserial OFF Heap Size: 137416  
@ 64 secs > BTserial ON  Heap Size: 111304  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (65696) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 65 secs > BTserial OFF Heap Size: 136968  
@ 66 secs > BTserial ON  Heap Size: 110856  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (67936) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 67 secs > BTserial OFF Heap Size: 136520  
@ 68 secs > BTserial ON  Heap Size: 110408  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (70178) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 70 secs > BTserial OFF Heap Size: 136072  
@ 71 secs > BTserial ON  Heap Size: 109960  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (72464) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 72 secs > BTserial OFF Heap Size: 135624  
@ 73 secs > BTserial ON  Heap Size: 109512  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (74706) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 74 secs > BTserial OFF Heap Size: 135176  
@ 75 secs > BTserial ON  Heap Size: 109064  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (76947) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 76 secs > BTserial OFF Heap Size: 134728  
@ 77 secs > BTserial ON  Heap Size: 108616  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (79187) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 79 secs > BTserial OFF Heap Size: 134280  
@ 80 secs > BTserial ON  Heap Size: 108168  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (81429) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 81 secs > BTserial OFF Heap Size: 133832  
@ 82 secs > BTserial ON  Heap Size: 107724  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
�[0;31mE (83714) BT_BTC: btc_spp_start_srv unable to malloc RFCOMM slot!�[0m
@ 83 secs > BTserial OFF Heap Size: 133384  
@ 84 secs > BTserial ON  Heap Size: 107276  
...

@copercini copercini added the Type: Bug 🐛 All bugs label Aug 26, 2018
@copercini
Copy link
Contributor

1 problem found: - The queue is not being deleted at end, to fix it's just add
vQueueDelete(_spp_queue);

inside void BluetoothSerial::end() of BluetoothSerial.cpp

this reduces the leak to just 96 bytes each iteration

@copercini
Copy link
Contributor

Problem 2 found: it's missing a call to esp_spp_deinit();

Now it seems stable =)

The device started, now you can pair it with bluetooth!
 --> 
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
@ 1 secs > BTserial ON  Heap Size: 127172  
�[0;31mE (2749) BT_APPL: JVenable fails�[0m
�[0;31mE (3750) BT_APPL: bta_jv_disable�[0m
@ 2 secs > BTserial OFF Heap Size: 153888  
@ 3 secs > BTserial ON  Heap Size: 127736  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (5990) BT_APPL: bta_jv_disable�[0m
@ 4 secs > BTserial OFF Heap Size: 153888  
@ 5 secs > BTserial ON  Heap Size: 127736  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (8229) BT_APPL: bta_jv_disable�[0m
@ 7 secs > BTserial OFF Heap Size: 153888  
@ 8 secs > BTserial ON  Heap Size: 127736  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (10468) BT_APPL: bta_jv_disable�[0m
@ 9 secs > BTserial OFF Heap Size: 153888  
@ 10 secs > BTserial ON  Heap Size: 127736  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (12707) BT_APPL: bta_jv_disable�[0m
@ 11 secs > BTserial OFF Heap Size: 153740  
@ 12 secs > BTserial ON  Heap Size: 127616  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (14993) BT_APPL: bta_jv_disable�[0m
@ 13 secs > BTserial OFF Heap Size: 153740  
@ 14 secs > BTserial ON  Heap Size: 127592  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (17232) BT_APPL: bta_jv_disable�[0m
@ 16 secs > BTserial OFF Heap Size: 153740  
@ 17 secs > BTserial ON  Heap Size: 127616  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (19471) BT_APPL: bta_jv_disable�[0m
@ 18 secs > BTserial OFF Heap Size: 153740  
@ 19 secs > BTserial ON  Heap Size: 127592  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (21710) BT_APPL: bta_jv_disable�[0m
@ 20 secs > BTserial OFF Heap Size: 153740  
@ 21 secs > BTserial ON  Heap Size: 127616  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (23949) BT_APPL: bta_jv_disable�[0m
@ 22 secs > BTserial OFF Heap Size: 153592  
@ 23 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (26234) BT_APPL: bta_jv_disable�[0m
@ 25 secs > BTserial OFF Heap Size: 153592  
@ 26 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (28476) BT_APPL: bta_jv_disable�[0m
@ 27 secs > BTserial OFF Heap Size: 153592  
@ 28 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (30717) BT_APPL: bta_jv_disable�[0m
@ 29 secs > BTserial OFF Heap Size: 153592  
@ 30 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (32959) BT_APPL: bta_jv_disable�[0m
@ 31 secs > BTserial OFF Heap Size: 153592  
@ 32 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (35200) BT_APPL: bta_jv_disable�[0m
@ 34 secs > BTserial OFF Heap Size: 153592  
@ 35 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (37487) BT_APPL: bta_jv_disable�[0m
@ 36 secs > BTserial OFF Heap Size: 153592  
@ 37 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (39728) BT_APPL: bta_jv_disable�[0m
@ 38 secs > BTserial OFF Heap Size: 153592  
@ 39 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (41970) BT_APPL: bta_jv_disable�[0m
@ 40 secs > BTserial OFF Heap Size: 153592  
@ 41 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (44211) BT_APPL: bta_jv_disable�[0m
@ 43 secs > BTserial OFF Heap Size: 153592  
@ 44 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (46453) BT_APPL: bta_jv_disable�[0m
@ 45 secs > BTserial OFF Heap Size: 153592  
@ 46 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (48736) BT_APPL: bta_jv_disable�[0m
@ 47 secs > BTserial OFF Heap Size: 153592  
@ 48 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (50976) BT_APPL: bta_jv_disable�[0m
@ 49 secs > BTserial OFF Heap Size: 153592  
@ 50 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (53215) BT_APPL: bta_jv_disable�[0m
@ 52 secs > BTserial OFF Heap Size: 153592  
@ 53 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (55455) BT_APPL: bta_jv_disable�[0m
@ 54 secs > BTserial OFF Heap Size: 153592  
@ 55 secs > BTserial ON  Heap Size: 127476  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (57694) BT_APPL: bta_jv_disable�[0m
@ 56 secs > BTserial OFF Heap Size: 153592  
@ 57 secs > BTserial ON  Heap Size: 127472  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (59983) BT_APPL: bta_jv_disable�[0m
@ 58 secs > BTserial OFF Heap Size: 153592  
@ 59 secs > BTserial ON  Heap Size: 127448  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (62222) BT_APPL: bta_jv_disable�[0m
@ 61 secs > BTserial OFF Heap Size: 153592  
@ 62 secs > BTserial ON  Heap Size: 127448  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (64462) BT_APPL: bta_jv_disable�[0m
@ 63 secs > BTserial OFF Heap Size: 153592  
@ 64 secs > BTserial ON  Heap Size: 127448  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (66701) BT_APPL: bta_jv_disable�[0m
@ 65 secs > BTserial OFF Heap Size: 153592  
@ 66 secs > BTserial ON  Heap Size: 127448  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT
�[0;31mE (68941) BT_APPL: bta_jv_disable�[0m
@ 67 secs > BTserial OFF Heap Size: 153592  
@ 68 secs > BTserial ON  Heap Size: 127448  
[I][BluetoothSerial.cpp:54] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:69] esp_spp_cb(): ESP_SPP_START_EVT

@copercini
Copy link
Contributor

this �[0;31mE (68941) BT_APPL: bta_jv_disable�[0m log comes from here https://github.com/espressif/esp-idf/blob/b85e8e10b90ab7089ec7989ba513f7a2235f9ea4/components/bt/bluedroid/bta/jv/bta_jv_act.c#L666 and seems normal

I think it's fixed now, I'll PR the changes

@usrdes
Copy link
Author

usrdes commented Aug 26, 2018

@stickbreaker : Thank you for letting me know how to add Markdown symbols, I have updated code above.

@copercini : Thank you for fixing, but I do not understand what PR means (Pull Request?) Also how about that log output you show in the link. Should that or will that need to be fixed as well? Please update here when is a good time to re-install (or update) the ESP32 arduino blue tooth serial library.
Again thank you very much!

Also:
"Problem 2 found: it's missing a call to esp_spp_deinit();"
Is this in "inside void BluetoothSerial::end() of BluetoothSerial.cpp" ?
Like the following: ?

void BluetoothSerial::end()
{
	vQueueDelete(_spp_queue);
	esp_spp_deinit();
    _stop_bt();
}

@copercini
Copy link
Contributor

@usrdes yes, the pull request with all fixes is here: #1801

it still need some review and merge to the main code

if you really want to use it right now, you can get it here with the fixes: https://github.com/copercini/arduino-esp32/blob/master/libraries/BluetoothSerial/src/BluetoothSerial.cpp and replace this file in your installation

@usrdes
Copy link
Author

usrdes commented Aug 26, 2018

@copercini , OK thank you, I will close this issue,

@usrdes usrdes closed this as completed Aug 26, 2018
@usrdes usrdes reopened this Aug 26, 2018
@usrdes
Copy link
Author

usrdes commented Aug 26, 2018

@copercini : Sad to re-open but after updating the library cpp file, and recompiling I am still getting leak. I made sure that the new file was being used by deliberately introducing a compile error in the cpp, and removing the deliberate error.

Do I need to update anything else?

Here is the console output:
The device started, now you can pair it with bluetooth!
Timer for a count of 1 seconds of BTserial ON/OFF started -->
@ 1 secs > BTserial ON Heap Size: 100688
@ 2 secs > BTserial OFF Heap Size: 171572
@ 3 secs > BTserial ON Heap Size: 96824
@ 4 secs > BTserial OFF Heap Size: 168300
@ 5 secs > BTserial ON Heap Size: 93544

@copercini
Copy link
Contributor

copercini commented Aug 26, 2018

this remaining leak seem related with timer code, please test with this code (without timers):

#include "BluetoothSerial.h"

BluetoothSerial SerialBT;
volatile int switch_off_Bluetooth = 0;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
  Serial.println(" --> ");
  delay(1000);
}

void loop() {
  if (switch_off_Bluetooth) { // check if the BT serial needs to be turned off
    switch_off_Bluetooth = 0;
    SerialBT.flush();
    SerialBT.end();
    Serial.print("@ ");
    Serial.print(millis() / 1000);
    Serial.printf(" secs > BTserial OFF Heap Size: %d ", ESP.getFreeHeap());
    Serial.println(" ");
  } else { // else switch on Bluetooth serial
    switch_off_Bluetooth = 1;
    SerialBT.begin("ESP32test"); //Bluetooth device name
    Serial.print("@ ");
    Serial.print(millis() / 1000);
    Serial.printf(" secs > BTserial ON  Heap Size: %d ", ESP.getFreeHeap());
    Serial.println(" ");
  }
  delay(1000);
}

@usrdes
Copy link
Author

usrdes commented Aug 26, 2018

@copercini ,

Tried your code on two devices. Results below,
In both cases, the ESP32 simply stops, not even the "Guru panic ..."

Device #1----------------------------------------

The device started, now you can pair it with bluetooth!
-->
@ 1 secs > BTserial ON Heap Size: 100856
@ 2 secs > BTserial OFF Heap Size: 171740
@ 3 secs > BTserial ON Heap Size: 97048
@ 4 secs > BTserial OFF Heap Size: 168468
@ 6 secs > BTserial ON Heap Size: 93780
@ 7 secs > BTserial OFF Heap Size: 165196
@ 8 secs > BTserial ON Heap Size: 90504
@ 9 secs > BTserial OFF Heap Size: 161924
@ 10 secs > BTserial ON Heap Size: 86844
@ 11 secs > BTserial OFF Heap Size: 158652
@ 12 secs > BTserial ON Heap Size: 83964
@ 14 secs > BTserial OFF Heap Size: 155232
@ 15 secs > BTserial ON Heap Size: 80548
@ 16 secs > BTserial OFF Heap Size: 151960
@ 17 secs > BTserial ON Heap Size: 77220
@ 18 secs > BTserial OFF Heap Size: 148688
@ 19 secs > BTserial ON Heap Size: 73948
.......
.......
@ 63 secs > BTserial ON Heap Size: 11832
@ 65 secs > BTserial OFF Heap Size: 83244
@ 66 secs > BTserial ON Heap Size: 8560
@ 67 secs > BTserial OFF Heap Size: 79972
@ 68 secs > BTserial ON Heap Size: 5280
@ 69 secs > BTserial OFF Heap Size: 76700
@ 72 secs > BTserial ON Heap Size: 1908
@ 73 secs > BTserial OFF Heap Size: 73428
@ 77 secs > BTserial ON Heap Size: 716

Device #2 -----------------------------

load:0x40078000,len:6084
load:0x40080000,len:6696
entry 0x400802e4
E (207) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

The device started, now you can pair it with bluetooth!
-->
@ 1 secs > BTserial ON Heap Size: 99076
@ 2 secs > BTserial OFF Heap Size: 170544
E (3527) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 3 secs > BTserial ON Heap Size: 95396
@ 4 secs > BTserial OFF Heap Size: 167272
E (5842) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 6 secs > BTserial ON Heap Size: 92072
@ 7 secs > BTserial OFF Heap Size: 163996
E (8158) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 8 secs > BTserial ON Heap Size: 88800
@ 9 secs > BTserial OFF Heap Size: 160728
E (10473) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 10 secs > BTserial ON Heap Size: 85528
@ 12 secs > BTserial OFF Heap Size: 157452
E (12789) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 13 secs > BTserial ON Heap Size: 82256
@ 14 secs > BTserial OFF Heap Size: 154184
E (15104) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 15 secs > BTserial ON Heap Size: 78984
@ 16 secs > BTserial OFF Heap Size: 150908
E (17419) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 17 secs > BTserial ON Heap Size: 75712
@ 19 secs > BTserial OFF Heap Size: 147640
E (19735) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

.
.
.
.

@ 65 secs > BTserial ON Heap Size: 10272
@ 66 secs > BTserial OFF Heap Size: 82200
E (66069) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 67 secs > BTserial ON Heap Size: 7028
@ 68 secs > BTserial OFF Heap Size: 78924
E (68383) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 71 secs > BTserial ON Heap Size: 3680
@ 73 secs > BTserial OFF Heap Size: 75656
E (72677) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 76 secs > BTserial ON Heap Size: 364
@ 77 secs > BTserial OFF Heap Size: 72380
E (76969) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@copercini
Copy link
Contributor

@usrdes what is you ESP32 core version? did you get it from arduino boards manager or directly from git?

@usrdes
Copy link
Author

usrdes commented Aug 28, 2018

@copercini
I followed instructions at :
https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/windows.md
on 8/12/2018.
So I figure that makes it the latest core version ..??
Which file in the install contains this ESP32 core version info?

@usrdes
Copy link
Author

usrdes commented Aug 28, 2018

@me-no-dev : Hi Can you please re-open this issue? As far as I can tell, it is not yet resolved. Thank you.

@copercini copercini reopened this Aug 28, 2018
@copercini
Copy link
Contributor

copercini commented Aug 28, 2018

@usrdes the issue was closed automatically when code was merged...

I'm using the boards manager installation https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md with /libraries/BluetoothSerial/src/BluetoothSerial.cpp patch and no leaks here

@usrdes
Copy link
Author

usrdes commented Aug 29, 2018

@copercini
OK, I used the board manager in the link you posted and updated my ESP32. Confirmed that the BluetoothSerial.cpp patch was included. Then I tried with the two devices, loading the compiled code once as ESP32 pico kit and once as ESP32 dev module. The memory leak is still there.
In the beginning of the run, the heap difference every "ON" is ~5K bytes, towards the end, i.e. before the crash it is ~3.8K bytes. The output is listed below.

Any suggestions on what to try next?
Thank you
--------------------------- Output --------------------

Device 1 loaded as ESP32 pico kit

------------------
The device started, now you can pair it with bluetooth!
 --> 
@ 1 secs > BTserial ON  Heap Size: 100800  
@ 2 secs > BTserial OFF Heap Size: 170460  
@ 3 secs > BTserial ON  Heap Size: 95720  
@ 4 secs > BTserial OFF Heap Size: 165824  


   |
   |
   |
   |

@ 56 secs > BTserial ON  Heap Size: 7112  
@ 58 secs > BTserial OFF Heap Size: 78060  
@ 61 secs > BTserial ON  Heap Size: 3296  
@ 62 secs > BTserial OFF Heap Size: 74336  
Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x4000c46c  PS      : 0x00060430  A0      : 0x80113686  A1      : 0x3ffdadb0 
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x0000001c  A5      : 0x00000000 
A6      : 0x4017994c  A7      : 0x00000001  A8      : 0x800d6d81  A9      : 0x3ffdad70 
A10     : 0x3ffe82d4  A11     : 0x00000000  A12     : 0x00000001  A13     : 0x3ffe6b4c 
A14     : 0x3ffe15f4  A15     : 0x00000084  SAR     : 0x00000008  EXCCAUSE: 0x0000001d 
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000 
Backtrace: 0x4000c46c:0x3ffdadb0 0x40113683:0x3ffdadc0 0x40113f59:0x3ffdade0 
0x400ef5b9:0x3ffdae00 0x400ef5f3:0x3ffdae20
Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:808
load:0x40078000,len:6084
load:0x40080000,len:6696
entry 0x400802e4
------------------

Device 2 loaded as ESP32 pico kit

--------------------

E (217) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

The device started, now you can pair it with bluetooth!
 --> 
@ 1 secs > BTserial ON  Heap Size: 98948  
@ 2 secs > BTserial OFF Heap Size: 169068  
E (3532) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 3 secs > BTserial ON  Heap Size: 93916  
@ 4 secs > BTserial OFF Heap Size: 164444  
E (5851) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)


   |
   |
   |
   |

@ 58 secs > BTserial ON  Heap Size: 5584  
@ 59 secs > BTserial OFF Heap Size: 76948  
E (59159) phy_init: store_cal_data_to_nvs_handle: store calibration data failed

(0x1105)

@ 62 secs > BTserial ON  Heap Size: 2876  
@ 63 secs > BTserial OFF Heap Size: 73232  
E (63449) phy_init: store_cal_data_to_nvs_handle: store calibration data failed

(0x1105)

Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x4000c46c  PS      : 0x00060e30  A0      : 0x80113966  A1      : 0x3ffdb330 
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x0000001c  A5      : 0x00000000 
A6      : 0x40179c2c  A7      : 0x00000001  A8      : 0x800d7049  A9      : 0x3ffdb2f0 
A10     : 0x3ffe6aa0  A11     : 0x00000000  A12     : 0x00000001  A13     : 0x3ffe68fc 
A14     : 0x3ffded94  A15     : 0x00000084  SAR     : 0x00000008  EXCCAUSE: 0x0000001d 
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000 
Backtrace: 0x4000c46c:0x3ffdb330 0x40113963:0x3ffdb340 0x40114239:0x3ffdb360 
0x400ef881:0x3ffdb380 0x400ef8bb:0x3ffdb3a0
Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:808
load:0x40078000,len:6084
load:0x40080000,len:6696
entry 0x400802e4
-------------------

Device 1 , code loaded as ESP32 dev kit

---------------------
The device started, now you can pair it with bluetooth!
 --> 
@ 1 secs > BTserial ON  Heap Size: 100780  
@ 2 secs > BTserial OFF Heap Size: 170472  
@ 3 secs > BTserial ON  Heap Size: 95780  
@ 4 secs > BTserial OFF Heap Size: 165840  
 
   |
   |
   |
   |

@ 56 secs > BTserial ON  Heap Size: 7188  
@ 57 secs > BTserial OFF Heap Size: 78088  
@ 61 secs > BTserial ON  Heap Size: 3364  
@ 62 secs > BTserial OFF Heap Size: 74364  
Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x4000c46c  PS      : 0x00060430  A0      : 0x80113686  A1      : 0x3ffdaeb0  
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x0000001c  A5      : 0x00000000  
A6      : 0x4017994c  A7      : 0x00000001  A8      : 0x800d6d81  A9      : 0x3ffdae70  
A10     : 0x3ffe6990  A11     : 0x00000000  A12     : 0x00000001  A13     : 0x3ffe8a3c  
A14     : 0x3ffe15f4  A15     : 0x00000084  SAR     : 0x00000008  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000  

Backtrace: 0x4000c46c:0x3ffdaeb0 0x40113683:0x3ffdaec0 0x40113f59:0x3ffdaee0 0x400ef5b9:0x3ffdaf00 0x400ef5f3:0x3ffdaf20

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:952
load:0x40078000,len:6084
load:0x40080000,len:7936
entry 0x40080310



-------------------

Device 2 , code loaded as ESP32 dev kit

---------------------

E (208) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

The device started, now you can pair it with bluetooth!
 --> 
@ 1 secs > BTserial ON  Heap Size: 99444  
@ 2 secs > BTserial OFF Heap Size: 169132  
E (3517) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 3 secs > BTserial ON  Heap Size: 94460  
@ 4 secs > BTserial OFF Heap Size: 164500  
E (5827) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

   |
   |
   |
   |

@ 57 secs > BTserial ON  Heap Size: 6136  
@ 59 secs > BTserial OFF Heap Size: 77020  
E (58905) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

@ 62 secs > BTserial ON  Heap Size: 2276  
@ 63 secs > BTserial OFF Heap Size: 73296  
E (63191) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)

Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x4000c46c  PS      : 0x00060c30  A0      : 0x80113686  A1      : 0x3ffdb2e0  
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x0000001c  A5      : 0x00000000  
A6      : 0x4017994c  A7      : 0x00000001  A8      : 0x800d6d81  A9      : 0x3ffdb2a0  
A10     : 0x3ffe783c  A11     : 0x00000000  A12     : 0x00000001  A13     : 0x3ffe6768  
A14     : 0x3ffded44  A15     : 0x00000084  SAR     : 0x00000008  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000  

Backtrace: 0x4000c46c:0x3ffdb2e0 0x40113683:0x3ffdb2f0 0x40113f59:0x3ffdb310 0x400ef5b9:0x3ffdb330 0x400ef5f3:0x3ffdb350

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:952
load:0x40078000,len:6084
load:0x40080000,len:7936
entry 0x40080310


------------------------

@usrdes
Copy link
Author

usrdes commented Sep 1, 2018

@copercini

Attempting to update my arduino install:
First I uninstalled ESP32, cleaned up any remaining folders
Uninstalled Arduino, again cleaned up any remaining folders
Updated my Java installation, so I have the latest environment.
Re-installed Arduino,
Re-installed ESP32.

Result:
The latest install did not get the Blue tooth serial updates. Further the Arduino boards manages shows that the ESP32 is version 1.0.0. So I am wondering if the version numbers are getting updated at all?

Anyway, I then downloaded the "zip" folder from github, to compare release dates and find some
discrepancies. I have attached a ms-paint picture, showing some of the folder structures and file
dates etc.

Can you please tell me if my arduino install is a problem?

Thanks

arduino_esp32_install

@lbernstone
Copy link
Contributor

Boards Manager has full releases only. It gets updated infrequently. Development happens in the git repository. Instructions are provided on the main page for installing the dev repo. Note that if you install both, you will have two sets of ESP32 boards in your IDE list.

@usrdes
Copy link
Author

usrdes commented Sep 1, 2018

@lbernstone
Hi, thank you for the quick response. Also forgive me for I do not understand your statements:
Please clarify:

  1. "Boards Manager has full releases only." --> is this for fresh clean complete release install ?
  2. "Instructions are provided on the main page for installing the dev repo. " --> is the "dev repo" some other place than github?

I followed the instructions below, after I completely wiped out my previous install.
So it should be up to date... right? Please help,. sorry that I do not understand your comments.
Thank you

arduino_esp32_install_instructions

@stickbreaker
Copy link
Contributor

@usrdes
If you want to use the current development branch you have to use the instructions for the repository:
dev branch

Chuck.

@usrdes
Copy link
Author

usrdes commented Sep 2, 2018

@copercini
I cleaned out my installs, and re-installed from development repository.
Checked that your updates to blue tooth serial is included.
Still memory leak exists.

I suspect that the core blue droid code may have an issue.

@IonicBob
Copy link

No update or resolution? As of Sep 12, I also see exactly the same memory leak, results as reported above (core panic after 63 iterations) using a ESP32 Dev Module and the latest dev branch and bluetoothserial.cpp update. I got here looking for resolution a random reset which occurs several times a day in a simple streaming bluetooth classic sketch. Is the the ESP32 bluetooth not yet ready for prime time? I notice a major update for bluetooth in ESP-IDF V3.1. Does this need to ripple through Arduino-ESP32?

@usrdes
Copy link
Author

usrdes commented Sep 19, 2018

@IonicBob
As far as I can tell, bluetoothserial.cpp is a wrapper for calls to bluedroid, as can be seen in the file:
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED)

While copercini appears to have fixed some of the open / close of memory leaks,
there is still some leak in the blue droid which is part of the core code that runs on esp32.

Don't know if the ESP-IDF V3.1 fix will take care of it or not, but for sure, it needs to ripple through to Arduino-ESP32.

@copercini
Copy link
Contributor

copercini commented Sep 22, 2018

@usrdes @IonicBob could you guys try cloning the last git code? (instructions here )
I think this was fixed by me-no-dev here 96822d7

@IonicBob
Copy link

IonicBob commented Sep 24, 2018

I tried this 3 times. Upgrade and then a fresh install of the last git code using instructions. Same result in all cases. This behaves a little different than before.

The device started, now you can pair it with bluetooth!
-->
@ 1 secs > BTserial ON Heap Size: 169884
@ 2 secs > BTserial OFF Heap Size: 244976
@ 3 secs > BTserial ON Heap Size: 166320
@ 5 secs > BTserial OFF Heap Size: 241692
@ 6 secs > BTserial ON Heap Size: 162928
@ 7 secs > BTserial OFF Heap Size: 238420
...
@ 71 secs > BTserial OFF Heap Size: 146812
@ 72 secs > BTserial ON Heap Size: 68056
@ 74 secs > BTserial OFF Heap Size: 143540
@ 75 secs > BTserial ON Heap Size: 64784
@ 76 secs > BTserial OFF Heap Size: 140264
@ 77 secs > BTserial ON Heap Size: 61500
@ 78 secs > BTserial OFF Heap Size: 136992
@ 79 secs > BTserial ON Heap Size: 58228
@ 80 secs > BTserial OFF Heap Size: 133720
@ 83 secs > BTserial ON Heap Size: 54820
@ 85 secs > BTserial OFF Heap Size: 130448
@ 88 secs > BTserial ON Heap Size: 52956
@ 89 secs > BTserial OFF Heap Size: 127176
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x4012f4a5 PS : 0x00060230 A0 : 0x80111bbf A1 : 0x3ffd5bf0
A2 : 0x00000000 A3 : 0x3fffff0c A4 : 0xffffff80 A5 : 0x3ffd5ed0
A6 : 0x3fffff14 A7 : 0x00001800 A8 : 0x8012f494 A9 : 0x3ffd5be0
A10 : 0x3ffd5bf4 A11 : 0x00000000 A12 : 0x00000268 A13 : 0x3ffd5e5c
A14 : 0x00000020 A15 : 0x00000026 SAR : 0x00000020 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000

Backtrace: 0x4012f4a5:0x3ffd5bf0 0x40111bbc:0x3ffd5e80 0x40114b82:0x3ffd5ea0 0x400efdaa:0x3ffd5ec0 0x4008c821:0x3ffd5ef0

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
...

@ConcepcionMota
Copy link

I have one problem with the BluetoothSerial.h, when i compile the project arduino says "error: 'EventGroupHandle_t' does not name a type

static EventGroupHandle_t _spp_event_group = NULL;", please someone help me

@piotrkundu
Copy link

Is this still a problem? Any updates?

@IonicBob
Copy link

Is this still a problem? Any updates?

Can't say, I needed an immediate resolution and switched back to an uart attached HC5/6 and its been running nonstop ever since. Having said that I believe there's been a lota work done on the libraries and its workwhile trying again. I don't have an immediate test system at hand, and would encourage you or someone else to re-run the BT test and close this issue if it now works.

@stale
Copy link

stale bot commented Aug 19, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 19, 2019
@stale
Copy link

stale bot commented Sep 2, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Sep 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck) Type: Bug 🐛 All bugs
Projects
None yet
Development

No branches or pull requests

7 participants