From cd22b050a9d7c14e9b1a71c96df2686b76c0e69c Mon Sep 17 00:00:00 2001 From: Warren Gay Date: Sat, 18 Mar 2017 20:35:49 -0400 Subject: [PATCH 1/8] Added -chipid=xxxx to st-flash command line for F103 128k support --- include/stlink/tools/flash.h | 5 ++++- src/tools/flash.c | 22 ++++++++++++++++------ src/tools/flash_opts.c | 7 ++++++- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/stlink/tools/flash.h b/include/stlink/tools/flash.h index 6a7b05484..0c93e57fb 100644 --- a/include/stlink/tools/flash.h +++ b/include/stlink/tools/flash.h @@ -4,6 +4,8 @@ #include #include +#include + #define DEBUG_LOG_LEVEL 100 #define STND_LOG_LEVEL 50 @@ -20,9 +22,10 @@ struct flash_opts int reset; int log_level; enum flash_format format; + enum stlink_stm32_chipids chipid; }; -#define FLASH_OPTS_INITIALIZER {0, NULL, {}, NULL, 0, 0, 0, 0, 0 } +#define FLASH_OPTS_INITIALIZER {0, NULL, {}, NULL, 0, 0, 0, 0, 0, 0 } int flash_get_opts(struct flash_opts* o, int ac, char** av); diff --git a/src/tools/flash.c b/src/tools/flash.c index f2c186e95..b84e219a3 100644 --- a/src/tools/flash.c +++ b/src/tools/flash.c @@ -29,14 +29,18 @@ static void cleanup(int signum) { static void usage(void) { - puts("stlinkv1 command line: ./st-flash [--debug] [--reset] [--format ] {read|write} /dev/sgX "); - puts("stlinkv1 command line: ./st-flash [--debug] /dev/sgX erase"); - puts("stlinkv2 command line: ./st-flash [--debug] [--reset] [--serial ] [--format ] {read|write} "); - puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] erase"); - puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] reset"); - puts(" Use hex format for addr, and ."); + puts("stlinkv1 command line: ./st-flash [--debug] [--reset] [--format ] [--chipid ] {read|write} /dev/sgX "); + puts("stlinkv1 command line: ./st-flash [--debug] [--chipid ] /dev/sgX erase"); + puts("stlinkv2 command line: ./st-flash [--debug] [--reset] [--serial ] [--format ] [--chipid ] {read|write} "); + puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] [--chipid ] erase"); + puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] [--chipid ] reset"); + puts(" Use hex format for addr, , and ."); puts(" Format may be 'binary' (default) or 'ihex', although must be specified for binary format only."); puts(" ./st-flash [--version]"); + puts("Note:"); + printf(" --chipid=0x%04X is F1 medium density, 0x%04X is F1 high density\n", + STLINK_CHIPID_STM32_F1_MEDIUM, + STLINK_CHIPID_STM32_F1_HIGH); } int main(int ac, char** av) @@ -64,6 +68,12 @@ int main(int ac, char** av) if (sl == NULL) return -1; + if ( (int)o.chipid != 0 ) { + if ( o.chipid == STLINK_CHIPID_STM32_F1_HIGH ) + sl->flash_size = 128 * 1024; + printf("Forcing chipid 0x%04X with %uk flash.\n",o.chipid,(unsigned)(sl->flash_size)/1024u); + } + sl->verbose = o.log_level; connected_stlink = sl; diff --git a/src/tools/flash_opts.c b/src/tools/flash_opts.c index c98424348..aa6329ed5 100644 --- a/src/tools/flash_opts.c +++ b/src/tools/flash_opts.c @@ -77,7 +77,12 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) else return -1; } - else { + else if ( starts_with(av[0], "--chipid=") ) { + const char *arg = av[0] + strlen("--chipid="); + + o->chipid = (enum stlink_stm32_chipids)strtol(arg,0,0); + } + else { break; // non-option found } From 5cd9cc8e4b122920a5c3a58db9b32120fadf6a7a Mon Sep 17 00:00:00 2001 From: Warren Gay Date: Sun, 19 Mar 2017 20:26:20 -0400 Subject: [PATCH 2/8] rm chipid + added flash_size for --flash= --- include/stlink/tools/flash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stlink/tools/flash.h b/include/stlink/tools/flash.h index 0c93e57fb..fe22e4f70 100644 --- a/include/stlink/tools/flash.h +++ b/include/stlink/tools/flash.h @@ -22,7 +22,7 @@ struct flash_opts int reset; int log_level; enum flash_format format; - enum stlink_stm32_chipids chipid; + uint32_t flash_size; /* --flash=n[k][m] */ }; #define FLASH_OPTS_INITIALIZER {0, NULL, {}, NULL, 0, 0, 0, 0, 0, 0 } From 91c2afa8e56ac2e83f152b5f856ccb4f9c3b113a Mon Sep 17 00:00:00 2001 From: Warren Gay Date: Sun, 19 Mar 2017 20:27:01 -0400 Subject: [PATCH 3/8] rm --chipid= + added --flash=n[k][m] --- src/tools/flash_opts.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/tools/flash_opts.c b/src/tools/flash_opts.c index aa6329ed5..4fa39de4c 100644 --- a/src/tools/flash_opts.c +++ b/src/tools/flash_opts.c @@ -77,11 +77,29 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) else return -1; } - else if ( starts_with(av[0], "--chipid=") ) { - const char *arg = av[0] + strlen("--chipid="); - - o->chipid = (enum stlink_stm32_chipids)strtol(arg,0,0); - } + else if ( starts_with(av[0], "--flash=") ) { + const char *arg = av[0] + strlen("--flash="); + char *ep = 0; + + o->flash_size = (uint32_t)strtoul(arg,&ep,0); + while ( *ep ) { + switch ( *ep++ ) { + case 0: + break; + case 'k': + case 'K': + o->flash_size *= 1024u; + break; + case 'm': + case 'M': + o->flash_size *= 1024u * 1024u; + break; + default: + fprintf(stderr,"Invalid --flash=%s\n",arg); + return -1; + } + } + } else { break; // non-option found } From 9c510600bb3c11ed0596bb40f8663cde803eaf77 Mon Sep 17 00:00:00 2001 From: Warren Gay Date: Sun, 19 Mar 2017 20:27:31 -0400 Subject: [PATCH 4/8] rm --chipid + added --flash=n[k][m] --- src/tools/flash.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/tools/flash.c b/src/tools/flash.c index b84e219a3..936e4a51c 100644 --- a/src/tools/flash.c +++ b/src/tools/flash.c @@ -29,18 +29,15 @@ static void cleanup(int signum) { static void usage(void) { - puts("stlinkv1 command line: ./st-flash [--debug] [--reset] [--format ] [--chipid ] {read|write} /dev/sgX "); - puts("stlinkv1 command line: ./st-flash [--debug] [--chipid ] /dev/sgX erase"); - puts("stlinkv2 command line: ./st-flash [--debug] [--reset] [--serial ] [--format ] [--chipid ] {read|write} "); - puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] [--chipid ] erase"); - puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] [--chipid ] reset"); + puts("stlinkv1 command line: ./st-flash [--debug] [--reset] [--format ] [--flash=] {read|write} /dev/sgX "); + puts("stlinkv1 command line: ./st-flash [--debug] /dev/sgX erase"); + puts("stlinkv2 command line: ./st-flash [--debug] [--reset] [--serial ] [--format ] [--flash=] {read|write} "); + puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] erase"); + puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] reset"); puts(" Use hex format for addr, , and ."); + puts(" fsize: Use decimal, octal or hex by prefix 0xXXX for hex, optionally followed by k=KB, or m=MB (eg. --flash=128k)"); puts(" Format may be 'binary' (default) or 'ihex', although must be specified for binary format only."); puts(" ./st-flash [--version]"); - puts("Note:"); - printf(" --chipid=0x%04X is F1 medium density, 0x%04X is F1 high density\n", - STLINK_CHIPID_STM32_F1_MEDIUM, - STLINK_CHIPID_STM32_F1_HIGH); } int main(int ac, char** av) @@ -68,10 +65,9 @@ int main(int ac, char** av) if (sl == NULL) return -1; - if ( (int)o.chipid != 0 ) { - if ( o.chipid == STLINK_CHIPID_STM32_F1_HIGH ) - sl->flash_size = 128 * 1024; - printf("Forcing chipid 0x%04X with %uk flash.\n",o.chipid,(unsigned)(sl->flash_size)/1024u); + if ( o.flash_size != 0u && o.flash_size != sl->flash_size ) { + sl->flash_size = o.flash_size; + printf("Forcing flash size: --flash=0x%08zX\n",sl->flash_size); } sl->verbose = o.log_level; From e2e4fa744faf346a6d52b3f0102489ad10589e86 Mon Sep 17 00:00:00 2001 From: Warren Gay Date: Mon, 20 Mar 2017 22:28:25 -0400 Subject: [PATCH 5/8] rm unneeded include + change uint32_t to size_t --- include/stlink/tools/flash.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/stlink/tools/flash.h b/include/stlink/tools/flash.h index fe22e4f70..35b3a4251 100644 --- a/include/stlink/tools/flash.h +++ b/include/stlink/tools/flash.h @@ -4,8 +4,6 @@ #include #include -#include - #define DEBUG_LOG_LEVEL 100 #define STND_LOG_LEVEL 50 @@ -22,7 +20,7 @@ struct flash_opts int reset; int log_level; enum flash_format format; - uint32_t flash_size; /* --flash=n[k][m] */ + size_t flash_size; /* --flash=n[k][m] */ }; #define FLASH_OPTS_INITIALIZER {0, NULL, {}, NULL, 0, 0, 0, 0, 0, 0 } From f2d7f8ed613ac3002c3cec1ef4099a0acf4c0996 Mon Sep 17 00:00:00 2001 From: Warren Gay Date: Mon, 20 Mar 2017 22:31:03 -0400 Subject: [PATCH 6/8] Added --flash description --- doc/man/st-flash.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/man/st-flash.md b/doc/man/st-flash.md index 4eacb7a07..d1844976c 100644 --- a/doc/man/st-flash.md +++ b/doc/man/st-flash.md @@ -49,6 +49,10 @@ reset --serial *iSerial* : TODO +--flash=fsize +: Where fsize is the size in decimal, octal, or hex followed by an optional multiplier +'k' for KB, or 'm' for MB. +Use a leading "0x" to specify hexadecimal, or a leading zero for octal. # EXAMPLES Flash `firmware.bin` to device From 0614f52aef4dd73647fb2d0638922fc0f6c290ca Mon Sep 17 00:00:00 2001 From: Warren Gay Date: Mon, 20 Mar 2017 22:45:45 -0400 Subject: [PATCH 7/8] Added man page description for --flash=size argument --- doc/man/st-flash.1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/man/st-flash.1 b/doc/man/st-flash.1 index 252ffcba8..77a8bb550 100644 --- a/doc/man/st-flash.1 +++ b/doc/man/st-flash.1 @@ -53,6 +53,14 @@ TODO TODO .RS .RE +.TP +.B --flash=\f[I]size\f[] +Override the device's normal flash size, where size is the flash size in bytes. +It can be specified in decimal, octal or hexadecimal. +The size argument can optionally be followed by 'k' for KB or 'm' for MB. +Examples --flash=128k or --flash=0x080k. +.RS +.RE .SH EXAMPLES .PP Flash \f[C]firmware.bin\f[] to device From 8b5aad70d8282dc2e2c78bdc6d389e0025ebe207 Mon Sep 17 00:00:00 2001 From: Warren Gay Date: Mon, 20 Mar 2017 22:56:46 -0400 Subject: [PATCH 8/8] rm old ref to chipid in the usage display --- src/tools/flash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/flash.c b/src/tools/flash.c index 936e4a51c..6fe365f88 100644 --- a/src/tools/flash.c +++ b/src/tools/flash.c @@ -34,7 +34,7 @@ static void usage(void) puts("stlinkv2 command line: ./st-flash [--debug] [--reset] [--serial ] [--format ] [--flash=] {read|write} "); puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] erase"); puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] reset"); - puts(" Use hex format for addr, , and ."); + puts(" Use hex format for addr, and ."); puts(" fsize: Use decimal, octal or hex by prefix 0xXXX for hex, optionally followed by k=KB, or m=MB (eg. --flash=128k)"); puts(" Format may be 'binary' (default) or 'ihex', although must be specified for binary format only."); puts(" ./st-flash [--version]");