Skip to content

Commit 5607011

Browse files
committed
update debug.cpp
- added error string - reduce default attr table size from 0xb00 to 0x800
1 parent 98775cd commit 5607011

File tree

2 files changed

+112
-22
lines changed

2 files changed

+112
-22
lines changed

cores/nRF5/debug.cpp

Lines changed: 103 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,19 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
218218
Serial.println();
219219
}
220220

221-
/*------------------------------------------------------------------*/
222-
/*
223-
*------------------------------------------------------------------*/
224-
225221
#if CFG_DEBUG
226222

227223
#include "ble.h"
228224
#include "ble_hci.h"
229225

230226
// TODO require update when upgrading SoftDevice
231227

228+
/*------------------------------------------------------------------*/
229+
/* Event String
230+
*------------------------------------------------------------------*/
231+
232232
// Common BLE Event base
233-
static const char* _base_evt_str[] =
233+
static const char* _evt_base_str[] =
234234
{
235235
#if SD_VER < 500
236236
"BLE_EVT_TX_COMPLETE" ,
@@ -239,7 +239,7 @@ static const char* _base_evt_str[] =
239239
"BLE_EVT_USER_MEM_RELEASE" ,
240240
};
241241

242-
static const char* _gap_evt_str[] =
242+
static const char* _evt_gap_str[] =
243243
{
244244
"BLE_GAP_EVT_CONNECTED" ,
245245
"BLE_GAP_EVT_DISCONNECTED" ,
@@ -265,7 +265,7 @@ static const char* _gap_evt_str[] =
265265
};
266266

267267
// GATTC Event
268-
static const char* _gattc_evt_str[] =
268+
static const char* _evt_gattc_str[] =
269269
{
270270
"BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP" ,
271271
"BLE_GATTC_EVT_REL_DISC_RSP" ,
@@ -287,7 +287,7 @@ static const char* _gattc_evt_str[] =
287287
};
288288

