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

Probe and control multiple connected programmers #318

Closed
trichner opened this issue Jun 30, 2015 · 20 comments · Fixed by #398 or #541
Closed

Probe and control multiple connected programmers #318

trichner opened this issue Jun 30, 2015 · 20 comments · Fixed by #398 or #541

Comments

@trichner
Copy link

I have multiple STM32F0Discovery Boards wired up to an USB hub and would like to specify which one to flash (I'm using st-flash main.bin 0x800000 right now).

Is there a way to specify the USB port to use? or even an actual selection?

@texane
Copy link
Collaborator

texane commented Jun 30, 2015

Hi,

you can use the STLINK_DEVICE environment variable
to specify which device to use. VID:PID format.

2015-06-30 12:15 GMT+02:00 Thomas [email protected]:

I have multiple STM32F0Discovery Boards wired up to an USB hub and would
like to specify which one to flash (I'm using st-flash main.bin 0x800000
right now).

Is there a way to specify the USB port to use? or even an actual selection?


Reply to this email directly or view it on GitHub
#318.

@trichner
Copy link
Author

But all stlink programmers have the same VID:PID, they only differ in Bus/Device

Example lsusb dump:

Bus 002 Device 012: ID 0483:3748 STMicroelectronics ST-LINK/V2
Bus 001 Device 014: ID 0483:3748 STMicroelectronics ST-LINK/V2

@trichner
Copy link
Author

Well, if anybody ever has the same need and is looking for a solution: OpenOCD can use multiple devices/programmers by using the hla_serial command.

Edit: Altough it's quite bad, you must hope your serial can be expressed in visible ASCII chars, otherwise you will not be able to input them. I forked a version which now uses serials as hexstrings, circumventing the limitation: https://github.com/trichner/openocd

@shkhaliq
Copy link

shkhaliq commented Apr 7, 2016

Any updates on this issue?

@shkhaliq
Copy link

shkhaliq commented Apr 8, 2016

I got a workaround. Special thanks to @xor-gate for the st-probe tool. Use that tool to get the serial number.
Note the last byte is a null character, So if the serial number is 483f6e06703f53483324096700 use 483f6e06703f534833240967.

One of the caveats of getting the serial number is that you have to make sure the programmer is connected to the board and its in a connectable state.

After that just invoke st-flash --serial <serial_no> <your_command_here>.

@xor-gate
Copy link
Member

xor-gate commented Apr 8, 2016

@shkhaliq could you post your st-probe output, maybe it prints a spurious 00 as last byte? It seems I also have the same which adds the extra 00 byte:

jjacobs@workbench ~/repos/github/stlink/build $ ./st-probe
Found 2 stlink programmers
563f6706677256563113066700
         flash: 262144 (pagesize: 2048)
          sram: 65536
        chipid: 0x0414
         descr: F1 High-density device
493f6d06667048513615106700
         flash: 1048576 (pagesize: 16384)
          sram: 196608
        chipid: 0x0413
         descr: F4 device

For openocd I have the following hla_serial which has no trailing zero byte:
hla_serial "\x56\x3f\x67\x06\x67\x72\x56\x56\x31\x13\x06\x67"

So this means the serials of the programmers have exact 12 bytes. Maybe someone can acknowledge this so we have correct output for st-probe and the struct stlink_t serial field then needs only 12 bytes instead.

Here are some other pages related to this:

texane added a commit that referenced this issue Apr 16, 2016
Refactoring some code, merge st-probe and fixup #318 serial print
@xor-gate
Copy link
Member

xor-gate commented May 2, 2016

For your convenience st-probe has been merged into st-info -> st-info --probe and the hla serial string is also printed. When only one programmer is attached you can use st-info --hla-serial. Have fun! Maybe this issue can be closed then @trichner ?

@trichner
Copy link
Author

trichner commented May 2, 2016

I ended up forking OpenOCD and fixing the horrible binary input there: https://github.com/trichner/openocd

Edit: Thanks for fixing it in st-flash :)

