]> granicus.if.org Git - esp-idf/commitdiff
component/bt : fix btdm mem release cause 0x3ffbbb28-0x3ffbdb28 add to region but...
authorTian Hao <tianhao@espressif.com>
Tue, 12 Dec 2017 07:24:43 +0000 (15:24 +0800)
committerTian Hao <tianhao@espressif.com>
Wed, 13 Dec 2017 03:37:31 +0000 (11:37 +0800)
1. fix the bug. Modify the condition that esp_bt_controller_mem_release() shoud be only called before esp_bt_controller_init() or after esp_bt_controller_deinit()
2. modify the example to use esp_bt_controller_mem_release()

14 files changed:
components/bt/bt.c
components/bt/include/esp_bt.h
examples/bluetooth/a2dp_sink/main/main.c
examples/bluetooth/ble_eddystone/main/esp_eddystone_demo.c
examples/bluetooth/ble_ibeacon/main/ibeacon_demo.c
examples/bluetooth/ble_spp_client/main/spp_client_demo.c
examples/bluetooth/ble_spp_server/main/ble_spp_server_demo.c
examples/bluetooth/blufi/main/blufi_example_main.c
examples/bluetooth/gatt_client/main/gattc_demo.c
examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c
examples/bluetooth/gatt_security_server/main/example_ble_sec_gatts_demo.c
examples/bluetooth/gatt_server/main/gatts_demo.c
examples/bluetooth/gatt_server_service_table/main/gatts_table_creat_demo.c
examples/bluetooth/gattc_multi_connect/main/gattc_multi_connect.c

index 6890bcf126f067d4be776096b49b1b6f59067a27..c53e9c933678697e78d815ed1790f2535c25f45e 100644 (file)
@@ -398,10 +398,8 @@ esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode)
     bool update = true;
     intptr_t mem_start, mem_end;
 
-    //get the mode which can be released, skip the mode which is running
-    mode &= ~btdm_controller_get_mode();
-    if (mode == 0x0) {
-        return ESP_ERR_INVALID_ARG;
+    if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
+        return ESP_ERR_INVALID_STATE;
     }
 
     //already relesed
index 30a535015d83b8bb6a039ac29639b1e500db6781..dcd531b6d035bbc8847bd7c2c7d07aa1ca47b4eb 100644 (file)
@@ -212,20 +212,18 @@ void esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback);
  * it can release the .bbs, .data and other section to heap.
  * The total size is about 70k bytes.
  *
- * If esp_bt_controller_enable(mode) has already been called, calling
- * esp_bt_controller_mem_release(ESP_BT_MODE_BTDM) will automatically
- * release all memory which is not needed for the currently enabled
- * Bluetooth controller mode.
+ * esp_bt_controller_mem_release(mode) should be called only before esp_bt_controller_init()
+ * or after esp_bt_controller_deinit().
  *
- * For example, calling esp_bt_controller_enable(ESP_BT_MODE_BLE) then
- * esp_bt_controller_mem_release(ESP_BT_MODE_BTDM) will enable BLE modes
- * and release memory only used by BT Classic. Also, call esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT)
- * is the same.
+ * Note that once BT controller memory is released, the process cannot be reversed. It means you can not use the bluetooth
+ * mode which you have released by this function.
  *
- * Note that once BT controller memory is released, the process cannot be reversed.
  * If your firmware will later upgrade the Bluetooth controller mode (BLE -> BT Classic or disabled -> enabled)
  * then do not call this function.
  *
+ * If the app calls esp_bt_controller_enable(ESP_BT_MODE_BLE) to use BLE only then it is safe to call
+ * esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT) at initialisation time to free unused BT Classic memory.
+ *
  * If user never use bluetooth controller, could call esp_bt_controller_mem_release(ESP_BT_MODE_BTDM)
  * before esp_bt_controller_init or after esp_bt_controller_deinit.
  *
