serprog: Refine flushing before synchronization
We used to wait for 1s before flushing buffers of the tty layer.
However, if the programmer had more data to send than would fit
into these buffers, it would continue to send after flushing the
latter. So we try to read all the data instead. The added loop
reads up to 512KiB and stops when no data is received for 10ms.
Overall, it should time out after at most 10s.
Tests show that an stm32-vserprog can be re-synchronized after
interrupted reads, where the old implementation failed. In case
synchronization is necessary, it also succeeds without notice-
able delay.
Change-Id: Iaa5dfceac0629381ca0924bb59b988525bacba3f
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/72996
Reviewed-by: Riku Viitanen <riku.viitanen@protonmail.com>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
1 file changed