From: Michael Pratt Date: Wed, 6 Mar 2013 20:24:15 +0000 (-0500) Subject: Add option to not reset board on connect X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=596fb35916ef2f1da8b817fa4b6e365e71c0fc5a;p=fw%2Fstlink Add option to not reset board on connect '-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. --- diff --git a/flash/main.c b/flash/main.c index 110c296..980af63 100644 --- a/flash/main.c +++ b/flash/main.c @@ -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; } diff --git a/gdbserver/gdb-server.c b/gdbserver/gdb-server.c index f9c06f9..d0a6a02 100644 --- a/gdbserver/gdb-server.c +++ b/gdbserver/gdb-server.c @@ -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"); /* diff --git a/src/st-term.c b/src/st-term.c index f464393..9be3263 100644 --- a/src/st-term.c +++ b/src/st-term.c @@ -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); diff --git a/src/stlink-sg.c b/src/stlink-sg.c index ae610ba..be1f752 100644 --- a/src/stlink-sg.c +++ b/src/stlink-sg.c @@ -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; diff --git a/src/stlink-sg.h b/src/stlink-sg.h index beecac3..f8871db 100644 --- a/src/stlink-sg.h +++ b/src/stlink-sg.h @@ -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 } diff --git a/src/stlink-usb.c b/src/stlink-usb.c index 9895da8..858361c 100644 --- a/src/stlink-usb.c +++ b/src/stlink-usb.c @@ -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); diff --git a/src/stlink-usb.h b/src/stlink-usb.h index 63b5369..f433193 100644 --- a/src/stlink-usb.h +++ b/src/stlink-usb.h @@ -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 diff --git a/src/test_sg.c b/src/test_sg.c index 51b0f07..bc16a1c 100644 --- a/src/test_sg.c +++ b/src/test_sg.c @@ -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; diff --git a/src/test_usb.c b/src/test_usb.c index be4981d..5e8806d 100644 --- a/src/test_usb.c +++ b/src/test_usb.c @@ -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);