Add option to not reset board on connect
authorMichael Pratt <michael@pratt.im>
Wed, 6 Mar 2013 20:24:15 +0000 (15:24 -0500)
committerMichael Pratt <michael@pratt.im>
Sun, 18 Aug 2013 18:44:58 +0000 (14:44 -0400)
'-n' in st-util will cause it to skip the reset step, and thus allow you
to begin debugging at whatever point the code may currently be at.

Adding this feature required changing the stlink_open functions to
accept a reset flag that tells them whether or not to reset after
connecting.  Skipping reset does not seem to have any adverse effects on
stlink usb devices.  Unfortunately, I have to stlink v1 devices to test.

flash/main.c
gdbserver/gdb-server.c
src/st-term.c
src/stlink-sg.c
src/stlink-sg.h
src/stlink-usb.c
src/stlink-usb.h
src/test_sg.c
src/test_usb.c

index 110c2964d894fc85136e7ea65adf6c8842ec120a..980af63be66dc714d3c5f0a65df9fab1ac79f2d2 100644 (file)
@@ -106,13 +106,13 @@ int main(int ac, char** av)
 
   if (o.devname != NULL) /* stlinkv1 */
   {
-    sl = stlink_v1_open(50);
+    sl = stlink_v1_open(50, 1);
     if (sl == NULL) goto on_error;
     sl->verbose = 50;
   }
   else /* stlinkv2 */
   {
-    sl = stlink_open_usb(50);
+    sl = stlink_open_usb(50, 1);
     if (sl == NULL) goto on_error;
     sl->verbose = 50;
   }
index f9c06f9831b17fee476e36b12e42472ad63ce4fe..d0a6a02d7e9be3f88e6f5316ff8466401bc7920d 100644 (file)
@@ -50,6 +50,7 @@ typedef struct _st_state_t {
     int logging_level;
        int listen_port;
     int persistent;
+    int reset;
 } st_state_t;
 
 
@@ -78,6 +79,7 @@ int parse_options(int argc, char** argv, st_state_t *st) {
         {"stlinkv1", no_argument, NULL, '1'},
                {"listen_port", required_argument, NULL, 'p'},
                {"multi", optional_argument, NULL, 'm'},
+               {"no-reset", optional_argument, NULL, 'n'},
         {0, 0, 0, 0},
     };
        const char * help_str = "%s - usage:\n\n"