289289
// GATTS Event
290-
static const char* _gatts_evt_str[] =
290+
static const char* _evt_gatts_str[] =
291291
{
292292
"BLE_GATTS_EVT_WRITE" ,
293293
"BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST" ,
@@ -307,20 +307,107 @@ const char* dbg_ble_event_str(uint16_t evt_id)
307307
{
308308
static char unknown_evt[7] = {0};
309309

310-
if ( is_within(BLE_EVT_BASE, evt_id, BLE_EVT_BASE+arrcount(_base_evt_str)) )
311-
return _base_evt_str[evt_id-BLE_EVT_BASE];
312-
else if ( is_within(BLE_GAP_EVT_BASE, evt_id, BLE_GAP_EVT_BASE+arrcount(_gap_evt_str)) )
313-
return _gap_evt_str[evt_id-BLE_GAP_EVT_BASE];
314-
else if ( is_within(BLE_GATTC_EVT_BASE, evt_id, BLE_GATTC_EVT_BASE+arrcount(_gattc_evt_str) ) )
315-
return _gattc_evt_str[evt_id-BLE_GATTC_EVT_BASE];
316-
else if ( is_within(BLE_GATTS_EVT_BASE, evt_id, BLE_GATTS_EVT_BASE+arrcount(_gatts_evt_str)) )
317-
return _gatts_evt_str[evt_id-BLE_GATTS_EVT_BASE];
310+
if ( is_within(BLE_EVT_BASE, evt_id, BLE_EVT_BASE+arrcount(_evt_base_str)) )
311+
return _evt_base_str[evt_id-BLE_EVT_BASE];
312+
else if ( is_within(BLE_GAP_EVT_BASE, evt_id, BLE_GAP_EVT_BASE+arrcount(_evt_gap_str)) )
313+
return _evt_gap_str[evt_id-BLE_GAP_EVT_BASE];
314+
else if ( is_within(BLE_GATTC_EVT_BASE, evt_id, BLE_GATTC_EVT_BASE+arrcount(_evt_gattc_str) ) )
315+
return _evt_gattc_str[evt_id-BLE_GATTC_EVT_BASE];
316+
else if ( is_within(BLE_GATTS_EVT_BASE, evt_id, BLE_GATTS_EVT_BASE+arrcount(_evt_gatts_str)) )
317+
return _evt_gatts_str[evt_id-BLE_GATTS_EVT_BASE];
318318
else
319319
{
320320
sprintf(unknown_evt, "0x%04X", evt_id);
321321
return unknown_evt;
322322
}
323323
}
324324

325+
/*------------------------------------------------------------------*/
326+
/* Error String
327+
*------------------------------------------------------------------*/
328+
static lookup_entry_t const _err_lookup_items[] =
329+
{
330+
// General
331+
{ .key = NRF_ERROR_SVC_HANDLER_MISSING , .data = "NRF_ERROR_SVC_HANDLER_MISSING" },
332+
{ .key = NRF_ERROR_SOFTDEVICE_NOT_ENABLED , .data = "NRF_ERROR_SOFTDEVICE_NOT_ENABLED" },
333+
{ .key = NRF_ERROR_INTERNAL , .data = "NRF_ERROR_INTERNAL" },
334+
{ .key = NRF_ERROR_NO_MEM , .data = "NRF_ERROR_NO_MEM" },
335+
{ .key = NRF_ERROR_NOT_FOUND , .data = "NRF_ERROR_NOT_FOUND" },
336+
{ .key = NRF_ERROR_NOT_SUPPORTED , .data = "NRF_ERROR_NOT_SUPPORTED" },
337+
{ .key = NRF_ERROR_INVALID_PARAM , .data = "NRF_ERROR_INVALID_PARAM" },
338+
{ .key = NRF_ERROR_INVALID_STATE , .data = "NRF_ERROR_INVALID_STATE" },
339+
{ .key = NRF_ERROR_INVALID_LENGTH , .data = "NRF_ERROR_INVALID_LENGTH" },
340+
{ .key = NRF_ERROR_INVALID_FLAGS , .data = "NRF_ERROR_INVALID_FLAGS" },
341+
{ .key = NRF_ERROR_INVALID_DATA , .data = "NRF_ERROR_INVALID_DATA" },
342+
{ .key = NRF_ERROR_DATA_SIZE , .data = "NRF_ERROR_DATA_SIZE" },
343+
{ .key = NRF_ERROR_TIMEOUT , .data = "NRF_ERROR_TIMEOUT" },
344+
{ .key = NRF_ERROR_NULL , .data = "NRF_ERROR_NULL" },
345+
{ .key = NRF_ERROR_FORBIDDEN , .data = "NRF_ERROR_FORBIDDEN" },
346+
{ .key = NRF_ERROR_INVALID_ADDR , .data = "NRF_ERROR_INVALID_ADDR" },
347+
{ .key = NRF_ERROR_BUSY , .data = "NRF_ERROR_BUSY" },
348+
{ .key = NRF_ERROR_CONN_COUNT , .data = "NRF_ERROR_CONN_COUNT" },
349+
{ .key = NRF_ERROR_RESOURCES , .data = "NRF_ERROR_RESOURCES" },
350+
351+
// SDM
352+
{ .key = NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN , .data = "NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN" },
353+
{ .key = NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION , .data = "NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION" },
354+
{ .key = NRF_ERROR_SDM_INCORRECT_CLENR0 , .data = "NRF_ERROR_SDM_INCORRECT_CLENR0" },
355+
356+
// SOC
357+
{ .key = NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN , .data = "NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN" },
358+
{ .key = NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE , .data = "NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE" },
359+
{ .key = NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED , .data = "NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED" },
360+
{ .key = NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN , .data = "NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN" },
361+
{ .key = NRF_ERROR_SOC_POWER_MODE_UNKNOWN , .data = "NRF_ERROR_SOC_POWER_MODE_UNKNOWN" },
362+
{ .key = NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN , .data = "NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN" },
363+
{ .key = NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN , .data = "NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN" },
364+
{ .key = NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES , .data = "NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES" },
365+
{ .key = NRF_ERROR_SOC_PPI_INVALID_CHANNEL , .data = "NRF_ERROR_SOC_PPI_INVALID_CHANNEL" },
366+
{ .key = NRF_ERROR_SOC_PPI_INVALID_GROUP , .data = "NRF_ERROR_SOC_PPI_INVALID_GROUP" },
367+
368+
// BLE Generic
369+
{ .key = BLE_ERROR_NOT_ENABLED , .data = "BLE_ERROR_NOT_ENABLED" },
370+
{ .key = BLE_ERROR_INVALID_CONN_HANDLE , .data = "BLE_ERROR_INVALID_CONN_HANDLE" },
371+
{ .key = BLE_ERROR_INVALID_ATTR_HANDLE , .data = "BLE_ERROR_INVALID_ATTR_HANDLE" },
372+
{ .key = BLE_ERROR_INVALID_ROLE , .data = "BLE_ERROR_INVALID_ROLE" },
373+
374+
// BLE GAP
375+
{ .key = BLE_ERROR_GAP_UUID_LIST_MISMATCH , .data = "BLE_ERROR_GAP_UUID_LIST_MISMATCH" },
376+
{ .key = BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST , .data = "BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST" },
377+
{ .key = BLE_ERROR_GAP_INVALID_BLE_ADDR , .data = "BLE_ERROR_GAP_INVALID_BLE_ADDR" },
378+
{ .key = BLE_ERROR_GAP_WHITELIST_IN_USE , .data = "BLE_ERROR_GAP_WHITELIST_IN_USE" },
379+
#if SD_VER >= 500
380+
{ .key = BLE_ERROR_GAP_DEVICE_IDENTITIES_IN_USE , .data = "BLE_ERROR_GAP_DEVICE_IDENTITIES_IN_USE" },
381+
{ .key = BLE_ERROR_GAP_DEVICE_IDENTITIES_DUPLICATE , .data = "BLE_ERROR_GAP_DEVICE_IDENTITIES_DUPLICATE" },
382+
#endif
383+
384+
// BLE GATTC
385+
{ .key = BLE_ERROR_GATTC_PROC_NOT_PERMITTED , .data = "BLE_ERROR_GATTC_PROC_NOT_PERMITTED" },
386+
387+
// BLE GATTS
388+
{ .key = BLE_ERROR_GATTS_INVALID_ATTR_TYPE , .data = "BLE_ERROR_GATTS_INVALID_ATTR_TYPE" },
389+
{ .key = BLE_ERROR_GATTS_SYS_ATTR_MISSING , .data = "BLE_ERROR_GATTS_SYS_ATTR_MISSING" },
390+
};
391+
392+
lookup_table_t const _err_table =
393+
{
394+
.count = arrcount(_err_lookup_items),
395+
.items = _err_lookup_items
396+
};
397+
398+
const char* dbg_err_str(uint32_t err_id)
399+
{
400+
const char * str = (const char *) lookup_find(&_err_table, err_id);
401+
static char unknown_err[7] = {0};
402+
403+
if ( str == NULL )
404+
{
405+
sprintf(unknown_err, "0x%04X", err_id);
406+
str = unknown_err;
407+
}
408+
409+
return str;
410+
}
411+
325412
#endif
326413

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ AdafruitBluefruit::AdafruitBluefruit(void)
102102
* to increase throughput for most user
103103
*/
104104
/*------------------------------------------------------------------*/
105-
_sd_cfg.attr_table_size = 0xB00;
105+
_sd_cfg.attr_table_size = 0x800;
106106
_sd_cfg.mtu_max = BLEGATT_ATT_MTU_MAX;
107107
_sd_cfg.service_changed = 0;
108108
_sd_cfg.uuid128_max = BLE_UUID_VS_COUNT_DEFAULT;
@@ -688,6 +688,10 @@ void adafruit_ble_task(void* arg)
688688
{
689689
(void) arg;
690690

691+
#if SD_VER >= 500
692+
uint8_t * ev_buf = (uint8_t*) rtos_malloc(BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX));
693+
#endif
694+
691695
while (1)
692696
{
693697
if ( xSemaphoreTake(Bluefruit._ble_event_sem, portMAX_DELAY) )
@@ -697,13 +701,12 @@ void adafruit_ble_task(void* arg)
697701
// Until no pending events
698702
while( NRF_ERROR_NOT_FOUND != err )
699703
{
700-
#if SD_VER < 500
704+
#if SD_VER < 500
701705
__ALIGN(4) uint8_t ev_buf[ sizeof(ble_evt_t) + (BLE_GATT_ATT_MTU_DEFAULT) ];
702-
#else
703-
__ALIGN(4) uint8_t ev_buf[ BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX) ];
704-
#endif
705-
706706
uint16_t ev_len = sizeof(ev_buf);
707+
#else
708+
uint16_t ev_len = BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX);
709+
#endif
707710

708711
// Get BLE Event
709712
err = sd_ble_evt_get(ev_buf, &ev_len);

0 commit comments

Comments
 (0)