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

Fix and Extend STLinkV2.1 support. Compiling on Windows and Linux. #1

Open
wants to merge 4 commits into
base: stlinkv21
Choose a base branch
from

Conversation

GabyPCgeeK
Copy link

  • show ST-Link dongle information
  • can show and modify device configuration (show is only for ST-Link V2.1)
  • can modify STLink type and reported firmware version
  • can add "Anti-Clone" Tag and "Firmware Flashed/EOF" Tag (to make flashed firmware bootable without needing to exit DFU on V2.1)
  • can decrypt and flash firmwares taken from STLinkUpgrade.jar

Jean THOMAS and others added 4 commits December 20, 2020 23:10
* show ST-Link dongle information
* can show and modify device configuration (show is only for ST-Link V2.1)
* can modify STLink type and reported firmware version
* can add "Anti-Clone" Tag and "Firmware Flashed/EOF" Tag (to make flashed firmware bootable without needing to exit DFU on V2.1)
* can decrypt and flash firmwares taken from `STLinkUpgrade.jar`
@UweBonnes UweBonnes force-pushed the stlinkv21 branch 2 times, most recently from 13c3351 to 8ef48fc Compare November 8, 2021 19:45
@UweBonnes
Copy link
Owner

Can you review with the new checkins

@DagAgren
Copy link

DagAgren commented Feb 12, 2022

I tried running the code from this branch to flash a Nucleo-F446RE, but it failed, and apparently bricked the STLink to the point where not even the official STLink updater can restore it? It no longer appears as a USB device and no lights turn on.

Loaded firmware : ../blackmagic_v1.7.1-283-ge1a928b-dirty.bin, size : 103684 bytes
Firmware Type V2

Unexpected DFU status : 3ne. 2.0%
Erase Error at 0x08004800

@GabyPCgeeK
Copy link
Author

@DagAgren The bootloader should still be intact. Try connecting it to your PC and short SB11 on the back of the board (it is connected to the RST pin on the stlink chip), then try the STLink updater or the program again.

@UweBonnes
Copy link
Owner

Power the device and reset it. Look for SB11 on the bottom and short it. That should get you back to the bootloader.

@UweBonnes
Copy link
Owner

UweBonnes commented Feb 12, 2022

@GabyPCgeeK: I compiled your branch and get the same result:
l> ./stlink-tool ~/devel/blackmagic/src/blackmagic.bin
STLinkV2-1 Bootloader Found
STLink Type: D [(null)]
Firmware Version: V2J34M25

Current Device Configuration:
USB Current: [300mA] MSD Volume: [NODE_F746ZG]
MBED Board Name: [0816]

Bootloader PID: 3748
HW Version: V2.1 Flags: 0x000000
Reported Flash Size: 128KB

STLink ID: 066EFF535452775187162947
Firmware Encryption Key: 8A75D84FD7C5BDCAF451EAF41A85A4D3
Anti-Clone Key: 3D563ABC79626E74D57CAD6A4FDC84A2
Current Mode: 2

Loaded firmware : /home/bon/devel/blackmagic/src/blackmagic.bin, size : 105224 bytes
Firmware Type V2

Unexpected DFU status : 3ne. 1.9%
Erase Error at 0x08004800

So there seems to be a problem with your code or some option is needed not well documented.

@UweBonnes
Copy link
Owner

Running my branch gets the device flashed again. BMP starts after flashing, but it does not start after replug ! ST programmer can load the stlink firmware and starts after replug. Any ideas?

@GabyPCgeeK
Copy link
Author

Can you try this version stlink-tool-dev.zip.

The not starting after replug problem is fixed by writing 0xA50027D3("Firmware Exists Flag"?) to 0x08000000 + FLASH_SIZE - 16 and writing to 0x08003C00 a "Anti-Clone Tag"? that is generated using FLASH_SIZE, RAM_SIZE? and Unique ID and encrypted. In my program the tags can be written using the -f argument.

@DagAgren
Copy link

Somehow it ended up being easier to find out that SB6 and SB10 can be used to connect another programmer directly, so I rewrote the bootloader which I guess reset the chip so the restoration worked. Wasn't entirely a waste of time figuring that out since I could then use it to write BMP directly.

I tested it again now, and the programming failed the exact same way, but shorting SB11 did bring it back so I could run the restoration. There definitely seems to be a bug there.

@DagAgren
Copy link

stlink-tool-dev.zip seems to work, though! Successfully wrote and accessed BMP with that.

@DagAgren
Copy link

And I can confirm that after using -f it seems to start automatically.

@UweBonnes
Copy link
Owner

./stlink-tool -f ~/devel/blackmagic/src/blackmagic.bin
now flashes, but BMP does not restart after replug. This is all with the same board. Did not yet try with a new board.

@UweBonnes
Copy link
Owner

Compile on linux also warns: "src/stlink.c:1134:7: error: ‘hash_list’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
stlink_dfu_hash_verify(info, header, hash_list, hash_len);"

@UweBonnes
Copy link
Owner

UweBonnes commented Feb 13, 2022

It seem Type D from Nucleo144 boards is missed:

STLinkV2-1 Bootloader Found
STLink Type: D [(null)]
Firmware Version: V2J38M27

Current Device Configuration:
USB Current: [300mA] MSD Volume: [NODE_H743ZI] 
MBED Board Name: [0813] 

Bootloader PID: 3748
HW Version: V2.1   Flags: 0x000000
Reported Flash Size: 128KB```

This is with a board that I only flashed with by stlink-tool branch

@UweBonnes
Copy link
Owner

@DagAgren: Any reason why you wnat to use GabyPCgeeK:stlinkv21 and not UweBonnes:stlinkv21?

@DagAgren
Copy link

@UweBonnes You branch didn't find the board at all. @GabyPCgeeK's managed to put it in DFU mode and found it.

@UweBonnes
Copy link
Owner

@DagAgren: The problem was with a Nucleo-f446 with original ST firmware? Any output from running UweBonnes:stlinkv21 that could give me a hint what failed for you?

@DagAgren
Copy link

Yeah, it worked fine with some v2 clones I had sitting around, but I think it just said it couldn't find any device at all when I ran it with the stock 446 with v2-1.

@GabyPCgeeK
Copy link
Author

UweBonnes:stlinkv21 needs

if (libusb_claim_interface(info.stinfo_dev_handle, 0)) {
  fprintf(stderr, "Unable to claim USB interface ! Please close all programs that "
    "may communicate with an ST-Link dongle.\n");
  continue;
}

between line 144 and 145 in main.c. It opens the usb device but never claims the interface so it can't put STLink v2-1 into DFU mode.

@DagAgren
Copy link

Managed to scroll back far enough to find the actual output I got when I was trying, which was simply this:

% ./stlink-tool
No ST-Link in DFU mode found. Replug ST-Link to flash!

Replugging did not help, and just got the same error.

@UweBonnes
Copy link
Owner

@DagAgren: Can you please try with the changes I just pushed to UweBonnes:stlinkv21 and report back? Thanks!

@DagAgren
Copy link

@UweBonnes I'm away from home for a few days but I'll try it when I get back!

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

Successfully merging this pull request may close these issues.

3 participants