[SOLVED] BLE and Wifi = out of memory ??

User avatar
PaulVdBergh
Posts: 58
Joined: Fri Feb 23, 2018 4:45 pm
Location: Brasschaat, Belgium

[SOLVED] BLE and Wifi = out of memory ??

Postby PaulVdBergh » Sat Apr 28, 2018 2:10 pm

Hi all,

I'm trying to setup BLE and Wifi together (ESP-WROVER-Kit), but the image is to big for the flash ?? :o

Code: Select all

paulvdbergh@ssd-debian:~/IoTTrains/IoTaT$ make monitor
MONITOR
--- idf_monitor on /dev/ttyUSB1 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x3e (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4672
ho 0 tail 12 room 4
load:0x40078000,len:0
load:0x40078000,len:13636
entry 0x40078578
E (505) esp_image: Image length 1316096 doesn't fit in partition length 1048576
E (505) boot: Factory app partition is not bootable
E (507) boot: No bootable app partitions in the partition table
user code done
My code is based on Kolban's BLE example in his esp32-snippets/cpp_utils :

Code: Select all

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "BLEDevice.h"
#include "BLEServer.h"
#include "BLEUtils.h"
#include "BLE2902.h"
#include "esp_log.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include <string>
#include "Task.h"
#include "esp_log.h"
#include "nvs_flash.h"

static char LOG_TAG[] = "SampleServer";

class MainBLEServer : public Task
{
	void run(void* data)
	{
		ESP_LOGD(LOG_TAG, "Starting BLE work!");

		BLEDevice::init("ESP32");
		BLEServer* pServer = BLEDevice::createServer();

		BLEService* pService = pServer->createService("91bad492-b950-4226-aa2b-4ede9fa42f59");

		BLECharacteristic* pCharacteristic = pService->createCharacteristic(
			BLEUUID("0d563a58-196a-48ce-ace2-dfec78acc814"),
			BLECharacteristic::PROPERTY_BROADCAST | BLECharacteristic::PROPERTY_READ  |
			BLECharacteristic::PROPERTY_NOTIFY    | BLECharacteristic::PROPERTY_WRITE |
			BLECharacteristic::PROPERTY_INDICATE
		);

		pCharacteristic->setValue("Hello World!");

		BLE2902* p2902Descriptor = new BLE2902();
		p2902Descriptor->setNotifications(true);
		pCharacteristic->addDescriptor(p2902Descriptor);

		pService->start();

		BLEAdvertising* pAdvertising = pServer->getAdvertising();
		pAdvertising->addServiceUUID(BLEUUID(pService->getUUID()));
		pAdvertising->start();

		ESP_LOGD(LOG_TAG, "Advertising started!");
		delay(1000000);
	}
};

esp_err_t event_handler(void *ctx, system_event_t *event)
{
    return ESP_OK;
}

extern "C"
void app_main(void)
{
    /* Initialize NVS — it is used to store PHY calibration data */
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES)
    {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK( ret );

    tcpip_adapter_init();
    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );

    wifi_config_t sta_config;
    memcpy(&sta_config.sta.ssid, "devolo-8f4", strlen("devolo-8f4"));
    memcpy(&sta_config.sta.password, "----------------", strlen("----------------"));
    sta_config.sta.bssid_set = false;

    ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
    ESP_ERROR_CHECK( esp_wifi_start() );
    ESP_ERROR_CHECK( esp_wifi_connect() );

	MainBLEServer* pMainBleServer = new MainBLEServer();
	pMainBleServer->setStackSize(20000);
	pMainBleServer->start();

    gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT);
    int level = 0;
    while (true) {
        gpio_set_level(GPIO_NUM_4, level);
        level = !level;
        vTaskDelay(300 / portTICK_PERIOD_MS);
    }
}

Anyone ?

Thanks,

Paul.
Last edited by PaulVdBergh on Sat Apr 28, 2018 10:41 pm, edited 1 time in total.

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

Re: BLE and Wifi = out of memory ??

Postby kolban » Sat Apr 28, 2018 3:44 pm

Howdy Paul,
What this is telling us is that the size of the compiled executable is larger than the default allowable size of 1MByte. See the following:

http://esp-idf.readthedocs.io/en/latest ... ables.html

This talks about the configuration of what is called the "partition table". By default, 1MByte is allocated for program space in flash (entry factory/app).

You can change/define this as you like. If your ESP32 is a "standard" one, then you have 4MBytes of flash to play with. Change the size from 1M to 2M and you should be fine. Read that doc section in detail to make sure you comprehend the whole story.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
PaulVdBergh
Posts: 58
Joined: Fri Feb 23, 2018 4:45 pm
Location: Brasschaat, Belgium

Re: BLE and Wifi = out of memory ??

Postby PaulVdBergh » Sat Apr 28, 2018 5:11 pm

Thanks for your answer.

I read the documentation and made my own partition file:

Code: Select all

# Espressif ESP32 Partition Table
# Name, Type, SubType, 	Offset, 	Size, Flags
nvs		,data,	nvs,		0x9000,	24K,
phy_init,	data,	phy,		0xf000,	4K,
factory,	app,		factory,	0x10000,	3M,
I changed menuconfig to use this partition table, make erase_flash, make -j4 flash & make monitor :

Code: Select all

