stlink-org / stlink

Open source STM32 MCU programming toolset
BSD 3-Clause "New" or "Revised" License
4.45k stars 1.24k forks source link

[STLINK-V3-SET]: If the device fails to enter SWD mode, the usb device is not released #1399

Open TheFissk opened 6 months ago

TheFissk commented 6 months ago


When there is no board connected to the programmer causing it to fail to enter SWD mode subsequent invokations of the tool hang before failing.

Commandline output: These commands are separated by several seconds, I'm not machinegunning the tool expecting it to work. The first command returns immediately, the second hangs for ~10s

$ st-flash reset
st-flash 1.8.0
Failed to enter SWD mode
Failed to connect to target
Failed to parse flash type or unrecognized flash type //This line went to stderr rather than stdout
$ st-flash reset
st-flash 1.8.0
2024-05-24T10:41:08 ERROR usb.c: GET_VERSION send request failed: LIBUSB_ERROR_TIMEOUT
2024-05-24T10:41:11 ERROR usb.c: GET_CURRENT_MODE send request failed: LIBUSB_ERROR_TIMEOUT
2024-05-24T10:41:14 ERROR usb.c: GET_COM_FREQ send request failed: LIBUSB_ERROR_TIMEOUT
2024-05-24T10:41:17 ERROR usb.c: GET_CURRENT_MODE send request failed: LIBUSB_ERROR_TIMEOUT
2024-05-24T10:41:20 ERROR usb.c: ENTER_SWD send request failed: LIBUSB_ERROR_TIMEOUT
Failed to parse flash type or unrecognized flash type
Failed to enter SWD mode
Failed to connect to target
2024-05-24T10:41:23 ERROR usb.c: DEBUG_EXIT send request failed: LIBUSB_ERROR_TIMEOUT

I also tested it against st-info --chipid and it works in much the same way, but it suppresses the stderr output, so that the program hangs for a ~10 seconds before outputting:

$ st-info --chipid
Failed to enter SWD mode
0x0000

Plugging a board into the programmer once its entered this degraded state does not resolve the issue, it will continue to output the same errors

st-info --probe works as expected returning instantly regardless of whether or not the device was able to enter SWD mode in previous invokations of st-info --probe

The V2 programmer works as expected, returning instantly even after failing to enter SWD mode.

Expected/description:

If the V3 programmer should return instantly after failing to enter SWD mode, regardless of whether or not it was able to enter SWD mode previously.

Nightwalker-87 commented 6 months ago

@Ant-ON: Can we be sure about that the STLINK-V3-SET is fully supported yet? The only thing I found are the respective VID:PIDs in the udev-rules ...

Ant-ON commented 5 months ago

@Nightwalker-87 STLINK-V3-SET has the same commands as STLINK-V3, therefore the STLINK-V3-SET should be supported too

Nightwalker-87 commented 5 months ago

So why shall there a problem then which does not seem to occur with other variants? Users: Please test your devices and give feedback on any issues.

ankurraji commented 4 months ago

I have the same issue with my ST-LINK V3 SET.

sending flash reset command when no MCU is connected, leads to first this message

$ st-flash reset
st-flash 1.8.0
Failed to enter SWD mode
Failed to connect to target
Failed to parse flash type or unrecognized flash type

And when the command is triggered another time you will receive an error

$ st-flash reset
st-flash 1.8.0
2024-07-19T13:20:37 ERROR usb.c: GET_VERSION send request failed: LIBUSB_ERROR_TIMEOUT
2024-07-19T13:20:40 ERROR usb.c: GET_CURRENT_MODE send request failed: LIBUSB_ERROR_TIMEOUT
2024-07-19T13:20:43 ERROR usb.c: GET_COM_FREQ send request failed: LIBUSB_ERROR_TIMEOUT
2024-07-19T13:20:46 ERROR usb.c: GET_CURRENT_MODE send request failed: LIBUSB_ERROR_TIMEOUT
2024-07-19T13:20:49 ERROR usb.c: ENTER_SWD send request failed: LIBUSB_ERROR_TIMEOUT
Failed to enter SWD mode
Failed to connect to target
Failed to parse flash type or unrecognized flash type
2024-07-19T13:20:52 ERROR usb.c: DEBUG_EXIT send request failed: LIBUSB_ERROR_TIMEOUT

