Skip to content

Commit e7b66d1

Browse files
MariuszSkamracarlescufi
authored andcommitted
Bluetooth: monitor: Fix sending logs over RTT
This fixes Bluetooth logs that were not sent over RTT. Minor cleanup has been made to limit the number of ifdefs. > ACL Data RX: Handle 0 flags 0x02 dlen 11 #1049 83.117000 ATT: Handle Value Indication (0x1d) len 6 Handle: 0x0003 Data: 0100ffff = bt: bt_att: Unhandled ATT code 0x1d 83.117100 > HCI Event: Disconnect Complete (0x05) plen 4 #1050 84.247700 Status: Success (0x00) Handle: 0 Reason: Remote User Terminated Connection (0x13) Signed-off-by: Mariusz Skamra <[email protected]>
1 parent 1a56f76 commit e7b66d1

File tree

2 files changed

+41
-34
lines changed

2 files changed

+41
-34
lines changed

subsys/bluetooth/common/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ config BT_DEBUG_MONITOR_RTT
313313
depends on USE_SEGGER_RTT
314314
depends on SEGGER_RTT_MAX_NUM_UP_BUFFERS >= 2
315315
select BT_DEBUG
316+
select LOG
317+
select CONSOLE_HAS_DRIVER
316318
select BT_MONITOR
317319
help
318320
Use a custom logging protocol over the RTT buffer instead of

subsys/bluetooth/host/monitor.c

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@
2727

2828
#include "monitor.h"
2929

30-
#ifdef CONFIG_BT_DEBUG_MONITOR_RTT
31-
#include <SEGGER_RTT.h>
32-
33-
#define RTT_BUFFER_NAME CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER_NAME
34-
#define RTT_BUF_SIZE CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER_SIZE
35-
static uint8_t rtt_buf[RTT_BUF_SIZE];
36-
#elif CONFIG_BT_DEBUG_MONITOR_UART
37-
static const struct device *monitor_dev;
38-
#endif
39-
4030
/* This is the same default priority as for other console handlers,
4131
* except that we're not exporting it as a Kconfig variable until a
4232
* clear need arises.
@@ -74,18 +64,40 @@ static struct {
7464
atomic_t other;
7565
} drops;
7666

67+
#if defined(CONFIG_BT_DEBUG_MONITOR_RTT)
68+
#include <SEGGER_RTT.h>
69+
70+
#define RTT_BUFFER_NAME CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER_NAME
71+
#define RTT_BUF_SIZE CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER_SIZE
72+
73+
static uint8_t rtt_buf[RTT_BUF_SIZE];
74+
7775
static void monitor_send(const void *data, size_t len)
7876
{
79-
#ifdef CONFIG_BT_DEBUG_MONITOR_RTT
8077
SEGGER_RTT_Write(CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER, data, len);
81-
#elif CONFIG_BT_DEBUG_MONITOR_UART
78+
}
79+
80+
static void poll_out(char c)
81+
{
82+
monitor_send(&c, sizeof(c));
83+
}
84+
#elif defined(CONFIG_BT_DEBUG_MONITOR_UART)
85+
static const struct device *monitor_dev;
86+
87+
static void poll_out(char c)
88+
{
89+
uart_poll_out(monitor_dev, c);
90+
}
91+
92+
static void monitor_send(const void *data, size_t len)
93+
{
8294
const uint8_t *buf = data;
8395

8496
while (len--) {
85-
uart_poll_out(monitor_dev, *buf++);
97+
poll_out(*buf++);
8698
}
87-
#endif
8899
}
100+
#endif /* CONFIG_BT_DEBUG_MONITOR_UART */
89101

90102
static void encode_drops(struct bt_monitor_hdr *hdr, uint8_t type,
91103
atomic_t *val)
@@ -191,19 +203,7 @@ void bt_monitor_new_index(uint8_t type, uint8_t bus, bt_addr_t *addr,
191203
bt_monitor_send(BT_MONITOR_NEW_INDEX, &pkt, sizeof(pkt));
192204
}
193205

