Skip to content

Commit

Permalink
Merge branch 'develop' into 'chipid_cleanup'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightwalker-87 committed Jan 2, 2022
2 parents 0d02a46 + 7cc1fda commit 5c303b3
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ When there is no executable available for your platform or you need the latest (
- Please start new forks from the develop branch, as pull requests will go into this branch as well.

Please also refer to our [Contribution Guidelines](CONTRIBUTING.md).

## User Reviews

*I hope it's not to out of topic, but I've been so frustrated with AVR related things on OpenBSD, the fact that stlink built out of the box without needing to touch anything was so relieving. Literally made my whole weekend better!
I take it's thanks to @Crest and also to the stlink-org team (@Nightwalker-87 and @xor-gate it seems) to have made a software that's not unfriendly to the "fringe" OSes.
Thank you <3"* - nbonfils, 11.12.2021
17 changes: 17 additions & 0 deletions cmake/modules/Findlibusb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") # FreeBSD; libusb is
message(FATAL_ERROR "Expected libusb library not found on your system! Verify your system integrity.")
endif ()

elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") # OpenBSD; libusb-1.0 is available from ports
FIND_PATH(
LIBUSB_INCLUDE_DIR NAMES libusb.h
HINTS /usr/local/include
PATH_SUFFIXES libusb-1.0
)
set(LIBUSB_NAME usb-1.0)
find_library(
LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS /usr/local
)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(libusb DEFAULT_MSG LIBUSB_LIBRARY LIBUSB_INCLUDE_DIR)
mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY)
if (NOT LIBUSB_FOUND)
message(FATAL_ERROR "No libusb-1.0 library found on your system! Install libusb-1.0 from ports or packages.")
endif ()

elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-toolchain on Debian
# MinGW/MSYS/MSVC: 64-bit or 32-bit?
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
Expand Down
1 change: 1 addition & 0 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Expand Down
4 changes: 3 additions & 1 deletion src/st-util/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,13 @@ static const char* const memory_map_template_H72x3x =
" <memory type=\"ram\" start=\"0x24000000\" length=\"0x80000\"/>" // RAM D1 320kB
" <memory type=\"ram\" start=\"0x30000000\" length=\"0x08000\"/>" // RAM D2 23kB
" <memory type=\"ram\" start=\"0x38000000\" length=\"0x04000\"/>" // RAM D3 16kB
" <memory type=\"ram\" start=\"0x38800000\" length=\"0x01000\"/>" // Backup RAM 4kB
" <memory type=\"ram\" start=\"0x38800000\" length=\"0x01000\"/>" // Backup RAM 4kB
" <memory type=\"flash\" start=\"0x08000000\" length=\"0x%x\">"
" <property name=\"blocksize\">0x%x</property>"
" </memory>"
" <memory type=\"ram\" start=\"0x40000000\" length=\"0x1fffffff\"/>" // peripheral regs
" <memory type=\"ram\" start=\"0x60000000\" length=\"0x3fffffff\"/>" // External Memory
" <memory type=\"ram\" start=\"0xC0000000\" length=\"0x1fffffff\"/>" // External device
" <memory type=\"ram\" start=\"0xe0000000\" length=\"0x1fffffff\"/>" // cortex regs
" <memory type=\"rom\" start=\"0x1ff00000\" length=\"0x20000\"/>" // bootrom
"</memory-map>";
Expand Down
18 changes: 17 additions & 1 deletion src/stlink-lib/chipid.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ void dump_a_chip (FILE *fp, struct stlink_chipid_params *dev) {
fprintf(fp, "flags %d\n\n", dev->flags);
}

static int chipid_params_eq(const struct stlink_chipid_params *p1, const struct stlink_chipid_params *p2)
{
return p1->chip_id == p2->chip_id &&
p1->description && p2->description &&
strcmp(p1->description, p2->description) == 0 &&
p1->flash_type == p2->flash_type &&
p1->flash_size_reg == p2->flash_size_reg &&
p1->flash_pagesize == p2->flash_pagesize &&
p1->sram_size == p2->sram_size &&
p1->bootrom_base == p2->bootrom_base &&
p1->bootrom_size == p2->bootrom_size &&
p1->option_base == p2->option_base &&
p1->option_size == p2->option_size &&
p1->flags == p2->flags;
}

