Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serialnumber support st-util and st-flash #541

Merged
merged 1 commit into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/gdbserver/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@

/* Semihosting doesn't have a short option, we define a value to identify it */
#define SEMIHOSTING_OPTION 128
#define SERIAL_OPTION 127

//Allways update the FLASH_PAGE before each use, by calling stlink_calculate_pagesize
#define FLASH_PAGE (sl->flash_pgsz)

static stlink_t *connected_stlink = NULL;
static bool semihosting = false;
static bool serial_specified = false;
static char serialnumber[28] = {0};

static const char hex[] = "0123456789abcdef";

Expand Down Expand Up @@ -73,7 +76,12 @@ static stlink_t* do_connect(st_state_t *st) {
stlink_t *ret = NULL;
switch (st->stlink_version) {
case 2:
ret = stlink_open_usb(st->logging_level, st->reset, NULL);
if(serial_specified){
ret = stlink_open_usb(st->logging_level, st->reset, serialnumber);
}
else{
ret = stlink_open_usb(st->logging_level, st->reset, NULL);
}
break;
case 1:
ret = stlink_v1_open(st->logging_level, st->reset);
Expand All @@ -94,6 +102,7 @@ int parse_options(int argc, char** argv, st_state_t *st) {
{"no-reset", optional_argument, NULL, 'n'},
{"version", no_argument, NULL, 'V'},
{"semihosting", no_argument, NULL, SEMIHOSTING_OPTION},
{"serial", required_argument, NULL, SERIAL_OPTION},
{0, 0, 0, 0},
};
const char * help_str = "%s - usage:\n\n"
Expand All @@ -114,6 +123,8 @@ int parse_options(int argc, char** argv, st_state_t *st) {
"\t\t\tDo not reset board on connection.\n"
" --semihosting\n"
"\t\t\tEnable semihosting support.\n"
" --serial <serial>\n"
"\t\t\tUse a specific serial number.\n"
"\n"
"The STLINKv2 device to use can be specified in the environment\n"
"variable STLINK_DEVICE on the format <USB_BUS>:<USB_ADDR>.\n"
Expand Down Expand Up @@ -170,6 +181,19 @@ int parse_options(int argc, char** argv, st_state_t *st) {
case SEMIHOSTING_OPTION:
semihosting = true;
break;
case SERIAL_OPTION:
printf("use serial %s\n",optarg);
/** @todo This is not really portable, as strlen really returns size_t we need to obey and not cast it to a signed type. */
int j = (int)strlen(optarg);
int length = j / 2; //the length of the destination-array
if(j % 2 != 0) return -1;
for(size_t k = 0; j >= 0 && k < sizeof(serialnumber); ++k, j -= 2) {
char buffer[3] = {0};
memcpy(buffer, optarg + j, 2);
serialnumber[length - k] = (uint8_t)strtol(buffer, NULL, 16);
}
serial_specified = true;
break;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/tools/flash_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av)

/** @todo This is not really portable, as strlen really returns size_t we need to obey and not cast it to a signed type. */
int j = (int)strlen(serial);
int length = j / 2; //the length of the destination-array
if(j % 2 != 0) return -1;

for(size_t k = 0; j >= 0 && k < sizeof(o->serial); ++k, j -= 2) {
char buffer[3] = {0};
memcpy(buffer, serial + j, 2);
o->serial[12 - k] = (uint8_t)strtol(buffer, NULL, 16);
o->serial[length - k] = (uint8_t)strtol(buffer, NULL, 16);
}

serial_specified = true;
Expand Down