vdudouyt / stm8flash

program your stm8 devices with SWIM/stlinkv(1,2)
GNU General Public License v2.0
403 stars 182 forks source link

Multiple Boards with same Serial Number #134

Open gicking opened 3 years ago

gicking commented 3 years ago

I need to reflash multiple STM8S Discovery boards within the same circuit. I expected that I can select the respective board via -S option. But both STLink are shown with the same serial number (see below), so -S option has no other effect than avoiding the warning. Specifically, even with -S option (and same serial number), "Programmer 1" is always used.

Determine FLASH area
WARNING: More than one programmer found but no serial number given. Programmer 1 will be used:
Programmer 1: STMicroelectronics STM32 Mass Storage, Serial Number:303030303030303030303031
Programmer 2: STMicroelectronics STM32 Mass Storage, Serial Number:303030303030303030303031
Due to its file extension (or lack thereof), "fast.ihx" is considered as INTEL HEX format!
115 bytes at 0x8000... OK
Bytes written: 115

I understand from here that the "-S" option uses USB vendor and procuct IDs to create a serial number. Unfortunately these are not unique if identical programmers are used. How about to also include the "Device" number from lsusb (see below). Apparently this is unique, even if VID and PID are identical

Bus 001 Device 008: ID 0483:3744 STMicroelectronics STLINK Pseudo disk
Bus 001 Device 007: ID 0483:3744 STMicroelectronics STLINK Pseudo disk
spth commented 3 years ago

On the other hand, VID and PID are permant. AFAIK the "Device" number can change if you unplug and replug the device.

gicking commented 3 years ago

that is correct. But as said I cannot address individual STM8S Discovery boards as they have the same VID and PID. The device number from lsusb was just a thought. Maybe there is a more persistent, unique USB identifier...?

spth commented 3 years ago

I wonder if there is an ST-Link-specific identifier that we could use? Maybe the STM32 in it has a serial number that can be read out?

gicking commented 3 years ago

That would be great! I searched the web today and this seems to be a viable option. However, I didn't find a C way to do this, all references were for OpenOCD configuration.

spth commented 3 years ago

Since linusb -v can display the serial number, then I think stm8flash should be able to get it through libusb.

schneidersoft commented 1 year ago

any chance some of my pull requests will get merged upstream?

spth commented 1 year ago

I'm in France for a few days, and have only an STM8A-Discovery here. When I'm back in Germany, assuming I'll find some time, I'll have a look at the pull requests again (and check that multiboard stuff by with multiple ones attached). I put it on my todo list for end of next week.

spth commented 1 year ago

I also encountered the problem with multiple "303030303030303030303031" serial numbers. However, I only see that number after having used stm8flash once with that programmer. On the first invokation of stm8flash after plugging in an ST-Link/V2, I see different numbers.

spth commented 1 year ago

In other places it was reported that the "303030303030303030303031" serial numbers after first use are an ST-Link/v2 firmware bug, and that updating the ST-Link/v2 to the latest firmware version will fix it. I haven't tested that yet myself.