Skip to content

Handle Stlink V21.#11

Open
UweBonnes wants to merge 8 commits intojeanthom:masterfrom
UweBonnes:stlinkv21
Open

Handle Stlink V21.#11
UweBonnes wants to merge 8 commits intojeanthom:masterfrom
UweBonnes:stlinkv21

Conversation

@UweBonnes
Copy link
Contributor

This patch allow to put the StlinkV2 to put into bootloader mode.

Copy link
Owner

@jeanthom jeanthom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi UweBonnes,

First of all, sorry for reacting so late to your pull request, and thank you very much for your contribution.

I have a few comments regarding your PR, but I don't have much free time currently so I can't for the moment implement the suggested changes.

Btw, I don't have those ST-Link 2.1 devices at home, what should I buy if I want to test stlink-tool on these?

printf("\tApplication is started when called without argument or after firmware load\n\n");
}

#include <string.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header should be at the beginning of the file

src/main.c Outdated
}

#include <string.h>
#define USB_TIMEOUT 5000
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add USB_TIMEOUT then this should be used everywhere a timeout value is needed

src/main.c Outdated
Comment on lines 78 to 105
int test_v21(libusb_context *usb_ctx)
{
libusb_device_handle *dev_handle;
int res = 0;
dev_handle = libusb_open_device_with_vid_pid(usb_ctx,
STLINK_VID,
STLINK_PIDV21);
if (!dev_handle) {
dev_handle = libusb_open_device_with_vid_pid(usb_ctx,
STLINK_VID,
STLINK_PIDV21_MSD);
if (dev_handle)
fprintf(stderr, "StlinkV21_MSD found\n");
} else {
fprintf(stderr, "StlinkV21 found\n");
}
if (dev_handle) {
res = stlink_dfu_mode(dev_handle, 0);
if (res != 0x8000) {
libusb_release_interface(dev_handle, 0);
return 0;
}
stlink_dfu_mode(dev_handle, 1);
libusb_release_interface(dev_handle, 0);
}
usleep(1000000);
return 1;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ideally this kind of check should be performed when trying to connect to the ST-Link interface. Otherwise this causes redundant connections to the device.

@UweBonnes
Copy link
Contributor Author

Any STM Nucleo board or recent Disco board have a stlinkv2.c. Nucleo32 starts at about 12 Euro.

The form of the patch was with the thought in mind to have the changes well localized.
0xfffc results from the rev-engineered values:
#define STLINK_DEV_DFU_MODE 0x00
#define STLINK_DEV_MASS_MODE 0x01
#define STLINK_DEV_DEBUG_MODE 0x02
#define STLINK_DEV_SWIM_MODE 0x03
#define STLINK_DEV_BOOTLOADER_MODE 0x04
#define STLINK_DEV_UNKNOWN_MODE -1

It should be cleaner.

I will try to have a look at my patch this weekend and try to send a revised version.

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.

2 participants