@@ -95,13 +97,15 @@ int parse_options(int argc, char** argv, st_state_t *st) {
     "  -m, --multi\n"
     "\t\t\tSet gdb server to extended mode.\n"
     "\t\t\tst-util will continue listening for connections after disconnect.\n"
+    "  -n, --no-reset\n"
+    "\t\t\tDo not reset board on connection.\n"
        ;
 
 
     int option_index = 0;
     int c;
     int q;
-    while ((c = getopt_long(argc, argv, "hv::d:s:1p:m", long_options, &option_index)) != -1) {
+    while ((c = getopt_long(argc, argv, "hv::d:s:1p:mn", long_options, &option_index)) != -1) {
         switch (c) {
         case 0:
             printf("XXXXX Shouldn't really normally come here, only if there's no corresponding option\n");
@@ -151,6 +155,9 @@ int parse_options(int argc, char** argv, st_state_t *st) {
                case 'm':
                        st->persistent = 1;
                        break;
+               case 'n':
+                       st->reset = 0;
+                       break;
         }
     }
 
@@ -174,14 +181,15 @@ int main(int argc, char** argv) {
        state.stlink_version = 2;
        state.logging_level = DEFAULT_LOGGING_LEVEL;
        state.listen_port = DEFAULT_GDB_LISTEN_PORT;
+       state.reset = 1;    /* By default, reset board */
        parse_options(argc, argv, &state);
        switch (state.stlink_version) {
        case 2:
-               sl = stlink_open_usb(state.logging_level);
+               sl = stlink_open_usb(state.logging_level, 0);
                if(sl == NULL) return 1;
                break;
        case 1:
-               sl = stlink_v1_open(state.logging_level);
+               sl = stlink_v1_open(state.logging_level, 0);
                if(sl == NULL) return 1;
                break;
     }
@@ -190,6 +198,10 @@ int main(int argc, char** argv) {
     signal(SIGINT, &cleanup);
     signal(SIGTERM, &cleanup);
 
+    if (state.reset) {
+               stlink_reset(sl);
+    }
+
        printf("Chip ID is %08x, Core ID is  %08x.\n", sl->chip_id, sl->core_id);
 
        sl->verbose=0;
@@ -205,6 +217,9 @@ int main(int argc, char** argv) {
 
        do {
                serve(sl, &state);
+
+               /* Continue */
+               stlink_run(sl);
        } while (state.persistent);
 
 #ifdef __MINGW32__
@@ -213,7 +228,6 @@ winsock_error:
 #endif
 
        /* Switch back to mass storage mode before closing. */
-       stlink_run(sl);
        stlink_exit_debug_mode(sl);
        stlink_close(sl);
 
@@ -679,11 +693,6 @@ int serve(stlink_t *sl, st_state_t *st) {
                return 1;
        }
 
-       stlink_force_debug(sl);
-       stlink_reset(sl);
-       init_code_breakpoints(sl);
-       init_data_watchpoints(sl);
-
        printf("Listening at *:%d...\n", st->listen_port);
 
        int client = accept(sock, NULL, NULL);
@@ -695,6 +704,13 @@ int serve(stlink_t *sl, st_state_t *st) {
 
        close(sock);
 
+       stlink_force_debug(sl);
+       if (st->reset) {
+               stlink_reset(sl);
+    }
+       init_code_breakpoints(sl);
+       init_data_watchpoints(sl);
+
        printf("GDB connected.\n");
 
        /*
index f4643933c015d0316242df4cabf13c9dc7c359e4..9be3263afde7d8d4b8771810d2c4825a7fa2f4a1 100644 (file)
@@ -136,7 +136,7 @@ int main(int ac, char** av) {
        /* unused */
        ac = ac;
        av = av;
-       sl = stlink_open_usb(10);
+       sl = stlink_open_usb(10, 1);
        if (sl != NULL) {
                printf("ST-Linky proof-of-concept terminal :: Created by Necromant for lulz\n");
                stlink_version(sl);
index ae610bac7d71ac9cf85ff9d5d4417bd73da63c8a..be1f7526b8fcee4cdf125702742a5060c50f487d 100644 (file)
@@ -1021,7 +1021,7 @@ stlink_t* stlink_v1_open_inner(const int verbose) {
     return sl;
 }
 
-stlink_t* stlink_v1_open(const int verbose) {
+stlink_t* stlink_v1_open(const int verbose, int reset) {
     stlink_t *sl = stlink_v1_open_inner(verbose);
     if (sl == NULL) {
         fputs("Error: could not open stlink device\n", stderr);
@@ -1030,7 +1030,9 @@ stlink_t* stlink_v1_open(const int verbose) {
     // by now, it _must_ be fully open and in a useful mode....
        stlink_enter_swd_mode(sl);
     /* Now we are ready to read the parameters  */
-    stlink_reset(sl);
+    if (reset) {
+        stlink_reset(sl);
+    }
     stlink_load_device_params(sl);
     ILOG("Successfully opened a stlink v1 debugger\n");
     return sl;
index beecac324e63b9408f1353789c70dedbacb17bb3..f8871db99a8c855c6e3f283a3c1f6c263c5d761c 100644 (file)
@@ -63,7 +63,7 @@ extern "C" {
         reg reg;
     };
 
-    stlink_t* stlink_v1_open(const int verbose);
+    stlink_t* stlink_v1_open(const int verbose, int reset);
 
 #ifdef __cplusplus
 }
index 9895da85573c166209767513ae97ae8d300cfb7a..858361c6695a2d65affe60f8aa32f163e1c5ba5d 100644 (file)
@@ -704,7 +704,7 @@ stlink_backend_t _stlink_usb_backend = {
 };
 
 
-stlink_t* stlink_open_usb(const int verbose) {
+stlink_t* stlink_open_usb(const int verbose, int reset) {
     stlink_t* sl = NULL;
     struct stlink_libusb* slu = NULL;
     int error = -1;
@@ -833,7 +833,9 @@ stlink_t* stlink_open_usb(const int verbose) {
       stlink_enter_swd_mode(sl);
     }
 
-    stlink_reset(sl);
+    if (reset) {
+        stlink_reset(sl);
+    }
     stlink_load_device_params(sl);
     stlink_version(sl);
 
index 63b53695e270fd5ecd1e5ec28ae6c4636d630ba3..f433193c81eae6ce95c20dbaa189f8f281c81c98 100644 (file)
@@ -30,7 +30,7 @@ extern "C" {
         unsigned int cmd_len;
     };
     
-    stlink_t* stlink_open_usb(const int verbose);
+    stlink_t* stlink_open_usb(const int verbose, int reset);
 
 
 #ifdef __cplusplus
index 51b0f074ca6f3dbc0c14c7683a67c026f6896733..bc16a1c7c8815be48adf48d7107cff6d9c1f783c 100644 (file)
@@ -52,7 +52,7 @@ int main(int argc, char *argv[]) {
         break;
        }
 
-       stlink_t *sl = stlink_v1_open(99);
+       stlink_t *sl = stlink_v1_open(99, 1);
        if (sl == NULL)
                return EXIT_FAILURE;
     
index be4981db051069cc0c97f0ee34572c56d9a59bcd..5e8806d29adde40d719807363195bd4e2899ad5a 100644 (file)
@@ -10,7 +10,7 @@ int main(int ac, char** av) {
     ac = ac;
     av = av;
 
-    sl = stlink_open_usb(10);
+    sl = stlink_open_usb(10, 1);
     if (sl != NULL) {
         printf("-- version\n");
         stlink_version(sl);