- {
- sl = stlink_open_usb(50, 1);
- if (sl == NULL) goto on_error;
- sl->verbose = 50;
+ sl = stlink_open_usb(o.log_level, 1, o.serial);
+
+ if (sl == NULL)
+ return -1;
+
+ 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) {
+ if (stlink_exit_dfu_mode(sl)) {
+ printf("Failed to exit DFU mode\n");
+ goto on_error;
+ }