Don't fail if the device sends leftover bytes before ACK/NACK #40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in #13, if the device is running a firmware that prints characters over the UART, those characters will on occasion get buffered. When the bootloader receives the synch sequence (
0x55, 0x55
), those buffered bytes will appear on the host's serial line before the ACK/NACK sequence.The current version of the script reads 2 bytes when expecting ACK/NACK, and it will therefore fail in the conditions discussed above (since the first 2 bytes received are buffered leftovers instead of an ACK/NACK).
This pull proposes changing
_wait_for_ack
to read byte-by-byte until it encounters ACK/NACK or until it times out.To reproduce, program the device with a firmware that prints stuff: Contiki's startup sequence will do. Reset the device manually a couple of times and then perform the key press sequence to enter the bootloader. Run the script and it will likely fail under the above conditions. Then repeat the above with this patch in place and run with
-V
. Observe the bold line below:whereas normally you should see:
A known downside of this approach is that, if the script runs while the firmware is running, it may erroneously interpret a normal printout as an ACK/NACK. However, this is unlikely because it can only ever happen if the ACK/NACK sequence gets encountered randomly during the
_wait_for_ack()
timeout window.Tested with Zolertia RE-Mote (CC2538 + FT2232 (I think!)) and SmartRF06 + CC2650EM. Tested with 2.7.10 and 3.4.3.
Closes #13