Skip to content

Commit

Permalink
General Project Update
Browse files Browse the repository at this point in the history
- Fixed compatibility with gcc-14 [-Werror=calloc-transposed-args]
- Updated compiling instructions and build script for Windows (Closes #1364) (Closes #1410)
- Updated CHANGELOG.md
- Minor formatting fixes
  • Loading branch information
Nightwalker-87 committed Aug 11, 2024
1 parent 1f0b95c commit e493109
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 57 deletions.
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# stlink Changelog

# v1.8.1

Release date: 2024-09-01

This release drops support for some older operating systems. Check project README for details.

Updated system requirements:
- `cmake` >= 3.13.0
- `libusb` >= 1.0.22
- `libgtk-dev` >= 3.22.30

Features:
- Added support for STLINK-V3PWR ([#1388](https://github.com/stlink-org/stlink/pull/1388), [#1389](https://github.com/stlink-org/stlink/pull/1389))
- Dynamic SRAM size for F4 memory map ([#1390](https://github.com/stlink-org/stlink/pull/1390))
- Modifications to allow building of toolset in OpenBSD ([#1392](https://github.com/stlink-org/stlink/pull/1392))
- --mass-erase for st-flash write commands ([#1397](https://github.com/stlink-org/stlink/pull/1397))
- Support for setting option bytes to STM32L41x_L42x (according to RM0394) ([#1405](https://github.com/stlink-org/stlink/pull/1405), [#1412](https://github.com/stlink-org/stlink/pull/1412), [#1413](https://github.com/stlink-org/stlink/pull/1413))
- Improvements for stlink-gui ([#1411](https://github.com/stlink-org/stlink/pull/1411))
- [STM32U575/585]: Added support for OTP bytes ([#1419](https://github.com/stlink-org/stlink/pull/1419))
- [STM32Gx]: Added erase support for multi-bank products ([#1420](https://github.com/stlink-org/stlink/pull/1420))

Updates & changes:
- Debian 11 x64 doesn't work with v1.8.0 because of incompatible glibc ([#1376](https://github.com/stlink-org/stlink/pull/1376), commit [#ece34ef](https://github.com/stlink-org/stlink/commit/ece34efbce579ca7d367c58f903ffa6dc7bd96e6))
- [STM32L4R5ZI]: gdb-multiarch uses wrong osabi ([#1386](https://github.com/stlink-org/stlink/pull/1386), [#1387](https://github.com/stlink-org/stlink/pull/1387), [#1394](https://github.com/stlink-org/stlink/pull/1394))
- [doc] STM32H573 reports chipid 0x000 ([#1398](https://github.com/stlink-org/stlink/pull/1398), commit [#3655871](https://github.com/stlink-org/stlink/commit/3655871f8dd97294bbee191c1c7341c8a129af2f))

Fixes:

- Cmake minimal version mismatch ([#1374](https://github.com/stlink-org/stlink/pull/1374), [#1375](https://github.com/stlink-org/stlink/pull/1375), commit [#1ee7f6b](https://github.com/stlink-org/stlink/commit/1ee7f6b6c05e305112bb070ae571ebbe26c55946))
- Added a graceful way to terminate st-util ([#1395](https://github.com/stlink-org/stlink/pull/1395), [#1396](https://github.com/stlink-org/stlink/pull/1396))
- [st-trace] Bug in function static bool read_trace( ) ([#1400](https://github.com/stlink-org/stlink/pull/1400), commit [#32ce4bf](https://github.com/stlink-org/stlink/commit/32ce4bf88a816fb6a9841a33e6c5f6b593a9b927))
- Fixed STM32H7 FLASH_OPTCR unlock sequence ([#1401](https://github.com/stlink-org/stlink/pull/1401), [#1416](https://github.com/stlink-org/stlink/pull/1416))
- Restored support for STM32G4 Cat4 device STM32G491 ([#1403](https://github.com/stlink-org/stlink/pull/1403), [#1414](https://github.com/stlink-org/stlink/pull/1414))
- Fixed STM32H7 option byte programming ([#1417](https://github.com/stlink-org/stlink/pull/1417))
- Latest release stlink-1.8.0-win32 doesn't run ([#1364](https://github.com/stlink-org/stlink/pull/1364), [#1410](https://github.com/stlink-org/stlink/pull/1410) commit [_commit-ID TBD_])

# v1.8.0

Release date: 2024-02-01
Expand Down
42 changes: 21 additions & 21 deletions cmake/modules/Findlibusb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ include(FindPackageHandleStandardArgs)

if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") # FreeBSD; libusb is integrated into the system
# libusb header file
FIND_PATH(
LIBUSB_INCLUDE_DIR NAMES libusb.h
FIND_PATH(LIBUSB_INCLUDE_DIR
NAMES libusb.h
HINTS /usr/include
)

# libusb library
set(LIBUSB_NAME usb)
find_library(
LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
find_library(LIBUSB_LIBRARY
NAMES ${LIBUSB_NAME}
HINTS /usr /usr/local /opt
)

Expand All @@ -32,16 +32,16 @@ if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") # FreeBSD; libus

elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") # OpenBSD; libusb is available from ports
# libusb header file
FIND_PATH(
LIBUSB_INCLUDE_DIR NAMES libusb.h
FIND_PATH(LIBUSB_INCLUDE_DIR
NAMES libusb.h
HINTS /usr/local/include
PATH_SUFFIXES libusb-1.0
)

# libusb library
set(LIBUSB_NAME usb-1.0)
find_library(
LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
find_library(LIBUSB_LIBRARY
NAMES ${LIBUSB_NAME}
HINTS /usr/local
)

Expand Down Expand Up @@ -87,8 +87,8 @@ elseif (WIN32 OR (MINGW AND EXISTS "/etc/debian_version")) # Windows OR cro
)

# libusb header file
FIND_PATH(
LIBUSB_INCLUDE_DIR NAMES libusb.h
FIND_PATH(LIBUSB_INCLUDE_DIR
NAMES libusb.h
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/include
PATH_SUFFIXES libusb-1.0
NO_DEFAULT_PATH
Expand All @@ -97,19 +97,19 @@ elseif (WIN32 OR (MINGW AND EXISTS "/etc/debian_version")) # Windows OR cro

if (MINGW OR MSYS)
# libusb library (static)
set(LIBUSB_NAME usb-1.0)
find_library(
LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
set(LIBUSB_NAME libusb-1.0)
find_library(LIBUSB_LIBRARY
NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW${ARCH}/static
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
else (MSVC)
# libusb library
set(LIBUSB_NAME libusb-1.0.lib)
find_library(
LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MS${ARCH}/dll
set(LIBUSB_NAME libusb-1.0)
find_library(LIBUSB_LIBRARY
NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW${ARCH}/dll
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
Expand All @@ -122,16 +122,16 @@ elseif (WIN32 OR (MINGW AND EXISTS "/etc/debian_version")) # Windows OR cro

else () # all other OS (unix-based)
# libusb header file
FIND_PATH(
LIBUSB_INCLUDE_DIR NAMES libusb.h
FIND_PATH(LIBUSB_INCLUDE_DIR
NAMES libusb.h
HINTS /usr/include
PATH_SUFFIXES libusb-1.0
)

# libusb library
set(LIBUSB_NAME usb-1.0)
find_library(
LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
find_library(LIBUSB_LIBRARY
NAMES ${LIBUSB_NAME}
HINTS /usr /usr/local
)

Expand Down
44 changes: 17 additions & 27 deletions doc/compiling.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,43 @@
# Compiling from sources


## Microsoft Windows (10, 11)

### Common Requirements

On Windows users should ensure that the following software is installed:

- `git` (_optional, but recommended_)
- `7zip`
- `cmake`
- `7-zip`
- `MinGW-w64`
- `MSYS2`

### Installation

1. Install `git` from <https://git-scm.com/download/win>
2. Install `cmake` from <https://cmake.org/download><br />
2. Install `cmake` from <https://cmake.org/download/#latest> --> Binary distributions --> Windows x64 Installer<br />
Ensure that you add cmake to the $PATH system variable when following the instructions by the setup assistant.
3. Install MinGW-w64<br />
Download **MinGW-w64** from <https://github.com/niXman/mingw-builds-binaries/releases/download/13.2.0-rt_v11-rev1/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev1.7z>. Extract content to `C:\mingw-w64\` and add `C:\mingw-w64\bin\` to PATH-Variable.<br />

4. Create a new destination folder at a place of your choice
5. Open the command-line (cmd.exe) and execute `cd C:\$Path-to-your-destination-folder$\`
6. Fetch the project sourcefiles by running `git clone https://github.com/stlink-org/stlink.git`from the command-line (cmd.exe)<br />
or download and extract the stlink zip-sourcefolder from the Release page on GitHub.
3. Install `MSYS2` from <https://www.msys2.org/><br />
Follow the installation instructions on the website.
4. Install `mingw-w64` via the MSYS2 UCRT64 Shell: `pacman -S mingw-w64-x86_64-make`
5. Fetch the project sourcefiles by running `git clone https://github.com/stlink-org/stlink.git`from the command-line (cmd.exe)<br />
or download and extract (`7zip`) the stlink zip-sourcefolder from the Release page on GitHub.

### Building

#### MinGW-w64

1. Open command-line with administrator privileges
2. Move to the `stlink` directory
1. Open the command-line (cmd.exe) with administrator privileges
2. Move to the `stlink` directory with `cd C:\$Path-to-your-stlink-folder$\`
3. Execute `mingw64-build.bat`

NOTE:<br />
Per default the build script (currently) uses `C:\mingw-w64\x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0\mingw64\bin`.<br />
When installing different toolchains make sure to update the path in the `mingw64-build.bat`.<br />
This can be achieved by opening the .bat file with a common text editor.

Options:

- `/m` - compilation runs in parallel utilizing multiple cores
- `/p:Configuration=Release` - generates _Release_, optimized build.

Directory `<project_root>\build\Release` contains final executables.
(`st-util.exe` is located in `<project_root>\build\src\gdbserver\Release`).
Depending on the flavour of compilation the final executables will be placed in the following directories:
- Local compilation: `<project_root>\build-mingw\bin`
- Local installation: `C:\Program Files (x86)\stlink\bin`
- Package Generation (portable): `C:\Users\swift\Desktop\stlink\build-mingw\dist`

**NOTE:**

[ST-LINK drivers](https://www.st.com/en/development-tools/stsw-link009.html) are required for `stlink` to work.
[ST-LINK drivers](https://www.st.com/en/development-tools/stsw-link009.html) are required for programmers to work with `stlink`.


## Linux

Expand Down
4 changes: 2 additions & 2 deletions mingw64-build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

mkdir build-mingw
cd build-mingw
set PATH=C:\Program Files\CMake\bin;C:\mingw-w64\x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev1\mingw64\bin;%PATH%
set PATH=C:\Program Files\CMake\bin;C:\msys64\ucrt64\bin;C:\msys64\mingw64\bin;%PATH%
cmake -G "MinGW Makefiles" ..
mingw32-make clean
mingw32-make
mingw32-make install
mingw32-make package
cd ..
12 changes: 6 additions & 6 deletions src/st-util/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) {
}

uint32_t queryNameLength = (uint32_t) (separator - &packet[1]);
char* queryName = calloc(queryNameLength + 1, 1);
char* queryName = calloc(1, queryNameLength + 1);
strncpy(queryName, &packet[1], queryNameLength);

DLOG("query: %s;%s\n", queryName, params);
Expand Down Expand Up @@ -1032,7 +1032,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) {
if (length == 0) {
reply = strdup("l");
} else {
reply = calloc(length + 2, 1);
reply = calloc(1, length + 2);
reply[0] = 'm';
strncpy(&reply[1], data, length);
}
Expand Down Expand Up @@ -1191,7 +1191,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) {

// Length of decoded data cannot be more than encoded, as escapes are removed.
// Additional byte is reserved for alignment fix.
uint8_t *decoded = calloc(data_length + 1, 1);
uint8_t *decoded = calloc(1, data_length + 1);
uint32_t dec_index = 0;

for (uint32_t i = 0; i < data_length; i++) {
Expand Down Expand Up @@ -1347,7 +1347,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) {

if (ret) { DLOG("g packet: read_all_regs failed\n"); }

reply = calloc(8 * 16 + 1, 1);
reply = calloc(1, 8 * 16 + 1);

for (int32_t i = 0; i < 16; i++) {
sprintf(&reply[i * 8], "%08x", (uint32_t) htonl(regp.r[i]));
Expand Down Expand Up @@ -1398,7 +1398,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) {

if (reply == NULL) {
// if reply is set to "E00", skip
reply = calloc(8 + 1, 1);
reply = calloc(1, 8 + 1);
sprintf(reply, "%08x", myreg);
}

Expand Down Expand Up @@ -1479,7 +1479,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) {

// read failed somehow, don't return stale buffer

reply = calloc(count * 2 + 1, 1);
reply = calloc(1, count * 2 + 1);

for (uint32_t i = 0; i < count; i++) {
reply[i * 2 + 0] = hex[sl->q_buf[i + adj_start] >> 4];
Expand Down
2 changes: 1 addition & 1 deletion src/stlink-lib/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ int32_t stlink_parse_ihex(const char *path, uint8_t erased_pattern, uint8_t **me
}

*size = (end - *begin) + 1;
data = calloc(*size, 1); // use calloc to get NULL if out of memory
data = calloc(1, *size); // use calloc to get NULL if out of memory

if (!data) {
ELOG("Cannot allocate %u bytes\n", (*size));
Expand Down

0 comments on commit e493109

Please sign in to comment.