stlink_usb: Fix swallowed error on read/write operations, add retries on SWD WAIT...
commit9fce8a21ca5f7f42ec36aa859637d37f5fba312a
authorAngus Gratton <gus@projectgus.com>
Fri, 27 Jun 2014 23:27:11 +0000 (28 09:27 +1000)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Mon, 11 Aug 2014 22:34:52 +0000 (11 22:34 +0000)
treec68599015b0dec70f37bf79562d29d747c30d621
parent6d26e3e768e3be66eb7edd43d52a039a601e03cd
stlink_usb: Fix swallowed error on read/write operations, add retries on SWD WAIT, clean up error debug output.

- stlink_usb_get_rw_status() had a bug where FAULT or WAIT responses
  in read/write operations were ignored, leading to incomplete data.

- Added wrapper stlink_cmd_allow_retry to handle
  SWD_AP_WAIT/SWD_DP_WAIT statuses in most commands. These statuses
  appear if an SWD read or write received a WAIT ACK response from the
  target more than 4 times in a row. The driver retries the operation
  (with exponential backoff) before failing outright (in testing 1
  retry was always enough.)

- As part of the implementation of stlink_cmd_allow_retry a large
  number of lines of boilerplate were refactored.

- Fleshed out stlink_usb_error_check and added it to some more code
  paths so WAIT or FAULT responses are logged to debug. WAIT responses
  will be logged even if they are subsequently retried, which should
  help in case the retries have subtle side effects (none
  anticipated.)

Tested with two targets: STLINK F0 Discovery, Nordic NRF51822. Only
tested with STLINK V2 programmers.

Change-Id: I9af24e8f0121b035356dbb9978d6bbf4feb2e4d3
Signed-off-by: Angus Gratton <gus@projectgus.com>
Reviewed-on: http://openocd.zylin.com/2201
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
src/helper/log.h
src/jtag/drivers/stlink_usb.c