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

[feature] Added connect under reset to stlink_open_usb( ) #963

Merged
merged 3 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ static stlink_backend_t _stlink_usb_backend = {
_stlink_usb_set_swdclk
};

stlink_t *stlink_open_usb(enum ugly_loglevel verbose, bool reset, char serial[STLINK_SERIAL_MAX_SIZE], int freq) {
stlink_t *stlink_open_usb(enum ugly_loglevel verbose, int reset, char serial[STLINK_SERIAL_MAX_SIZE], int freq) {
stlink_t* sl = NULL;
struct stlink_libusb* slu = NULL;
int ret = -1;
Expand Down Expand Up @@ -1145,9 +1145,10 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, bool reset, char serial[ST
break;
}

if (reset == 2) stlink_jtag_reset(sl,0);
if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) stlink_enter_swd_mode(sl);

if (reset) {
if (reset == 1) {
if ( sl->version.stlink_v > 1) stlink_jtag_reset(sl, 2);
stlink_reset(sl);
usleep(10000);
Expand Down
2 changes: 1 addition & 1 deletion src/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extern "C" {
* @retval NULL Error while opening the stlink
* @retval !NULL Stlink found and ready to use
*/
stlink_t *stlink_open_usb(enum ugly_loglevel verbose, bool reset, char serial[STLINK_SERIAL_MAX_SIZE], int freq);
stlink_t *stlink_open_usb(enum ugly_loglevel verbose, int reset, char serial[STLINK_SERIAL_MAX_SIZE], int freq);
size_t stlink_probe_usb(stlink_t **stdevs[]);
void stlink_probe_usb_free(stlink_t **stdevs[], size_t size);

Expand Down
23 changes: 20 additions & 3 deletions tests/usb.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
#include <stdio.h>

#include <stlink.h>
#include <string.h>

static void usage(void)
{
puts("test-usb --reset");
puts("test-usb --no-reset");
}

int main(int ac, char** av) {
(void)ac;
(void)av;

stlink_t* sl;
struct stlink_reg regs;
int reset = 0;

if (ac == 2) {
if (strcmp(av[1], "--reset") == 0)
reset = 2;
if (strcmp(av[1], "--no-reset") == 0)
reset = 1;
}
if (reset == 0) {
usage();
return 0;
}

sl = stlink_open_usb(10, 1, NULL, 0);
sl = stlink_open_usb(10, reset, NULL, 0);
if (sl != NULL) {
printf("-- version\n");
stlink_version(sl);
Expand Down