194-
#ifdef CONFIG_BT_DEBUG_MONITOR_RTT
195-
static int bt_monitor_init(const struct device *d)
196-
{
197-
ARG_UNUSED(d);
198-
199-
SEGGER_RTT_ConfigUpBuffer(CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER,
200-
RTT_BUFFER_NAME, rtt_buf, RTT_BUF_SIZE,
201-
SEGGER_RTT_MODE_NO_BLOCK_SKIP);
202-
return 0;
203-
}
204-
#elif CONFIG_BT_DEBUG_MONITOR_UART
205-
206-
#if !defined(CONFIG_UART_CONSOLE) && !defined(CONFIG_LOG_PRINTK)
206+
#if !defined(CONFIG_UART_CONSOLE) && !defined(CONFIG_RTT_CONSOLE) && !defined(CONFIG_LOG_PRINTK)
207207
static int monitor_console_out(int c)
208208
{
209209
static char buf[MONITOR_MSG_MAX];
@@ -231,7 +231,7 @@ static int monitor_console_out(int c)
231231

232232
extern void __printk_hook_install(int (*fn)(int));
233233
extern void __stdout_hook_install(int (*fn)(int));
234-
#endif /* !CONFIG_UART_CONSOLE */
234+
#endif /* !CONFIG_UART_CONSOLE && !CONFIG_RTT_CONSOLE && !CONFIG_LOG_PRINTK */
235235

236236
#ifndef CONFIG_LOG_MODE_MINIMAL
237237
struct monitor_log_ctx {
@@ -316,7 +316,7 @@ static void monitor_log_put(const struct log_backend *const backend,
316316
monitor_send(ctx.msg, ctx.total_len);
317317

318318
/* Terminate the string with null */
319-
uart_poll_out(monitor_dev, '\0');
319+
poll_out('\0');
320320

321321
atomic_clear_bit(&flags, BT_LOG_BUSY);
322322
}
@@ -353,7 +353,7 @@ static void monitor_log_process(const struct log_backend *const backend,
353353
monitor_send(ctx.msg, ctx.total_len);
354354

355355
/* Terminate the string with null */
356-
uart_poll_out(monitor_dev, '\0');
356+
poll_out('\0');
357357

358358
atomic_clear_bit(&flags, BT_LOG_BUSY);
359359
}
@@ -381,22 +381,27 @@ static int bt_monitor_init(const struct device *d)
381381
{
382382
ARG_UNUSED(d);
383383

384+
#if defined(CONFIG_BT_DEBUG_MONITOR_RTT)
385+
SEGGER_RTT_ConfigUpBuffer(CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER,
386+
RTT_BUFFER_NAME, rtt_buf, RTT_BUF_SIZE,
387+
SEGGER_RTT_MODE_NO_BLOCK_SKIP);
388+
#elif defined(CONFIG_BT_DEBUG_MONITOR_UART)
384389
monitor_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_mon_uart));
385390

386391
__ASSERT_NO_MSG(device_is_ready(monitor_dev));
387392

388393
#if defined(CONFIG_UART_INTERRUPT_DRIVEN)
389394
uart_irq_rx_disable(monitor_dev);
390395
uart_irq_tx_disable(monitor_dev);
391-
#endif
396+
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
397+
#endif /* CONFIG_BT_DEBUG_MONITOR_UART */
392398

393-
#if !defined(CONFIG_UART_CONSOLE) && !defined(CONFIG_LOG_PRINTK)
399+
#if !defined(CONFIG_UART_CONSOLE) && !defined(CONFIG_RTT_CONSOLE) && !defined(CONFIG_LOG_PRINTK)
394400
__printk_hook_install(monitor_console_out);
395401
__stdout_hook_install(monitor_console_out);
396-
#endif
402+
#endif /* !CONFIG_UART_CONSOLE && !CONFIG_RTT_CONSOLE && !CONFIG_LOG_PRINTK */
397403

398404
return 0;
399405
}
400-
#endif /* CONFIG_BT_DEBUG_MONITOR_UART */
401406

402407
SYS_INIT(bt_monitor_init, PRE_KERNEL_1, MONITOR_INIT_PRIORITY);

0 commit comments

Comments
 (0)