@trichner trichner closed this as completed May 2, 2016
@xor-gate xor-gate changed the title Multiple Programmers Probe and control multiple connected programmers May 14, 2016
@xor-gate
Copy link
Member

We need some reworking and documentation here.

@xor-gate xor-gate reopened this May 14, 2016
@xor-gate xor-gate added this to the v1.3.0 milestone May 14, 2016
@xor-gate xor-gate self-assigned this Jun 18, 2016
@xor-gate xor-gate modified the milestones: v2.1.0, v2.0.0 Aug 3, 2016
@xor-gate xor-gate modified the milestones: Unplanned (Contributions Welcome), v2.1.0 Sep 19, 2016
@xor-gate xor-gate modified the milestones: v1.3.0, Unplanned (Contributions Welcome) Dec 30, 2016
@GagoSoft
Copy link
Contributor

GagoSoft commented Jan 10, 2017

Hallo
the serialnumber is a very nice thing, but it works only on my STM32F0-discovery ST-Link V2 ...
the standalone ST-Link V2 and the Nucleo-board-ST-LINK hast other serial number-formats.
by the way, the serial-numbers are usefull in st-util too. I integrated the serial for F0-Discovery into the gdb-server.c . It works on my single board, but it's not well testet...
Uploading gdbserver.c.diff.zip…

greets Gabriel

@xor-gate
Copy link
Member

xor-gate commented Jan 10, 2017

@GagoSoft there is already issue #417 about this problem but no fix yet. It should no be fixed in gdb-server.c but in the library itself. I have some code in my own library but not migrated yet to texane/stlink (see https://github.com/xor-gate/stlink2/blob/master/src/usb.c#L60-L107)

@GagoSoft
Copy link
Contributor

the serial-number problem for the nucleo is quite easy, and allready solved in my local sources. I will post my patch soon.
st-info fails reading the serial of both of my standalone-ST-Link-V2. and leave them with a yellow LED ?!

@GagoSoft
Copy link
Contributor

here my patches for gdbserver.c and flash_opts.c for the serials of my nucleo-boards
gdbserver.c.diff_and_flash_opts.c.diff.zip
the flash_opts.c.diff affects only two lines of code...

@xor-gate
Copy link
Member

Please make a pull request from your changes (https://help.github.com/articles/about-pull-requests/). Then you get the credits and the history is tracked.

@GagoSoft
Copy link
Contributor

sorry, I've never used git before ... :(
I just downloaded the sources from the git-website.
Do I have understand the act right?

  • "git clone ... " the sources to my computer or make a branch first?
    and then?

@xor-gate
Copy link
Member

xor-gate commented Jan 10, 2017

  • Fork the repository to your github account in the webgui (right corner of the texane/stlink project)
  • Clone the git repository to your computer from your account
  • Create a feature branch
  • Commit your work in the branch
  • Push the branch to github
  • Create a pull request of the branch

I know this sounds like a lot of work (and to learn) for just a few lines of code, but that is the way how distributed contributions work with git (in comparision to subversion). This is some nice reading about git workflows: https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows

Even if you write little pieces of code for yourself Git is a awesome tool to track history and safe your ass of hacking.

@GagoSoft
Copy link
Contributor

GagoSoft commented Jan 10, 2017

st-info fails reading the serial of both of my standalone-ST-Link-V2. and leave them with a yellow LED ?!

...this behaviour is only seen, when no target is connected to the ST-Link (the chipid can't be read and the initialization of the st-Link fails). Not really a Problem.

@xor-gate
Copy link
Member

xor-gate commented Jan 10, 2017

Hi all @GagoSoft has supplied a feature to control multiple programmers simultaneous which has just been merged. If there are any problems feel free to comment here.

@WayneKeenan
Copy link

WayneKeenan commented Jul 23, 2017

If st-info --probe can detect, say 4, programmers can it also display each serial in the output for convenience?

@xor-gate
Copy link
Member

xor-gate commented Jul 24, 2017

@WayneKeenan that is a limitation currently how probe is implemented, it needs to have the microcontrollers attached. I have written xor-gate/stlink2 which is able to show the serials even when there are no microcontrollers attached.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.