Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SIGINT handler for stlink cleanup #135

Merged
merged 1 commit into from
Mar 6, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions gdbserver/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
//Allways update the FLASH_PAGE before each use, by calling stlink_calculate_pagesize
#define FLASH_PAGE (sl->flash_pgsz)

stlink_t *connected_stlink = NULL;

static const char hex[] = "0123456789abcdef";

static const char* current_memory_map = NULL;
Expand All @@ -54,6 +56,16 @@ typedef struct _st_state_t {
int serve(stlink_t *sl, st_state_t *st);
char* make_memory_map(stlink_t *sl);

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);
}

int parse_options(int argc, char** argv, st_state_t *st) {
static struct option long_options[] = {
Expand Down Expand Up @@ -172,6 +184,9 @@ int main(int argc, char** argv) {
break;
}

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

printf("Chip ID is %08x, Core ID is %08x.\n", sl->chip_id, sl->core_id);

sl->verbose=0;
Expand Down