paulvdbergh@ssd-debian:~/IoTTrains/IoTaT$ make flash monitor
Flashing binaries to serial port /dev/ttyUSB1 (app at offset 0x10000)...
esptool.py v2.3.1
Connecting........__
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 2000000
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 18416 bytes to 10933...
Wrote 18416 bytes (10933 compressed) at 0x00001000 in 0.1 seconds (effective 2295.6 kbit/s)...
Hash of data verified.
Compressed 1316096 bytes to 716098...
Wrote 1316096 bytes (716098 compressed) at 0x00010000 in 13.1 seconds (effective 802.6 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 105...
Wrote 3072 bytes (105 compressed) at 0x00008000 in 0.0 seconds (effective 1525.1 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
MONITOR
--- idf_monitor on /dev/ttyUSB1 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x3e (SPI_FAST_FLASH_BOOT)
flash read err, 1000
Falling back to built-in command interpreter.
OK
>ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x3e (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4672
ho 0 tail 12 room 4
load:0x40078000,len:0
load:0x40078000,len:13636
entry 0x40078578
I (517) cpu_start: Pro cpu up.
I (517) cpu_start: Single core mode
I (517) heap_init: Initializing. RAM available for dynamic allocation:
I (521) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (527) heap_init: At 3FFD5390 len 0000AC70 (43 KiB): DRAM
I (533) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (539) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (546) heap_init: At 40092DD0 len 0000D230 (52 KiB): IRAM
I (552) cpu_start: Pro cpu start user code
I (122) cpu_start: Starting scheduler on PRO CPU.
I (146) wifi: wifi firmware version: 2de7507
I (147) wifi: config NVS flash: enabled
I (147) wifi: config nano formating: disabled
I (147) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (157) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (179) wifi: Init dynamic tx buffer num: 32
I (179) wifi: Init data frame dynamic rx buffer num: 32
I (179) wifi: Init management frame dynamic rx buffer num: 32
I (183) wifi: wifi driver task: 3ffdd294, prio:23, stack:4096
I (189) wifi: Init static rx buffer num: 10
I (192) wifi: Init dynamic rx buffer num: 32
I (251) phy: phy_version: 386.0, 67c798f, Mar 14 2018, 16:34:06, 0, 0
I (252) wifi: mode : sta (24:0a:c4:11:a7:38)
I (255) BTDM_INIT: BT controller compile version [fad425d]

I (257) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
E (448) BT: bta_gattc_co_cache_addr_init, Line = 333, nvs flash get blob data fail, err_code = 1102
E (673) BT: osi_mem_dbg_record invalid !!

Anyone ?

Paul.

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

Re: BLE and Wifi = out of memory ??

Postby kolban » Sat Apr 28, 2018 6:50 pm

Maybe:

Code: Select all

$ make erase
$ make erase_flash
$ make -j4 flash
$ make monitor
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
PaulVdBergh
Posts: 58
Joined: Fri Feb 23, 2018 4:45 pm
Location: Brasschaat, Belgium

Re: BLE and Wifi = out of memory ??

Postby PaulVdBergh » Sat Apr 28, 2018 7:23 pm

Hi,

since "make erase" gives "no rule to make target", I suppose you mean "make clean" ?

But the sequence

Code: Select all

make clean
make erase_flash
make -j4 all
make flash
make monitor
gives the same error...

Since I'm experiencing difficulties debugging over JTAG, it's hard to follow the flow of the program. I'll try to find bta_gattc_co_cache_addr_init and place a breakpoint in the hope that will enlightening something...

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

Re: BLE and Wifi = out of memory ??

Postby chegewara » Sat Apr 28, 2018 8:28 pm

Since you store wifi data in RAM, maybe try to comment out this code:

Code: Select all

    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES)
    {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK( ret );

User avatar
PaulVdBergh
Posts: 58
Joined: Fri Feb 23, 2018 4:45 pm
Location: Brasschaat, Belgium

[SOLVED] BLE and Wifi = out of memory ??

Postby PaulVdBergh » Sat Apr 28, 2018 10:40 pm

Hi all,

I solved the problem : if you enable the Bluedroid in the esp-idf-template via make menuconfig, by default both GATT Server AND GATT client are enabled. After un-checking "Include GATT client module (GATTC) (NEW)" and rebuilding my project didn't crash anymore.

Apparently one has to choose either to be a client OR a server, but not both....

cheers,

Paul.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: [SOLVED] BLE and Wifi = out of memory ??

Postby fly135 » Sun Apr 29, 2018 12:16 am

That's good to know.

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

Re: [SOLVED] BLE and Wifi = out of memory ??

Postby chegewara » Sun Apr 29, 2018 2:30 am

Nice catch but very strange, because most of time i have both turned on (GATTS and GATTC).

anandvilayil
Posts: 22
Joined: Mon Apr 30, 2018 12:14 pm

BLE + http server(enabled APSTA mode) not working

Postby anandvilayil » Mon Apr 30, 2018 12:39 pm

hi, all
i am new to this community, i also have a problem. while i tried to run a http server in esp32 (enable APSTA mode) and bluetooth LE also enabled and working as gatt client, there showing an error "no mem" . and after i removed the blutooth part now the esp succesfully host http server. why this so?

some one please help me. i doubt that esp32 is't capable of working all at once?

regards

Who is online

Users browsing this forum: No registered users and 23 guests