From 5c561a9983896ac0e581ab53f72163ca7e46cde1 Mon Sep 17 00:00:00 2001 From: Joby Taffey Date: Fri, 9 Mar 2012 01:05:51 +0000 Subject: [PATCH] Added sending of "+++" on reflash. Firmware can detect this and reset, to avoid needing to manually reset the board. Fixed timeouts. --- README.markdown | 3 +++ cctl-prog/cctl-prog.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 80203b5..efa839c 100644 --- a/README.markdown +++ b/README.markdown @@ -41,6 +41,9 @@ For usage instructions, run cctl-prog with no arguments: If both `--console` and `--flash` are specified, then the device will be reflashed first, then the console will connect. +Before flashing, `cctl-prog` sends the string "+++", which firmware can detect +and reset automatically. + Preparing your user code for usage with the bootloader is very simple. All you need to do is set your linker to start the code section at 0x400. For an example of this see the `Makefile` file in the `example_payload` subdirectory. diff --git a/cctl-prog/cctl-prog.c b/cctl-prog/cctl-prog.c index 5ea1892..f717c2a 100644 --- a/cctl-prog/cctl-prog.c +++ b/cctl-prog/cctl-prog.c @@ -250,6 +250,7 @@ int serialRead(int fd, void* buf, int len) return rc; if (rc > 0) return rc; + gettimeofday(&now, NULL); } while((now.tv_sec - start.tv_sec) < SERIAL_TIMEOUT); @@ -285,6 +286,7 @@ int serialWrite(int fd, void* buf, int len) return rc; if (rc > 0) return rc; + gettimeofday(&now, NULL); } while((now.tv_sec - start.tv_sec) < SERIAL_TIMEOUT); @@ -449,13 +451,24 @@ int wait_for_bootloader(int fd, int timeout) uint8_t prev_c = 0; struct timeval start, now; int rc; + int last_sec = -1; gettimeofday(&start, NULL); + serialWrite(fd, "+++", 3); + printf("Waiting %ds for bootloader, reset board now\n", timeout); do { + gettimeofday(&now, NULL); + if (((now.tv_sec - start.tv_sec)) != last_sec) + { + printf("."); + fflush(stdout); + last_sec = (now.tv_sec - start.tv_sec); + } + if ((rc = serialRead(fd, &c, 1)) < 0) { fprintf(stderr, "read failed\n"); @@ -468,7 +481,6 @@ int wait_for_bootloader(int fd, int timeout) break; prev_c = c; } - gettimeofday(&now, NULL); } while((now.tv_sec - start.tv_sec) < timeout); if (now.tv_sec - start.tv_sec >= timeout)