Skip to content

Commit

Permalink
【更新】修正内存溢出等问题
Browse files Browse the repository at this point in the history
内存溢出修正如下:
1. 减小GATT属性表的大小到合适大小
2. 同步减小SD内存占用到合适的大小
3. 减小marco宏的存储大小(由于宏需读取到内存,即减小了内存占用)

其他更新:
1. 更新通讯协议V5:适配通讯命令
2. 减小蓝牙MTU到28
3. caps灯的独立控制【RGB】
4. 调整Usage配合新版配置工具
5. 其他耗电更新及代码优化
  • Loading branch information
genokolar committed Dec 7, 2024
1 parent 8f3ef79 commit 246861b
Show file tree
Hide file tree
Showing 33 changed files with 465 additions and 377 deletions.
2 changes: 1 addition & 1 deletion application/bootloader/project/nrf52832.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ASMFLAGS += -DNRF52832_XXAA
ASMFLAGS += -DNRF52_PAN_74
ASMFLAGS += -DBOARD_PCA10040

ifndef NRF52_DISABLE_FPU
ifdef NRF52_ENABLE_FPU
CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
Expand Down
8 changes: 1 addition & 7 deletions application/main/project/nrf52810_s112.ld
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x19000, LENGTH = 0x17000
RAM (rwx) : ORIGIN = 0x20001E00, LENGTH = 0x4200
RAM (rwx) : ORIGIN = 0x20001AE0, LENGTH = 0x4520
}

SECTIONS
Expand Down Expand Up @@ -46,12 +46,6 @@ SECTIONS
KEEP(*(.fn_handler))
PROVIDE(__stop_fn_handler = .);
} > RAM
.control_handler :
{
PROVIDE(__start_control_handler = .);
KEEP(*(.control_handler))
PROVIDE(__stop_control_handler = .);
} > RAM
.host_driver :
{
PROVIDE(__start_host_driver = .);
Expand Down
8 changes: 1 addition & 7 deletions application/main/project/nrf52811_s112.ld
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x19000, LENGTH = 0x17000
RAM (rwx) : ORIGIN = 0x20001E00, LENGTH = 0x4200
RAM (rwx) : ORIGIN = 0x20001AE0, LENGTH = 0x4520
}

SECTIONS
Expand Down Expand Up @@ -46,12 +46,6 @@ SECTIONS
KEEP(*(.fn_handler))
PROVIDE(__stop_fn_handler = .);
} > RAM
.control_handler :
{
PROVIDE(__start_control_handler = .);
KEEP(*(.control_handler))
PROVIDE(__stop_control_handler = .);
} > RAM
.host_driver :
{
PROVIDE(__start_host_driver = .);
Expand Down
8 changes: 1 addition & 7 deletions application/main/project/nrf52832_s132.ld
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x5a000
RAM (rwx) : ORIGIN = 0x200028B0, LENGTH = 0xD750
RAM (rwx) : ORIGIN = 0x20002590, LENGTH = 0xda70
}

