Skip to content

Commit 75c410a

Browse files
committed
rtt: Refactor some of the code
1 parent 99f4737 commit 75c410a

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

UsingRTT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ grep 2000 HelloWorld.ino.map | grep RTT
119119
sets RTT ident to *string*. If *string* contains a space, replace the space with an
120120
underscore _. Setting ident string is optional, RTT works fine without.
121121

122-
- ``monitor rtt down string``
122+
- ``monitor rtt send string``
123123

124-
push *string* to the rtt down buffer. It is equivalent to pushing the string to ttyBmpTarg.
124+
push *string* to the RTT down buffer. It is equivalent to pushing the string to ttyBmpTarg.
125125

126126
- ``monitor rtt ident``
127127

src/command.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ const command_s cmd_list[] = {
9696
#endif
9797
#ifdef ENABLE_RTT
9898
{"rtt", cmd_rtt,
99-
"[enable|disable|status|channel [0..15 ...]|ident [STR]|down [STR]|cblock|ram [RAM_START RAM_END]|poll [MAXMS MINMS "
100-
"MAXERR]]"},
99+
"[enable|disable|status|channel [0..15 ...]|ident [STR]|send [STR]|cblock|ram [RAM_START RAM_END]|"
100+
"poll [MAXMS MINMS MAXERR]]"},
101101
#endif
102102
#ifdef PLATFORM_HAS_TRACESWO
103103
#if defined TRACESWO_PROTOCOL && TRACESWO_PROTOCOL == 2
@@ -564,19 +564,10 @@ static bool cmd_rtt(target_s *t, int argc, const char **argv)
564564
if (rtt_ident[i] == '_')
565565
rtt_ident[i] = ' ';
566566
}
567-
} else if (argc == 3 && strncmp(argv[1], "down", command_len) == 0) {
568-
/*
569-
* here we bypass the if statement to save flash
570-
* as it's not critical to check if the rtt block is found
571-
*/
572-
if(rtt_found || true) {
573-
uint16_t len = strlen(argv[2]);
574-
rtt_load_recv_buf(argv[2], len);
575-
} else {
576-
gdb_out("the rtt block is not yet found\n");
577-
}
578-
}
579-
else if (argc == 2 && strncmp(argv[1], "ram", command_len) == 0)
567+
} else if (argc == 3 && strncmp(argv[1], "send", command_len) == 0) {
568+
size_t len = strlen(argv[2]);
569+
rtt_load_recv_buf(argv[2], len);
570+
} else if (argc == 2 && strncmp(argv[1], "ram", command_len) == 0)
580571
rtt_flag_ram = false;
581572
else if (argc == 4 && strncmp(argv[1], "ram", command_len) == 0) {
582573
const int cnt1 = sscanf(argv[2], "%" SCNx32, &rtt_ram_start);

src/include/rtt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ typedef struct rtt_channel {
6060
extern rtt_channel_s rtt_channel[MAX_RTT_CHAN];
6161

6262
void poll_rtt(target_s *cur_target);
63-
void rtt_load_recv_buf(const char *data_buf, uint16_t len);
63+
void rtt_load_recv_buf(const char *data_buf, size_t len);
6464

6565
#endif /* INCLUDE_RTT_H */

src/platforms/common/stm32/rtt_if.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ inline static bool recv_set_nak()
5858
return recv_bytes_free() < 2U * CDCACM_PACKET_SIZE;
5959
}
6060

61-
void rtt_load_recv_buf(const char *data_buf, uint16_t len)
61+
void rtt_load_recv_buf(const char *data_buf, size_t len)
6262
{
6363
/* copy data to recv_buf */
64-
for (int i = 0; i < len; i++) {
64+
for (size_t i = 0; i < len; i++) {
6565
uint32_t next_recv_head = (recv_head + 1U) % sizeof(recv_buf);
6666
if (next_recv_head == recv_tail)
6767
break; /* overflow */
6868
recv_buf[recv_head] = data_buf[i];
6969
recv_head = next_recv_head;
7070
}
7171
}
72+
7273
/* debug_serial_receive_callback is called when usb uart has received new data for target.
7374
this routine has to be fast */
74-
7575
void rtt_serial_receive_callback(usbd_device *dev, uint8_t ep)
7676
{
7777
(void)dev;

0 commit comments

Comments
 (0)