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

MCU hotplug - Stlink can't recover from MCU hotplug #449

Closed
6 tasks done
poglazov opened this issue Jul 26, 2016 · 11 comments
Closed
6 tasks done

MCU hotplug - Stlink can't recover from MCU hotplug #449

poglazov opened this issue Jul 26, 2016 · 11 comments

Comments

@poglazov
Copy link

poglazov commented Jul 26, 2016

  • Programmer/board type: Stlink/v2
  • Programmer firmware version: don't know how to get it
  • Operating system: Ubuntu 16.04.1 LTS 4.4.0-31-generic USB Issues after bad code write #50-Ubuntu SMP
  • Stlink tools version and/or git commit hash: a781594
  • Stlink commandline tool name: st-info, st-flash, probably any
  • Target chip (and optional board): STM32F030C6T6

Steps to reproduce:

  1. Connected my device using STM32F030C6T6 to Stlink/v2 programmer.
  2. Flashed it succesfully.
  3. Disconnected my device from programmer, DON'T disconnect programmer from laptop's USB.
  4. Connected the device to programmer again.
  5. Tried to flash it with the same command or even just got any information and get error.

Output:

pavel@pavel-UX31A:~/stlink$ ./st-flash --reset write ../Desktop/WB-MSW_2.0.1.bin 0x8000000
2016-07-26T13:27:41 INFO src/stlink-common.c: Loading device parameters....
2016-07-26T13:27:41 INFO src/stlink-common.c: Device connected is: F0 small device, id 0x10006444
2016-07-26T13:27:41 INFO src/stlink-common.c: SRAM size: 0x1000 bytes (4 KiB), Flash: 0x8000 bytes (32 KiB) in pages of 1024 bytes
2016-07-26T13:27:42 INFO src/stlink-common.c: Attempting to write 19860 (0x4d94) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08004c00 erased
2016-07-26T13:27:42 INFO src/stlink-common.c: Finished erasing 20 pages of 1024 (0x400) bytes
2016-07-26T13:27:42 INFO src/stlink-common.c: Starting Flash write for VL/F0/F3 core id
2016-07-26T13:27:42 INFO src/stlink-common.c: Successfully loaded flash loader in sram
 19/19 pages written
2016-07-26T13:27:43 INFO src/stlink-common.c: Starting verification of write complete
2016-07-26T13:27:44 INFO src/stlink-common.c: Flash written and verified! jolly good!
pavel@pavel-UX31A:~/stlink$ ./st-flash --reset write ../Desktop/WB-MSW_2.0.1.bin 0x8000000
[!] send_recv
[!] send_recv
[!] send_recv
[!] send_recv
[!] send_recv
2016-07-26T13:28:18 INFO src/stlink-common.c: Loading device parameters....
[!] send_recv
2016-07-26T13:28:18 ERROR src/stlink-common.c: Failed to read core_id
[!] send_recv
2016-07-26T13:28:18 WARN src/stlink-common.c: unknown chip id! 0x19c6010
pavel@pavel-UX31A:~/stlink$ ./st-info --descr
[!] send_recv
[!] send_recv
[!] send_recv
[!] send_recv
[!] send_recv
[!] send_recv
[!] send_recv

Expected/description:
If disconnect programmer from USB and connect again error goes away. Now I use special script from here to reset USB port before flashing: http://askubuntu.com/questions/645/how-do-you-reset-a-usb-device-from-the-command-line

@xor-gate
Copy link
Member

I think this has something todo with the programmer firmware itself, as it is in a state where it has the old target remembered and you hot-plug your target. Currently the tools can not recover from this, as the programmer needs probably a jtag reset. Normaly when this occurs the tools should try to recover and reset the programmer into a know state. I have seen this kind of behaviour.

When you reset the usb port with a script it reinitialized the programmer and the stlink tools then run from a clean state.

This is related to the older issue #244.

@poglazov
Copy link
Author

Thank you for your answer.

  1. Is it correct that only some programmers are subjected to this error, and some are not?
  2. Do you know if it can be resolved with programmer reflashing?
  3. Though the solution I use isn't fully correct, may it be helpful for other users? Certainly it's platform-dependent but should be short and simple on each.

@xor-gate
Copy link
Member

  1. I think this is applicable to all programmers with all firmwares (but better try if it remains after upgrade)
  2. I think a firmware upgrade will not resolve the issue
  3. It is not platform-dependent, but a special use-case which not many users have. Still the tooling should be able to recover from this.

@poglazov
Copy link
Author

Ok.
So what do you think? If USB reset functionality should be included in Stlink Tools or not?

@xor-gate
Copy link
Member

I'm not 100% how the reset will behave with the programmer when calling libusb_reset_device. The tools/library need to rescan after programmer reset and create a new context and is currently not supported. Doing a USB reset is also a workaround instead of a real fix.

@poglazov
Copy link
Author

I don't know how often typical Stlink Tools user deals with this bug, but for me it happens dozens of times every day and takes tens minutes daily.

Also I still don't understand if it possible to create real fix (not workaround) without complete rewrite of programmers firmware (which looks almost impossible).

@xor-gate
Copy link
Member

You could try to patch and add libusb_reset_device and then rescan all devices or exit/rerun the tool. And see if it works for you. It is currently difficult to implement a reset mechanism so the library/tools pick-up again on the same serial number (programmer) after a USB reset. As there are two backends (mass-storage and raw usb) and alot of code duplication in the usb.c backend.

I'm not sure where in the flow we should place the reset currently.

@xor-gate xor-gate added this to the Unplanned (Contributions Welcome) milestone Aug 3, 2016
@xor-gate xor-gate changed the title Nothing works after MCU hot unplug-plug Stlink can't recover from MCU hotplug Aug 3, 2016
@xor-gate xor-gate modified the milestones: v1.3.0, Unplanned (Contributions Welcome) Dec 30, 2016
@xor-gate
Copy link
Member

Not many people use it this way, and it is not a very easy fix. I will close it for now. If somebody feels like to implement this feature feel free and I will reopen this issue. Thanks for reporting!

@Nightwalker-87
Copy link
Member

Reopening this "lost" request.

@Nightwalker-87 Nightwalker-87 added this to the v1.6.1 milestone Mar 27, 2020
@Nightwalker-87 Nightwalker-87 modified the milestones: v1.6.1, v1.6.2 Apr 28, 2020
@Nightwalker-87 Nightwalker-87 modified the milestones: v1.6.2, v1.6.3 Mar 10, 2021
@Nightwalker-87 Nightwalker-87 modified the milestones: v1.8.0, v1.7.1 Apr 25, 2021
@Nightwalker-87 Nightwalker-87 changed the title [feature] MCU hotplug - Stlink can't recover from MCU hotplug MCU hotplug - Stlink can't recover from MCU hotplug Aug 15, 2021
@Nightwalker-87 Nightwalker-87 pinned this issue Jan 3, 2022
@Nightwalker-87
Copy link
Member

Related to #888 and #1151.

@Nightwalker-87
Copy link
Member

This issue is now closed due to inactivity.
Please also note that any version prior to v1.7.0 is unsupported according to our #Security Policy.
Should the problem persist, please retry with the latest version in the develop branch.
If this is the case, one should then open a new ticket.

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

No branches or pull requests

4 participants