openocd -f interface/stlink-v2-1.cfg \
-f target/stm32l1.cfg \
-c 'hla_serial \x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31' \
-c "program main.hex verify reset exit" \
The line:
-c 'hla_serial \x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31'
is used to select the particular st-link
Use
st-info --probe
To find these serial numbers for all connected st-links
Edit the flashing rule of the rules.mk file with something like this:
%.flash: %.hex
@printf " FLASH $<\n"
(echo "halt; program $(realpath $(*).hex) verify reset" | nc -4 localhost 4444 2>/dev/null) || \
$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
-f target/$(OOCD_TARGET).cfg \
$(OOCD_EXTRA) \
-c "program $(*).hex verify reset exit" \
$(NULL)
Now you can use this for selecting one particular st-link:
OOCD_EXTRA="-c 'hla_serial \x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31'" make flash
https://ardupilot.org/dev/docs/using-DFU-to-load-bootloader.html