Skip to content

Commit 9726eac

Browse files
authored
Update serial.c
Empty the UDR0 register to mitigate leaking '\n' character
1 parent 12c3ce9 commit 9726eac

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/serial.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ void uart_getline(char* command_buf, int size)
103103
{
104104
int count = 0;
105105
char incoming;
106+
107+
// Tohrow-away variable, used to drain the UDR0 registry when transmission is complete.
108+
char _;
106109

107110
ATOMIC_BLOCK(ATOMIC_FORCEON)
108111
{
@@ -113,7 +116,10 @@ void uart_getline(char* command_buf, int size)
113116
if (incoming < 1 || incoming == WIN_ENDL || incoming == LINUX_ENDL)
114117
{
115118
// Empty the UDR0 register to mitigate leaking '\n' character
116-
while(serial_available());
119+
while(serial_available())
120+
{
121+
_ = uart_getchar();
122+
}
117123
break;
118124
}
119125

@@ -131,4 +137,4 @@ void uart_echo()
131137
memset(input, 0, sizeof(input) / sizeof(input[0]));
132138
uart_getline(input, sizeof(input) / sizeof(input[0]));
133139
uart_putstr(input);
134-
}
140+
}

0 commit comments

Comments
 (0)