Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtt: Add gdb monitor rtt down command #1704

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion UsingRTT.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ grep 2000 HelloWorld.ino.map | grep RTT
sets RTT ident to *string*. If *string* contains a space, replace the space with an
underscore _. Setting ident string is optional, RTT works fine without.

- `monitor rtt ident`
- ``monitor rtt send string``

push *string* to the RTT down buffer. It is equivalent to pushing the string to ttyBmpTarg.

- ``monitor rtt ident``

clears ident string. (default)

Expand Down
7 changes: 5 additions & 2 deletions src/command.c
dragonmux marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ const command_s cmd_list[] = {
#endif
#ifdef ENABLE_RTT
{"rtt", cmd_rtt,
"[enable|disable|status|channel [0..15 ...]|ident [STR]|cblock|ram [RAM_START RAM_END]|poll [MAXMS MINMS "
"MAXERR]]"},
"[enable|disable|status|channel [0..15 ...]|ident [STR]|send [STR]|cblock|ram [RAM_START RAM_END]|"
"poll [MAXMS MINMS MAXERR]]"},
#endif
#ifdef PLATFORM_HAS_TRACESWO
#if defined TRACESWO_PROTOCOL && TRACESWO_PROTOCOL == 2
Expand Down Expand Up @@ -572,6 +572,9 @@ static bool cmd_rtt(target_s *t, int argc, const char **argv)
if (rtt_ident[i] == '_')
rtt_ident[i] = ' ';
}
} else if (argc == 3 && strncmp(argv[1], "send", command_len) == 0) {
size_t len = strlen(argv[2]);
rtt_load_recv_buf(argv[2], len);
} else if (argc == 2 && strncmp(argv[1], "ram", command_len) == 0)
rtt_flag_ram = false;
else if (argc == 4 && strncmp(argv[1], "ram", command_len) == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/include/rtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ typedef struct rtt_channel {
extern rtt_channel_s rtt_channel[MAX_RTT_CHAN];

void poll_rtt(target_s *cur_target);
void rtt_load_recv_buf(const char *data_buf, size_t len);

#endif /* INCLUDE_RTT_H */
22 changes: 13 additions & 9 deletions src/platforms/common/stm32/rtt_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,20 @@ inline static bool recv_set_nak()
return recv_bytes_free() < 2U * CDCACM_PACKET_SIZE;
}

void rtt_load_recv_buf(const char *data_buf, size_t len)
{
/* copy data to recv_buf */
for (size_t i = 0; i < len; i++) {
uint32_t next_recv_head = (recv_head + 1U) % sizeof(recv_buf);
if (next_recv_head == recv_tail)
break; /* overflow */
recv_buf[recv_head] = data_buf[i];
recv_head = next_recv_head;
}
}

/* debug_serial_receive_callback is called when usb uart has received new data for target.
dragonmux marked this conversation as resolved.
Show resolved Hide resolved
this routine has to be fast */

void rtt_serial_receive_callback(usbd_device *dev, uint8_t ep)
{
(void)dev;
Expand All @@ -78,14 +89,7 @@ void rtt_serial_receive_callback(usbd_device *dev, uint8_t ep)
return;
}

/* copy data to recv_buf */
for (int i = 0; i < len; i++) {
uint32_t next_recv_head = (recv_head + 1U) % sizeof(recv_buf);
if (next_recv_head == recv_tail)
break; /* overflow */
recv_buf[recv_head] = usb_buf[i];
recv_head = next_recv_head;
}
rtt_load_recv_buf(usb_buf, len);

/* block flag: flow control closed if not enough free buffer space */
if (!(rtt_flag_block && recv_set_nak()))
Expand Down
21 changes: 13 additions & 8 deletions src/platforms/launchpad-icdi/rtt_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ inline static bool recv_set_nak()
return recv_bytes_free() < 2U * CDCACM_PACKET_SIZE;
}

void rtt_load_recv_buf(const char *data_buf, size_t len)
{
/* copy data to recv_buf */
for (size_t i = 0; i < len; i++) {
uint32_t next_recv_head = (recv_head + 1U) % sizeof(recv_buf);
if (next_recv_head == recv_tail)
break; /* overflow */
recv_buf[recv_head] = data_buf[i];
recv_head = next_recv_head;
}
}

/* debug_serial_receive_callback is called when usb uart has received new data for target.
this routine has to be fast */

Expand All @@ -78,14 +90,7 @@ void rtt_serial_receive_callback(usbd_device *dev, uint8_t ep)
return;
}

/* copy data to recv_buf */
for (int i = 0; i < len; i++) {
uint32_t next_recv_head = (recv_head + 1U) % sizeof(recv_buf);
if (next_recv_head == recv_tail)
break; /* overflow */
recv_buf[recv_head] = usb_buf[i];
recv_head = next_recv_head;
}
rtt_load_recv_buf(usb_buf, len);

/* block flag: flow control closed if not enough free buffer space */
if (!(rtt_flag_block && recv_set_nak()))
Expand Down
Loading