【已解决】紧急求助!蓝牙gatt_server_service_table例程存在问题

linshc
Posts: 59
Joined: Mon Feb 21, 2022 2:06 am

【已解决】紧急求助!蓝牙gatt_server_service_table例程存在问题

Postby linshc » Fri Aug 18, 2023 8:42 am

环境:使用的IDF为ESP-IDF V5.1,开发板为ESP32s3。
问题描述:在使用蓝牙的gatt_server_service_table例程,当创建的GATT Server数超过6个之后(menuconfig中设定了CONFIG_BT_GATT_MAX_SR_PROFILES为11),ble就没有启动服务,也没有启动广播,接着就发生了任务看门狗超时。
当GATT Server的数量小于等于6时,程序正常运行。
问题:
1.上述的问题,我在使用IDF-4.4.4的时候,没有出现这个问题。更新到IDF-5.1后,出现了该问题,本来是在自己工程发现的,后来为了验证,跑了示例工程,然后添加了多个server。
2.从日志看,是否是蓝牙中BTU_TASK任务死掉了,导致触发了任务看门狗。如果是,那是什么原因导致他死掉了呢?
3.我已经修改了CONFIG_BT_GATT_MAX_SR_PROFILES,是否底层没有将这个作为判断依据。依然默认只能创建6个+2个BLE预先使用的server呢?
4.附件是我测试的demo例程,可以下载进行测试。因为是测试demo,所以里面有些乱,但能进行测试,请包涵。

发生错误的日志如下:

Code: Select all

I (506) GATTS_TABLE_DEMO: create dev attribute table successfully, the number handle = 32
I (506) GATTS_TABLE_DEMO: create vol attribute table successfully, the number handle = 13
I (516) GATTS_TABLE_DEMO: create 01 attribute table successfully, the number handle = 175
I (536) GATTS_TABLE_DEMO: create 02 attribute table successfully, the number handle = 175
I (546) GATTS_TABLE_DEMO: create 03 attribute table successfully, the number handle = 175
I (556) GATTS_TABLE_DEMO: create 04 attribute table successfully, the number handle = 175
I (566) GATTS_TABLE_DEMO: create 05 attribute table successfully, the number handle = 175
E (5416) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (5416) task_wdt:  - IDLE (CPU 0)
E (5416) task_wdt: Tasks currently running:
E (5416) task_wdt: CPU 0: BTU_TASK
E (5416) task_wdt: CPU 1: IDLE
E (5416) task_wdt: Print CPU 0 (current core) backtrace


Backtrace: 0x42054AE2:0x3FC98280 0x42054C8E:0x3FC982A0 0x40376FA9:0x3FC982C0 0x4037619E:0x3FCB11F0 0x4037623D:0x3FCB1210 0x40376272:0x3FCB1230 0x40384BF1:0x3FCB1250 0x4202D7FF:0x3FCB1270 0x4202D29A:0x3FCB1390 0x4202D36A:0x3FCB13B0 0x4202D4D7:0x3FCB1400 0x42024E31:0x3FCB1430 0x4201D4C6:0x3FCB1470 0x4201D978:0x3FCB1490 0x42047421:0x3FCB14B0 0x4203472D:0x3FCB14F0 0x42034B05:0x3FCB1510 0x42031F4E:0x3FCB1530 0x4038181D:0x3FCB1560
0x42054ae2: task_wdt_timeout_handling at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/task_wdt/task_wdt.c:461 (discriminator 3)

0x42054c8e: task_wdt_isr at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/task_wdt/task_wdt.c:585

0x40376fa9: _xt_lowint1 at C:/Espressif/frameworks/esp-idf-v5.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/xtensa_vectors.S:1226

0x4037619e: heap_caps_malloc_base at C:/Espressif/frameworks/esp-idf-v5.1/components/heap/heap_caps.c:156

0x4037623d: heap_caps_malloc at C:/Espressif/frameworks/esp-idf-v5.1/components/heap/heap_caps.c:197

0x40376272: heap_caps_malloc_default at C:/Espressif/frameworks/esp-idf-v5.1/components/heap/heap_caps.c:223

0x40384bf1: malloc at C:/Espressif/frameworks/esp-idf-v5.1/components/newlib/heap.c:24

0x4202d7ff: smp_encrypt_data at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/host/bluedroid/stack/smp/smp_keys.c:175

0x4202d29a: SMP_Encrypt at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/host/bluedroid/stack/smp/smp_api.c:542

0x4202d36a: cmac_aes_k_calculate at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/host/bluedroid/stack/smp/smp_cmac.c:145

0x4202d4d7: aes_cipher_msg_auth_code at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/host/bluedroid/stack/smp/smp_cmac.c:312

