Fri Jun 15 12:28:33 EDT 2012

PK2 robustness

It looks like the main problem is the device getting out-of-sync.
There is not so much of a problem with stuck PK2 firmware with some
safe-guards installed.

Let's investigate.  Run current usb test app a couple of times, using
CTRL-C to interrupt and power-cycle the target.  The error message
after a while is:
    C-c C-c
  Command "test" interrupted.
  Trying cold restart...
  icsp-recv: pk2 read: expected 3 bytes, got 1:
  icsp-recv: b:2 h:#t a:#f -> (0)

So it gets out of sync and after that never recovers.  How to resync?

Will try resync on this:

            (unless (= expect-size real-size)
              (error 'icsp-recv "pk2 read: expected ~a bytes, got ~a:\n~a\n"
                     expect-size real-size (log-msg reply)))

Looking on the logic analyzer, there is some transfer going on, but
it's not sure who is writing.  This probably needs a look on the scope
to see if the read/write phase got messed up..

There is a collision during one bit, so something is out of sync.

What I don't understand is why a power reset doesn't solve it.

Hard to see what's going on, but I think it's safe to assume the
problem is on PK2 side.  Target seems to be fine.

Solution for now:

  (define (reconnect)
    (sleep 1)

The PK2 RESET command doesn't work if PK2 is stuck.  It disconnects
the USB device while opened with libusb which seems to cause trouble..