SECTIONS
Expand Down Expand Up @@ -46,12 +46,6 @@ SECTIONS
KEEP(*(.fn_handler))
PROVIDE(__stop_fn_handler = .);
} > RAM
.control_handler :
{
PROVIDE(__start_control_handler = .);
KEEP(*(.control_handler))
PROVIDE(__stop_control_handler = .);
} > RAM
.host_driver :
{
PROVIDE(__start_host_driver = .);
Expand Down
8 changes: 4 additions & 4 deletions application/main/src/ble/ble_hid_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@ static uint8_t hid_descriptor[] = {
0xc0, // END_COLLECTION
#endif
// HID control
0x06, 0x00, 0xff, // Usage Page (Vendor Defined)
0x09, 0x01, // Usage Page (Vendor Defined)
0x06, 0xea, 0xff, // Usage Page (Vendor Defined)
0x09, 0x72, // Usage Page (Vendor Defined)
0xa1, 0x01, // COLLECTION (Application)
0x85, 0x3f, // Report ID (63)
0x95, 0x3f, // Report Count 63
0x95, 0x1C, // Report Count 28
0x75, 0x08, // Report Size
0x25, 0x01, // Usage Maximum
0x15, 0x01, // Usage Minimum
0x09, 0x01, // Vendor Usage
0x81, 0x02, // Input (Data,Var,Abs)
0x85, 0x3f, // Report ID (63)
0x95, 0x3f, // Report Count 63
0x95, 0x1C, // Report Count 28
0x75, 0x08, // Report Size
0x25, 0x01, // Usage Maximum
0x15, 0x01, // Usage Minimum
Expand Down
19 changes: 12 additions & 7 deletions application/main/src/ble/ble_hid_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "keyboard_fn.h"
#include "hid_configuration.h"
#include "host.h"
#include "usb_comm.h"
#include "ble_comm.h"


#define MAX_BUFFER_ENTRIES 5 /**< Number of elements that can be enqueued */
#define BASE_USB_HID_SPEC_VERSION 0x0101 /**< Version number of base USB HID Specification implemented by this application. */
Expand All @@ -48,8 +51,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define INPUT_REPORT_LEN_MOUSE 5
#define INPUT_REPORT_LEN_SYSTEM 2
#define INPUT_REPORT_LEN_CONSUMER 2
#define INPUT_REPORT_LEN_DATA 63
#define OUTPUT_REPORT_LEN_DATA 63
#define INPUT_REPORT_LEN_DATA 28
#define OUTPUT_REPORT_LEN_DATA 28

#define INPUT_REP_INDEX_INVALID 0xFF /** Invalid index **/

Expand Down Expand Up @@ -276,10 +279,10 @@ static void hids_init(ble_srv_error_handler_t err_handler)
*/
void ble_send_conf(uint8_t len, uint8_t* data)
{
if (len > 63)
if (len > INPUT_REPORT_LEN_DATA)
return;

uint8_t buff[63] = {0};
uint8_t buff[INPUT_REPORT_LEN_DATA] = {0};
memcpy(&buff[0], data, len);
ble_hids_inp_rep_send(&m_hids,
INPUT_REP_DATA_INDEX,
Expand Down Expand Up @@ -489,10 +492,8 @@ static void on_hid_rep_char_write(ble_hids_evt_t* p_evt)
control_val);

if (err_code == NRF_SUCCESS) {
respond_flag = true;
hid_on_recv(control_val[0], control_val[1], &control_val[2]);
ble_hid_on_recv(control_val[0], control_val[1], &control_val[2]);
} else {
respond_flag = true;
hid_response_generic(HID_RESP_UART_CHECKSUM_ERROR);
}
}
Expand Down Expand Up @@ -539,6 +540,10 @@ void hid_service_init(ble_srv_error_handler_t err_handler)
{
hids_init(err_handler);
buffer_init();
//蓝牙初始化时正确设定协议
if(!usb_working()){
keyboard_protocol = m_ble_in_report_mode;
}
}

void hid_event_handler(enum user_event evt, void* arg)
Expand Down
69 changes: 28 additions & 41 deletions application/main/src/ble/ble_services.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,13 @@ static void pm_evt_handler(pm_evt_t const* p_evt)
*/
static void gap_params_init(void)
{
//ret_code_t err_code;
ret_code_t err_code;
ble_gap_conn_params_t gap_conn_params;

set_device_name();

//err_code =
sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_HID);
//APP_ERROR_CHECK(err_code);
err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_HID);
APP_ERROR_CHECK(err_code);

memset(&gap_conn_params, 0, sizeof(gap_conn_params));

Expand All @@ -518,19 +517,17 @@ static void gap_params_init(void)
gap_conn_params.slave_latency = SLAVE_LATENCY;
gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT;

//err_code =
sd_ble_gap_ppcp_set(&gap_conn_params);
//APP_ERROR_CHECK(err_code);
err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
APP_ERROR_CHECK(err_code);
}

/**
* @brief Function for initializing the GATT module.
*/
static void gatt_init(void)
{
//ret_code_t err_code =
nrf_ble_gatt_init(&m_gatt, NULL);
//APP_ERROR_CHECK(err_code);
ret_code_t err_code = nrf_ble_gatt_init(&m_gatt, NULL);
APP_ERROR_CHECK(err_code);
}

/**
Expand All @@ -551,22 +548,21 @@ static void nrf_qwr_error_handler(uint32_t nrf_error)
*/
static void qwr_init(void)
{
//ret_code_t err_code;
ret_code_t err_code;
nrf_ble_qwr_init_t qwr_init_obj = { 0 };

qwr_init_obj.error_handler = nrf_qwr_error_handler;

//err_code =
nrf_ble_qwr_init(&m_qwr, &qwr_init_obj);
//APP_ERROR_CHECK(err_code);
err_code = nrf_ble_qwr_init(&m_qwr, &qwr_init_obj);
APP_ERROR_CHECK(err_code);
}

