Skip to content

Commit

Permalink
Merge pull request #895 from slyshykO/update_libusb
Browse files Browse the repository at this point in the history
[compatibility] update of libusb
  • Loading branch information
Nightwalker-87 committed Apr 2, 2020
2 parents 0b0d8ce + db6e93e commit d3ad0c9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 38 deletions.
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)
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
)
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

#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>
#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

0 comments on commit d3ad0c9

Please sign in to comment.