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

[refactoring] st-util: removed now useless v1/v2 STLink version stuff #934

Merged
merged 3 commits into from
Apr 22, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/man/st-flash.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ You can use this instead of st-util(1) if you prefer, but remember to use the

Use hexadecimal format for the *ADDR* and *SIZE*.

The STLink device to use can be specified using the --serial parameter, or via
the environment variable STLINK_DEVICE on the format <USB_BUS>:<USB_ADDR>.

# COMMANDS

write *FILE* *ADDR*
Expand Down
3 changes: 3 additions & 0 deletions doc/man/st-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ st-info - Provides information about connected STLink and STM32 devices


# DESCRIPTION

Provides information about connected STLink programmers and STM32 devices:
Serial code, OpenOCD hla-serial, flash, page size, sram, chipid, description.

The STLink device to probe can be specified via the environment variable
STLINK_DEVICE on the format <USB_BUS>:<USB_ADDR>.

# OPTIONS

Expand Down
12 changes: 2 additions & 10 deletions doc/man/st-util.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ Run the main binary of the local package (src/main.rs).
If a port number is not specified using the **--listen_port** option, the
default **4242** port will be used.

Stlink version 2 is used by default unless the option **--stlinkv1** is given.

The STLinkV2 device to use can be specified in the environment
variable STLINK_DEVICE on the format <USB_BUS>:<USB_ADDR>.
The STLink device to use can be specified using the --serial parameter, or via
the environment variable STLINK_DEVICE on the format <USB_BUS>:<USB_ADDR>.

# OPTIONS

Expand All @@ -36,12 +34,6 @@ variable STLINK_DEVICE on the format <USB_BUS>:<USB_ADDR>.
-v, \--verbose
: Specify generally verbose logging

-s *X*, \--stlink_version=*X*
: Choose what version of stlink to use, (defaults to 2)

-1, \--stlinkv1
: Force stlink version 1

-p *4242*, \--listen_port=1234
: Set the gdb server listen port. (default port: 4242)

Expand Down
29 changes: 8 additions & 21 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,14 @@ will help you verify that:
- Your arm-none-eabi-gdb is functional
- Your board is functional

A GDB server must be started to interact with the STM32. Depending on
the discovery kit you are using, you must run one of the 2 commands:
A GDB server must be started to interact with the STM32 by running
st-util tool :

```
# STM32VL discovery kit (onboard ST-link)
$> ./st-util --stlinkv1

# STM32L or STM32F4 discovery kit (onboard ST-link/V2)
$> ./st-util
$> st-util

# Full help for other options (listen port, version)
$> ./st-util --help
$> st-util --help
```

Then, GDB can be used to interact with the kit:
Expand Down Expand Up @@ -226,16 +222,10 @@ memory, or read arbitary addresses of memory out to a binary file, use
the st-flash tool, as shown below:

```
# stlinkv1 command to read 4096 from flash into out.bin
$> ./st-flash read out.bin 0x8000000 4096

# stlinkv2 command
# stlink command to read 4096 from flash into out.bin
$> ./st-flash read out.bin 0x8000000 4096

# stlinkv1 command to write the file in.bin into flash
$> ./st-flash write in.bin 0x8000000

# stlinkv2 command
# stlinkv command to write the file in.bin into flash
$> ./st-flash write in.bin 0x8000000
```