/**
* @brief Function for initializing Device Information Service.
*/
static void dis_init(void)
{
//ret_code_t err_code;
ret_code_t err_code;
ble_dis_init_t dis_init_obj;
ble_dis_pnp_id_t pnp_id;

Expand All @@ -582,9 +578,8 @@ static void dis_init(void)

dis_init_obj.dis_char_rd_sec = SEC_JUST_WORKS;

//err_code =
ble_dis_init(&dis_init_obj);
//APP_ERROR_CHECK(err_code);
err_code = ble_dis_init(&dis_init_obj);
APP_ERROR_CHECK(err_code);
}

#ifdef BUTTONLESS_DFU
Expand Down Expand Up @@ -621,7 +616,7 @@ static void conn_params_error_handler(uint32_t nrf_error)
*/
static void conn_params_init(void)
{
//ret_code_t err_code;
ret_code_t err_code;
ble_conn_params_init_t cp_init;

memset(&cp_init, 0, sizeof(cp_init));
Expand All @@ -635,9 +630,8 @@ static void conn_params_init(void)
cp_init.evt_handler = NULL;
cp_init.error_handler = conn_params_error_handler;

//err_code =
ble_conn_params_init(&cp_init);
//APP_ERROR_CHECK(err_code);
err_code = ble_conn_params_init(&cp_init);
APP_ERROR_CHECK(err_code);
}

/**
Expand Down Expand Up @@ -877,11 +871,10 @@ void ble_stack_stop(void)
static void peer_manager_init(void)
{
ble_gap_sec_params_t sec_param;
//ret_code_t err_code;
ret_code_t err_code;

//err_code =
pm_init();
//APP_ERROR_CHECK(err_code);
err_code = pm_init();
APP_ERROR_CHECK(err_code);

memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));

Expand All @@ -899,13 +892,11 @@ static void peer_manager_init(void)
sec_param.kdist_peer.enc = 1;
sec_param.kdist_peer.id = 1;

//err_code =
pm_sec_params_set(&sec_param);
//APP_ERROR_CHECK(err_code);
err_code = pm_sec_params_set(&sec_param);
APP_ERROR_CHECK(err_code);

//err_code =
pm_register(pm_evt_handler);
//APP_ERROR_CHECK(err_code);
err_code = pm_register(pm_evt_handler);
APP_ERROR_CHECK(err_code);
}

/**
Expand All @@ -923,7 +914,7 @@ static void ble_advertising_error_handler(uint32_t nrf_error)
*/
static void advertising_init(void)
{
//uint32_t err_code;
uint32_t err_code;
uint8_t adv_flags;
ble_advertising_init_t init;

Expand All @@ -943,16 +934,14 @@ static void advertising_init(void)
init.evt_handler = on_adv_evt;
init.error_handler = ble_advertising_error_handler;

//err_code =
ble_advertising_init(&m_advertising, &init);
//APP_ERROR_CHECK(err_code);
err_code = ble_advertising_init(&m_advertising, &init);
APP_ERROR_CHECK(err_code);

ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
#ifdef HIGH_TX_POWER
//更改发射功率到+4dBm
//err_code =
sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, 4);
//APP_ERROR_CHECK(err_code);
err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, 4);
APP_ERROR_CHECK(err_code);
#endif
}

Expand All @@ -978,9 +967,7 @@ void ble_services_init()
}
dis_init();
#ifdef BUTTONLESS_DFU
#ifdef NRF52832_XXAA
dfu_init();
#endif
#endif
conn_params_init();
}
6 changes: 3 additions & 3 deletions application/main/src/config/sdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3997,7 +3997,7 @@
// <0=> Pause in SLEEP and HALT

#ifndef NRFX_WDT_CONFIG_BEHAVIOUR
#define NRFX_WDT_CONFIG_BEHAVIOUR 1
#define NRFX_WDT_CONFIG_BEHAVIOUR 0
#endif

// <o> NRFX_WDT_CONFIG_RELOAD_VALUE - Reload value <15-4294967295>
Expand Down Expand Up @@ -9904,12 +9904,12 @@

// <o> NRF_SDH_BLE_GATT_MAX_MTU_SIZE - Static maximum MTU size.
#ifndef NRF_SDH_BLE_GATT_MAX_MTU_SIZE
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 23
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 31
#endif

// <o> NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE - Attribute Table size in bytes. The size must be a multiple of 4.
#ifndef NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE
#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408
#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1444
#endif

// <o> NRF_SDH_BLE_VS_UUID_COUNT - The number of vendor-specific UUIDs.
Expand Down
Loading

0 comments on commit 246861b

Please sign in to comment.