From eaefd0bd25862fcc7d98c95fbc1f1f0c6a48dca7 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Fri, 17 Jan 2025 17:20:45 +0100 Subject: [PATCH 1/9] fix(coredump): only clear high bit in PC when set --- components/espcoredump/src/port/xtensa/core_dump_port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/espcoredump/src/port/xtensa/core_dump_port.c b/components/espcoredump/src/port/xtensa/core_dump_port.c index 8efae60d57..3aff19c537 100644 --- a/components/espcoredump/src/port/xtensa/core_dump_port.c +++ b/components/espcoredump/src/port/xtensa/core_dump_port.c @@ -241,7 +241,7 @@ static esp_err_t esp_core_dump_get_regs_from_stack(void* stack_addr, for (int i = 0; i < XT_SOL_AR_NUM; i++) { regs->ar[i] = stack_arr[XT_SOL_AR_START + i]; } - regs->pc = (regs->pc & 0x3fffffff); + if (regs->pc & 0x80000000) { regs->pc = (regs->pc & 0x3fffffff); } From 21161b2fb3dfa517d3f3db670c57dbd01a1e7dfa Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Fri, 17 Jan 2025 17:12:40 +0100 Subject: [PATCH 2/9] fix(coredump): fix note section alignments --- components/espcoredump/src/core_dump_elf.c | 50 +++++++++++++--------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/components/espcoredump/src/core_dump_elf.c b/components/espcoredump/src/core_dump_elf.c index 4b6852f318..4a4ccdb955 100644 --- a/components/espcoredump/src/core_dump_elf.c +++ b/components/espcoredump/src/core_dump_elf.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -196,15 +196,28 @@ static int elf_add_segment(core_dump_elf_t *self, return data_len; } -static int elf_write_note_header(core_dump_elf_t *self, - const char* name, uint32_t name_len, uint32_t data_sz, uint32_t type) +/* + * Example Note Segment + * +================================================================+ + * | Offset | +0 | +1 | +2 | +3 | Description | + * +----------------------------------------------------------------+ + * | 0 | 0x05 | 0x00 | 0x00 | 0x00 | namesz = 5 | + * | 4 | 0x06 | 0x00 | 0x00 | 0x00 | descsz = 6 | + * | 8 | 0x01 | 0x00 | 0x00 | 0x00 | type = 1 | + * | 12 | 'C' | 'O' | 'R' | 'E' | name ("CORE") | + * | 16 | 0x00 | pad | pad | pad | NULL + padding | + * | 20 | 0x1 | 0x2 | 0x3 | 0x4 | desc (6 bytes) | + * | 24 | 0x5 | 0x6 | pad | pad | desc + padding | + * +================================================================+ +*/ +static int elf_write_note_header(core_dump_elf_t *self, const char* name, uint32_t data_sz, uint32_t type) { // temporary aligned buffer for note name static char name_buffer[ELF_NOTE_NAME_MAX_SIZE] = { 0 }; elf_note note_hdr = { 0 }; - memcpy(name_buffer, name, name_len); - note_hdr.n_namesz = ALIGN_UP(name_len + 1, 4); + size_t name_len = strlcpy(name_buffer, name, sizeof(name_buffer)); + note_hdr.n_namesz = name_len + 1; /* name_buffer must be null terminated */ note_hdr.n_descsz = data_sz; note_hdr.n_type = type; // write note header @@ -212,7 +225,7 @@ static int elf_write_note_header(core_dump_elf_t *self, ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL, "Write ELF note header failure (%d)", err); // write note name - err = esp_core_dump_write_data(&self->write_data, name_buffer, note_hdr.n_namesz); + err = esp_core_dump_write_data(&self->write_data, name_buffer, ALIGN_UP(note_hdr.n_namesz, 4)); ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL, "Write ELF note name failure (%d)", err); @@ -226,18 +239,17 @@ static int elf_write_note(core_dump_elf_t *self, uint32_t data_sz) { esp_err_t err = ESP_FAIL; - uint32_t name_len = ALIGN_UP(strlen(name) + 1, 4); // get name length including terminator - uint32_t data_len = ALIGN_UP(data_sz, 4); + uint32_t name_len = strlen(name) + 1; // get name length including terminator ELF_CHECK_ERR((name_len <= ELF_NOTE_NAME_MAX_SIZE), 0, "Segment note name is too long %d.", name_len); - uint32_t note_size = ALIGN_UP(name_len + data_len + sizeof(elf_note), 4); + uint32_t note_size = ALIGN_UP(name_len, 4) + ALIGN_UP(data_sz, 4) + sizeof(elf_note); // write segment data during second pass if (self->elf_stage == ELF_STAGE_PLACE_DATA) { ELF_CHECK_ERR(data, ELF_PROC_ERR_OTHER, "Invalid data pointer %x.", (uint32_t)data); - err = elf_write_note_header(self, name, strlen(name), data_sz, type); + err = elf_write_note_header(self, name, data_sz, type); if (err != ESP_OK) { return err; } @@ -246,8 +258,8 @@ static int elf_write_note(core_dump_elf_t *self, // which might not be aligned by default. Therefore, we need to verify alignment and add padding if necessary. err = esp_core_dump_write_data(&self->write_data, data, data_sz); if (err == ESP_OK) { - int pad_size = data_len - data_sz; - if (pad_size != 0) { + const int pad_size = ALIGN_UP(data_sz, 4) - data_sz; + if (pad_size > 0) { uint8_t pad_bytes[3] = {0}; ESP_COREDUMP_LOG_PROCESS("Core dump note data needs %d bytes padding", pad_size); err = esp_core_dump_write_data(&self->write_data, pad_bytes, pad_size); @@ -621,7 +633,7 @@ static void elf_write_core_dump_note_cb(void *opaque, const char *data) static int elf_add_wdt_panic_details(core_dump_elf_t *self) { - uint32_t name_len = sizeof(ELF_ESP_CORE_DUMP_PANIC_DETAILS_NOTE_NAME) - 1; + uint32_t name_len = sizeof(ELF_ESP_CORE_DUMP_PANIC_DETAILS_NOTE_NAME); /* len includes the null terminator */ core_dump_elf_opaque_t param = { .self = self, .total_size = 0, @@ -636,7 +648,6 @@ static int elf_add_wdt_panic_details(core_dump_elf_t *self) } else if (self->elf_stage == ELF_STAGE_PLACE_DATA) { esp_err_t err = elf_write_note_header(self, ELF_ESP_CORE_DUMP_PANIC_DETAILS_NOTE_NAME, - name_len, self->note_data_size, ELF_ESP_CORE_DUMP_PANIC_DETAILS_TYPE); if (err != ESP_OK) { @@ -645,17 +656,16 @@ static int elf_add_wdt_panic_details(core_dump_elf_t *self) esp_task_wdt_print_triggered_tasks(elf_write_core_dump_note_cb, ¶m, NULL); ELF_CHECK_ERR((param.total_size > 0), ELF_PROC_ERR_WRITE_FAIL, "Write ELF note data failure (%d)", err); - const uint32_t mod = self->note_data_size & 3; - if (mod != 0) { + const int pad_size = ALIGN_UP(self->note_data_size, 4) - self->note_data_size; + if (pad_size > 0) { uint8_t pad_bytes[3] = {0}; - uint32_t pad_size = 4 - mod; ESP_COREDUMP_LOG_PROCESS("Core dump note needs %d bytes padding", pad_size); err = esp_core_dump_write_data(&self->write_data, pad_bytes, pad_size); ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL, "Write ELF note padding failure (%d)", err); } } - return ALIGN_UP(ALIGN_UP(name_len, 4) + ALIGN_UP(self->note_data_size, 4) + sizeof(elf_note), 4); + return ALIGN_UP(name_len, 4) + ALIGN_UP(self->note_data_size, 4) + sizeof(elf_note); } #endif //CONFIG_ESP_TASK_WDT_EN @@ -928,14 +938,14 @@ static void esp_core_dump_parse_note_section(uint8_t *coredump_data, elf_note_co for (size_t idx = 0; idx < size; ++idx) { if (target_notes[idx].n_type == note->n_type) { char *nm = (char *)¬e[1]; - target_notes[idx].n_ptr = nm + note->n_namesz; + target_notes[idx].n_ptr = nm + ALIGN_UP(note->n_namesz, 4); target_notes[idx].n_descsz = note->n_descsz; ESP_COREDUMP_LOGD("%d bytes target note (%X) found in the note section", note->n_descsz, note->n_type); break; } } - consumed_note_sz += ALIGN_UP(note->n_namesz + note->n_descsz + sizeof(elf_note), 4); + consumed_note_sz += ALIGN_UP(note->n_namesz, 4) + ALIGN_UP(note->n_descsz, 4) + sizeof(elf_note); } } } From 37ef076c070ce7dd558a41ca743534e548a90d87 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Tue, 21 Jan 2025 15:54:44 +0100 Subject: [PATCH 3/9] fix(coredump): disable uart txd pullup using gpio hal --- components/espcoredump/src/core_dump_uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/espcoredump/src/core_dump_uart.c b/components/espcoredump/src/core_dump_uart.c index 69ab1c2805..60e4ffc133 100644 --- a/components/espcoredump/src/core_dump_uart.c +++ b/components/espcoredump/src/core_dump_uart.c @@ -154,7 +154,7 @@ static esp_err_t esp_core_dump_uart_hw_init(void) //Make sure txd/rxd are enabled // use direct reg access instead of gpio_pullup_dis which can cause exception when flash cache is disabled - REG_CLR_BIT(GPIO_PIN_REG_1, FUN_PU); //TODO: IDF-9948 + gpio_hal_pullup_dis(&gpio_hal, U0TXD_GPIO_NUM); gpio_hal_func_sel(&gpio_hal, U0RXD_GPIO_NUM, U0RXD_MUX_FUNC); gpio_hal_func_sel(&gpio_hal, U0TXD_GPIO_NUM, U0TXD_MUX_FUNC); ESP_COREDUMP_LOGI("Press Enter to print core dump to UART..."); From a8041a99533628b044a8158bcc4410404f83ea63 Mon Sep 17 00:00:00 2001 From: Nebojsa Cvetkovic Date: Wed, 4 Dec 2024 11:42:46 +0000 Subject: [PATCH 4/9] refactor(ble/bluedroid): Fix typos in bta_gatts_act.c --- components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c b/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c index d09eaa96b2..6cb95fd109 100644 --- a/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c +++ b/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c @@ -733,7 +733,7 @@ void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) } } } else { - APPL_TRACE_ERROR("Not an registered servce attribute ID: 0x%04x", + APPL_TRACE_ERROR("Not a registered service attribute ID: 0x%04x", p_msg->api_indicate.attr_id); } } @@ -923,7 +923,7 @@ void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) ** ** Function bta_gatts_show_local_database ** -** Description print loacl service database +** Description print local service database ** ** Returns none. ** From 9b5a52e2f784a50c0e4c1a422a2b3d22ce5e9998 Mon Sep 17 00:00:00 2001 From: Nebojsa Cvetkovic Date: Sat, 28 Sep 2024 11:55:16 -0700 Subject: [PATCH 5/9] fix(ble/bluedroid): Allow 0 length indications --- components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c b/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c index 6cb95fd109..759baed015 100644 --- a/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c +++ b/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c @@ -723,8 +723,6 @@ void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) } else { APPL_TRACE_ERROR("%s, malloc failed", __func__); } - } else { - APPL_TRACE_ERROR("%s, incorrect length", __func__); } (*p_rcb->p_cback)(BTA_GATTS_CONF_EVT, &cb_data); if (cb_data.req_data.value != NULL) { From 63b2dcc3a7b4b56486a7ef82050d8a43dd2bb4af Mon Sep 17 00:00:00 2001 From: Nebojsa Cvetkovic Date: Wed, 4 Dec 2024 01:04:25 +0000 Subject: [PATCH 6/9] refactor(ble/bluedroid): Fix typos in gatt_sr.c --- .../bt/host/bluedroid/stack/gatt/gatt_sr.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/components/bt/host/bluedroid/stack/gatt/gatt_sr.c b/components/bt/host/bluedroid/stack/gatt/gatt_sr.c index 79e161c1e3..2d0d6e749a 100644 --- a/components/bt/host/bluedroid/stack/gatt/gatt_sr.c +++ b/components/bt/host/bluedroid/stack/gatt/gatt_sr.c @@ -200,7 +200,7 @@ static BOOLEAN process_read_multi_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS status, *p++ = GATT_RSP_READ_MULTI; p_buf->len = 1; - /* Now walk through the buffers puting the data into the response in order */ + /* Now walk through the buffers putting the data into the response in order */ list_t *list = NULL; const list_node_t *node = NULL; if (! fixed_queue_is_empty(p_cmd->multi_rsp_q)) { @@ -321,7 +321,7 @@ static BOOLEAN process_read_multi_var_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS sta *p++ = GATT_RSP_READ_MULTI_VAR; p_buf->len = 1; - /* Now walk through the buffers puting the data into the response in order */ + /* Now walk through the buffers putting the data into the response in order */ list_t *list = NULL; const list_node_t *node = NULL; if (! fixed_queue_is_empty(p_cmd->multi_rsp_q)) { @@ -735,7 +735,7 @@ static tGATT_STATUS gatt_build_primary_service_rsp (BT_HDR *p_msg, tGATT_TCB *p_ handle_len = 4 + p_uuid->len; } - /* get the length byte in the repsonse */ + /* get the length byte in the response */ if (p_msg->offset == 0) { *p ++ = op_code + 1; p_msg->len ++; @@ -889,7 +889,7 @@ static tGATT_STATUS gatts_validate_packet_format(UINT8 op_code, UINT16 *p_len, /* parse uuid now */ if (gatt_parse_uuid_from_cmd (p_uuid_filter, uuid_len, &p) == FALSE || p_uuid_filter->len == 0) { - GATT_TRACE_DEBUG("UUID filter does not exsit"); + GATT_TRACE_DEBUG("UUID filter does not exist"); reason = GATT_INVALID_PDU; } else { len -= p_uuid_filter->len; @@ -1042,7 +1042,7 @@ static void gatts_process_find_info(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, ** ** Function gatts_process_mtu_req ** -** Description This function is called to process excahnge MTU request. +** Description This function is called to process exchange MTU request. ** Only used on LE. ** ** Returns void @@ -1055,7 +1055,7 @@ static void gatts_process_mtu_req (tGATT_TCB *p_tcb, UINT16 len, UINT8 *p_data) BT_HDR *p_buf; UINT16 conn_id; - /* BR/EDR conenction, send error response */ + /* BR/EDR connection, send error response */ if (p_tcb->att_lcid != L2CAP_ATT_CID) { gatt_send_error_rsp (p_tcb, GATT_REQ_NOT_SUPPORTED, GATT_REQ_MTU, 0, FALSE); } else if (len < GATT_MTU_REQ_MIN_LEN) { @@ -1081,7 +1081,7 @@ static void gatts_process_mtu_req (tGATT_TCB *p_tcb, UINT16 len, UINT8 *p_data) attp_send_sr_msg (p_tcb, p_buf); /* Notify all registered application with new MTU size. Us a transaction ID */ - /* of 0, as no response is allowed from applcations */ + /* of 0, as no response is allowed from applications */ for (i = 0; i < GATT_MAX_APPS; i ++) { if (gatt_cb.cl_rcb[i].in_use ) { @@ -1448,7 +1448,7 @@ void gatt_attr_process_prepare_write (tGATT_TCB *p_tcb, UINT8 i_rcb, UINT16 hand } if ((prepare_record->error_code_app == GATT_SUCCESS) - // update prepare write status for excute write request + // update prepare write status for execute write request && (status == GATT_INVALID_OFFSET || status == GATT_INVALID_ATTR_LEN || status == GATT_REQ_NOT_SUPPORTED)) { prepare_record->error_code_app = status; } @@ -1855,7 +1855,7 @@ void gatt_server_handle_client_req (tGATT_TCB *p_tcb, UINT8 op_code, gatts_process_primary_service_req (p_tcb, op_code, len, p_data); break; - case GATT_REQ_FIND_INFO: /* discover char descrptor */ + case GATT_REQ_FIND_INFO: /* discover char descriptor */ gatts_process_find_info(p_tcb, op_code, len, p_data); break; From fed1d41aa7170d8418dd126dd8e3b47a977b4aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Neboj=C5=A1a=20Cvetkovi=C4=87?= Date: Wed, 4 Dec 2024 00:25:41 +0000 Subject: [PATCH 7/9] fix(ble/bluedroid): Don't log error on 16/128-bit UUID mixed descriptors --- components/bt/host/bluedroid/stack/gatt/gatt_sr.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/components/bt/host/bluedroid/stack/gatt/gatt_sr.c b/components/bt/host/bluedroid/stack/gatt/gatt_sr.c index 2d0d6e749a..5947239cf1 100644 --- a/components/bt/host/bluedroid/stack/gatt/gatt_sr.c +++ b/components/bt/host/bluedroid/stack/gatt/gatt_sr.c @@ -788,7 +788,7 @@ static tGATT_STATUS gatt_build_primary_service_rsp (BT_HDR *p_msg, tGATT_TCB *p_ ** buffer. ** ** Returns TRUE: if data filled successfully. -** FALSE: packet full, or format mismatch. +** FALSE: packet full. ** *******************************************************************************/ static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SR_REG *p_rcb, BT_HDR *p_msg, UINT16 *p_len, @@ -831,10 +831,9 @@ static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SR_REG *p_rcb, BT_HDR *p_msg, gatt_convert_uuid32_to_uuid128(p, ((tGATT_ATTR32 *) p_attr)->uuid); p += LEN_UUID_128; } else { - GATT_TRACE_ERROR("format mismatch"); - status = GATT_NO_RESOURCES; + // UUID format mismatch in sequential attributes + // A new request will be sent with the starting handle of the next attribute break; - /* format mismatch */ } p_msg->len += info_pair_len[p_msg->offset - 1]; len -= info_pair_len[p_msg->offset - 1]; From fa40d971a52e9eb66686ac3ae645fca2589f0807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erast=20=EF=A3=BF?= <78802792+MatoiDev@users.noreply.github.com> Date: Wed, 10 Jan 2024 14:15:03 +0300 Subject: [PATCH 8/9] docs(ble/bluedroid): Optimize doc for implementation of a characteristic with 128 bit UUID --- ...erver_Service_Table_Example_Walkthrough.md | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md index 75d83dfd4f..636d2bb62e 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md @@ -441,6 +441,46 @@ static const esp_gatts_attr_db_t heart_rate_gatt_db[HRS_IDX_NB] = }; ``` +### 128-bit UUID + +To add characteristics with 128-bit UUIDs, a similar approach is used, but with minor differences. + +Let's suppose we have the following UUID: `12345678-a1b2-c3d4-e5f6-9fafd205e457` and we want to assign it to +the `HRS_IDX_128_BIT_LEN_UUID_CHAR` characteristic we also have. + +Here is an example of how this can be done: + +- First, let's declare our UUID + +```c +static const uint8_t our_128_bit_uuid_characteristic_uuid[ESP_UUID_LEN_128] = { // ESP_UUID_LEN_128 defined as 16 + 0x57, 0xe4, 0x05, 0xd2, 0xaf, 0x9f, 0xf6, 0xe5, 0xd4, 0xc3, 0xb2, 0xa1, 0x78, 0x56, 0x34, 0x12 +}; +``` + +> ##### `0x57 0xe4 0x05 0xd2 0xaf 0x9f 0xf6 0xe5 0xd4 0xc3 0xb2 0xa1 0x78 0x56 0x34 0x12` - reversed version of the original UUID represented by uuid_byte_array. + +- Now, all we need is to set `uuid_length` to `ESP_UUID_LEN_128` in the *Characteristic Value* setup. + +> ##### Not to be confused with the *Characteristic Declaration*! + +```c +static const esp_gatts_attr_db_t heart_rate_gatt_db[HRS_IDX_NB] = +{ +<...> + // 128-bit UUID Characteristic Declaration + [HRS_IDX_128_BIT_LEN_UUID_CHAR] = + {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, + CHAR_DECLARATION_SIZE,CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_notify}}, + + // 128-bit UUID Characteristic Value + [HRS_IDX_128_BIT_LEN_UUID_VAL] = + {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&our_128_bit_uuid_characteristic_uuid, ESP_GATT_PERM_READ, + THIS_CHAR_VAL_MAX_LEN,0, NULL}}, +<...> +}; +``` + ## Starting the Service When the attribute table is created, an ``ESP_GATTS_CREAT_ATTR_TAB_EVT`` event is triggered. This event has the following parameters: @@ -495,4 +535,3 @@ struct gatts_profile_inst { This document explains the work flow of the GATT Server Service Table example code that implements a Heart Rate Profile. This example begins by defining a table of attributes which include all the services and characteristics of the server, then it registers the Application Profile which triggers events that are used to configure GAP parameters and to create the service table. A service table is initialized with all the parameters required for each attribute and the service is started. This example shows a practical way of defining the server attributes by using a table instead of adding characteristic one by one. - From d4b3a7e99d29150d9718415384db7ac5ae7673d5 Mon Sep 17 00:00:00 2001 From: Mitch Cairns Date: Sun, 2 Feb 2025 15:52:34 -0800 Subject: [PATCH 9/9] feat(ble/bluedroid): Support change HID task size by Kconfig in HID example --- components/esp_hid/Kconfig | 17 +++++++++++++++++ components/esp_hid/include/esp_hid_common.h | 19 ++++++++++++++++--- components/esp_hid/src/ble_hidd.c | 2 +- components/esp_hid/src/bt_hidd.c | 2 +- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 components/esp_hid/Kconfig diff --git a/components/esp_hid/Kconfig b/components/esp_hid/Kconfig new file mode 100644 index 0000000000..619042645c --- /dev/null +++ b/components/esp_hid/Kconfig @@ -0,0 +1,17 @@ +menu "ESP HID" + config ESPHID_TASK_SIZE_BT + int "Task stack size for ESP HID BR/EDR" + range 2048 10240 + default 2048 + help + This is the stack size for the BT HID task. + Default is 2048 bytes. + + config ESPHID_TASK_SIZE_BLE + int "Task stack size for ESP HID BLE" + range 2048 10240 + default 4096 + help + This is the stack size for the BLE HID task. + Default is 4096 bytes. +endmenu diff --git a/components/esp_hid/include/esp_hid_common.h b/components/esp_hid/include/esp_hid_common.h index d3dfc204b8..461f48f867 100644 --- a/components/esp_hid/include/esp_hid_common.h +++ b/components/esp_hid/include/esp_hid_common.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -85,6 +85,19 @@ extern "C" { #define ESP_HID_CCC_NOTIFICATIONS_ENABLED 0x01 // Notifications enabled #define ESP_HID_CCC_INDICATIONS_ENABLED 0x02 // Indications enabled +/* HID Task Size configuration */ +#ifdef CONFIG_ESPHID_TASK_SIZE_BT +#define BT_HID_DEVICE_TASK_SIZE_BT CONFIG_ESPHID_TASK_SIZE_BT +#else +#define BT_HID_DEVICE_TASK_SIZE_BT 2048 +#endif + +#ifdef CONFIG_ESPHID_TASK_SIZE_BLE +#define BT_HID_DEVICE_TASK_SIZE_BLE CONFIG_ESPHID_TASK_SIZE_BLE +#else +#define BT_HID_DEVICE_TASK_SIZE_BLE 4096 +#endif + /* HID Transports */ typedef enum { ESP_HID_TRANSPORT_BT, @@ -202,8 +215,8 @@ esp_hid_report_map_t *esp_hid_parse_report_map(const uint8_t *hid_rm, size_t hid void esp_hid_free_report_map(esp_hid_report_map_t *map); /** - * @brief Calculate the HID Device usage type from the BLE Apperance - * @param appearance : BLE Apperance value + * @brief Calculate the HID Device usage type from the BLE Appearance + * @param appearance : BLE Appearance value * * @return: the hid usage type */ diff --git a/components/esp_hid/src/ble_hidd.c b/components/esp_hid/src/ble_hidd.c index ec8d9fd29b..c46c3cab92 100644 --- a/components/esp_hid/src/ble_hidd.c +++ b/components/esp_hid/src/ble_hidd.c @@ -971,7 +971,7 @@ esp_err_t esp_ble_hidd_dev_init(esp_hidd_dev_t *dev_p, const esp_hid_device_conf .queue_size = 5, .task_name = "ble_hidd_events", .task_priority = uxTaskPriorityGet(NULL), - .task_stack_size = 4096, + .task_stack_size = BT_HID_DEVICE_TASK_SIZE_BLE, .task_core_id = tskNO_AFFINITY }; ret = esp_event_loop_create(&event_task_args, &s_dev->event_loop_handle); diff --git a/components/esp_hid/src/bt_hidd.c b/components/esp_hid/src/bt_hidd.c index acf9d7e7ab..61f421d451 100644 --- a/components/esp_hid/src/bt_hidd.c +++ b/components/esp_hid/src/bt_hidd.c @@ -809,7 +809,7 @@ esp_err_t esp_bt_hidd_dev_init(esp_hidd_dev_t *dev_p, const esp_hid_device_confi .queue_size = 5, .task_name = "bt_hidd_events", .task_priority = uxTaskPriorityGet(NULL), - .task_stack_size = 2048, + .task_stack_size = BT_HID_DEVICE_TASK_SIZE_BT, .task_core_id = tskNO_AFFINITY }; ret = esp_event_loop_create(&event_task_args, &s_hidd_param.dev->event_loop_handle);