Skip to content

Commit 5d27f98

Browse files
committed
serial_putc() can cause rx bytes to be dropped
While fixing this issue in the various LPC* ports, I noticed a comment pointing to this mbed forum post which summarizes this bug quite well: https://mbed.org/forum/bugs-suggestions/topic/4473/ This bug was introduced in the following commit: 2662e10 The following code was added to serial_putc() as part of this commit: uint32_t lsr = obj->uart->LSR; lsr = lsr; uint32_t thr = obj->uart->THR; thr = thr; As the forum post indicates, this causes the serial_putc() routine to actually eat an inbound received byte if it exists since reading THR is really reading the RBR, the Receiver Buffer Register. This code looks like code that was probably added so that the developer could take a snapshot of these registers and look at them in the debugger. It probably got committed in error.
1 parent e03e337 commit 5d27f98

File tree

7 files changed

+0
-36
lines changed

7 files changed

+0
-36
lines changed

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11CXX/serial_api.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,6 @@ int serial_getc(serial_t *obj) {
249249
void serial_putc(serial_t *obj, int c) {
250250
while (!serial_writable(obj));
251251
obj->uart->THR = c;
252-
253-
#warning TODO(@toyowata): need to fix a full-duplex bug? https://mbed.org/forum/bugs-suggestions/topic/4473/
254-
uint32_t lsr = obj->uart->LSR;
255-
lsr = lsr;
256-
uint32_t thr = obj->uart->THR;
257-
thr = thr;
258252
}
259253

260254
int serial_readable(serial_t *obj) {

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/serial_api.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,6 @@ int serial_getc(serial_t *obj) {
247247
void serial_putc(serial_t *obj, int c) {
248248
while (!serial_writable(obj));
249249
obj->uart->THR = c;
250-
251-
uint32_t lsr = obj->uart->LSR;
252-
lsr = lsr;
253-
uint32_t thr = obj->uart->THR;
254-
thr = thr;
255250
}
256251

257252
int serial_readable(serial_t *obj) {

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/serial_api.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,6 @@ int serial_getc(serial_t *obj) {
247247
void serial_putc(serial_t *obj, int c) {
248248
while (!serial_writable(obj));
249249
obj->uart->THR = c;
250-
251-
uint32_t lsr = obj->uart->LSR;
252-
lsr = lsr;
253-
uint32_t thr = obj->uart->THR;
254-
thr = thr;
255250
}
256251

257252
int serial_readable(serial_t *obj) {

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,6 @@ int serial_getc(serial_t *obj) {
283283
void serial_putc(serial_t *obj, int c) {
284284
while (!serial_writable(obj));
285285
obj->uart->THR = c;
286-
287-
uint32_t lsr = obj->uart->LSR;
288-
lsr = lsr;
289-
uint32_t thr = obj->uart->THR;
290-
thr = thr;
291286
}
292287

293288
int serial_readable(serial_t *obj) {

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/serial_api.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,6 @@ int serial_getc(serial_t *obj) {
283283
void serial_putc(serial_t *obj, int c) {
284284
while (!serial_writable(obj));
285285
obj->uart->THR = c;
286-
287-
uint32_t lsr = obj->uart->LSR;
288-
lsr = lsr;
289-
uint32_t thr = obj->uart->THR;
290-
thr = thr;
291286
}
292287

293288
int serial_readable(serial_t *obj) {

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,6 @@ int serial_getc(serial_t *obj) {
276276
void serial_putc(serial_t *obj, int c) {
277277
while (!serial_writable(obj));
278278
obj->uart->THR = c;
279-
280-
uint32_t lsr = obj->uart->LSR;
281-
lsr = lsr;
282-
uint32_t thr = obj->uart->THR;
283-
thr = thr;
284279
}
285280

286281
int serial_readable(serial_t *obj) {

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,6 @@ int serial_getc(serial_t *obj) {
257257
void serial_putc(serial_t *obj, int c) {
258258
while (!serial_writable(obj));
259259
obj->uart->THR = c;
260-
261-
uint32_t lsr = obj->uart->LSR;
262-
lsr = lsr;
263-
uint32_t thr = obj->uart->THR;
264-
thr = thr;
265260
}
266261

267262
int serial_readable(serial_t *obj) {

0 commit comments

Comments
 (0)