-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Memory leak in Blue tooth serial with bluedroid #1798
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
Comments
@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
} |
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:
|
1 problem found: - The queue is not being deleted at end, to fix it's just add inside this reduces the leak to just 96 bytes each iteration |
Problem 2 found: it's missing a call to Now it seems stable =)
|
this I think it's fixed now, I'll PR the changes |
@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. Also: void BluetoothSerial::end()
{
vQueueDelete(_spp_queue);
esp_spp_deinit();
_stop_bt();
} |
@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 |
@copercini , OK thank you, I will close this issue, |
@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: |
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);
} |
Tried your code on two devices. Results below, Device #1---------------------------------------- The device started, now you can pair it with bluetooth! Device #2 ----------------------------- load:0x40078000,len:6084 The device started, now you can pair it with bluetooth! @ 3 secs > BTserial ON Heap Size: 95396 @ 6 secs > BTserial ON Heap Size: 92072 @ 8 secs > BTserial ON Heap Size: 88800 @ 10 secs > BTserial ON Heap Size: 85528 @ 13 secs > BTserial ON Heap Size: 82256 @ 15 secs > BTserial ON Heap Size: 78984 @ 17 secs > BTserial ON Heap Size: 75712 . @ 65 secs > BTserial ON Heap Size: 10272 @ 67 secs > BTserial ON Heap Size: 7028 @ 71 secs > BTserial ON Heap Size: 3680 @ 76 secs > BTserial ON Heap Size: 364 |
@usrdes what is you ESP32 core version? did you get it from arduino boards manager or directly from git? |
@copercini |
@me-no-dev : Hi Can you please re-open this issue? As far as I can tell, it is not yet resolved. Thank you. |
@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 |
@copercini Any suggestions on what to try next? 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
------------------------
|
Attempting to update my arduino install: Result: Anyway, I then downloaded the "zip" folder from github, to compare release dates and find some Can you please tell me if my arduino install is a problem? Thanks |
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. |
@lbernstone
I followed the instructions below, after I completely wiped out my previous install. |
@usrdes Chuck. |
@copercini I suspect that the core blue droid code may have an issue. |
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? |
@IonicBob While copercini appears to have fixed some of the open / close of memory leaks, 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. |
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! Backtrace: 0x4012f4a5:0x3ffd5bf0 0x40111bbc:0x3ffd5e80 0x40114b82:0x3ffd5ea0 0x400efdaa:0x3ffd5ec0 0x4008c821:0x3ffd5ef0 Rebooting... rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) |
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 |
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. |
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. |
This stale issue has been automatically closed. Thank you for your contributions. |
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:
Sketch: Modified serial to serial blue tooth example as follows:
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
The text was updated successfully, but these errors were encountered: