Skip to content

Commit

Permalink
make st-flash clean up on sigint/term/segv, make gdb-server clean up …
Browse files Browse the repository at this point in the history
…on sigsegv.
  • Loading branch information
gtalusan committed Feb 23, 2016
1 parent 969fa12 commit 09a8113
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions flash/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// TODO - this should be done as just a simple flag to the st-util command line...


#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -12,6 +13,19 @@
#define DEBUG_LOG_LEVEL 100
#define STND_LOG_LEVEL 50

stlink_t *connected_stlink = NULL;

static void cleanup(int signal __attribute__((unused))) {
if (connected_stlink) {
/* Switch back to mass storage mode before closing. */
stlink_run(connected_stlink);
stlink_exit_debug_mode(connected_stlink);
stlink_close(connected_stlink);
}

exit(1);
}

enum st_cmds {DO_WRITE = 0, DO_READ = 1, DO_ERASE = 2};
struct opts
{
Expand Down Expand Up @@ -174,6 +188,11 @@ int main(int ac, char** av)
sl->verbose = o.log_level;
}

connected_stlink = sl;
signal(SIGINT, &cleanup);
signal(SIGTERM, &cleanup);
signal(SIGSEGV, &cleanup);

if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE)
stlink_exit_dfu_mode(sl);

Expand Down
2 changes: 1 addition & 1 deletion gdbserver/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#ifdef __MINGW32__
Expand Down Expand Up @@ -186,6 +185,7 @@ int main(int argc, char** argv) {
connected_stlink = sl;
signal(SIGINT, &cleanup);
signal(SIGTERM, &cleanup);
signal(SIGSEGV, &cleanup);

if (state.reset) {
stlink_reset(sl);
Expand Down

0 comments on commit 09a8113

Please sign in to comment.