From 2c668b632abc84d15dd0e2135c6e061148c4e4e1 Mon Sep 17 00:00:00 2001 From: "Mitrev Hristo (HAU-DCEE)" Date: Mon, 18 Dec 2023 18:32:21 +0200 Subject: [PATCH 1/4] rtt: Add gdb monitor rtt down command Just for convenience I wanted to be able to push strings to the rtt down buffer without the need to change the active window from the one where the gdb session is running Signed-off-by: Hristo Mitrev --- UsingRTT.md | 4 ++++ src/command.c | 16 ++++++++++++++-- src/include/rtt.h | 1 + src/platforms/common/stm32/rtt_if.c | 20 ++++++++++++-------- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/UsingRTT.md b/UsingRTT.md index 24f664cb2ba..f595d590a59 100644 --- a/UsingRTT.md +++ b/UsingRTT.md @@ -119,6 +119,10 @@ 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`` + + push *string* to the rtt down buffer. It is equivalent to pushing the string to ttyBmpTarg. + - ``monitor rtt ident`` clears ident string. (default) diff --git a/src/command.c b/src/command.c index 1e44bbd5d1d..9245252ee11 100644 --- a/src/command.c +++ b/src/command.c @@ -96,7 +96,7 @@ 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 " + "[enable|disable|status|channel [0..15 ...]|ident [STR]|down [STR]|cblock|ram [RAM_START RAM_END]|poll [MAXMS MINMS " "MAXERR]]"}, #endif #ifdef PLATFORM_HAS_TRACESWO @@ -564,7 +564,19 @@ static bool cmd_rtt(target_s *t, int argc, const char **argv) if (rtt_ident[i] == '_') rtt_ident[i] = ' '; } - } else if (argc == 2 && strncmp(argv[1], "ram", command_len) == 0) + } 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) 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); diff --git a/src/include/rtt.h b/src/include/rtt.h index 029b8018135..79b934e5561 100644 --- a/src/include/rtt.h +++ b/src/include/rtt.h @@ -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, uint16_t len); #endif /* INCLUDE_RTT_H */ diff --git a/src/platforms/common/stm32/rtt_if.c b/src/platforms/common/stm32/rtt_if.c index f781918e837..2e3fa772a7f 100644 --- a/src/platforms/common/stm32/rtt_if.c +++ b/src/platforms/common/stm32/rtt_if.c @@ -58,6 +58,17 @@ 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) +{ + /* 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] = 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 */ @@ -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())) From 5e8d8a3fd2b78abc0be66b5c8e7cbbbc0c7cfb4c Mon Sep 17 00:00:00 2001 From: Hristo Mitrev Date: Mon, 18 Dec 2023 22:50:44 +0200 Subject: [PATCH 2/4] rtt: Refactor some of the code --- UsingRTT.md | 2 +- src/command.c | 21 ++++++--------------- src/include/rtt.h | 2 +- src/platforms/common/stm32/rtt_if.c | 6 +++--- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/UsingRTT.md b/UsingRTT.md index f595d590a59..d1cf3994421 100644 --- a/UsingRTT.md +++ b/UsingRTT.md @@ -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. diff --git a/src/command.c b/src/command.c index 9245252ee11..350a6805e8b 100644 --- a/src/command.c +++ b/src/command.c @@ -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]]"}, #endif #ifdef PLATFORM_HAS_TRACESWO #if defined TRACESWO_PROTOCOL && TRACESWO_PROTOCOL == 2 @@ -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); diff --git a/src/include/rtt.h b/src/include/rtt.h index 79b934e5561..7f31be144e1 100644 --- a/src/include/rtt.h +++ b/src/include/rtt.h @@ -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 */ diff --git a/src/platforms/common/stm32/rtt_if.c b/src/platforms/common/stm32/rtt_if.c index 2e3fa772a7f..e727b3d89fc 100644 --- a/src/platforms/common/stm32/rtt_if.c +++ b/src/platforms/common/stm32/rtt_if.c @@ -58,10 +58,10 @@ 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 */ @@ -69,9 +69,9 @@ void rtt_load_recv_buf(const char *data_buf, uint16_t len) 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 */ - void rtt_serial_receive_callback(usbd_device *dev, uint8_t ep) { (void)dev; From 6c88ef53ff3b79f43796796308610cd8a1207cf5 Mon Sep 17 00:00:00 2001 From: Hristo Mitrev Date: Sat, 30 Dec 2023 00:03:05 +0200 Subject: [PATCH 3/4] rtt: fix build on launchpad-icdi --- src/platforms/launchpad-icdi/rtt_if.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/platforms/launchpad-icdi/rtt_if.c b/src/platforms/launchpad-icdi/rtt_if.c index 57544cf5652..b10cce071c7 100644 --- a/src/platforms/launchpad-icdi/rtt_if.c +++ b/src/platforms/launchpad-icdi/rtt_if.c @@ -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 */ @@ -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())) From 0022d0bae7802a97eccfd077722007669712c5f9 Mon Sep 17 00:00:00 2001 From: Hristo Mitrev Date: Mon, 18 Dec 2023 22:50:44 +0200 Subject: [PATCH 4/4] rtt: Refactor some of the code --- UsingRTT.md | 2 +- src/command.c | 2 +- src/platforms/launchpad-icdi/rtt_if.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/UsingRTT.md b/UsingRTT.md index d1cf3994421..7c0aa8d9d14 100644 --- a/UsingRTT.md +++ b/UsingRTT.md @@ -121,7 +121,7 @@ grep 2000 HelloWorld.ino.map | grep RTT - ``monitor rtt send string`` - push *string* to the rtt down buffer. It is equivalent to pushing the string to ttyBmpTarg. + push *string* to the RTT down buffer. It is equivalent to pushing the string to ttyBmpTarg. - ``monitor rtt ident`` diff --git a/src/command.c b/src/command.c index 350a6805e8b..e11f5d09725 100644 --- a/src/command.c +++ b/src/command.c @@ -97,7 +97,7 @@ const command_s cmd_list[] = { #ifdef ENABLE_RTT {"rtt", cmd_rtt, "[enable|disable|status|channel [0..15 ...]|ident [STR]|send [STR]|cblock|ram [RAM_START RAM_END]|" - "poll [MAXMS MMINMS AXERR]]"}, + "poll [MAXMS MINMS MAXERR]]"}, #endif #ifdef PLATFORM_HAS_TRACESWO #if defined TRACESWO_PROTOCOL && TRACESWO_PROTOCOL == 2 diff --git a/src/platforms/launchpad-icdi/rtt_if.c b/src/platforms/launchpad-icdi/rtt_if.c index b10cce071c7..d02a7434037 100644 --- a/src/platforms/launchpad-icdi/rtt_if.c +++ b/src/platforms/launchpad-icdi/rtt_if.c @@ -90,7 +90,7 @@ void rtt_serial_receive_callback(usbd_device *dev, uint8_t ep) return; } - rtt_load_recv_buf(usb_buf, len); + 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()))