0x42024e31: gatts_calculate_datebase_hash at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/host/bluedroid/stack/gatt/gatt_sr_hash.c:161

0x4201d4c6: gatt_update_for_database_change at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/host/bluedroid/stack/gatt/gatt_api.c:129

0x4201d978: GATTS_StartService at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/host/bluedroid/stack/gatt/gatt_api.c:530

0x42047421: bta_gatts_start_service at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c:583

0x4203472d: bta_gatts_hdl_event at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/host/bluedroid/bta/gatt/bta_gatts_main.c:128

0x42034b05: bta_sys_event at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/host/bluedroid/bta/sys/bta_sys_main.c:499

0x42031f4e: osi_thread_run at C:/Espressif/frameworks/esp-idf-v5.1/components/bt/common/osi/thread.c:165 (discriminator 1)

0x4038181d: vPortTaskWrapper at C:/Espressif/frameworks/esp-idf-v5.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162
Last edited by linshc on Wed Aug 23, 2023 6:27 am, edited 2 times in total.

linshc
Posts: 59
Joined: Mon Feb 21, 2022 2:06 am

Re: 紧急求助!蓝牙gatt_server_service_table例程存在问题

Postby linshc » Tue Aug 22, 2023 2:13 am

希望乐鑫官方工程师,进行下实验,看是否会出现相同的问题?

ESP_zhanghaipeng
Posts: 38
Joined: Thu May 04, 2023 3:49 am

Re: 紧急求助!蓝牙gatt_server_service_table例程存在问题

Postby ESP_zhanghaipeng » Tue Aug 22, 2023 7:20 am

可以给出完整的 log 吗?

linshc
Posts: 59
Joined: Mon Feb 21, 2022 2:06 am

Re: 紧急求助!蓝牙gatt_server_service_table例程存在问题

Postby linshc » Tue Aug 22, 2023 7:41 am

之前给的工程中,少了nghttp的外部组件,是因为我把他放到了IDF的组件中了,所以编译能通过。现在我把他放到工程中了,我重新上传了工程,以及log文件。

linshc
Posts: 59
Joined: Mon Feb 21, 2022 2:06 am

Re: 紧急求助!蓝牙gatt_server_service_table例程存在问题

Postby linshc » Tue Aug 22, 2023 7:44 am

ESP_zhanghaipeng wrote:
Tue Aug 22, 2023 7:20 am
可以给出完整的 log 吗?
之前给的工程中,少了nghttp的外部组件,是因为我把他放到了IDF的组件中了,所以编译能通过。现在我把他放到工程中了,我重新上传了工程,以及log文件。
Attachments
gatt_server_service_table.rar
(2.3 MiB) Downloaded 311 times
esp-com4_2023-08-22_15_37_09.log
(19.85 KiB) Downloaded 468 times

ESP_zhanghaipeng
Posts: 38
Joined: Thu May 04, 2023 3:49 am

Re: 紧急求助!蓝牙gatt_server_service_table例程存在问题

Postby ESP_zhanghaipeng » Tue Aug 22, 2023 10:30 am

感谢你报告的问题,问题我这面已经复现,将会尽快修复。

linshc
Posts: 59
Joined: Mon Feb 21, 2022 2:06 am

Re: 紧急求助!蓝牙gatt_server_service_table例程存在问题

Postby linshc » Tue Aug 22, 2023 10:39 am

ESP_zhanghaipeng wrote:
Tue Aug 22, 2023 10:30 am
感谢你报告的问题,问题我这面已经复现,将会尽快修复。
好的,如修复好了,到时麻烦您告知一下。谢谢!

ESP_zhanghaipeng
Posts: 38
Joined: Thu May 04, 2023 3:49 am

Re: 紧急求助!蓝牙gatt_server_service_table例程存在问题

Postby ESP_zhanghaipeng » Tue Aug 22, 2023 11:48 am

我们已经找到了问题的原因,你可以使用我提供的 patch 来修复该问题,也可以自己进行修改:
找到 esp-idf/components/bt/host/bluedroid/stack/smp/smp_cmac.c 中
static BOOLEAN cmac_aes_k_calculate(BT_OCTET16 key, UINT8 *p_signature, UINT16 tlen) 函数


修改:
UINT8 i = 1, err = 0;

UINT16 i = 1, err = 0;

再次感谢你报告的问题,后面我们会将更新同步到最新的 IDF。
Attachments
0001-fix-bt-Fix-bug-while-calculating-block-cipher.rar
(635 Bytes) Downloaded 512 times

Who is online

Users browsing this forum: HangHang and 129 guests