Commit 961f2b44 authored by David Lechner's avatar David Lechner

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: https://github.com/pybricks/support/issues/747
parent 398672a4
......@@ -14,9 +14,11 @@
- Fixed BLE broadcast not working on City hub.
- Fixed crash on BTStack hubs when program stopped during call to `ble.broadcast()`.
- Fixed BLE broadcast not working on Technic hub when not connected ([support#1086]).
- Fixed delayed sensor sync on boot on City hub ([support#747]).
[support#402]: https://github.com/pybricks/support/issues/402
[support#1086]: https://github.com/pybricks/support/issues/402
[support#747]: https://github.com/pybricks/support/issues/747
[support#1086]: https://github.com/pybricks/support/issues/1086
## [3.3.0b5] - 2023-05-16
......
......@@ -756,15 +756,15 @@ static PT_THREAD(pbio_uartdev_update(uartdev_port_data_t * data)) {
// block until pbio_uartdev_ready() is called
PT_WAIT_UNTIL(&data->pt, data->status == PBIO_UARTDEV_STATUS_SYNCING);
pbdrv_uart_flush(data->uart);
// Send SPEED command at 115200 baud
pbdrv_uart_set_baud_rate(data->uart, EV3_UART_SPEED_LPF2);
debug_pr("set baud: %d\n", EV3_UART_SPEED_LPF2);
PT_SPAWN(&data->pt, &data->speed_pt, pbio_uartdev_send_speed_msg(data, EV3_UART_SPEED_LPF2));
pbdrv_uart_flush(data->uart);
// read one byte to check for ACK
PBIO_PT_WAIT_READY(&data->pt, err = pbdrv_uart_read_begin(data->uart, data->rx_msg, 1, 100));
PBIO_PT_WAIT_READY(&data->pt, err = pbdrv_uart_read_begin(data->uart, data->rx_msg, 1, 10));
if (err != PBIO_SUCCESS) {
DBG_ERR(data->last_err = "UART Rx error during baud");
goto err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment