diff --git a/CMakeLists.txt b/CMakeLists.txt index d9e2bf6bd..306d3d6ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake/modules/FindLibUSB.cmake b/cmake/modules/FindLibUSB.cmake index 2ad35b3d8..f88556205 100644 --- a/cmake/modules/FindLibUSB.cmake +++ b/cmake/modules/FindLibUSB.cmake @@ -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}) @@ -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}) diff --git a/include/stlink/sg.h b/include/stlink/sg.h index e521ba217..98efd4e58 100644 --- a/include/stlink/sg.h +++ b/include/stlink/sg.h @@ -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 -#pragma warning(pop) -#else -#include -#endif +#define STLINK_SG_H +#include "stlinkusb.h" #include "stlink.h" -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -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 } diff --git a/include/stlink/stlinkusb.h b/include/stlink/stlinkusb.h new file mode 100644 index 000000000..4d904b0c5 --- /dev/null +++ b/include/stlink/stlinkusb.h @@ -0,0 +1,46 @@ +#ifndef STLINKUSB_H +#define STLINKUSB_H + +#include + +/* + + 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 diff --git a/include/stlink/usb.h b/include/stlink/usb.h index 4bf28c355..2d5ff731c 100644 --- a/include/stlink/usb.h +++ b/include/stlink/usb.h @@ -9,9 +9,9 @@ #define STLINK_USB_H #include -#include #include "stlink.h" +#include "stlinkusb.h" #include "stlink/logging.h" #ifdef __cplusplus diff --git a/src/usb.c b/src/usb.c index 7832612cf..bfa5fd2f4 100644 --- a/src/usb.c +++ b/src/usb.c @@ -2,19 +2,12 @@ #include #include #include +#include #if !defined(_MSC_VER) #include #endif #include #include -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable: 4200 4255 4668 4820) -#include -#pragma warning(pop) -#else -#include -#endif #include #include