summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2012-05-31 21:57:55 +0000
committerGerrit <chrome-bot@google.com>2012-06-01 13:13:25 -0700
commitc25c92ff5e1dde14657ade5eea13703f94e772de (patch)
treee778cb93962a56c4573cdd6f14474f71c128b2dd
parent3f129c161e2636e6e4d0c5f1cb1d5fe53f452fcc (diff)
downloadchrome-ec-c25c92ff5e1dde14657ade5eea13703f94e772de.tar.gz
stm32mon: more robust serial communication
- throw away all the incoming garbage after a NACK to be protect against unexpected behavior on the embedded monitor. - increase the command timeout : on STM32F100, I have measured up to 1.4s to execute the erase 64kB command. With the current 2s timeout, it was failing when you are unlucky (since it's using a integer second timestamp to measure the timeout). Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BUG=None TEST=with a Snow, flash the board using stm32mon -w ec.bin from various states. Change-Id: I260b3b1311eac9be7c43f835eeac68051befd24a Reviewed-on: https://gerrit.chromium.org/gerrit/24314 Reviewed-by: David Hendricks <dhendrix@chromium.org> Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--util/stm32mon.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/util/stm32mon.c b/util/stm32mon.c
index 6ccabbae6e..e356e9bde9 100644
--- a/util/stm32mon.c
+++ b/util/stm32mon.c
@@ -58,7 +58,7 @@ struct stm32_def {
{ 0 }
};
-#define DEFAULT_TIMEOUT 2 /* seconds */
+#define DEFAULT_TIMEOUT 4 /* seconds */
#define DEFAULT_BAUDRATE B38400
#define PAGE_SIZE 256
@@ -119,6 +119,23 @@ int open_serial(const char *port)
return fd;
}
+static void discard_input(int fd)
+{
+ uint8_t buffer[64];
+ int res, i;
+
+ /* eat trailing garbage */
+ do {
+ res = read(fd, buffer, sizeof(buffer));
+ if (res > 0) {
+ printf("Recv[%d]:", res);
+ for (i = 0; i < res; i++)
+ printf("%02x ", buffer[i]);
+ printf("\n");
+ }
+ } while (res > 0);
+}
+
int wait_for_ack(int fd)
{
uint8_t resp;
@@ -136,12 +153,14 @@ int wait_for_ack(int fd)
return 0;
else if (resp == RESP_NACK) {
fprintf(stderr, "NACK\n");
+ discard_input(fd);
return -EINVAL;
} else {
fprintf(stderr, "Receive junk: %02x\n", resp);
}
}
}
+ fprintf(stderr, "Timeout\n");
return -ETIMEDOUT;
}
@@ -202,7 +221,8 @@ int send_command(int fd, uint8_t cmd, payload_t *loads, int cnt,
/* Wait for the ACK */
if (wait_for_ack(fd) < 0) {
- fprintf(stderr, "Failed to get payload %d ACK\n", c);
+ fprintf(stderr, "payload %d ACK failed for CMD%02x\n",
+ c, cmd);
return -1;
}
@@ -253,9 +273,8 @@ struct stm32_def *command_get_id(int fd)
int init_monitor(int fd)
{
- int res, i;
+ int res;
uint8_t init = CMD_INIT;
- uint8_t buffer[64];
printf("Waiting for the monitor startup ...");
fflush(stdout);
@@ -288,13 +307,7 @@ int init_monitor(int fd)
printf("Done.\n");
/* read trailing chars */
- res = read(fd, buffer, sizeof(buffer));
- if (res > 0) {
- printf("Recv[%d]:", res);
- for (i = 0; i < res; i++)
- printf("%02x ", buffer[i]);
- printf("\n");
- }
+ discard_input(fd);
return 0;
}