From ddd00223505d8283637bcd4c0796f2f01262db64 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 10 May 2011 11:51:46 -0300 Subject: [PATCH] atusb/fw/boot.c (main): don't time out until there is an application This prevents the boot loader from resetting all the time and makes it easier to "catch" it with dfu-util. --- atusb/fw/boot.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/atusb/fw/boot.c b/atusb/fw/boot.c index 9bf74d5..3dad768 100644 --- a/atusb/fw/boot.c +++ b/atusb/fw/boot.c @@ -14,6 +14,7 @@ #include #include +#include #define F_CPU 8000000UL #include @@ -34,6 +35,11 @@ static void (*run_payload)(void) = 0; int main(void) { + /* + * pgm_read_byte gets cached and there doesn't seem to be any other + * way to dissuade gcc from doing this. + */ + volatile int zero = 0; uint32_t loop = 0; board_init(); @@ -49,7 +55,7 @@ int main(void) while (loop != MS_TO_LOOPS(2000)) { usb_poll(); - if (dfu.state == dfuIDLE) + if (dfu.state == dfuIDLE && pgm_read_byte(zero) != 0xff) loop++; else loop = 0;