struct stlink_chipid_params *stlink_chipid_get_params(uint32_t chipid) {
struct stlink_chipid_params *params = NULL;
struct stlink_chipid_params *p2;
Expand All @@ -53,7 +69,7 @@ struct stlink_chipid_params *stlink_chipid_get_params(uint32_t chipid) {
#if 1
if (params == NULL) {
params = p2;
} else if (memcmp (p2, params, sizeof(struct stlink_chipid_params) - sizeof(struct stlink_chipid_params *)) != 0) {
} else if (!chipid_params_eq(params, p2)) {
// fprintf (stderr, "Error, chipid params not identical\n");
// return NULL;
fprintf(stderr, "---------- old ------------\n");
Expand Down
2 changes: 2 additions & 0 deletions src/stlink-lib/libusb_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#if defined (__FreeBSD__)
#define MINIMAL_API_VERSION 0x01000102 // v1.0.16
#elif defined (__OpenBSD__)
#define MINIMAL_API_VERSION 0x01000104 // v1.0.20
#elif defined (__linux__)
#define MINIMAL_API_VERSION 0x01000104 // v1.0.20
#elif defined (__APPLE__)
Expand Down
3 changes: 2 additions & 1 deletion src/stlink-lib/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,8 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, enum connect_type connect,
desc.idProduct == STLINK_USB_PID_STLINK_V3_USBLOADER ||
desc.idProduct == STLINK_USB_PID_STLINK_V3E_PID ||
desc.idProduct == STLINK_USB_PID_STLINK_V3S_PID ||
desc.idProduct == STLINK_USB_PID_STLINK_V3_2VCP_PID) {
desc.idProduct == STLINK_USB_PID_STLINK_V3_2VCP_PID ||
desc.idProduct == STLINK_USB_PID_STLINK_V3_NO_MSD_PID) {
slu->ep_req = 1 /* ep req */ | LIBUSB_ENDPOINT_OUT;
slu->ep_trace = 2 | LIBUSB_ENDPOINT_IN;
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/stlink-lib/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C" {
#define STLINK_USB_PID_STLINK_V3E_PID 0x374e
#define STLINK_USB_PID_STLINK_V3S_PID 0x374f
#define STLINK_USB_PID_STLINK_V3_2VCP_PID 0x3753
#define STLINK_USB_PID_STLINK_V3_NO_MSD_PID 0x3754

#define STLINK_V1_USB_PID(pid) ((pid) == STLINK_USB_PID_STLINK)

Expand All @@ -38,7 +39,8 @@ extern "C" {
#define STLINK_V3_USB_PID(pid) ((pid) == STLINK_USB_PID_STLINK_V3_USBLOADER || \
(pid) == STLINK_USB_PID_STLINK_V3E_PID || \
(pid) == STLINK_USB_PID_STLINK_V3S_PID || \
(pid) == STLINK_USB_PID_STLINK_V3_2VCP_PID)
(pid) == STLINK_USB_PID_STLINK_V3_2VCP_PID || \
(pid) == STLINK_USB_PID_STLINK_V3_NO_MSD_PID)

#define STLINK_SUPPORTED_USB_PID(pid) (STLINK_V1_USB_PID(pid) || \
STLINK_V2_USB_PID(pid) || \
Expand Down
3 changes: 3 additions & 0 deletions src/win32/unistd/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
*/

#define ssize_t int
#ifndef SSIZE_MAX
#define SSIZE_MAX ((sizeof(ssize_t) == 4) ? 2147483647 : 9223372036854775807)
#endif

#define STDIN_FILENO 0
#define STDOUT_FILENO 1
Expand Down

0 comments on commit 5c303b3

Please sign in to comment.