The debug flag does not give more information

$ st-flash reset --debug
st-flash 1.8.0
2024-07-19T13:20:59 ERROR usb.c: GET_VERSION send request failed: LIBUSB_ERROR_TIMEOUT
2024-07-19T13:21:02 ERROR usb.c: GET_CURRENT_MODE send request failed: LIBUSB_ERROR_TIMEOUT
2024-07-19T13:21:05 ERROR usb.c: GET_COM_FREQ send request failed: LIBUSB_ERROR_TIMEOUT
2024-07-19T13:21:08 ERROR usb.c: GET_CURRENT_MODE send request failed: LIBUSB_ERROR_TIMEOUT
2024-07-19T13:21:11 ERROR usb.c: ENTER_SWD send request failed: LIBUSB_ERROR_TIMEOUT
Failed to enter SWD mode
Failed to connect to target
Failed to parse flash type or unrecognized flash type
2024-07-19T13:21:14 ERROR usb.c: DEBUG_EXIT send request failed: LIBUSB_ERROR_TIMEOUT

Additionally, it looks like the ST-LINK V3 SET is stuck/hanging. This is something that I diagonalised with the LEDs and the response time delay when you execute the st-flash reset. Sometimes I have to wait for ~10 Secs to see any log message printed out in the terminal after the line st-flash 1.8.0 is printed.

ST-LINK-V3-SET Stuck

The issue remains the same even though I connect the MCU back again to the ST-LINK V3 SET; only a power reset of debugger i.e. unplugging the USB cable and connecting it back again solves the issue.

Finally, as @TheFissk mentioned, I too have not observed any issue with ST-LINK V2 it just comes out of the command with an error, and is able to connect to the MCU when the MCU is connected again to the debugger. The V2 does not produce LIBUSB_ERROR_TIMEOUT error.

Flash reset with ST-LINK V2.

$ st-flash reset
st-flash 1.8.0
Failed to enter SWD mode
Failed to connect to target
Failed to parse flash type or unrecognized flash type

Feel free to comment, if more information is required 😃

bfueldner commented 2 months ago

I can confirm the behaviour like @ankurraji mentioned with v1.8.0 and ST-LINK V3 MINIE. So it seems not to depend only on the combination command set and ST-LINK V3 SET.

Nightwalker-87 commented 1 month ago

Please investigate further. We need some volunteers with the appropriate hardware that are able to look into this.

ypearson-bdai commented 1 month ago

Got this on a stm32 G0 using a STlink-v3mini st-flash 1.8.0 2024-10-24T13:09:06 ERROR usb.c: GET_VERSION send request failed: LIBUSB_ERROR_TIMEOUT 2024-10-24T13:09:09 ERROR usb.c: GET_CURRENT_MODE send request failed: LIBUSB_ERROR_TIMEOUT 2024-10-24T13:09:12 ERROR usb.c: GET_COM_FREQ send request failed: LIBUSB_ERROR_TIMEOUT 2024-10-24T13:09:15 ERROR usb.c: GET_CURRENT_MODE send request failed: LIBUSB_ERROR_TIMEOUT 2024-10-24T13:09:18 ERROR usb.c: ENTER_SWD send request failed: LIBUSB_ERROR_TIMEOUT Failed to enter SWD mode Failed to connect to target Failed to parse flash type or unrecognized flash type 2024-10-24T13:09:21 ERROR usb.c: DEBUG_EXIT send request failed: LIBUSB_ERROR_TIMEOUT

Nightwalker-87 commented 4 days ago

We are still looking for further investigation and further ideas here. Please contribute.