X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fst-info.c;fp=src%2Fst-info.c;h=2cea40e5c2b602a45aabde482d48f646e68df085;hb=6fe3a02c18ccfc8d5d9b15b6de1ac01f40fdaf33;hp=66d9fb391776556a0d2f30bf291b1d2709404dfc;hpb=17e3571a93284410ae96e8e4b227ca93bd87e065;p=fw%2Fstlink diff --git a/src/st-info.c b/src/st-info.c index 66d9fb3..2cea40e 100644 --- a/src/st-info.c +++ b/src/st-info.c @@ -1,13 +1,9 @@ -/* simple wrapper around the stlink_flash_write function */ - -// TODO - this should be done as just a simple flag to the st-util command line... - - #include #include #include #include -#include "stlink-common.h" + +#include static void usage(void) { @@ -16,9 +12,52 @@ static void usage(void) puts("st-info --descr"); puts("st-info --pagesize"); puts("st-info --chipid"); + puts("st-info --serial"); + puts("st-info --probe"); +} + +static void stlink_print_info(stlink_t *sl) +{ + const chip_params_t *params = NULL; + + if (!sl) + return; + + for (int n = 0; n < sl->serial_size; n++) + printf("%02x", sl->serial[n]); + printf("\n"); + + printf("\t flash: %zu (pagesize: %zu)\n", sl->flash_size, sl->flash_pgsz); + printf("\t sram: %zu\n", sl->sram_size); + printf("\tchipid: 0x%.4x\n", sl->chip_id); + + for (size_t i = 0; i < sizeof(devices) / sizeof(devices[0]); i++) { + if (devices[i].chip_id == sl->chip_id) { + params = &devices[i]; + break; + } + } + + if (params) + printf("\t descr: %s\n", params->description); +} + +static void stlink_probe(void) +{ + stlink_t **stdevs; + size_t size; + + size = stlink_probe_usb(&stdevs); + + printf("Found %zu stlink programmers\n", size); + + for (size_t n = 0; n < size; n++) + stlink_print_info(stdevs[n]); + + stlink_probe_usb_free(&stdevs, size); } -static int print_data(stlink_t* sl, char** av) +static int print_data(stlink_t *sl, char **av) { int ret = 0; if (strcmp(av[1], "--flash") == 0) @@ -29,7 +68,13 @@ static int print_data(stlink_t* sl, char** av) printf("0x%zx\n", sl->flash_pgsz); else if (strcmp(av[1], "--chipid") == 0) printf("0x%.4x\n", sl->chip_id); - else if (strcmp(av[1], "--descr")==0) { + else if (strcmp(av[1], "--probe") == 0) + stlink_probe(); + else if (strcmp(av[1], "--serial") == 0) { + for (int n = 0; n < sl->serial_size; n++) + printf("%02x", sl->serial[n]); + printf("\n"); + } else if (strcmp(av[1], "--descr") == 0) { const chip_params_t *params = NULL; for (size_t i = 0; i < sizeof(devices) / sizeof(devices[0]); i++) { if(devices[i].chip_id == sl->chip_id) { @@ -51,7 +96,7 @@ stlink_t* open_sl(void) stlink_t* sl; sl = stlink_v1_open(0, 1); if (sl == NULL) - sl = stlink_open_usb(0, 1, NULL); + sl = stlink_open_usb(0, 1, NULL); return sl; }