mirror of
https://github.com/pine64/blisp.git
synced 2025-02-25 21:33:42 +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:
parent
dd2801d6e9
commit
115f1df0b3
12
lib/blisp.c
12
lib/blisp.c
@ -155,8 +155,6 @@ blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) {
|
||||
if (bytes_count > 600) bytes_count = 600;
|
||||
memset(handshake_buffer, 'U', bytes_count);
|
||||
|
||||
// sp_flush(serial_port, SP_BUF_BOTH);
|
||||
|
||||
for (uint8_t i = 0; i < 5; i++) {
|
||||
if (!in_ef_loader) {
|
||||
if (device->is_usb) {
|
||||
@ -169,15 +167,17 @@ blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) {
|
||||
if (ret < 0) {
|
||||
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) {
|
||||
for (uint8_t j = 0; j < (ret - 1); j++) {
|
||||
if (device->rx_buffer[j] == 'O' && device->rx_buffer[j + 1] == 'K') {
|
||||
if (device->rx_buffer[0] == 'O' && device->rx_buffer[1] == 'K') {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -4; // didn't received response
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user