8000 Add debugging for Bluetooth (#1767) · rondlh/arduino-pico@10ddaee · GitHub
[go: up one dir, main page]

Skip to content

Commit 10ddaee

Browse files
Add debugging for Bluetooth (earlephilhower#1767)
BTStack requires a special logger registration to enable debugging. Add support through the IDE menus.
1 parent 5678bb9 commit 10ddaee

11 files changed

+293
-68
lines changed

boards.txt

Lines changed: 198 additions & 66 deletions
Large diffs are not rendered by default.

cores/rp2040/BluetoothDebug.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
Enable BTStack debugging to a Print-able object
3+
4+
Copyright (c) 2023 Earle F. Philhower, III <earlephilhower@yahoo.com>
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19< 10000 span class="diff-text-marker">+
*/
20+
21+
#if defined(ENABLE_CLASSIC) || defined(ENABLE_BLE)
22+
#include <Arduino.h>
23+
#include <btstack.h>
24+
#include <hci_dump.h>
25+
26+
static Print *_print;
27+
28+
static void _log_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) {
29+
if (!_print) {
30+
return;
31+
}
32+
_print->printf("[BT @%lu] ", millis());
33+
34+
switch (packet_type) {
35+
case HCI_COMMAND_DATA_PACKET:
36+
_print->printf("CMD => ");
37+
break;
38+
case HCI_EVENT_PACKET:
39+
_print->printf("EVT <= ");
40+
break;
41+
case HCI_ACL_DATA_PACKET:
42+
_print->printf("ACL %s ", in ? "<=" : "=>");
43+
break;
44+
case HCI_SCO_DATA_PACKET:
45+
_print->printf("SCO %s ", in ? "<=" : "=>");
46+
break;
47+
case HCI_ISO_DATA_PACKET:
48+
_print->printf("ISO %s ", in ? "<=" : "=>");
49+
break;
50+
case LOG_MESSAGE_PACKET:
51+
_print->printf("LOG -- %s\n", (char*) packet);
52+
return;
53+
default:
54+
_print->printf("UNK(%x) %s ", packet_type, in ? "<=" : "=>");
55+
break;
56+
}
57+
58+
for (uint16_t i = 0; i < len; i++) {
59+
_print->printf("%02X ", packet[i]);
60+
}
61+
_print->printf("\n");
62+
}
63+
64+
static void _log_message(int log_level, const char * format, va_list argptr) {
65+
(void)log_level;
66+
char log_message_buffer[HCI_DUMP_MAX_MESSAGE_LEN];
67+
if (!_print) {
68+
return;
69+
}
70+
vsnprintf(log_message_buffer, sizeof(log_message_buffer), format, argptr);
71+
_print->printf("[BT @%lu] LOG -- %s\n", millis(), log_message_buffer);
72+
}
73+
74+
75+
static const hci_dump_t hci_dump_instance = {
76+
NULL,
77+
_log_packet,
78+
_log_message
79+
};
80+
81+
82+
void __EnableBluetoothDebug(Print &print) {
83+
_print = &print;
84+
hci_dump_init(&hci_dump_instance);
85+
}
86+
87+
#endif

cores/rp2040/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern void startFreeRTOS() __attribute__((weak));
3838
bool __isFreeRTOS;
3939
volatile bool __freeRTOSinitted;
4040

41+
extern void __EnableBluetoothDebug(Print &);
4142

4243
// Weak empty variant initialization. May be redefined by variant files.
4344
void initVariant() __attribute__((weak));
@@ -118,6 +119,9 @@ extern "C" int main() {
118119
#if defined DEBUG_RP2040_PORT
119120
if (!__isFreeRTOS) {
120121
DEBUG_RP2040_PORT.begin(115200);
122+
#if (defined(ENABLE_BLUETOOTH) || defined(ENABLE_BLE)) && defined(DEBUG_RP2040_BLUETOOTH)
123+
__EnableBluetoothDebug(DEBUG_RP2040_PORT);
124+
#endif
121125
}
122126
#endif
123127

include/btstack_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// BTstack features that can be enabled
44
#define ENABLE_LOG_INFO
5+
#define ENABLE_LOG_DEBUG
56
#define ENABLE_LOG_ERROR
67
#define ENABLE_PRINTF_HEXDUMP
78
#define ENABLE_SCO_OVER_HCI

lib/libpico.a

-2.45 KB
Binary file not shown.

lib/libpicow-ipv6-btc-ble.a

4.29 KB
Binary file not shown.

lib/libpicow-ipv6-nobtc-noble.a

-4.26 KB
Binary file not shown.

lib/libpicow-noipv6-btc-ble.a

4.61 KB
Binary file not shown.

lib/libpicow-noipv6-nobtc-noble.a

-3.94 KB
Binary file not shown.

tools/libpico/btstack_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// BTstack features that can be enabled
44
#define ENABLE_LOG_INFO
5+
#define ENABLE_LOG_DEBUG
56
#define ENABLE_LOG_ERROR
67
#define ENABLE_PRINTF_HEXDUMP
78
#define ENABLE_SCO_OVER_HCI

0 commit comments

Comments
 (0)
0