st->off = sram_base + off;
stlink_read_mem32(sl, st->off + 4, 4);
st->bufsize = (size_t) *(unsigned char*) sl->q_buf;
- printf("stlinky buffer size 0x%zu\n", st->bufsize);
+ printf("stlinky buffer size 0x%zu \n", st->bufsize);
return st;
}
}
}
static int keep_running = 1;
+static int sigcount=0;
void cleanup(int dummy)
{
+ sigcount++;
keep_running = 0;
- printf("\n\nGot a signal - terminating\n");
+ printf("\n\nGot a signal\n");
+ if (sigcount==2) {
+ printf("\n\nGot a second signal - bailing out\n");
+ exit(1);
+ }
}
struct stlinky *st = stlinky_detect(sl);
if (st == NULL)
{
- printf("stlinky magic not found in sram :(");
+ printf("stlinky magic not found in sram :(\n");
+ goto bailout;
}
char* rxbuf = malloc(st->bufsize);
char* txbuf = malloc(st->bufsize);
int saved_flags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, saved_flags & ~O_NONBLOCK);
signal(SIGINT, cleanup);
- printf("Entering interactive terminal. CTRL+C to exit\n");
+ printf("Entering interactive terminal. CTRL+C to exit\n\n\n");
while(1) {
if (stlinky_canrx(st)) {
tmp = stlinky_rx(st, rxbuf);
if (!keep_running)
break;
}
+ bailout:
nonblock(0);
stlink_exit_debug_mode(sl);
stlink_close(sl);