Skip to content

Commit 5e61785

Browse files
committed
bricks/_common/mphalport: Don't WFI on completed prints.
This would cause Bluetooth messages to inefficiently buffer. MicroPython calls mp_hal_stdout_tx_strn at least twice for every print because it makes another call for \r\n. The user may also call it multiple times with short messages. Running the poll hook even when the buffer is not full meant that it would begin to transmit it rather than concatenate them as we intended (this has been in the driver for years). It would also hold up the virtual hub, incrementing the clock twice for every print.
1 parent da615f7 commit 5e61785

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

bricks/_common/mphalport.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,18 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
7171
return len - remaining;
7272
}
7373

74-
// May raise, so long print can be stopped.
75-
MICROPY_EVENT_POLL_HOOK
74+
// Allow long prints to be interrupted.
75+
if (remaining) {
76+
MICROPY_EVENT_POLL_HOOK
77+
}
7678
}
7779

7880
return len;
7981
}
8082

8183
void mp_hal_stdout_tx_flush(void) {
84+
// Don't raise, just wait for data to clear.
8285
while (!pbsys_host_tx_is_idle()) {
83-
// Don't raise, just wait for data to clear.
8486
MICROPY_VM_HOOK_LOOP;
8587
}
8688
}

0 commit comments

Comments
 (0)