mirror of
https://github.com/pine64/blisp.git
synced 2026-09-18 18:31:29 +00:00
Make handshake more reliable via UART
Added waiting for transmitting whole handshake, and then flushing RX buffer in case we received 0xFF data in mean time.
This commit is contained in:
+6
-6
@@ -155,8 +155,6 @@ blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) {
|
|||||||
if (bytes_count > 600) bytes_count = 600;
|
if (bytes_count > 600) bytes_count = 600;
|
||||||
memset(handshake_buffer, 'U', bytes_count);
|
memset(handshake_buffer, 'U', bytes_count);
|
||||||
|
|
||||||
// sp_flush(serial_port, SP_BUF_BOTH);
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 5; i++) {
|
for (uint8_t i = 0; i < 5; i++) {
|
||||||
if (!in_ef_loader) {
|
if (!in_ef_loader) {
|
||||||
if (device->is_usb) {
|
if (device->is_usb) {
|
||||||
@@ -169,15 +167,17 @@ blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) {
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = sp_blocking_read(serial_port, device->rx_buffer, 20, 50);
|
|
||||||
|
sp_drain(serial_port); // Wait for write to send all data
|
||||||
|
sp_flush(serial_port, SP_BUF_INPUT); // Flush garbage out of RX
|
||||||
|
|
||||||
|
ret = sp_blocking_read(serial_port, device->rx_buffer, 2, 50);
|
||||||
if (ret >= 2) {
|
if (ret >= 2) {
|
||||||
for (uint8_t j = 0; j < (ret - 1); j++) {
|
if (device->rx_buffer[0] == 'O' && device->rx_buffer[1] == 'K') {
|
||||||
if (device->rx_buffer[j] == 'O' && device->rx_buffer[j + 1] == 'K') {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return -4; // didn't received response
|
return -4; // didn't received response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user