index e77aa449cb34c1ecfe9b26d792e215cba03b854c..aa489f5839fc41fc26a06a4512e5f0a52f108544 100644 (file)
@@ -83,6 +83,7 @@ void app_main()
 #endif
 
 
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE));
 
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
     if (esp_bt_controller_init(&bt_cfg) != ESP_OK) {
index 7def481ae0a64432dd848a255dbf102e7b72db06..95f239431e769c314f9fd2284ee74896fc09f5f3 100644 (file)
@@ -166,9 +166,10 @@ void esp_eddystone_init(void)
 void app_main()
 {
     ESP_ERROR_CHECK(nvs_flash_init());
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
     esp_bt_controller_init(&bt_cfg);
-    esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    esp_bt_controller_enable(ESP_BT_MODE_BLE);
  
     esp_eddystone_init();
 
index e0d71ba8ed91c5e8263b7e94120e18ecfef7d477..ded43782850e5f30c0d92eba5d6c81c3377b1b22 100644 (file)
@@ -160,9 +160,10 @@ void ble_ibeacon_init(void)
 void app_main()
 {
     ESP_ERROR_CHECK(nvs_flash_init());
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
     esp_bt_controller_init(&bt_cfg);
-    esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    esp_bt_controller_enable(ESP_BT_MODE_BLE);
 
     ble_ibeacon_init();
 
index b2968b38ca8013c6143fd35c4d0aadd6170fc536..855cc0f764c4a0477b2e0ac61e47db4892205b4f 100644 (file)
@@ -956,6 +956,9 @@ static void spp_uart_init(void)
 void app_main()
 {
     esp_err_t ret;
+
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
+
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
 
     nvs_flash_init();
@@ -965,7 +968,7 @@ void app_main()
         return;
     }
 
-    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
     if (ret) {
         ESP_LOGE(GATTC_TAG, "%s enable controller failed\n", __func__);
         return;
index 399dc7e1df9db604a42061b5d18dcf444fd0a42c..6ed2a2380073c3d25d0e69a42677c35cad715a15 100644 (file)
@@ -658,14 +658,23 @@ void app_main()
     esp_err_t ret;
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
 
-    nvs_flash_init();
+    // Initialize NVS
+    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 );
+
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
+
     ret = esp_bt_controller_init(&bt_cfg);
     if (ret) {
         ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed\n", __func__);
         return;
     }
 
-    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
     if (ret) {
         ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed\n", __func__);
         return;
index 5895d5e2855e8cd7775349235665639fab218956..a780d606ca8ebf56d594d20e7ae216fea559e403 100644 (file)
@@ -331,13 +331,15 @@ void app_main()
 
     initialise_wifi();
 
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
+
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
     ret = esp_bt_controller_init(&bt_cfg);
     if (ret) {
         BLUFI_ERROR("%s initialize bt controller failed\n", __func__);
     }
 
-    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
     if (ret) {
         BLUFI_ERROR("%s enable bt controller failed\n", __func__);
         return;
index d9bb810f925a773fb901dd7d1cadd10f6b317bc9..3dac182661d9bcf5293716ae0fbf3adbb7c5669f 100644 (file)
@@ -425,6 +425,8 @@ void app_main()
     }
     ESP_ERROR_CHECK( ret );
 
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
+
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
     ret = esp_bt_controller_init(&bt_cfg);
     if (ret) {
@@ -432,7 +434,7 @@ void app_main()
         return;
     }
 
-    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
     if (ret) {
         ESP_LOGE(GATTC_TAG, "%s enable controller failed, error code = %x\n", __func__, ret);
         return;
index a71d496df3f186dbf26d07b97b911e1690f7ffbd..3679b33afd8578af14c4f116e47f7fec9966522a 100644 (file)
@@ -468,6 +468,8 @@ void app_main()
     }
     ESP_ERROR_CHECK( ret );
 
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
+
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
     ret = esp_bt_controller_init(&bt_cfg);
     if (ret) {
@@ -475,7 +477,7 @@ void app_main()
         return;
     }
 
-    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
     if (ret) {
         ESP_LOGE(GATTC_TAG, "%s enable controller failed, error code = %x\n", __func__, ret);
         return;
index eb328c4f66ac7c7cfacc9f6126464aeadd82ddfd..5b7d460c4acad442f49a73d8761c23c9ce31da9b 100644 (file)
@@ -476,13 +476,15 @@ void app_main()
     }
     ESP_ERROR_CHECK( ret );
 
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
+
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
     ret = esp_bt_controller_init(&bt_cfg);
     if (ret) {
         ESP_LOGE(GATTS_TABLE_TAG, "%s init controller failed", __func__);
         return;
     }
-    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
     if (ret) {
         ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed", __func__);
         return;
index 1bc35e4fd5f4d19c6803bd3a82642ed68f5cef9b..4e298dcae1f75c3b92b2742e8210f4a8e0650141 100644 (file)
@@ -691,6 +691,8 @@ void app_main()
     }
     ESP_ERROR_CHECK( ret );
 
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
+
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
     ret = esp_bt_controller_init(&bt_cfg);
     if (ret) {
@@ -698,7 +700,7 @@ void app_main()
         return;
     }
 
-    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
     if (ret) {
         ESP_LOGE(GATTS_TAG, "%s enable controller failed\n", __func__);
         return;
index 25aee69649102990a094a6af8ed06eb8c2df7f35..a38babd65655f3f33377b2fa174e4a0a1f63444c 100644 (file)
@@ -522,6 +522,8 @@ void app_main()
     }
     ESP_ERROR_CHECK( ret );
 
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
+
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
     ret = esp_bt_controller_init(&bt_cfg);
     if (ret) {
@@ -529,7 +531,7 @@ void app_main()
         return;
     }
 
-    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
     if (ret) {
         ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed\n", __func__);
         return;
index 6e19d57b16ac6121e7d1f7bb5e10d29aa7887131..eb09cee232a609d860ceee19195a4fe7f6202fe0 100644 (file)
@@ -896,6 +896,8 @@ void app_main()
     }
     ESP_ERROR_CHECK( ret );
 
+    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
+
     esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
     ret = esp_bt_controller_init(&bt_cfg);
     if (ret) {
@@ -903,7 +905,7 @@ void app_main()
         return;
     }
 
-    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
+    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
     if (ret) {
         ESP_LOGE(GATTC_TAG, "%s enable controller failed\n", __func__);
         return;