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

[compatibility] update of libusb #895

Merged
merged 8 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ set(STLINK_HEADERS
include/stlink/mmap.h
include/stlink/chipid.h
include/stlink/flash_loader.h
include/stlink/stlinkusb.h
)

set(STLINK_SOURCE
Expand Down
3 changes: 2 additions & 1 deletion cmake/modules/FindLibUSB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if(NOT LIBUSB_FOUND)
if(WIN32 OR MSVC OR MINGW OR MSYS)
find_package(7Zip REQUIRED)

set(LIBUSB_WIN_VERSION 1.0.22)
set(LIBUSB_WIN_VERSION 1.0.23)
Nightwalker-87 marked this conversation as resolved.
Show resolved Hide resolved
set(LIBUSB_WIN_ARCHIVE libusb-${LIBUSB_WIN_VERSION}.7z)
set(LIBUSB_WIN_ARCHIVE_PATH ${CMAKE_BINARY_DIR}/${LIBUSB_WIN_ARCHIVE})
set(LIBUSB_WIN_OUTPUT_FOLDER ${CMAKE_BINARY_DIR}/3thparty/libusb-${LIBUSB_WIN_VERSION})
Expand All @@ -79,6 +79,7 @@ if(NOT LIBUSB_FOUND)
file(DOWNLOAD
https://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-${LIBUSB_WIN_VERSION}/libusb-${LIBUSB_WIN_VERSION}.7z/download
${LIBUSB_WIN_ARCHIVE_PATH}
EXPECTED_MD5 cf3d38d2ff053ef343d10c0b8b0950c2
Nightwalker-87 marked this conversation as resolved.
Show resolved Hide resolved
)
endif()
file(MAKE_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER})
Expand Down
48 changes: 20 additions & 28 deletions include/stlink/sg.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@
*/

#ifndef STLINK_SG_H
#define STLINK_SG_H

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4200 4255 4668 4820)
#include <libusb.h>
#pragma warning(pop)
#else
#include <libusb.h>
#endif
#define STLINK_SG_H

#include "stlinkusb.h"
#include "stlink.h"

#ifdef __cplusplus
#ifdef __cplusplus
extern "C" {
#endif

Expand Down Expand Up @@ -49,29 +41,29 @@ extern "C" {



struct stlink_libsg {
libusb_context* libusb_ctx;
libusb_device_handle *usb_handle;
unsigned ep_rep;
unsigned ep_req;
struct stlink_libsg {
libusb_context* libusb_ctx;
libusb_device_handle *usb_handle;
unsigned ep_rep;
unsigned ep_req;

int sg_fd;
int do_scsi_pt_err;
int sg_fd;
int do_scsi_pt_err;

unsigned char cdb_cmd_blk[CDB_SL];
unsigned char cdb_cmd_blk[CDB_SL];

int q_data_dir; // Q_DATA_IN, Q_DATA_OUT
// the start of the query data in the device memory space
uint32_t q_addr;
int q_data_dir; // Q_DATA_IN, Q_DATA_OUT
// the start of the query data in the device memory space
uint32_t q_addr;

// Sense (error information) data
// obsolete, this was fed to the scsi tools
unsigned char sense_buf[SENSE_BUF_LEN];
// Sense (error information) data
// obsolete, this was fed to the scsi tools
unsigned char sense_buf[SENSE_BUF_LEN];

struct stlink_reg reg;
};
struct stlink_reg reg;
};

stlink_t* stlink_v1_open(const int verbose, int reset);
stlink_t* stlink_v1_open(const int verbose, int reset);

#ifdef __cplusplus
}
Expand Down
46 changes: 46 additions & 0 deletions include/stlink/stlinkusb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef STLINKUSB_H
#define STLINKUSB_H

#include <libusb.h>

/*

libusb ver | LIBUSB_API_VERSION
-------------+--------------------
v1.0.13 | 0x01000100
v1.0.14 | 0x010000FF
v1.0.15 | 0x01000101
v1.0.16 | 0x01000102
v1.0.17 | 0x01000102
v1.0.18 | 0x01000102
v1.0.19 | 0x01000103
v1.0.20 | 0x01000104
v1.0.21 | 0x01000105
v1.0.22 | 0x01000106
v1.0.23 | 0x01000107

*/

#if defined (__FreeBSD__)
#if !defined ( LIBUSBX_API_VERSION )
#define LIBUSBX_API_VERSION LIBUSB_API_VERSION
#elif !defined (LIBUSB_API_VERSION)
#error unsupported libusb version
#endif
#endif

#if defined (__FreeBSD__)
#define MINIMAL_API_VERSION 0x01000102
#elif defined (__linux__)
#define MINIMAL_API_VERSION 0x01000104
#elif defined (__APPLE__)
#define MINIMAL_API_VERSION 0x01000104
#elif defined (_WIN32)
#define MINIMAL_API_VERSION 0x01000106
#endif

#if ( LIBUSB_API_VERSION < MINIMAL_API_VERSION )
#error unsupported libusb version
#endif

Nightwalker-87 marked this conversation as resolved.
Show resolved Hide resolved
#endif // STLINKUSB_H
2 changes: 1 addition & 1 deletion include/stlink/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#define STLINK_USB_H

#include <stdbool.h>
#include <libusb.h>

#include "stlink.h"
#include "stlinkusb.h"
#include "stlink/logging.h"

#ifdef __cplusplus
Expand Down
9 changes: 1 addition & 8 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <limits.h>
Nightwalker-87 marked this conversation as resolved.
Show resolved Hide resolved
#if !defined(_MSC_VER)
#include <sys/time.h>
#endif
#include <sys/types.h>
#include <mingw.h>
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4200 4255 4668 4820)
#include <libusb.h>
#pragma warning(pop)
#else
#include <libusb.h>
#endif
#include <errno.h>
#include <unistd.h>

Expand Down