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

STM32F100RBT6: Failed to read core_id and unknown device #1045

Closed
1 task done
WK-M opened this issue Oct 5, 2020 · 63 comments · Fixed by #1104
Closed
1 task done

STM32F100RBT6: Failed to read core_id and unknown device #1045

WK-M opened this issue Oct 5, 2020 · 63 comments · Fixed by #1104

Comments

@WK-M
Copy link

WK-M commented Oct 5, 2020

Thank you for giving feedback to the stlink project.

NOTICE: Please read and follow instructions in #906 before submitting a ticket. This feature request will be deleted without notice when not enough information is provided! So please ensure that all fields are filled out.

  • I made serious effort to avoid creating duplicate or nearly similar issue

In order to allow developers and other contributors to isolate and target your respective issue, please take some time to fill out each of the following items appropriate to your specific problem:

  • Programmer/board type: Onboard STLINK/V1
  • Operating system and version: Fedora 32
  • Stlink tools version and/or git commit hash: v1.6.1
  • Stlink commandline tool name: st-info and st-util
  • Target chip (and board if applicable): STM32F100RBT6

Futher we kindly ask you to describe the detected problem as detailed as possible and to add debug output if available, by using the following template:

Commandline-Output:

For st-util:

st-util -1
st-util: invalid option -- '1'
st-util
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_VERSION
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_CURRENT_MODE
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_CURRENT_MODE
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_ENTER
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_RESETSYS
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_READCOREID
2020-10-05T03:31:27 ERROR common.c: Failed to read core_id
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
2020-10-05T03:31:27 WARN common.c: Invalid flash type, please check device declaration
2020-10-05T03:31:27 ERROR gdb-server.c: Unsupported Target (Chip ID is 0000000000, Core ID is 0000000000).

For st-info:

[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_VERSION
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_CURRENT_MODE
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_CURRENT_MODE
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_ENTER
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_RESETSYS
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_READCOREID
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
Found 1 stlink programmers
 serial:     303030303030303030303031
 hla-serial: "\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31"
 flash:      0 (pagesize: 0)
 sram:       0
 chipid:     0x0000
 descr:      unknown device

Expected/description:

The device should not be read as an unknown device when executing st-info --probe, and there should not be a gdb-server error when running st-util. However, the board is able to be detected when running lsusb.

Bus 001 Device 013: ID 0483:3744 STMicroelectronics ST-LINK/V1

I'm still relatively new to STM32 and ARM, please let me know if there's any other details that I can provide.

Thank you for your support.

The stlink project maintainers

@WK-M WK-M changed the title [STM32F100RB]: [Failed to read core_id and unknown device] [STM32F100RBT6]: [Failed to read core_id and unknown device] Oct 5, 2020
@Nightwalker-87 Nightwalker-87 added this to the v1.6.2 milestone Oct 5, 2020
@Nightwalker-87
Copy link
Member

Thx for reporting. I can verify this with my STM32VL Discovery board that comes with this chip.

@Nightwalker-87 Nightwalker-87 changed the title [STM32F100RBT6]: [Failed to read core_id and unknown device] STM32F100RBT6: [Failed to read core_id and unknown device] Oct 10, 2020
@Nightwalker-87 Nightwalker-87 changed the title STM32F100RBT6: [Failed to read core_id and unknown device] STM32F100RBT6: Failed to read core_id and unknown device Oct 10, 2020
@corecell
Copy link

Have the same problem.
Checked with version from repository community/stlink 1.6.1-1 and latest develop branch.
Board - STM32VLDISCOVERY

Linux i5 5.4.61-rt37-MANJARO #1 SMP PREEMPT_RT Sat Aug 29 17:09:34 UTC 2020 x86_64 GNU/Linux
core/libusb 1.0.23-2
extra/libusb-compat 0.1.7-1

Latest working commit: e3aa887

@Nightwalker-87 Nightwalker-87 self-assigned this Oct 23, 2020
@Ant-ON
Copy link
Collaborator

Ant-ON commented Oct 25, 2020

How I wrote in stlinkV3 issue: it patch may break v1 support ( #820 (comment) )

@WK-M Can you try patch to develop branch:

index 9726ddc..a683267 100644
--- a/src/stlink-lib/usb.c
+++ b/src/stlink-lib/usb.c
@@ -261,7 +261,10 @@ int _stlink_usb_write_debug32(stlink_t *sl, uint32_t addr, uint32_t data) {
 }
 
 int _stlink_usb_get_rw_status(stlink_t *sl) {
-    if (sl->version.jtag_api == STLINK_JTAG_API_V1) { return(-1); }
+    if (sl->version.jtag_api == STLINK_JTAG_API_V1) { 
+        /* STLINK does not support getting statuses. Returns the IO operation is success */
+        return 0;
+    }
 
     unsigned char* const rdata = sl->q_buf;
     struct stlink_libusb * const slu = sl->backend_data;
@@ -300,7 +303,7 @@ int _stlink_usb_write_mem32(stlink_t *sl, uint32_t addr, uint16_t len) {
 
     if (ret == -1) { return(ret); }
 
-    ret = send_only(slu, 0, data, len);
+    ret = send_only(slu, 1, data, len);
 
     if (ret == -1) { return(ret); }
 

@WK-M
Copy link
Author

WK-M commented Oct 25, 2020

How I wrote in stlinkV3 issue: it patch may break v1 support ( #820 (comment) )

@WK-M Can you try patch to develop branch:

index 9726ddc..a683267 100644
--- a/src/stlink-lib/usb.c
+++ b/src/stlink-lib/usb.c
@@ -261,7 +261,10 @@ int _stlink_usb_write_debug32(stlink_t *sl, uint32_t addr, uint32_t data) {
 }
 
 int _stlink_usb_get_rw_status(stlink_t *sl) {
-    if (sl->version.jtag_api == STLINK_JTAG_API_V1) { return(-1); }
+    if (sl->version.jtag_api == STLINK_JTAG_API_V1) { 
+        /* STLINK does not support getting statuses. Returns the IO operation is success */
+        return 0;
+    }
 
     unsigned char* const rdata = sl->q_buf;
     struct stlink_libusb * const slu = sl->backend_data;
@@ -300,7 +303,7 @@ int _stlink_usb_write_mem32(stlink_t *sl, uint32_t addr, uint16_t len) {
 
     if (ret == -1) { return(ret); }
 
-    ret = send_only(slu, 0, data, len);
+    ret = send_only(slu, 1, data, len);
 
     if (ret == -1) { return(ret); }
 

When you state "patch to develop branch", did you want me to checkout to the develop branch and attempt the same commands? If that is not what you meant, please let me know.

Otherwise, I have performed the checkout to the develop branch and performed the proper reinstallation. I am still running into the same errors mentioned in the original posting.

@Ant-ON
Copy link
Collaborator

Ant-ON commented Oct 26, 2020

@WK-M I apply patch to new branch https://github.com/Ant-ON/stlink/tree/try_fix_stlinkv1. Try clone try_fix_stlinkv1 branch and build stlink tool from source.

@WK-M
Copy link
Author

WK-M commented Oct 27, 2020

Thanks for the clarification. I cloned the patch, and I'm still running into the same issues.

I'm not sure if this is a Fedora-specific issue as I am not running into the same error on my Ubuntu machine.

@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Dec 12, 2020

@Vascom Any idea regarding Fedora? It looks like an issue with libusb.
@WK-M which version of libusb do you use. Have you tried to reinstall or update it?

@Vascom
Copy link
Collaborator

Vascom commented Dec 12, 2020

F32 use libusbx-1.0.23.
Which version at ubuntu?

@WK-M
Copy link
Author

WK-M commented Dec 18, 2020

Sorry for the late response.

From the command: dpkg -l libusb-1.0*, I got the following:

+++-======================-================-============-===================================================
ii  libusb-1.0-0:amd64     2:1.0.23-2build1 amd64        userspace USB programming library
ii  libusb-1.0-0-dev:amd64 2:1.0.23-2build1 amd64        userspace USB programming library development files

@Nightwalker-87 Nightwalker-87 mentioned this issue Dec 25, 2020
6 tasks
@mosagepa
Copy link

mosagepa commented Jan 16, 2021

Is this being tackled, any advance?
I didn’t see the id for this on announce for 1.6.2 still, yet of course thanks to all the efforts by developers.
I myself have same issue, on VL Discovery, I’m on the road but will post my details later on. Ubuntu 16.04LTS fresh box, yeah I love kinda retro! ....
Gave it a try, remember stlink-download.c posted somewhere else? (Fiddled with this code to see whether the 0’s were from other strange bug, but I have also the feeling that libusb is to blame...)
Regards

@mosagepa
Copy link

mosagepa commented Jan 17, 2021

I update.
Everything is working now for my VL Discovery.
Using Ubuntu 16.04LTS kernel 4.15.18-041518-generic.
Libusb-0.1.4 (2:0.1.12-28) both :amd and :i386, and
Libusb-1.0.0 (2:1.0.20-1) both :amd and :i386 are installed on this machine acording to ‘dpkg -l libusb*’ output
(I guess this is because for other problems I had before, not related to STLink, I did a lot of recompiling and version trying for libusb in the past, can’t recall exactly now...)
(Also correct me if I could be wrong, but I don’t think the coexistance of i386 versions makes a difference to this reported problem.)
Anyway, this is what worked for me:
I just had to rm -fr all libstlink* under /usr/local/lib,
Then proceed to recompile stlink from 1.6.0 tree I had in backup.
Maybe this can shed some light also:
I had noticed previously that invoking ‘stlink-download /dev/stlinkv1-1 info’ just after connecting the VL to the USB port, and then invoking ‘stlink-gui’ the Stlink-gui let me query the device and yielded the Value Line id and chipid without any problem, and then afterwards also ‘st-info —probe’ gave out the right values, but then any debug session in gdb didn’t get to load into SRAM the flash routine to erase, and it failed...
Also, if I proceed to launch ‘st-info -probe’ right after plugging the USB,it didn’t work, I always had to launch ‘stlink-download’ (even if it failed itself) for both ‘stlink-gui’ and ‘st-info —probe’ to yield the right ID values from that moment on... quite strange, it seems as if the stlink-download executable makes casually for some not so ovbious internal change in VL that gets it right (mostly) afterwards.
This experiment could maybe give some hint to the developers about what could be the issue underneath... I hope so!
Anyway, as I said the fix for me was as I mentioned, to wipe old/conflicting libs and recompile BUT use 1.6.0. You maybe want to make sure also, to do a ‘sudo ldconfig’ afterwards just in case.
Btw, the aforementioned ‘stlink-download’ is to be found under:
https://github.com/vanbwodonk/arm-utilities/blob/master/stlink-download/stlink-download.c
(This site seems to maintain also a v2 consolidated version. Any of those two is clarifying -see comments within the C code- as of the deeply broken nature of the ST-Link/V1 scsi-based coding...)
I really can’t fathom why the ST engineers opted for that unorthodox way of communicating with the F103 chip... this is as cheesy a programming firmware job as I’ve ever seen... I guess they deserve the firmware “decrypting” notices they had to suffer from a bunch of hobbyist out there, deserved punishment IMHO ;)
So, I am now finally happy and GDB-ing all the way in Linux with my VL Discovery.
I got so happy, I ordered TWO more of this board, for just $15 apiece, the two finals in stock there were from some distributor. Go figure out! I really hate programmed obsolescence, so I tend to get quite happy when I resurrect deprecated hardware for all things uC-related, specially if it’s on Linux!

@Nightwalker-87
Copy link
Member

Libusb-0.1.x is not used and thus not needed by this toolset.
@mosagepa This looks way to complicated to serve as a common solution.

I have a STM32F100RBT6 (VL Discovery) with STLINK-V1 as well, but unfortunately had no time to run any tests yet besides professional work...

@mosagepa
Copy link

mosagepa commented Jan 18, 2021

Hi, thanks for your comments.

The solution I've found to satisfy my needs, and couldn't be too hard to follow for disatisfied StLink v1/ VL owners, who are trying to use it under Linux, as a workaround until the developer/s find a time frame to tackle this :) But I agree, the stlink-download.c is a rigmarole, but a rigmarole I mentioned only just in case it could give you a hint. I mean, why executing it allows the st-info utility to get the right values afterwards? (but no flashing works until you delete current libs and replace it with 1.6.0's as I said...) Does this give you a bit of a hint, even if only by intuition?

I guess I can try and compare/ track/ debug by myself the actual calls, parameters and execution of the current 1.6.x against the "bad" libraries versus the 1.6.0 versions, as it seems pretty obvious the differences couldn't be due to differing interfaces or something, so I'm almost sure this has to be some subtle quirk we've / you've not yet found.

If I make some advance on this of course I'll let people now here.

@mosagepa
Copy link

New update:
I've noticed that, even with the libraries "purged" as I commented above, first call to 'st-info --probe' yields out a significant (and different but consistent for any one of my 3 VL Discoveries) serial number, just after plugging them to USB port, BUT as soon as you relaunch 'st-info --probe' the model is correctly detected still as Value Line F1xxx blah blah... BUT, yields now 0x30 0x30 0x30..... i.e. all zeroes chain as "serial".
So maybe this gives me a clue to debug what is really happening here, hopefully I can trace the "bug" (or problem) down to its origin following the inner calls in the 'st-info' execution.
I am being stubborn in this just because I'd like the VL Discovery not to get into forever oblivion but to end up having proper "support" under Linux, so I guess any help in this regard can be appreciated by a bunch of people using VLs if yet a minority I know...

@Nightwalker-87
Copy link
Member

It compiles, but produces same output as posted earlier.
We should better not try and error here - one needs to understand what is happening and where to look at exactly.

I'll have to put this aside for now to deal with some other issues as long as I have the chance to fix stuff and do some maintenance for a few days. I certainly do what I can, but can't help the fact that there aren't enough developers around that address advanced tasks regularly. 😞

@mosagepa
Copy link

mosagepa commented Mar 10, 2021

It must be LIBUSB_LOG_LEVEL_INFO maybe? (suggested to me by the compiler).

Anyway, on first execution from just connected VL I get:

[!] send_recv read reply failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_RESETSYS
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_READCOREID
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
Found 1 stlink programmers
  version:    V1J13
  serial:     393f6f064d42343816512543
  hla-serial: "\x39\x3f\x6f\x06\x4d\x42\x34\x38\x16\x51\x25\x43"
  flash:      0 (pagesize: 0)
  sram:       0
  chipid:     0x0000
  descr:      unknown device

and that's surely the "good" serial BUT you see the chipid zero'd and something goes wrong, the lights on VL get both RED leds on (but it's apparently still executing my previously flashed blinky on the GREEN one),
whereas on second and further executions afterwards not even the serial is given out right, it gets the wrong "interface", "device" or whatever personality which is the STM32 Mass Storage broken "index", with serial 00000...1:

[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_VERSION
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_CURRENT_MODE
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_CURRENT_MODE
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_ENTER
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_RESETSYS
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_READCOREID
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
Found 1 stlink programmers
  version:    V1
  serial:     303030303030303030303031
  hla-serial: "\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31"
  flash:      0 (pagesize: 0)
  sram:       0
  chipid:     0x0000
  descr:      unknown device

I've got myself a good TRACE of a lot of previously and after error calls to libusb from the st-link code, and I'll gladly share the details since this is giving me the feeling about the index problem. It's just that I am not fully able to explain it in technical terms, it's just that, my tracing experiments...

@mosagepa
Copy link

mosagepa commented Mar 10, 2021

What about this "home-made" trace I got?

BIEN (GOOD RESULT, ON FIRST EXECUTION):
=====

DEBUG: I am going to call libusb_get_device_descriptor with IDs = 00001D6B:00000002...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 00001D6B:00000001...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 000005AC:00008206...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 000005AC:0000020C...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 000005AC:00001003...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 00001D6B:00000001...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 0000045E:000000CB...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 00001D6B:00000001...
DEBUG : libusb_get_string_descriptor_ascii() with sizeof(serial) = 64... done.
  desc.iSerialNumber = 0
  serial = 
done.
  desc.iSerialNumber = 1
  serial = STMicroelectronics
done.
  desc.iSerialNumber = 2
  **serial = STM32 STLink**
done.
  desc.iSerialNumber = 3
  **serial = 9?o�MB48�Q%C** 

MAL (BAD SUBSEQUENT RESULTS, SEE THE DIFFERING TAGS AND STRINGS ON APPARENTLY SAME CALLS):
====

DEBUG: I am going to call libusb_get_device_descriptor with IDs = 00001D6B:00000002...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 00001D6B:00000001...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 000005AC:00008206...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 000005AC:0000020C...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 000005AC:00001003...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 00001D6B:00000001...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 0000045E:000000CB...
DEBUG: I am going to call libusb_get_device_descriptor with IDs = 00001D6B:00000001...
DEBUG : libusb_get_string_descriptor_ascii() with sizeof(serial) = 64... done.
  desc.iSerialNumber = 0
  serial = 
done.
  desc.iSerialNumber = 1
  serial = STMicroelectronics
done.
  desc.iSerialNumber = 2
  **serial = STM32 Mass Storage**
done.
  desc.iSerialNumber = 3
  **serial = 000000000001**
done.```

@mosagepa
Copy link

Please btw tell me how can I insert CR+LFs within pasted code in order to edit my recent posts and make them more readable... ;)

@Nightwalker-87
Copy link
Member

Usually one can simply copy console output as is and paste it and use < > afterwards to define a codeblock formatting around it.
However, note that there also is www.pastebin.com for complete console outputs.

@petertorelli
Copy link
Collaborator

@Nightwalker-87
pong: Unfortunately I do not have any L100 series boards, so I cannot reproduce the issue.

@Nightwalker-87
Copy link
Member

@petertorelli: Ok, but can you review the current state of STLINK/V1 device handling with libusb? I saw that you dealt with such problems before in the codebase. We have at least two people here with the right hardware to assist with testing and can provide feedback - this shouldn't be an issue.

@GadgetAngel
Copy link

@petertorelli: Ok, but can you review the current state of STLINK/V1 device handling with libusb? I saw that you dealt with such problems before in the codebase. We have at least two people here with the right hardware to assist with testing and can provide feedback - this shouldn't be an issue.

I have both Mint Linux (20.1) machine and Windows 10 machine to do testing on the following boards:

  1. STM32VLDISCOVERY (STM32F100RB) using ST-LINK-V1
  2. STM32F4DISCOVERY (STM32F407VG) using ST-LINK/V2-A
  3. NUCLEO-F103RB (STM32F103RB) using ST-LINK-V2-1
  4. NUCLEO-F446RE (STM32F446RE) using ST-LINK/V2-1
  5. NUCLEO-L433RC-P (STM32L433RC-P) using ST-LINK/V2-1
  6. NUCLEO-F302R8 (STM32F302R8) using ST-LINK/V2-1
  7. NUCLEO-F767ZI (STM32F767ZI) using ST-LINK/V2-1

I also own an ST-LINK-V2 device and ST-LINK-V3 device and various ST-LINK-V2 clones

just let me know what you want me to test.

@Ant-ON
Copy link
Collaborator

Ant-ON commented Mar 11, 2021

@Nightwalker-87 I looked again at the changes when stlink V3 support was added. Here are the fixes for the bugs I found. Can you check work stlink v1 after it is applied to src/stlink-lib/usb.c?

--- a/src/stlink-lib/usb.c
+++ b/src/stlink-lib/usb.c
@@ -301,7 +301,7 @@ int _stlink_usb_write_mem32(stlink_t *sl, uint32_t addr, uint16_t len) {

     if (ret == -1) { return(ret); }

-    ret = send_only(slu, 0, data, len);
+    ret = send_only(slu, 1, data, len);

     if (ret == -1) { return(ret); }

@@ -431,6 +431,8 @@ int _stlink_usb_status(stlink_t * sl) {
         } else {
             sl->core_stat = TARGET_UNKNOWN;
         }
+    } else {
+        sl->core_stat = TARGET_UNKNOWN;
     }

     return(0);
@@ -469,19 +471,14 @@ int _stlink_usb_enter_swd_mode(stlink_t * sl) {
     unsigned char* const cmd  = sl->c_buf;
     ssize_t size;
     unsigned char* const data = sl->q_buf;
-    const uint32_t rep_len = sl->version.stlink_v > 1 ? 2 : 0;
+    const uint32_t rep_len = sl->version.jtag_api == STLINK_JTAG_API_V1 ? 0 : 2;
     int i = fill_command(sl, SG_DXFER_FROM_DEV, rep_len);

     cmd[i++] = STLINK_DEBUG_COMMAND;
     // select correct API-Version for entering SWD mode: V1 API (0x20) or V2 API (0x30).
     cmd[i++] = sl->version.jtag_api == STLINK_JTAG_API_V1 ? STLINK_DEBUG_APIV1_ENTER : STLINK_DEBUG_APIV2_ENTER;
     cmd[i++] = STLINK_DEBUG_ENTER_SWD;
-
-    if (rep_len == 0) {
-        size = send_only(slu, 1, cmd, slu->cmd_len);
-    } else {
-        size = send_recv(slu, 1, cmd, slu->cmd_len, data, rep_len);
-    }
+    size = send_recv(slu, 1, cmd, slu->cmd_len, data, rep_len);

     if (size == -1) {
         printf("[!] send_recv STLINK_DEBUG_ENTER\n");

@rewolff
Copy link
Contributor

rewolff commented Mar 11, 2021 via email

@mosagepa
Copy link

mosagepa commented Mar 11, 2021

@rewolff My udev settings are ok and as I said above in another post a compilation of libusb calls mixed code which asks also for the serial works beautifully and consistenly with the ST Link v1 in the VL Discovery, so I am pretty sure privileges is not the problem. Also, @Nightwalker-87 had the same log messages and he surely doesn't have a privilege issue neither.

As I pointed out before, the problem seems to be in something that goes wrong just after an initial inquiry by st-link --probe, just in the part in which I copied out my own debug info, notice that first time it gets the correct (sub)device, which is the ST-Link programmer "device", at second and further times the same index passed gets to the dreaded "storage device" whose serial is the "0000...00001".

So the first "pass" takes the VL Discovery into some wrong "state" so to speak which also causes both red leds to light. From then on any access gets directed to the "storage device" which we know it's broken by design and we don't use for anything in Linux case, it addresses that "part" of the device when it should address the "ST Link" part of it, so to speak.

@Ant-ON
Copy link
Collaborator

Ant-ON commented Mar 11, 2021

@mosagepa See the third part of my patch #1045 (comment). I think that the process of receiving information stops with the error because the application does not read the response from the STLINK_DEBUG_ENTER_SWD command.

@mosagepa
Copy link

mosagepa commented Mar 11, 2021

@Ant-ON Please, I highly recommend that when you have a spare time you check this out. I think that proper comparison of the libusb calls that an st-link --probe command issues correlating them with my code's could give us some insight. As you can see in my code and related post, it works like a charm. So does st-link --probe amount to the very same sequence of libusb calls? If not, then we're on the good route for further tracking of this issue (you could trace the flow and correlate both sequences just to pinpoint the moment when st-link --probe goes divergent!)

Also, I don't fully understand the inner working of the inside code you mention. All I know is, if st-link were to (effectively after all its encapsulations, switches and checks) reduce its sequence of (final, ultimate) libusb calls to the same I've been using in my particular code (which is something quite natural to expect), then it should work flawlessly also. So why does it not?

@Nightwalker-87
Copy link
Member

@Ant-ON: I can test your code with my STLink/V1 now, after merging develop into master to have a common codebase again.

I know by now that the merge itself does not make any difference to the behaviour of my device, but we can now be sure that there will be no more code ingress from old parts because we'll only accept new PRs that start from this commit or later. Hence I ask everybody to work with latest develop based on this latest commit also for any further testing and/or fixes. Thanks in advance. 😉

@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Mar 11, 2021

@Ant-ON: Yes, that seems to be the key:

$ sudo make uninstall && sudo make clean && hash -r && sudo make install && st-info --probe
[...]
Found 1 stlink programmers
  version:    V1J13
  serial:     553f6d06483f48534641213f
  hla-serial: "\x55\x3f\x6d\x06\x48\x3f\x48\x53\x46\x41\x21\x3f"
  flash:      131072 (pagesize: 1024)
  sram:       8192
  chipid:     0x0420
  descr:      F1xx Value Line

Great work! Thx. 🎉

I find both red LEDs to remain in a lit up state, but assume that this is an equal behaviour to the red LED turning blue on my STLink/V2-clone programmer when testing with my bluepill-board for other open issues.

I'll now continue to test other commands with it.
However this is a first step to solve this topic here. 👍

@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Mar 11, 2021

General test with st-flash:

$ st-flash --debug --reset --area=option read
2021-03-11T18:01:39 DEBUG common.c: *** looking up stlink version
2021-03-11T18:01:39 DEBUG common.c: st vid         = 0x0483 (expect 0x0483)
2021-03-11T18:01:39 DEBUG common.c: stlink pid     = 0x3744
2021-03-11T18:01:39 DEBUG common.c: stlink version = 0x1
2021-03-11T18:01:39 DEBUG common.c: jtag version   = 0xd
2021-03-11T18:01:39 DEBUG common.c: swim version   = 0x0
2021-03-11T18:01:39 DEBUG common.c:     notice: the firmware doesn't support a swim interface
2021-03-11T18:01:39 DEBUG common.c: stlink current mode: debug (jtag or swd)
2021-03-11T18:01:39 DEBUG usb.c: JTAG/SWD freq set to 0
2021-03-11T18:01:39 DEBUG common.c: *** set_swdclk ***
2021-03-11T18:01:39 DEBUG common.c: stlink current mode: debug (jtag or swd)
2021-03-11T18:01:39 DEBUG common.c: *** stlink_reset ***
2021-03-11T18:01:39 WARN usb.c: NRST is not connected
2021-03-11T18:01:39 DEBUG usb.c: Using reset through SYSRESETREQ
2021-03-11T18:01:39 DEBUG common.c: *** stlink_soft_reset ***
2021-03-11T18:01:39 DEBUG common.c: *** stlink_write_debug32 0xa05f0003 to 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_write_debug32 0x01000500 to 0xe000edfc
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x00030003 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_write_debug32 0x05fa0004 to 0xe000ed0c
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x03030003 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x00030003 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_write_debug32 0x0000001f to 0xe000ed30
2021-03-11T18:01:39 DEBUG common.c: Loading device parameters....
2021-03-11T18:01:39 DEBUG common.c: *** stlink_core_id ***
2021-03-11T18:01:39 DEBUG common.c: core_id = 0x1ba01477
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x10016420 at 0xe0042000
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0xffff0080 at 0x1ffff7e0
2021-03-11T18:01:39 INFO common.c: F1xx Value Line: 8 KiB SRAM, 128 KiB flash in at least 1 KiB pages.
2021-03-11T18:01:39 DEBUG common.c: stlink current mode: debug (jtag or swd)
2021-03-11T18:01:39 DEBUG common.c: stlink current mode: debug (jtag or swd)
2021-03-11T18:01:39 DEBUG common.c: *** stlink_reset ***
2021-03-11T18:01:39 WARN usb.c: NRST is not connected
2021-03-11T18:01:39 DEBUG usb.c: Using reset through SYSRESETREQ
2021-03-11T18:01:39 DEBUG common.c: *** stlink_soft_reset ***
2021-03-11T18:01:39 DEBUG common.c: *** stlink_write_debug32 0xa05f0003 to 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_write_debug32 0x01000500 to 0xe000edfc
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x00030003 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_write_debug32 0x05fa0004 to 0xe000ed0c
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x02010001 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x03030003 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_read_debug32 0x00030003 at 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_write_debug32 0x0000001f to 0xe000ed30
2021-03-11T18:01:39 DEBUG common.c: *** stlink_force_debug_mode ***
2021-03-11T18:01:39 DEBUG common.c: *** stlink_status ***
2021-03-11T18:01:39 DEBUG usb.c: core status: 00030003
2021-03-11T18:01:39 DEBUG common.c:   core status: halted
2021-03-11T18:01:39 DEBUG flash.c: @@@@ Read 0 (0) option bytes from          0
2021-03-11T18:01:39 ERROR common.c: Option bytes read is currently not supported for connected chip
2021-03-11T18:01:39 DEBUG common.c: *** stlink_exit_debug_mode ***
2021-03-11T18:01:39 DEBUG common.c: *** stlink_write_debug32 0xa05f0000 to 0xe000edf0
2021-03-11T18:01:39 DEBUG common.c: *** stlink_close ***

Flashing:

$ sudo make uninstall && sudo make clean && sudo make install && st-flash write /.../Blinker.bin 0x8000000
st-flash 1.6.1-216-gcc9bedd-dirty
2021-03-11T18:04:07 WARN usb.c: NRST is not connected
2021-03-11T18:04:07 INFO common.c: F1xx Value Line: 8 KiB SRAM, 128 KiB flash in at least 1 KiB pages.
file /[...]/Blinker.bin md5 checksum: 16277ff2c027d497361dbae4255081a1, stlink checksum: 0x0004644a
2021-03-11T18:04:07 INFO common.c: Attempting to write 3520 (0xdc0) bytes to stm32 address: 134217728 (0x8000000)
2021-03-11T18:04:07 INFO common.c: Flash page at addr: 0x08000000 erased
2021-03-11T18:04:07 INFO common.c: Flash page at addr: 0x08000400 erased
2021-03-11T18:04:07 INFO common.c: Flash page at addr: 0x08000800 erased
2021-03-11T18:04:07 INFO common.c: Flash page at addr: 0x08000c00 erased
2021-03-11T18:04:07 INFO common.c: Finished erasing 4 pages of 1024 (0x400) bytes
2021-03-11T18:04:07 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL
2021-03-11T18:04:07 INFO flash_loader.c: Successfully loaded flash loader in sram
  4/  4 pages written
2021-03-11T18:04:07 INFO common.c: Starting verification of write complete
2021-03-11T18:04:07 INFO common.c: Flash written and verified! jolly good!

However I find that no LED is blinking... 😞

@igor-m
Copy link

igor-m commented Mar 11, 2021

I've built the latest on Ubuntu 18.04 running in latest VM_Virtualbox (git clone, make clean, make release, make install). I had to do sudo ldconfig in addition as I got error with missing lib.. something.
I get

~/st-flash/stlink$ st-info
st-info: error while loading shared libraries: libstlink.so.1: cannot open shared object file: No such file or directory
~/st-flash/stlink$ sudo ldconfig
~/st-flash/stlink$ git branch
* develop
~/st-flash/stlink$ sudo st-info --probe
[!] send_recv read reply failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_RESETSYS
[!] send_recv send request failed: LIBUSB_ERROR_TIMEOUT
[!] send_recv STLINK_DEBUG_READCOREID
[!] send_recv send request failed: LIBUSB_ERROR_TIMEOUT
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
Found 1 stlink programmers
  version:    V1J13
  serial:     553f6f06483f48536145153f
  hla-serial: "\x55\x3f\x6f\x06\x48\x3f\x48\x53\x61\x45\x15\x3f"
  flash:      0 (pagesize: 0)
  sram:       0
  chipid:     0x0000
  descr:      unknown device
~/st-flash/stlink$ st-info --version
v1.6.1-216-gcc9bedd
~/st-flash/stlink$ st-info --chipid
0x0420
~/st-flash/stlink$ st-info --sram
0x2000
~/st-flash/stlink$ st-info --flash
0x20000
~/st-flash/stlink$ st-info --descr
F1xx Value Line
~/st-flash/stlink$ st-info --pagesize
0x400
~/st-flash/stlink$ st-info --hla-serial
""
~/st-flash/stlink$ st-info --serial

~/st-flash/stlink$ 
~$ sudo st-flash write /tmp/arduino_build_890538/Fade.ino.bin 0x08000000
[sudo] password for xyz: 
st-flash 1.6.1-216-gcc9bedd
[!] send_recv read reply failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_RESETSYS
[!] send_recv send request failed: LIBUSB_ERROR_TIMEOUT
[!] send_recv STLINK_DEBUG_READCOREID
2021-03-11T19:55:06 ERROR common.c: Failed to read core_id
[!] send_recv send request failed: LIBUSB_ERROR_TIMEOUT
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
2021-03-11T19:55:09 WARN common.c: Invalid flash type, please check device declaration
Failed to connect to target

~/st-flash/stlink$ st-flash --debug --reset --area=option read
st-flash 1.6.1-216-gcc9bedd
2021-03-11T20:11:21 DEBUG common.c: *** looking up stlink version
2021-03-11T20:11:21 DEBUG common.c: st vid         = 0x0483 (expect 0x0483)
2021-03-11T20:11:21 DEBUG common.c: stlink pid     = 0x3744
2021-03-11T20:11:21 DEBUG common.c: stlink version = 0x1
2021-03-11T20:11:21 DEBUG common.c: jtag version   = 0xd
2021-03-11T20:11:21 DEBUG common.c: swim version   = 0x0
2021-03-11T20:11:21 DEBUG common.c:     notice: the firmware doesn't support a swim interface
2021-03-11T20:11:21 DEBUG common.c: stlink current mode: dfu
2021-03-11T20:11:21 DEBUG usb.c: -- exit_dfu_mode
2021-03-11T20:11:21 DEBUG common.c: *** stlink_exit_dfu_mode ***
2021-03-11T20:11:21 DEBUG usb.c: JTAG/SWD freq set to 0
2021-03-11T20:11:21 DEBUG common.c: *** set_swdclk ***
2021-03-11T20:11:21 DEBUG common.c: stlink current mode: mass
2021-03-11T20:11:21 DEBUG common.c: *** stlink_enter_swd_mode ***
2021-03-11T20:11:21 DEBUG common.c: *** stlink_reset ***
[!] send_recv read reply failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_RESETSYS
2021-03-11T20:11:21 DEBUG common.c: Loading device parameters....
2021-03-11T20:11:21 DEBUG common.c: *** stlink_core_id ***
[!] send_recv send request failed: LIBUSB_ERROR_TIMEOUT
[!] send_recv STLINK_DEBUG_READCOREID
2021-03-11T20:11:24 ERROR common.c: Failed to read core_id
[!] send_recv send request failed: LIBUSB_ERROR_TIMEOUT
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
2021-03-11T20:11:27 WARN common.c: Invalid flash type, please check device declaration
Failed to connect to target
~/st-flash/stlink$ 

@Ant-ON
Copy link
Collaborator

Ant-ON commented Mar 12, 2021

@igor-m Try apply patch to develop branch from #1045 (comment)
@Nightwalker-87 The firmware is being flashed with verification. In theory, it should be work normally. You can read the firmware back and compare them if in doubt about correct operation.

@igor-m
Copy link

igor-m commented Mar 12, 2021

With applied patch (the patch lines at 431 are not valid anymore, it seems):

~/st-flash/stlink$ st-info --probe
Found 1 stlink programmers
  version:    V1J13
  serial:     553f6f06483f48536145153f
  hla-serial: "\x55\x3f\x6f\x06\x48\x3f\x48\x53\x61\x45\x15\x3f"
  flash:      131072 (pagesize: 1024)
  sram:       8192
  chipid:     0x0420
  descr:      F1xx Value Line

~/st-flash/stlink$ sudo st-flash write /tmp/arduino_build_760260/Fade.ino.bin 0x08000000
st-flash 1.6.1-216-gcc9bedd-dirty
2021-03-12T08:14:35 WARN usb.c: NRST is not connected
2021-03-12T08:14:35 INFO common.c: F1xx Value Line: 8 KiB SRAM, 128 KiB flash in at least 1 KiB pages.
file /tmp/arduino_build_760260/Fade.ino.bin md5 checksum: e9b51d95f4bb16984758f44491e4c237, stlink checksum: 0x0013fb42
2021-03-12T08:14:35 INFO common.c: Attempting to write 13708 (0x358c) bytes to stm32 address: 134217728 (0x8000000)
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08000000 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08000400 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08000800 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08000c00 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08001000 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08001400 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08001800 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08001c00 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08002000 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08002400 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08002800 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08002c00 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08003000 erased
2021-03-12T08:14:35 INFO common.c: Flash page at addr: 0x08003400 erased
2021-03-12T08:14:35 INFO common.c: Finished erasing 14 pages of 1024 (0x400) bytes
2021-03-12T08:14:35 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL
2021-03-12T08:14:35 INFO flash_loader.c: Successfully loaded flash loader in sram
 14/ 14 pages written
2021-03-12T08:14:36 INFO common.c: Starting verification of write complete
2021-03-12T08:14:36 INFO common.c: Flash written and verified! jolly good!
~/st-flash/stlink$ 

..and the LED fades 👍

@igor-m
Copy link

igor-m commented Mar 12, 2021

@Nightwalker-87: the leds on the VL board are called LED_BLUE and LED_GREEN - double-check in your arduino Blink source..

@Nightwalker-87
Copy link
Member

On my STM32VL Discovery Board the status LEDs in the front part are called LD1 and LD2 and both are red ones.
Further there are LD3 and LD4 at the other end of the board, but I've not seen those lit up yet.

@igor-m
Copy link

igor-m commented Mar 12, 2021

LD3 and LD4 are the leds you may let blink with the Blink demo (arduino with stm32 support installed). The leds are called LED_BLUE and LED_GREEN inside arduino IDE then (with the DiscoveryVL board selected). The default LED in the Blink sketch is named "LED_BUILTIN" thus you will not see the led blinking with the default..

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