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 1 commit
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
2 changes: 1 addition & 1 deletion UsingRTT.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ 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 down string``
- ``monitor rtt send string``

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

Expand Down
21 changes: 6 additions & 15 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 @@ -96,8 +96,8 @@ const command_s cmd_list[] = {
#endif
#ifdef ENABLE_RTT
{"rtt", cmd_rtt,
"[enable|disable|status|channel [0..15 ...]|ident [STR]|down [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 MMINMS AXERR]]"},
dragonmux marked this conversation as resolved.
Show resolved Hide resolved
#endif
#ifdef PLATFORM_HAS_TRACESWO
#if defined TRACESWO_PROTOCOL && TRACESWO_PROTOCOL == 2
Expand Down Expand Up @@ -564,19 +564,10 @@ 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], "down", command_len) == 0) {
/*
* here we bypass the if statement to save flash
* as it's not critical to check if the rtt block is found
*/
if(rtt_found || true) {
uint16_t len = strlen(argv[2]);
rtt_load_recv_buf(argv[2], len);
} else {
gdb_out("the rtt block is not yet found\n");
}
}
else if (argc == 2 && strncmp(argv[1], "ram", command_len) == 0)
} 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) {
const int cnt1 = sscanf(argv[2], "%" SCNx32, &rtt_ram_start);
Expand Down
2 changes: 1 addition & 1 deletion src/include/rtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +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, uint16_t len);
void rtt_load_recv_buf(const char *data_buf, size_t len);

#endif /* INCLUDE_RTT_H */
6 changes: 3 additions & 3 deletions src/platforms/common/stm32/rtt_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +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, uint16_t len)
void rtt_load_recv_buf(const char *data_buf, size_t len)
{
/* copy data to recv_buf */
for (int i = 0; i < len; i++) {
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 Down