i write a demo,reference examples\bluetooth\bluedroid\classic_bt\hfp_ag and examples\bluetooth\bluedroid\ble\gatt_client
first hfp_ag connect headset. success
then start ble scan, appear panic
below is monitor output log
Code: Select all
rst:0x1 (POWERON_RESET),boot:0x12 (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:0x3fff0030,len:7100
ho 0 tail 12 room 4
load:0x40078000,len:14292
load:0x40080400,len:3688
0x40080400: _init at ??:?
entry 0x40080678
I (29) boot: ESP-IDF v4.3-dirty 2nd stage bootloader
I (29) boot: compile time 15:17:17
I (29) boot: chip revision: 3
I (32) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed : 40MHz
I (44) boot.esp32: SPI Mode : DIO
I (49) boot.esp32: SPI Flash Size : 2MB
I (53) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (62) boot: ## Label Usage Type ST Offset Length
I (69) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (77) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (84) boot: 2 factory factory app 00 00 00010000 00100000
I (92) boot: End of partition table
I (96) boot_comm: chip revision: 3, min. application chip revision: 0
I (103) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=2a77ch (173948) map
I (177) esp_image: segment 1: paddr=0003a7a4 vaddr=3ffbdb60 size=040d8h ( 16600) load
I (184) esp_image: segment 2: paddr=0003e884 vaddr=40080000 size=01794h ( 6036) load
I (187) esp_image: segment 3: paddr=00040020 vaddr=400d0020 size=a2d88h (667016) map
I (443) esp_image: segment 4: paddr=000e2db0 vaddr=40081794 size=164b0h ( 91312) load
I (482) esp_image: segment 5: paddr=000f9268 vaddr=50000000 size=00010h ( 16) load
I (495) boot: Loaded app from partition at offset 0x10000
I (495) boot: Disabling RNG early entropy source...
I (507) cpu_start: Pro cpu up.
I (507) cpu_start: Starting app cpu, entry point is 0x400813cc
0x400813cc: call_start_cpu1 at /home/liupeng/WorkSpace/espressif/esp/esp-idf/components/esp_system/port/cpu_start.c:141
I (0) cpu_start: App cpu up.
I (524) cpu_start: Pro cpu start user code
I (524) cpu_start: cpu freq: 160000000
I (524) cpu_start: Application information:
I (528) cpu_start: Project name: bt_ble_coex
I (533) cpu_start: App version: v4.3-dirty
I (539) cpu_start: Compile time: Aug 24 2021 15:17:17
I (545) cpu_start: ELF file SHA256: 2ba164595fb42e8d...
I (551) cpu_start: ESP-IDF: v4.3-dirty
I (556) heap_init: Initializing. RAM available for dynamic allocation:
I (563) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (569) heap_init: At 3FFB6BF8 len 00001408 (5 KiB): DRAM
I (575) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (581) heap_init: At 3FFC9C00 len 00016400 (89 KiB): DRAM
I (588) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (594) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (600) heap_init: At 40097C44 len 000083BC (32 KiB): IRAM
I (608) spi_flash: detected chip: gd
I (611) spi_flash: flash io: dio
W (615) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (629) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (639) BT_APP_HF: [app_main] app main start....
I (689) BTDM_INIT: BT controller compile version [1342a48]
I (689) system_api: Base MAC address is not set
I (689) system_api: read default base MAC address from EFUSE
I (699) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
E (1419) BT_BTC: btc_hf_cb_handler: Invalid index -1
I (1429) gpio: GPIO[19]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1429) gpio: GPIO[21]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1439) gpio: GPIO[22]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
Type 'help' to get the list of commands.
Use UP/DOWN arrows to navigate through command history.
Press TAB when typing command name to auto-complete.
==================================================
| Steps to test hfp_ag |
| |
| 1. Print 'help' to gain overview of commands |
| 2. Setup a service level connection |
| 3. Run hfp_ag to test |
| |
=================================================
I (1689) BT_APP_HF: ble_gattc_init in.
I (1699) APP_GATTC: REG_EVT
I (1699) APP_GATTC: scan param set complete
hfp_ag>
hfp_ag> W (7539) BT_APPL: new conn_srvc id:5, app_id:0
I (7539) BT_APP_HF: APP HFP event: CONNECTION_STATE_EVT
I (7539) BT_APP_HF: --connection state CONNECTED, peer feats 0x0, chld_feats 0x0
I (7609) BT_APP_HF: APP HFP event: CIND_RESPONSE_EVT
I (7609) BT_APP_HF: --CIND Start.
I (7639) BT_APP_HF: APP HFP event: CONNECTION_STATE_EVT
I (7639) BT_APP_HF: --connection state SLC_CONNECTED, peer feats 0x3f, chld_feats 0x4013
I (7659) BT_APP_HF: APP HFP event: NREC_RESPONSE_EVT
I (7659) BT_APP_HF: --NREC status is: NREC DISABLE.
I (7669) BT_APP_HF: APP HFP event: VOLUME_CONTROL_EVT
I (7669) BT_APP_HF: --Volume Target: SPEAKER, Volume 13
I (7719) BT_APP_HF: APP HFP event: UNKNOW_AT_CMD
I (7719) BT_APP_HF: --UNKOW AT CMD: +XAPL=0000-0000-0100,7
I (7739) BT_APP_HF: APP HFP event: UNKNOW_AT_CMD
I (7739) BT_APP_HF: --UNKOW AT CMD: +IPHONEACCEV=2,1,8,2,0
I (7789) BT_APP_HF: APP HFP event: CLCC_RESPONSE_EVT
I (7789) BT_APP_HF: --Calling Line Identification.
I (7829) BT_APP_HF: APP HFP event: UNKNOW_AT_CMD
I (7829) BT_APP_HF: --UNKOW AT CMD: +CSRSF=0,0,0,1,0,0,0
hfp_ag>
hfp_ag>
hfp_ag>
hfp_ag>
hfp_ag>
hfp_ag>
hfp_ag> blescan
ble start scanning
I (17059) APP_GATTC: scan start success
I (17089) APP_GATTC: 1d a8 c0 ac e8 da
I (17089) APP_GATTC: searched Adv Data Len 31, Scan Response Len 0
I (17089) APP_GATTC: searched Device Name Len 0
I (17099) APP_GATTC:
I (17119) APP_GATTC: 53 7b 57 35 54 29
I (17119) APP_GATTC: searched Adv Data Len 17, Scan Response Len 0
I (17119) APP_GATTC: searched Device Name Len 0
I (17129) APP_GATTC:
I (17129) APP_GATTC: 5d be a4 a5 2f 6f
I (17129) APP_GATTC: searched Adv Data Len 31, Scan Response Len 0
I (17149) APP_GATTC: searched Device Name Len 0
I (17149) APP_GATTC:
hfp_ag> I (17189) APP_GATTC: 1d a8 c0 ac e8 da
I (17199) APP_GATTC: searched Adv Data Len 31, Scan Response Len 0
I (17199) APP_GATTC: searched Device Name Len 0
I (17209) APP_GATTC:
I (17219) APP_GATTC: 2a 67 91 78 8e 5d
I (17219) APP_GATTC: searched Adv Data Len 31, Scan Response Len 0
I (17219) APP_GATTC: searched Device Name Len 0
I (17229) APP_GATTC:
I (17319) APP_GATTC: d4 f2 5d 21 96 5a
I (17319) APP_GATTC: searched Adv Data Len 31, Scan Response Len 0
I (17319) APP_GATTC: searched Device Name Len 0
I (17329) APP_GATTC:
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x4001ac19 PS : 0x00060e31 A0 : 0x800881fe A1 : 0x3ffbe7f0
A2 : 0x008479d4 A3 : 0x00000007 A4 : 0x00000000 A5 : 0x3ffb8360
A6 : 0x000005b4 A7 : 0x00000000 A8 : 0x0000002f A9 : 0x00000507
A10 : 0x00000000 A11 : 0x3ffcc584 A12 : 0x00000000 A13 : 0x00000001
A14 : 0x00000000 A15 : 0x3ffb8360 SAR : 0x0000001e EXCCAUSE: 0x0000001c
EXCVADDR: 0x008479d8 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Backtrace:0x4001ac16:0x3ffbe7f0 0x400881fb:0x3ffbe810 0x40085502:0x3ffbe850 0x4008aaea:0x3ffbe870 0x4008b603:0x3ffbe890 0x40082b59:0x3ffbe8b0 0x40170413:0x3ffbd690 0x400da8ca:0x3ffbd6b0 0x40091fb5:0x3ffbd6d0 0x40093cd9:0x3ffbd6f0
0x400881fb: r_lld_evt_schedule at ??:?
0x40085502: r_ea_finetimer_isr at ??:?
0x4008aaea: r_rwbt_isr at ??:?
0x4008b603: r_rwbtdm_isr_wrapper at intc.c:?
0x40082b59: _xt_lowint1 at /home/liupeng/WorkSpace/espressif/esp/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1105
0x40170413: cpu_ll_waiti at /home/liupeng/WorkSpace/espressif/esp/esp-idf/examples/bluetooth/bluedroid/coex/bt_ble_coex/build/../../../../../../components/hal/esp32/include/hal/cpu_ll.h:183
(inlined by) esp_pm_impl_waiti at /home/liupeng/WorkSpace/espressif/esp/esp-idf/components/esp_pm/pm_impl.c:827
0x400da8ca: esp_vApplicationIdleHook at /home/liupeng/WorkSpace/espressif/esp/esp-idf/components/esp_common/src/freertos_hooks.c:63
0x40091fb5: prvIdleTask at /home/liupeng/WorkSpace/espressif/esp/esp-idf/components/freertos/tasks.c:3839 (discriminator 1)
0x40093cd9: vPortTaskWrapper at /home/liupeng/WorkSpace/espressif/esp/esp-idf/components/freertos/port/xtensa/port.c:168
Code: Select all
void ble_gattc_init(void)
{
esp_err_t ret;
ESP_LOGI(BT_HF_TAG, "ble_gattc_init in.");
//register the callback function to the gap module
ret = esp_ble_gap_register_callback(esp_gap_cb);
if (ret){
ESP_LOGE(BT_HF_TAG, "%s gap register failed, error code = %x\n", __func__, ret);
return;
}
//register the callback function to the gattc module
ret = esp_ble_gattc_register_callback(esp_gattc_cb);
if(ret){
ESP_LOGE(BT_HF_TAG, "%s gattc register failed, error code = %x\n", __func__, ret);
return;
}
ret = esp_ble_gattc_app_register(PROFILE_A_APP_ID);
if (ret){
ESP_LOGE(BT_HF_TAG, "%s gattc app register failed, error code = %x\n", __func__, ret);
}
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
if (local_mtu_ret){
ESP_LOGE(BT_HF_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
}
}
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);
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE));
esp_err_t err;
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
if ((err = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
ESP_LOGE(BT_HF_TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
if ((err = esp_bt_controller_enable(ESP_BT_MODE_BTDM)) != ESP_OK) {
ESP_LOGE(BT_HF_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
if ((err = esp_bluedroid_init()) != ESP_OK) {
ESP_LOGE(BT_HF_TAG, "%s initialize bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
if ((err = esp_bluedroid_enable()) != ESP_OK) {
ESP_LOGE(BT_HF_TAG, "%s enable bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
/* create application task */
bt_app_task_start_up();
/* Bluetooth device name, connection mode and profile set up */
bt_app_work_dispatch(bt_hf_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL);
#if CONFIG_BT_HFP_AUDIO_DATA_PATH_PCM
/* configure the PCM interface and PINs used */
app_gpio_pcm_io_cfg();
#endif
/* configure externel chip for acoustic echo cancellation */
#if ACOUSTIC_ECHO_CANCELLATION_ENABLE
app_gpio_aec_io_cfg();
#endif /* ACOUSTIC_ECHO_CANCELLATION_ENABLE */
esp_console_repl_t *repl = NULL;
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
repl_config.prompt = "hfp_ag>";
// init console REPL environment
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
/* Register commands */
register_hfp_ag();
printf("\n ==================================================\n");
printf(" | Steps to test hfp_ag |\n");
printf(" | |\n");
printf(" | 1. Print 'help' to gain overview of commands |\n");
printf(" | 2. Setup a service level connection |\n");
printf(" | 3. Run hfp_ag to test |\n");
printf(" | |\n");
printf(" =================================================\n\n");
// start console REPL
ESP_ERROR_CHECK(esp_console_start_repl(repl));
ble_gattc_init();
}