1 /* simple wrapper around the stlink_flash_write function */
6 #include "stlink-common.h"
9 int main(int ac, char** av)
11 /* stlinkv1 command line: ./flash /dev/sgX path addr */
12 /* stlinkv2 command line: ./flash path addr */
19 if (ac == 4) /* stlinkv1 */
21 static const int scsi_verbose = 2;
22 sl = stlink_quirk_open(av[1], scsi_verbose);
24 addr = strtoul(av[3], NULL, 16);
26 else if (ac == 3) /* stlinkv2 */
28 sl = stlink_open_usb(NULL, 10);
30 addr = strtoul(av[2], NULL, 16);
34 printf("invalid command line\n");
38 if (sl == NULL) goto on_error;
40 if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE)
41 stlink_exit_dfu_mode(sl);
42 stlink_enter_swd_mode(sl);
45 err = stlink_fwrite_flash(sl, path, addr);
48 printf("stlink_fwrite_flash() == -1\n");
56 if (sl != NULL) stlink_close(sl);