Expand Down Expand Up @@ -273,9 +263,6 @@ There are a few options:
-h, --help Print this help
-vXX, --verbose=XX Specify a specific verbosity level (0..99)
-v, --verbose Specify generally verbose logging
-s X, --stlink_version=X
Choose what version of stlink to use, (defaults to 2)
-1, --stlinkv1 Force stlink version 1
-p 4242, --listen_port=1234
Set the gdb server listen port. (default port: 4242)
-m, --multi
Expand All @@ -285,8 +272,8 @@ There are a few options:
Do not reset board on connection.
```

The STLINKv2 device to use can be specified in the environment
variable `STLINK_DEVICE` in the format `<USB_BUS>:<USB_ADDR>`.
The STLink device to use can be specified using the --serial parameter, or via
the environment variable STLINK_DEVICE on the format <USB_BUS>:<USB_ADDR>.

Then, in your project directory, someting like this...
(remember, you need to run an _ARM_ gdb, not an x86 gdb)
Expand Down
42 changes: 9 additions & 33 deletions src/gdbserver/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ static const char* current_memory_map = NULL;

typedef struct _st_state_t {
// things from command line, bleh
int stlink_version;
int logging_level;
int listen_port;
int persistent;
Expand All @@ -86,30 +85,20 @@ static void cleanup(int signum) {


static stlink_t* do_connect(st_state_t *st) {
stlink_t *ret = NULL;
switch (st->stlink_version) {
case 2:
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);
break;
stlink_t *sl = NULL;
if (serial_specified) {
sl = stlink_open_usb(st->logging_level, st->reset, serialnumber);
} else {
sl = stlink_open_usb(st->logging_level, st->reset, NULL);
}
return ret;
return sl;
}


int parse_options(int argc, char** argv, st_state_t *st) {
static struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"verbose", optional_argument, NULL, 'v'},
{"stlink_version", required_argument, NULL, 's'},
{"stlinkv1", no_argument, NULL, '1'},
{"listen_port", required_argument, NULL, 'p'},
{"multi", optional_argument, NULL, 'm'},
{"no-reset", optional_argument, NULL, 'n'},
Expand All @@ -123,7 +112,6 @@ int parse_options(int argc, char** argv, st_state_t *st) {
" -V, --version\t\tPrint the version\n"
" -vXX, --verbose=XX\tSpecify a specific verbosity level (0..99)\n"
" -v, --verbose\t\tSpecify generally verbose logging\n"
" -s X, --stlink_version=X\n"
"\t\t\tChoose what version of stlink to use, (defaults to 2)\n"
" -1, --stlinkv1\tForce stlink version 1\n"
" -p 4242, --listen_port=1234\n"
Expand All @@ -139,7 +127,7 @@ int parse_options(int argc, char** argv, st_state_t *st) {
" --serial <serial>\n"
"\t\t\tUse a specific serial number.\n"
"\n"
"The STLINKv2 device to use can be specified in the environment\n"
"The STLINK device to use can be specified in the environment\n"
"variable STLINK_DEVICE on the format <USB_BUS>:<USB_ADDR>.\n"
"\n"
;
Expand All @@ -148,7 +136,7 @@ int parse_options(int argc, char** argv, st_state_t *st) {
int option_index = 0;
int c;
int q;
while ((c = getopt_long(argc, argv, "hv::s:1p:mn", long_options, &option_index)) != -1) {
while ((c = getopt_long(argc, argv, "hv::p:mn", long_options, &option_index)) != -1) {
switch (c) {
case 0:
break;
Expand All @@ -163,17 +151,6 @@ int parse_options(int argc, char** argv, st_state_t *st) {
st->logging_level = DEBUG_LOGGING_LEVEL;
}
break;
case '1':
st->stlink_version = 1;
break;
case 's':
sscanf(optarg, "%i", &q);
if (q < 0 || q > 2) {
fprintf(stderr, "stlink version %d unknown!\n", q);
exit(EXIT_FAILURE);
}
st->stlink_version = q;
break;
case 'p':
sscanf(optarg, "%i", &q);
if (q < 0) {
Expand Down Expand Up @@ -225,13 +202,12 @@ int main(int argc, char** argv) {
memset(&state, 0, sizeof(state));

// set defaults...
state.stlink_version = 2;
state.logging_level = DEFAULT_LOGGING_LEVEL;
state.listen_port = DEFAULT_GDB_LISTEN_PORT;
state.reset = 1; /* By default, reset board */
parse_options(argc, argv, &state);

printf("st-util %s\n", STLINK_VERSION);
printf("st-util\n");

sl = do_connect(&state);
if (sl == NULL) return 1;
Expand Down