ao-tools/ao-stmload: Add --verbose flag
authorKeith Packard <keithp@keithp.com>
Sat, 27 Apr 2013 07:26:11 +0000 (00:26 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 8 May 2013 04:30:26 +0000 (21:30 -0700)
This dumps out the serial communication so you can see where things go wrong.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-stmload/ao-selfload.c
ao-tools/ao-stmload/ao-stmload.c
ao-tools/ao-stmload/ao-stmload.h
ao-tools/lib/cc-usb.c

index b3105b211beebe8f046d62286b5b7d8c0c884cae..95667dcac21f4e8459d1729f344121a44140bc24 100644 (file)
 #include "ccdbg.h"
 #include "ao-stmload.h"
 
+int    ao_self_verbose;
+
+#define TRACE(...) if (ao_self_verbose) printf (__VA_ARGS__)
+
 void
 ao_self_block_read(struct cc_usb *cc, uint32_t address, uint8_t block[256])
 {
        int                     byte;
        cc_usb_sync(cc);
        cc_usb_printf(cc, "R %x\n", address);
-//     printf ("read %08x\n", address);
        for (byte = 0; byte < 0x100; byte++) {
                block[byte] = cc_usb_getchar(cc);
-//             printf (" %02x", block[byte]);
-//             if ((byte & 0xf) == 0xf)
-//                     printf ("\n");
+       }
+       TRACE ("\nread %08x\n", address);
+       for (byte = 0; byte < 0x100; byte++) {
+               TRACE (" %02x", block[byte]);
+               if ((byte & 0xf) == 0xf)
+                       TRACE ("\n");
        }
 }
 
@@ -47,12 +53,14 @@ ao_self_block_write(struct cc_usb *cc, uint32_t address, uint8_t block[256])
        int                     byte;
        cc_usb_sync(cc);
        cc_usb_printf(cc, "W %x\n", address);
-//     printf ("write %08x\n", address);
+       TRACE ("write %08x\n", address);
+       for (byte = 0; byte < 0x100; byte++) {
+               TRACE (" %02x", block[byte]);
+               if ((byte & 0xf) == 0xf)
+                       TRACE ("\n");
+       }
        for (byte = 0; byte < 0x100; byte++) {
                cc_usb_printf(cc, "%c", block[byte]);
-//             printf (" %02x", block[byte]);
-//             if ((byte & 0xf) == 0xf)
-//                     printf ("\n");
        }
 }
 
@@ -114,5 +122,6 @@ ao_self_write(struct cc_usb *cc, struct hex_image *image)
                putchar('.'); fflush(stdout);
        }
        printf("done\n");
+       cc_usb_printf(cc,"a\n");
        return 1;
 }
index 130f8707c75da8a0cb5c30952439c050d9403cf0..dd25f07f8e0cb6f2d355a15a72c1e09931a1c92e 100644 (file)
@@ -224,12 +224,13 @@ static const struct option options[] = {
        { .name = "device", .has_arg = 1, .val = 'D' },
        { .name = "cal", .has_arg = 1, .val = 'c' },
        { .name = "serial", .has_arg = 1, .val = 's' },
+       { .name = "verbose", .has_arg = 0, .val = 'v' },
        { 0, 0, 0, 0},
 };
 
 static void usage(char *program)
 {
-       fprintf(stderr, "usage: %s [--stlink] [--device=<device>] [-tty=<tty>] [--cal=<radio-cal>] [--serial=<serial>] file.{elf,ihx}\n", program);
+       fprintf(stderr, "usage: %s [--stlink] [--verbose] [--device=<device>] [-tty=<tty>] [--cal=<radio-cal>] [--serial=<serial>] file.{elf,ihx}\n", program);
        exit(1);
 }
 
@@ -286,8 +287,9 @@ main (int argc, char **argv)
        int                     use_stlink = 0;
        char                    *tty = NULL;
        int                     success;
+       int                     verbose = 0;
 
-       while ((c = getopt_long(argc, argv, "T:D:c:s:S", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "T:D:c:s:Sv", options, NULL)) != -1) {
                switch (c) {
                case 'T':
                        tty = optarg;
@@ -308,12 +310,20 @@ main (int argc, char **argv)
                case 'S':
                        use_stlink = 1;
                        break;
+               case 'v':
+                       verbose++;
+                       break;
                default:
                        usage(argv[0]);
                        break;
                }
        }
 
+       ao_self_verbose = verbose;
+
+       if (verbose > 1)
+               ccdbg_add_debug(CC_DEBUG_BITBANG);
+
        filename = argv[optind];
        if (filename == NULL)
                usage(argv[0]);
@@ -412,6 +422,7 @@ main (int argc, char **argv)
                        fprintf(stderr, "Cannot switch to boot loader\n");
                        exit(1);
                }
+#if 0
                {
                        uint8_t check[256];
                        int     i = 0;
@@ -433,6 +444,7 @@ main (int argc, char **argv)
                                }
                        }
                }
+#endif
        }
 
        /* Go fetch existing config values
index 754c1c5bc7cd9d46230a63ba7b8242a1d3338d1f..98884535f6ecaf4926685d4d99e70a807b31d00b 100644 (file)
@@ -44,4 +44,6 @@ ao_self_read(struct cc_usb *cc, uint32_t address, uint32_t length);
 int
 ao_self_write(struct cc_usb *cc, struct hex_image *image);
 
+extern int ao_self_verbose;
+
 #endif /* _AO_STMLOAD_H_ */
index 485583f98b3897c1816547ffc4b7ae95ee32a6b1..d7ac138c6e1210b87c6bae203d76569c23812e26 100644 (file)
@@ -123,9 +123,10 @@ cc_handle_hex_read(struct cc_usb *cc)
 static void
 cc_usb_dbg(int indent, uint8_t *bytes, int len)
 {
-       int     eol = 1;
+       static int      eol = 1;
        int     i;
        uint8_t c;
+       ccdbg_debug(CC_DEBUG_BITBANG, "<<<%d bytes>>>", len);
        while (len--) {
                c = *bytes++;
                if (eol) {
@@ -135,10 +136,12 @@ cc_usb_dbg(int indent, uint8_t *bytes, int len)
                }
                switch (c) {
                case '\r':
-                       ccdbg_debug(CC_DEBUG_BITBANG, "^M");
+                       ccdbg_debug(CC_DEBUG_BITBANG, "\\r");
                        break;
                case '\n':
                        eol = 1;
+                       ccdbg_debug(CC_DEBUG_BITBANG, "\\n\n");
+                       break;
                default:
                        if (c < ' ' || c > '~')
                                ccdbg_debug(CC_DEBUG_BITBANG, "\\%02x", c);
@@ -193,7 +196,6 @@ _cc_usb_sync(struct cc_usb *cc, int wait_for_input)
                        ret = read(cc->fd, cc->in_buf + cc->in_count,
                                   CC_IN_BUF - cc->in_count);
                        if (ret > 0) {
-                               int i;
                                cc_usb_dbg(24, cc->in_buf + cc->in_count, ret);
                                cc->in_count += ret;
                                if (cc->hex_count)