Skip to content

Commit 961f2b4

Browse files
committed
pbio/uartdev: fix sync on city hub
The flush needs to be immediately before the read, otherwise the read buffer can contain garbage that was read while sending the baud rate. Also, the ACK usually comes in < 1 ms so we don't need to wait so long. This improves the chances of not missing data if the ACK doesn't come, e.g. on the BOOST Color Distance sensor. Fixes: pybricks/support#747
1 parent 398672a commit 961f2b4

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
- Fixed BLE broadcast not working on City hub.
1515
- Fixed crash on BTStack hubs when program stopped during call to `ble.broadcast()`.
1616
- Fixed BLE broadcast not working on Technic hub when not connected ([support#1086]).
17+
- Fixed delayed sensor sync on boot on City hub ([support#747]).
1718

1819
[support#402]: https://github.com/pybricks/support/issues/402
19-
[support#1086]: https://github.com/pybricks/support/issues/402
20+
[support#747]: https://github.com/pybricks/support/issues/747
21+
[support#1086]: https://github.com/pybricks/support/issues/1086
2022

2123
## [3.3.0b5] - 2023-05-16
2224

lib/pbio/src/uartdev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,15 +756,15 @@ static PT_THREAD(pbio_uartdev_update(uartdev_port_data_t * data)) {
756756
// block until pbio_uartdev_ready() is called
757757
PT_WAIT_UNTIL(&data->pt, data->status == PBIO_UARTDEV_STATUS_SYNCING);
758758

759-
pbdrv_uart_flush(data->uart);
760-
761759
// Send SPEED command at 115200 baud
762760
pbdrv_uart_set_baud_rate(data->uart, EV3_UART_SPEED_LPF2);
763761
debug_pr("set baud: %d\n", EV3_UART_SPEED_LPF2);
764762
PT_SPAWN(&data->pt, &data->speed_pt, pbio_uartdev_send_speed_msg(data, EV3_UART_SPEED_LPF2));
765763

764+
pbdrv_uart_flush(data->uart);
765+
766766
// read one byte to check for ACK
767-
PBIO_PT_WAIT_READY(&data->pt, err = pbdrv_uart_read_begin(data->uart, data->rx_msg, 1, 100));
767+
PBIO_PT_WAIT_READY(&data->pt, err = pbdrv_uart_read_begin(data->uart, data->rx_msg, 1, 10));
768768
if (err != PBIO_SUCCESS) {
769769
DBG_ERR(data->last_err = "UART Rx error during baud");
770770
goto err;

0 commit comments

Comments
 (0)