No heap anymore after adding bluetooth in menuconfig

jumjum123
Posts: 199
Joined: Mon Oct 17, 2016 3:11 pm

No heap anymore after adding bluetooth in menuconfig

Postby jumjum123 » Wed Sep 20, 2017 9:06 am

Plan was to start adding bluetooth support to my application.
First step was to set Bluetooth in Component Config and compiled everything without any other changes.
Download to board, reset and got abort after starting scheduler.
Some time later after a lot of testing etc. found the problem is in heapsize

In my application, without bluetooth, after starting everything, esp_get_free_heap_size() returns 133644
Checking heapsize in start_cpu0_default, without bluetooth, gives 73644 only.
Looks like lot of heap is used during startup (?)
Checking heapsize in start_cpu0_default, now with bluetooth, gives 720 only.
Fully understand, that this is too poor to do anything.

Where is memory gone, I only added Bluetooth to components ?
Is there anything I can do ?

jumjum123
Posts: 199
Joined: Mon Oct 17, 2016 3:11 pm

Re: No heap anymore after adding bluetooth in menuconfig

Postby jumjum123 » Wed Sep 20, 2017 9:26 am

Some more info, compared heap during startup with / without bluetooth.
BTW, line 333 in components/esp32/cpu_start.c changed to get heapsize

Code: Select all

ESP_LOGI(TAG, "Starting scheduler(%d) on PRO CPU.",esp_get_free_heap_size());
without bluetooth
I (4571) cpu_start: Single core mode
I (4604) heap_init: Initializing. RAM available for dynamic allocation:
I (4660) heap_init: At 3FFAE2A0 len 00001D60 (7 KiB): DRAM
I (4708) heap_init: At 3FFCCFC8 len 00013038 (76 KiB): DRAM
I (4757) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (4807) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (4858) heap_init: At 400909E0 len 0000F620 (61 KiB): IRAM
I (4907) cpu_start: Pro cpu start user code
I (5059) cpu_start: Starting scheduler(73644) on PRO CPU.
with bluetooth
I (4753) cpu_start: Single core mode
I (4786) heap_init: Initializing. RAM available for dynamic allocation:
I (4842) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (4890) heap_init: At 3FFDCFC8 len 00003038 (12 KiB): DRAM
I (4939) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (4989) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (5041) heap_init: At 400909E0 len 0000F620 (61 KiB): IRAM
I (5090) cpu_start: Pro cpu start user code
I (5241) cpu_start: Starting scheduler(828) on PRO CPU.
There is a difference of 64 k in 2nd heap_init

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: No heap anymore after adding bluetooth in menuconfig

Postby loboris » Wed Sep 20, 2017 10:16 am

Bluetooth, when enabled, uses a lot of memory. You can free ~30K by selecting → Component config → Bluetooth → Bluedroid Bluetooth stack enabled → Release DRAM from Classic BT controller if you are using BLE only.
If this is not enough, you will need to use ESP32 with psRAM...

jumjum123
Posts: 199
Joined: Mon Oct 17, 2016 3:11 pm

Re: No heap anymore after adding bluetooth in menuconfig

Postby jumjum123 » Wed Sep 20, 2017 11:23 am

@ loboris,
thanks a lot. This helped to get my app running again.
I will continue and try to get BLE implemented.

When ESP32 arrived, memory seemed to be endless.
Now we are close to good old ESP8266, starting to fight for bytes :(
Hopefully, there is somebody who will optimize memory consumption.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: No heap anymore after adding bluetooth in menuconfig

Postby loboris » Wed Sep 20, 2017 12:11 pm

If your application needs a lot of heap, I would recommend using ESP32 with spiram. In small quantities you can get two modules from AnalogLamb, ALB32-WROVER and ESP32-WROVER.
SPIRAM support is now included in latest esp-idf and xtensa toolchain, so there should be no problem using it.
You will have 4MB of heap available for application usage and more DRAM can be left for the system.

jumjum123
Posts: 199
Joined: Mon Oct 17, 2016 3:11 pm

Re: No heap anymore after adding bluetooth in menuconfig

Postby jumjum123 » Wed Sep 20, 2017 12:41 pm

AFAIK, there is no bread board with psram.
We have a nice wording for people like me, I'm born with (at least) 2 left hands.
Means soldering a chip on a board is far beyond my skills.
Therefore I'm waiting for a board, acceptable priced.

Anyway, from my point of view, there is a bottleneck during start.
Available heap is about 60 k less, compared to running tasks.
There should be a way to bypass this bottleneck.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: No heap anymore after adding bluetooth in menuconfig

Postby kolban » Wed Sep 20, 2017 2:02 pm

jumjum123,
While I am also not aware of any breakout boards support WROVER, I am delighted with this board:

https://www.analoglamb.com/product/esp- ... er-module/

(see @loboris post above).

While the board is indeed pricy ($47) it is (opinion) well worth it. Think how much time we spend tinkering with these things. Not only does that board contain a WROVER module, it has a screen, great breakout pins and ... most importantly of all ... built in JTAG. This means that you can source step through your running apps on the ESP32 in real time.

This contains a WROVER as well as male header pins. These can be connected by male/female socket wires to your breadboard. The result was an immediate whopping 4.5MBytes of RAM available to my apps. In my JavaScript Duktape experiments, I was dead in the water with 190K of RAM on the WROOM but with WROVER, memory issues are gone. Its early days for WROVER, but "its-a-coming".

WROOM = ESP32 module.
WROVER = ESP32 module where module includes pSRAM.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: No heap anymore after adding bluetooth in menuconfig

Postby loboris » Wed Sep 20, 2017 3:52 pm

kolban wrote:While I am also not aware of any breakout boards support WROVER...
AnalogLam now has breakout board for ESP32-WROVER.
It looks like it is sold without any component soldered. It would be good if AnalogLamb could release this board with all components (including ESP32-WROVER module) soldered, for those with no soldering skills.

BuddyCasino
Posts: 263
Joined: Sun Jun 19, 2016 12:00 am

Re: No heap anymore after adding bluetooth in menuconfig

Postby BuddyCasino » Wed Sep 20, 2017 4:40 pm

I have three Wrover modules and some unpopulated Wroom breakout boards. Does that mean they are not pin-compatible and I need new breakouts?

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: No heap anymore after adding bluetooth in menuconfig

Postby loboris » Wed Sep 20, 2017 4:57 pm

BuddyCasino wrote:I have three Wrover modules and some unpopulated Wroom breakout boards. Does that mean they are not pin-compatible and I need new breakouts?
Wrower and Wroon has different footprint. There is also ALB32-WROVER which has the same footprint as ESP32-WROOM, but with 4MB psRAM included.

Who is online

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