From 9f84dcdef89e8950bc631ba15b286530547bec72 Mon Sep 17 00:00:00 2001 From: murray Date: Thu, 15 Feb 2024 10:33:25 +0000 Subject: [PATCH 01/15] Fix poll.h include path The correct include path for poll(2) is poll.h not sys/poll.h. sys/poll.h may not be available on some libcs or may issue a warning. In particular this fixes a warning on musl systems. --- src/st-util/gdb-remote.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/st-util/gdb-remote.c b/src/st-util/gdb-remote.c index 25ca4da5b..0e6c69e72 100644 --- a/src/st-util/gdb-remote.c +++ b/src/st-util/gdb-remote.c @@ -12,7 +12,7 @@ #include #else #include -#include +#include #endif #include "gdb-remote.h" From 7a93f7a24d0afb69cf521cecc9d1bdff850ca4e4 Mon Sep 17 00:00:00 2001 From: murray Date: Thu, 15 Feb 2024 10:48:37 +0000 Subject: [PATCH 02/15] Add missing newline to log message --- src/stlink-lib/flash_loader.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stlink-lib/flash_loader.c b/src/stlink-lib/flash_loader.c index 16c717ca7..adce5e821 100644 --- a/src/stlink-lib/flash_loader.c +++ b/src/stlink-lib/flash_loader.c @@ -750,8 +750,8 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t sl->flash_type == STM32_FLASH_TYPE_C0) { if (sl->flash_type == STM32_FLASH_TYPE_L5_U5_H5 && (len % 16)) { - WLOG("Data size is aligned to 16 byte"); - len += 16 - len%16; + WLOG("Aligning data size to 16 bytes\n"); + len += 16 - len % 16; } DLOG("Starting %3u page write\n", len / sl->flash_pgsz); for (off = 0; off < len; off += sizeof(uint32_t)) { @@ -780,7 +780,7 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t uint32_t flash_regs_base = get_stm32l0_flash_base(sl); uint32_t pagesize = (flash_regs_base == FLASH_L0_REGS_ADDR)? L0_WRITE_BLOCK_SIZE : L1_WRITE_BLOCK_SIZE; - DLOG("Starting %3u page write\r\n", len / sl->flash_pgsz); + DLOG("Starting %3u page write\n", len / sl->flash_pgsz); off = 0; From 2d483db866f2afaedf4c5435bcb4a1403367ede8 Mon Sep 17 00:00:00 2001 From: murray Date: Thu, 15 Feb 2024 14:57:39 +0000 Subject: [PATCH 03/15] Rewrite usage text --- src/st-flash/flash.c | 59 ++++++++++++++++++++++++++------------- src/st-flash/flash_opts.c | 2 ++ 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/st-flash/flash.c b/src/st-flash/flash.c index 0b7c0cfca..c6c8768e8 100644 --- a/src/st-flash/flash.c +++ b/src/st-flash/flash.c @@ -44,25 +44,39 @@ static void cleanup(int32_t signum) { } static void usage(void) { - puts("command line: ./st-flash [--debug] [--reset] [--connect-under-reset] [--hot-plug] [--opt] [--serial ] [--format ] [--flash=] [--freq=] [--area=] {read|write} [path] [addr] [size]"); - puts("command line: ./st-flash [--debug] [--connect-under-reset] [--hot-plug] [--freq=] [--serial ] erase [addr] [size]"); - puts("command line: ./st-flash [--debug] [--freq=] [--serial ] reset"); - puts(" , and : Use hex format."); - puts(" : Use decimal, octal or hex (prefix 0xXXX) format, optionally followed by k=KB, or m=MB (eg. --flash=128k)"); - puts(" : Can be 'binary' (default) or 'ihex', although must be specified for binary format only."); - puts(" : Can be 'main' (default), 'system', 'otp', 'optcr', 'optcr1', 'option' or 'option_boot_add'"); - puts("print tool version info: ./st-flash [--version]"); - puts("example read option byte: ./st-flash --area=option read [path] [size]"); - puts("example write option byte: ./st-flash --area=option write 0xXXXXXXXX"); - puts("On selected targets:"); - puts("example read boot_add option byte: ./st-flash --area=option_boot_add read"); - puts("example write boot_add option byte: ./st-flash --area=option_boot_add write 0xXXXXXXXX"); - puts("example read option control register byte: ./st-flash --area=optcr read"); - puts("example write option control register1 byte: ./st-flash --area=optcr write 0xXXXXXXXX"); - puts("example read option control register1 byte: ./st-flash --area=optcr1 read"); - puts("example write option control register1 byte: ./st-flash --area=optcr1 write 0xXXXXXXXX"); - puts("example read OTP area: ./st-flash --area=otp read [path]"); - puts("example write OTP area: ./st-flash --area=otp write [path] 0xXXXXXXXX"); + puts("usage: st-flash [options] read [file] [addr] [size]"); + puts(" st-flash [options] write [addr] [size]"); + puts(" st-flash [options] write "); + puts(" st-flash [options] erase "); + puts(" st-flash [options] reset"); + puts(""); + puts("options:"); + puts(" --freq Frequency of JTAG/SWD, default 1800kHz."); + puts(" --serial STLink device to use."); + puts(" --connect-under-reset Pull reset low while connecting."); + puts(" --hot-plug Connect without reset."); + puts(" --reset Reset after writing."); + puts(" --format {binary|ihex} Format of file to read or write. When writing"); + puts(" with ihex specifying addr is not needed."); + puts(" --flash Specify size of flash, e.g. 128k, 1M."); + puts(" --area Area to access, one of: main(default), system,"); + puts(" otp, option, option_boot_add, optcr, optcr1."); + puts(" --opt Skip writing empty bytes at the tail end."); + puts(" --debug Output extra debug information."); + puts(" --version Print version information."); + puts(" --help Show this help."); + puts(""); + puts("examples:"); + puts(" st-flash --area=option read [file] [size]"); + puts(" st-flash --area=option write 0xXXXXXXXX"); + puts(" st-flash --area=option_boot_add read"); + puts(" st-flash --area=option_boot_add write 0xXXXXXXXX"); + puts(" st-flash --area=optcr read"); + puts(" st-flash --area=optcr write 0xXXXXXXXX"); + puts(" st-flash --area=optcr1 read"); + puts(" st-flash --area=optcr1 write 0xXXXXXXXX"); + puts(" st-flash --area=otp read "); + puts(" st-flash --area=otp write 0xXXXXXXXX"); } int32_t main(int32_t ac, char** av) { @@ -70,14 +84,19 @@ int32_t main(int32_t ac, char** av) { struct flash_opts o; int32_t err = -1; uint8_t * mem = NULL; + int32_t getopt_ret; o.size = 0; o.connect = CONNECT_NORMAL; - if (flash_get_opts(&o, ac - 1, av + 1) == -1) { + getopt_ret = flash_get_opts(&o, ac - 1, av + 1); + if (getopt_ret == -1) { printf("invalid command line\n"); usage(); return (-1); + } else if (getopt_ret == 1) { + usage(); + return 0; } printf("st-flash %s\n", STLINK_VERSION); diff --git a/src/st-flash/flash_opts.c b/src/st-flash/flash_opts.c index e2d4154fe..3403c56d5 100644 --- a/src/st-flash/flash_opts.c +++ b/src/st-flash/flash_opts.c @@ -98,6 +98,8 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) { if (strcmp(av[0], "--version") == 0) { printf("v%s\n", STLINK_VERSION); exit(EXIT_SUCCESS); + } else if (strcmp(av[0], "--help") == 0 || strcmp(av[0], "-h") == 0) { + return 1; } else if (strcmp(av[0], "--debug") == 0) { o->log_level = DEBUG_LOG_LEVEL; } else if (strcmp(av[0], "--opt") == 0) { From 6a6718b3342b6c5e282a4e33325b9f97908a0692 Mon Sep 17 00:00:00 2001 From: nightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:55:41 +0100 Subject: [PATCH 04/15] Post release patch for v1.8.0 - Fixed terminal screen output (Closes #1363) - Fixed compatibility with gcc-14 (Closes #1365) - Updated contact info in CODE_OF_CONDUCT - Updated man files & related install path - Updated libusb to v1.0.27 for Windows builds - Updated cmake_policy to CM0153 NEW --- .gitignore | 1 + CMakeLists.txt | 61 ++++++++----------- CODE_OF_CONDUCT.md | 2 +- cmake/modules/Findlibusb.cmake | 58 ++++++++++-------- cmake/modules/c_flags.cmake | 2 +- .../{packaging => modules}/cpack_config.cmake | 2 +- cmake/packaging/CMakeLists.txt | 2 +- cmake_uninstall.cmake.in | 6 +- doc/compiling.md | 7 +-- doc/man/CMakeLists.txt | 14 ++--- doc/man/st-flash.md | 4 +- doc/man/st-info.md | 4 +- doc/man/st-util.md | 4 +- ...nerate_binaries.sh => generate_binaries.sh | 8 +-- mingw64-build.bat | 2 +- src/stlink-lib/chipid.c | 2 +- src/stlink-lib/common_flash.c | 2 +- src/stlink-lib/flash_loader.c | 16 ++--- 18 files changed, 93 insertions(+), 104 deletions(-) rename cmake/{packaging => modules}/cpack_config.cmake (97%) rename cmake/packaging/windows/generate_binaries.sh => generate_binaries.sh (69%) diff --git a/.gitignore b/.gitignore index 1a5fd5ab1..382ea092f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ build build-mingw-32 build-mingw-64 +3rdparty .project .cmake/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 59d9970a7..d3344e394 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ ### cmake_minimum_required(VERSION 3.10.2) -cmake_policy(SET CMP0042 NEW) +cmake_policy(SET CMP0153 NEW) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) @@ -254,35 +254,22 @@ add_library(${STLINK_LIB_SHARED} SHARED ${STLINK_HEADERS} ${STLINK_SOURCE}) set(STLINK_SHARED_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) message(STATUS "STLINK_LIB_SHARED: ${STLINK_LIB_SHARED}") -message(STATUS "PROJECT_VERSION_MAJOR: ${PROJECT_VERSION_MAJOR}") message(STATUS "VERSION: ${STLINK_SHARED_VERSION}") set_target_properties(${STLINK_LIB_SHARED} PROPERTIES - SOVERSION ${PROJECT_VERSION_MAJOR} - VERSION ${STLINK_SHARED_VERSION} - OUTPUT_NAME ${PROJECT_NAME} - ) + SOVERSION ${PROJECT_VERSION_MAJOR} + VERSION ${STLINK_SHARED_VERSION} + OUTPUT_NAME ${PROJECT_NAME} + ) # Link shared library -if (WIN32) # ... with Windows libraries +if (WIN32) target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB} wsock32 ws2_32) else () target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB}) endif() -install(TARGETS ${STLINK_LIB_SHARED} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ) - -# Copy libusb DLL-library to binary output folder -if (WIN32) -file(COPY ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW64/dll/libusb-1.0.dll - DESTINATION ${CMAKE_INSTALL_BINDIR}) -file(COPY ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW64/dll/libusb-1.0.dll - DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}) -endif() +install(TARGETS ${STLINK_LIB_SHARED} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) ### @@ -300,17 +287,16 @@ add_library(${STLINK_LIB_STATIC} STATIC ${STLINK_HEADERS} ${STLINK_SOURCE}) set(STLINK_STATIC_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) message(STATUS "STLINK_LIB_STATIC: ${STLINK_LIB_STATIC}") -message(STATUS "PROJECT_VERSION_MAJOR: ${PROJECT_VERSION_MAJOR}") message(STATUS "VERSION: ${STLINK_STATIC_VERSION}") set_target_properties(${STLINK_LIB_STATIC} PROPERTIES - SOVERSION ${PROJECT_VERSION_MAJOR} - VERSION ${STLINK_STATIC_VERSION} - OUTPUT_NAME ${STLINK_LIB_STATIC_OUTPUT_NAME} - ) + SOVERSION ${PROJECT_VERSION_MAJOR} + VERSION ${STLINK_STATIC_VERSION} + OUTPUT_NAME ${STLINK_LIB_STATIC_OUTPUT_NAME} + ) # Link static library -if (WIN32) # ... with Windows libraries +if (WIN32) target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB} wsock32 ws2_32) else () target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB}) @@ -341,15 +327,15 @@ add_executable(st-util ${ST-UTIL_SOURCES}) add_executable(st-trace ${ST-TRACE_SOURCES}) if (WIN32) - target_link_libraries(st-flash ${STLINK_LIB_STATIC} ${SSP_LIB}) - target_link_libraries(st-info ${STLINK_LIB_STATIC} ${SSP_LIB}) - target_link_libraries(st-util ${STLINK_LIB_STATIC} ${SSP_LIB}) - target_link_libraries(st-trace ${STLINK_LIB_STATIC} ${SSP_LIB}) + target_link_libraries(st-flash ${STLINK_LIB_STATIC}) + target_link_libraries(st-info ${STLINK_LIB_STATIC}) + target_link_libraries(st-util ${STLINK_LIB_STATIC}) + target_link_libraries(st-trace ${STLINK_LIB_STATIC}) else () - target_link_libraries(st-flash ${STLINK_LIB_SHARED} ${SSP_LIB}) - target_link_libraries(st-info ${STLINK_LIB_SHARED} ${SSP_LIB}) - target_link_libraries(st-util ${STLINK_LIB_SHARED} ${SSP_LIB}) - target_link_libraries(st-trace ${STLINK_LIB_SHARED} ${SSP_LIB}) + target_link_libraries(st-flash ${STLINK_LIB_SHARED}) + target_link_libraries(st-info ${STLINK_LIB_SHARED}) + target_link_libraries(st-util ${STLINK_LIB_SHARED}) + target_link_libraries(st-trace ${STLINK_LIB_SHARED}) endif() install(TARGETS st-flash DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -380,10 +366,10 @@ endif() # MCU configuration files if (WIN32) -set(CMAKE_CHIPS_DIR ${CMAKE_INSTALL_PREFIX}/config/chips) + set(CMAKE_CHIPS_DIR ${CMAKE_INSTALL_PREFIX}/config/chips) else () -set(CMAKE_CHIPS_DIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/chips) -endif () + set(CMAKE_CHIPS_DIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/config/chips) +endif() add_definitions( -DSTLINK_CHIPS_DIR="${CMAKE_CHIPS_DIR}" ) file(GLOB CHIP_FILES ${CMAKE_SOURCE_DIR}/config/chips/*.chip) install(FILES ${CHIP_FILES} DESTINATION ${CMAKE_CHIPS_DIR}) @@ -396,6 +382,7 @@ add_subdirectory(src/stlink-gui) # contains subordinate CMakeLists to build GUI add_subdirectory(tests) # contains subordinate CMakeLists to build test executables add_subdirectory(cmake/packaging) # contains subordinate CMakeLists to build packages + ### # Uninstall target ### diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index b0623068a..2de1cc754 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -55,7 +55,7 @@ further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at texane@gmail.com. All +reported by contacting the project team [here](https://github.com/stlink-org/stlink/discussions). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. diff --git a/cmake/modules/Findlibusb.cmake b/cmake/modules/Findlibusb.cmake index 830060486..d26639b99 100644 --- a/cmake/modules/Findlibusb.cmake +++ b/cmake/modules/Findlibusb.cmake @@ -10,41 +10,49 @@ include(FindPackageHandleStandardArgs) -if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") # FreeBSD; libusb is integrated into the system +if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") # FreeBSD; libusb is integrated into the system + # libusb header file FIND_PATH( LIBUSB_INCLUDE_DIR NAMES libusb.h HINTS /usr/include ) + + # libusb library set(LIBUSB_NAME usb) find_library( LIBUSB_LIBRARY NAMES ${LIBUSB_NAME} HINTS /usr /usr/local /opt ) + 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 "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 +elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") # OpenBSD; libusb is available from ports + # libusb header file 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} 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? +elseif (WIN32 OR (MINGW AND EXISTS "/etc/debian_version")) # Windows OR cross-build with MinGW-toolchain on Debian + # MinGW: 64-bit or 32-bit? if (CMAKE_SIZEOF_VOID_P EQUAL 8) message(STATUS "=== Building for Windows (x86-64) ===") set(ARCH 64) @@ -53,26 +61,20 @@ elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-to set(ARCH 32) endif() - if (WIN32 AND NOT EXISTS "/etc/debian_version") # Skip this for Debian... + if (NOT LIBUSB_FOUND) # Preparations for installing libusb library - set(LIBUSB_WIN_VERSION 1.0.25) # set libusb version - set(LIBUSB_WIN_ARCHIVE libusb-${LIBUSB_WIN_VERSION}.7z) - if (WIN32 AND NOT EXISTS "/etc/debian_version") # ... on native Windows systems - set(LIBUSB_WIN_ARCHIVE_PATH ${CMAKE_BINARY_DIR}/${LIBUSB_WIN_ARCHIVE}) - set(LIBUSB_WIN_OUTPUT_FOLDER ${CMAKE_BINARY_DIR}/3rdparty/libusb-${LIBUSB_WIN_VERSION}) - elseif (EXISTS "/etc/debian_version" AND MINGW) # ... only for cross-building on Debian - set(LIBUSB_WIN_ARCHIVE_PATH ${CMAKE_SOURCE_DIR}/build-mingw-${ARCH}/${LIBUSB_WIN_ARCHIVE}) - set(LIBUSB_WIN_OUTPUT_FOLDER ${CMAKE_SOURCE_DIR}/build-mingw-${ARCH}/3rdparty/libusb-${LIBUSB_WIN_VERSION}) - endif() + set(LIBUSB_WIN_VERSION 1.0.27) # set libusb version + set(LIBUSB_WIN_ARCHIVE_PATH ${CMAKE_SOURCE_DIR}/3rdparty/libusb-${LIBUSB_WIN_VERSION}.7z) + set(LIBUSB_WIN_OUTPUT_FOLDER ${CMAKE_SOURCE_DIR}/3rdparty/libusb-${LIBUSB_WIN_VERSION}) # Get libusb package - if (EXISTS ${LIBUSB_WIN_ARCHIVE_PATH}) # ... should the package be already there (for whatever reason) + if (EXISTS ${LIBUSB_WIN_ARCHIVE_PATH}) # ... should the package be already there message(STATUS "libusb archive already in build folder") else () # ... download the package message(STATUS "downloading libusb ${LIBUSB_WIN_VERSION}") 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 aabe177bde869bfad34278335eaf8955 + ${LIBUSB_WIN_ARCHIVE_PATH} EXPECTED_MD5 c72153fc5a32f3b942427b0671897a1a ) endif() @@ -84,7 +86,7 @@ elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-to WORKING_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER} ) - # Find path to libusb library + # libusb header file FIND_PATH( LIBUSB_INCLUDE_DIR NAMES libusb.h HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/include @@ -94,6 +96,7 @@ elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-to ) if (MINGW OR MSYS) + # libusb library (static) set(LIBUSB_NAME usb-1.0) find_library( LIBUSB_LIBRARY NAMES ${LIBUSB_NAME} @@ -101,8 +104,8 @@ elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-to NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH ) - - elseif (MSVC) + else (MSVC) + # libusb library set(LIBUSB_NAME libusb-1.0.lib) find_library( LIBUSB_LIBRARY NAMES ${LIBUSB_NAME} @@ -111,23 +114,28 @@ elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-to NO_CMAKE_FIND_ROOT_PATH ) endif() - message(STATUS "Missing libusb library has been installed") endif() - FIND_PACKAGE_HANDLE_STANDARD_ARGS(libusb DEFAULT_MSG LIBUSB_LIBRARY LIBUSB_INCLUDE_DIR) + + FIND_PACKAGE_HANDLE_STANDARD_ARGS(libusb DEFAULT_MSG LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY) mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY) + message(STATUS "Missing libusb library has been installed") -else () # all other OS (unix-based) +else () # all other OS (unix-based) + # libusb header file FIND_PATH( LIBUSB_INCLUDE_DIR NAMES libusb.h - HINTS /usr /usr/local /opt + HINTS /usr/include PATH_SUFFIXES libusb-1.0 ) + + # libusb library set(LIBUSB_NAME usb-1.0) find_library( LIBUSB_LIBRARY NAMES ${LIBUSB_NAME} - HINTS /usr /usr/local /opt + HINTS /usr /usr/local ) - FIND_PACKAGE_HANDLE_STANDARD_ARGS(libusb DEFAULT_MSG LIBUSB_LIBRARY LIBUSB_INCLUDE_DIR) + + FIND_PACKAGE_HANDLE_STANDARD_ARGS(libusb DEFAULT_MSG LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY) mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY) if (NOT LIBUSB_FOUND) diff --git a/cmake/modules/c_flags.cmake b/cmake/modules/c_flags.cmake index d30f45ec9..e28ea2dae 100644 --- a/cmake/modules/c_flags.cmake +++ b/cmake/modules/c_flags.cmake @@ -40,7 +40,7 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") add_cflag_if_supported("-Wredundant-decls") endif() -if (NOT (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW))) +if (NOT (WIN32 OR (MINGW AND EXISTS "/etc/debian_version"))) add_cflag_if_supported("-fPIC") endif() diff --git a/cmake/packaging/cpack_config.cmake b/cmake/modules/cpack_config.cmake similarity index 97% rename from cmake/packaging/cpack_config.cmake rename to cmake/modules/cpack_config.cmake index 17de607ef..d1d6ff069 100644 --- a/cmake/packaging/cpack_config.cmake +++ b/cmake/modules/cpack_config.cmake @@ -25,7 +25,7 @@ elseif (WIN32) # Wi set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${TOOLCHAIN_PREFIX}") set(CPACK_INSTALL_PREFIX "") -elseif (EXISTS "/etc/debian_version" AND NOT EXISTS WIN32) # Package-build is available on Debian/Ubuntu only +elseif (EXISTS "/etc/debian_version" AND (NOT EXISTS WIN32)) # Package-build on Debian/Ubuntu message(STATUS "Debian-based Linux OS detected") set(CPACK_GENERATOR "DEB;RPM") # RPM requires package `rpm` diff --git a/cmake/packaging/CMakeLists.txt b/cmake/packaging/CMakeLists.txt index 1cf640552..b50b679a9 100644 --- a/cmake/packaging/CMakeLists.txt +++ b/cmake/packaging/CMakeLists.txt @@ -2,4 +2,4 @@ add_subdirectory(deb) add_subdirectory(rpm) add_subdirectory(windows) -include(cpack_config.cmake) +include(${CMAKE_MODULE_PATH}/cpack_config.cmake) diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in index 0c9f6a437..1b9a48296 100644 --- a/cmake_uninstall.cmake.in +++ b/cmake_uninstall.cmake.in @@ -7,10 +7,10 @@ string(REGEX REPLACE "\n" ";" files "${files}") foreach (file ${files}) message(STATUS "Uninstalling $ENV{DESTDIR}${file}") if (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") - exec_program("@CMAKE_COMMAND@" - ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + execute_process( + COMMAND "@CMAKE_COMMAND@" -E remove \"$ENV{DESTDIR}${file}\" OUTPUT_VARIABLE rm_out - RETURN_VALUE rm_retval + RESULT_VARIABLE rm_retval ) if (NOT "${rm_retval}" STREQUAL 0) message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") diff --git a/doc/compiling.md b/doc/compiling.md index 804781faa..68fc5994e 100644 --- a/doc/compiling.md +++ b/doc/compiling.md @@ -45,12 +45,7 @@ Options: Directory `\build\Release` contains final executables. (`st-util.exe` is located in `\build\src\gdbserver\Release`). -**NOTE 1:** - -Executables link against libusb.dll library. It has to be placed in the same directory as binaries or in PATH. -It can be copied from: `\build\3rdparty\libusb-{version}\MS{arch}\dll\libusb-1.0.dll`. - -**NOTE 2:** +**NOTE:** [ST-LINK drivers](https://www.st.com/en/development-tools/stsw-link009.html) are required for `stlink` to work. diff --git a/doc/man/CMakeLists.txt b/doc/man/CMakeLists.txt index f225c85b7..41092aae3 100644 --- a/doc/man/CMakeLists.txt +++ b/doc/man/CMakeLists.txt @@ -2,7 +2,7 @@ # Generate manpages ### -set(MANPAGES st-util st-flash st-info) +set(MANPAGES st-info st-flash st-util) # Only generate manpages with pandoc in Debug builds if (${STLINK_GENERATE_MANPAGES}) @@ -12,7 +12,7 @@ if (${STLINK_GENERATE_MANPAGES}) ${manpage}.1 SOURCES ${manpage}.md PANDOC_DIRECTIVES -s -t man - PRODUCT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + PRODUCT_DIRECTORY ${CMAKE_INSTALL_FULL_DATADIR} ) endforeach () else () @@ -21,16 +21,16 @@ endif() # Install from output folder or this folder foreach (manpage ${MANPAGES}) - if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${manpage}.1) - set(f "${CMAKE_CURRENT_BINARY_DIR}/${manpage}.1") - elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.1") + if (EXISTS ${CMAKE_INSTALL_FULL_DATADIR}/${manpage}.1) + set(f "${CMAKE_INSTALL_FULL_DATADIR}/${manpage}.1") + elseif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.1) set(f "${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.1") - else() + else () message(AUTHOR_WARNING "Manpage ${manpage} not generated") endif() if (f AND NOT WIN32) - install(FILES ${f} DESTINATION ${CMAKE_INSTALL_DATADIR}/man/man1) + install(FILES ${f} DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/man/man1) unset(f) endif() endforeach () diff --git a/doc/man/st-flash.md b/doc/man/st-flash.md index 9b2cfcad5..7ab86d87f 100644 --- a/doc/man/st-flash.md +++ b/doc/man/st-flash.md @@ -1,6 +1,6 @@ -% st-flash(1) Open Source STMicroelectronics Stlink Tools | stlink +% st-flash(1) Open source version of the STMicroelectronics STLINK Tools | stlink % -% Feb 2018 +% Feb 2023 # NAME diff --git a/doc/man/st-info.md b/doc/man/st-info.md index 2cca61f83..685e8988d 100644 --- a/doc/man/st-info.md +++ b/doc/man/st-info.md @@ -1,6 +1,6 @@ -% st-flash(1) Open Source STMicroelectronics Stlink Tools | stlink +% st-flash(1) Open source version of the STMicroelectronics STLINK Tools | stlink % -% Oct 2020 +% Feb 2023 # NAME st-info - Provides information about connected STLink and STM32 devices diff --git a/doc/man/st-util.md b/doc/man/st-util.md index 62f850203..2c597402a 100644 --- a/doc/man/st-util.md +++ b/doc/man/st-util.md @@ -1,6 +1,6 @@ -% st-util(1) Open Source STMicroelectronics Stlink Tools | stlink +% st-util(1) Open source version of the STMicroelectronics STLINK Tools | stlink % -% Feb 2018 +% Feb 2023 # NAME diff --git a/cmake/packaging/windows/generate_binaries.sh b/generate_binaries.sh similarity index 69% rename from cmake/packaging/windows/generate_binaries.sh rename to generate_binaries.sh index f3642c316..e8efc4c8d 100644 --- a/cmake/packaging/windows/generate_binaries.sh +++ b/generate_binaries.sh @@ -3,28 +3,26 @@ ### # Install this cross-compiler toolchain: -#sudo apt-get install mingw-w64 +# sudo apt-get install mingw-w64 # x86_64 mkdir build-mingw-64 cd build-mingw-64 cmake -DCMAKE_SYSTEM_NAME=Windows \ -DTOOLCHAIN_PREFIX=x86_64-w64-mingw32 \ - -DCMAKE_TOOLCHAIN_FILE=./../cmake/modules/set_toolchain.cmake .. + -DCMAKE_TOOLCHAIN_FILE=./cmake/modules/set_toolchain.cmake .. make package sudo cp dist/*.zip ../build/Release/dist make clean cd .. -rm -rf build-mingw-64 # i686 mkdir build-mingw-32 cd build-mingw-32 cmake -DCMAKE_SYSTEM_NAME=Windows \ -DTOOLCHAIN_PREFIX=i686-w64-mingw32 \ - -DCMAKE_TOOLCHAIN_FILE=./../cmake/modules/set_toolchain.cmake .. + -DCMAKE_TOOLCHAIN_FILE=./cmake/modules/set_toolchain.cmake .. make package sudo cp dist/*.zip ../build/Release/dist make clean cd .. -rm -rf build-mingw-32 diff --git a/mingw64-build.bat b/mingw64-build.bat index bc50c97a3..735618405 100644 --- a/mingw64-build.bat +++ b/mingw64-build.bat @@ -4,7 +4,7 @@ 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% cmake -G "MinGW Makefiles" .. -mingw32-make +mingw32-make clean mingw32-make install mingw32-make package cd .. diff --git a/src/stlink-lib/chipid.c b/src/stlink-lib/chipid.c index c115089a4..0a6a4e9c1 100644 --- a/src/stlink-lib/chipid.c +++ b/src/stlink-lib/chipid.c @@ -65,7 +65,7 @@ void process_chipfile(char *fname) { return; } - ts = calloc(sizeof(struct stlink_chipid_params), 1); + ts = calloc(1, sizeof(struct stlink_chipid_params)); while (fgets(buf, sizeof(buf), fp) != NULL) { diff --git a/src/stlink-lib/common_flash.c b/src/stlink-lib/common_flash.c index aa8db5bfd..73c77d090 100644 --- a/src/stlink-lib/common_flash.c +++ b/src/stlink-lib/common_flash.c @@ -1223,7 +1223,7 @@ int32_t stlink_erase_flash_section(stlink_t *sl, stm32_addr_t base_addr, uint32_ return (-1); } - fprintf(stdout, "-> Flash page at %#x erased (size: %#x)\r", addr, page_size); + fprintf(stdout, "-> Flash page at %#x erased (size: %#x)\n", addr, page_size); fflush(stdout); // check the next page is within the range to erase diff --git a/src/stlink-lib/flash_loader.c b/src/stlink-lib/flash_loader.c index 16c717ca7..57868db3c 100644 --- a/src/stlink-lib/flash_loader.c +++ b/src/stlink-lib/flash_loader.c @@ -471,7 +471,7 @@ int32_t stm32l1_write_half_pages(stlink_t *sl, flash_loader_t *fl, stm32_addr_t if (sl->verbose >= 1) { // show progress; writing procedure is slow and previous errors are misleading - fprintf(stdout, "\r%3u/%3u halfpages written", count + 1, num_half_pages); + fprintf(stdout, "%3u/%3u halfpages written\n", count + 1, num_half_pages); fflush(stdout); } @@ -614,7 +614,7 @@ int32_t stlink_flashloader_start(stlink_t *sl, flash_loader_t *fl) { int32_t voltage; if (sl->version.stlink_v == 1) { - WLOG("STLINK V1 cannot read voltage, use default voltage 3.2V\n"); + WLOG("STLINK V1 cannot read voltage, use default voltage 3.2 V\n"); voltage = 3200; } else { voltage = stlink_target_voltage(sl); @@ -758,7 +758,7 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t uint32_t data; if ((off % sl->flash_pgsz) > (sl->flash_pgsz - 5)) { - fprintf(stdout, "\r%3u/%-3u pages written", (off / sl->flash_pgsz + 1), (len / sl->flash_pgsz)); + fprintf(stdout, "%3u/%-3u pages written\n", (off / sl->flash_pgsz + 1), (len / sl->flash_pgsz)); fflush(stdout); } @@ -780,7 +780,7 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t uint32_t flash_regs_base = get_stm32l0_flash_base(sl); uint32_t pagesize = (flash_regs_base == FLASH_L0_REGS_ADDR)? L0_WRITE_BLOCK_SIZE : L1_WRITE_BLOCK_SIZE; - DLOG("Starting %3u page write\r\n", len / sl->flash_pgsz); + DLOG("Starting %3u page write\n", len / sl->flash_pgsz); off = 0; @@ -797,7 +797,7 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t uint32_t data; if ((off % sl->flash_pgsz) > (sl->flash_pgsz - 5)) { - fprintf(stdout, "\r%3u/%-3u pages written", (off / sl->flash_pgsz + 1), (len / sl->flash_pgsz)); + fprintf(stdout, "%3u/%-3u pages written\n", (off / sl->flash_pgsz + 1), (len / sl->flash_pgsz)); fflush(stdout); } @@ -834,7 +834,7 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t if (sl->verbose >= 1) { // show progress; writing procedure is slow and previous errors are // misleading - fprintf(stdout, "\r%3u/%-3u pages written", ++write_block_count, + fprintf(stdout, "%3u/%-3u pages written\n", ++write_block_count, (len + sl->flash_pgsz - 1) / sl->flash_pgsz); fflush(stdout); } @@ -854,7 +854,7 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t if (sl->verbose >= 1) { // show progress - fprintf(stdout, "\r%u/%u bytes written", off, len); + fprintf(stdout, "%u/%u bytes written\n", off, len); fflush(stdout); } } @@ -902,7 +902,7 @@ int32_t stlink_flashloader_stop(stlink_t *sl, flash_loader_t *fl) { // enable interrupt if (!stlink_read_debug32(sl, STLINK_REG_DHCSR, &dhcsr)) { stlink_write_debug32(sl, STLINK_REG_DHCSR, STLINK_REG_DHCSR_DBGKEY | STLINK_REG_DHCSR_C_DEBUGEN | - (dhcsr & (~STLINK_REG_DHCSR_C_MASKINTS))); + (dhcsr & (~STLINK_REG_DHCSR_C_MASKINTS))); } // restore DMA state From 20c4ae1e0fb5ec41bfbc2a8946646bc3f3247bca Mon Sep 17 00:00:00 2001 From: nightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:34:37 +0100 Subject: [PATCH 05/15] Updated debian package config - Switched to gbp workflow - binary OSX blobs no longer included - Install chips definitions in stlink-tools - Updated symbols files for v1.8.0 - Updated changelog for v1.8.0-1 release --- debian/changelog | 10 +++++ debian/control | 22 ++++----- debian/copyright | 3 -- debian/gbp.conf | 11 +++-- ...-lib-dev.install => libstlink-dev.install} | 0 ...{stlink-lib.install => libstlink1.install} | 0 debian/rules | 3 ++ debian/stlink-lib.symbols | 45 ++++++++++++++++--- debian/stlink-tools.install | 3 +- debian/stlink.pc.in | 2 +- debian/upstream/metadata | 4 ++ debian/watch | 2 +- 12 files changed, 76 insertions(+), 29 deletions(-) rename debian/{stlink-lib-dev.install => libstlink-dev.install} (100%) rename debian/{stlink-lib.install => libstlink1.install} (100%) create mode 100644 debian/upstream/metadata diff --git a/debian/changelog b/debian/changelog index 7a7b4e54a..ce77e233a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +stlink (1.8.0-1) unstable; urgency=medium + + * Switch to gbp workflow, binary OSX blobs no longer included upstream + * Merge tag 'upstream/1.8.0' into debian + * Drop cross.patch, merged upstream + * Install chips definitions in stlink-tools + * Update symbols files for 1.8.0 + + -- Luca Boccassi Thu, 08 Feb 2024 19:28:19 +0000 + stlink (1.7.0+ds-1) unstable; urgency=medium * Merge tag 'v1.7.0' into debian. (Closes: #984356) diff --git a/debian/control b/debian/control index c3e654ec5..e2900cf62 100644 --- a/debian/control +++ b/debian/control @@ -1,47 +1,43 @@ Source: stlink Priority: optional Maintainer: Luca Boccassi -Build-Depends: debhelper-compat (= 13), cmake (>= 3.4.2), libusb-1.0-0-dev, libgtk-3-dev -Standards-Version: 4.5.1 +Build-Depends: debhelper-compat (= 13), cmake, libusb-1.0-0-dev, libgtk-3-dev, pkgconf, systemd-dev +Standards-Version: 4.6.2 Rules-Requires-Root: no Section: electronics Homepage: https://github.com/stlink-org/stlink Vcs-Git: https://github.com/bluca/stlink.git -b debian Vcs-Browser: https://github.com/bluca/stlink -Package: stlink-lib-dev +Package: libstlink-dev Section: libdevel Architecture: linux-any Multi-Arch: same -Depends: stlink-lib (= ${binary:Version}), ${misc:Depends} -Replaces: libstlink-dev (<< 1.7.0+ds-1) -Breaks: libstlink-dev (<< 1.7.0+ds-1) +Depends: libstlink1 (= ${binary:Version}), ${misc:Depends} Description: Open source version of the STMicroelectronics STLINK Tools . - This package contains development files for stlink. + This package contains the development files for stlink. -Package: stlink-lib +Package: libstlink1 Section: libs Architecture: linux-any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends} -Replaces: libstlink1 (<< 1.7.0+ds-1) -Breaks: libstlink1 (<< 1.7.0+ds-1) Description: Open source version of the STMicroelectronics STLINK Tools . This package contains the shared library for stlink. Package: stlink-tools Architecture: linux-any -Depends: stlink-lib (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} +Depends: libstlink1 (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} Description: Open source version of the STMicroelectronics STLINK Tools . - This package contains commandline utilities for stlink, as well as modprobe + This package contains commandline utilities for stlink, and modprobe and udev rules. Package: stlink-gui Architecture: linux-any -Depends: stlink-lib (= ${binary:Version}), stlink-tools (= ${binary:Version}), +Depends: libstlink1 (= ${binary:Version}), stlink-tools (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} Description: Open source version of the STMicroelectronics STLINK Tools . diff --git a/debian/copyright b/debian/copyright index b7f9c3106..17ec74960 100644 --- a/debian/copyright +++ b/debian/copyright @@ -2,9 +2,6 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: stlink Upstream-Contact: Nightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com> Source: https://github.com/stlink-org/stlink -Comment: Upstream tarball has been repackaged to remove binary OSX kernel - drivers that are of unknown license and of no use to Debian. -Files-Excluded: stlinkv1_macos_driver Files: * Copyright: 2011-2021 The stlink project maintainers diff --git a/debian/gbp.conf b/debian/gbp.conf index 418e536e9..4e9d55574 100644 --- a/debian/gbp.conf +++ b/debian/gbp.conf @@ -1,7 +1,12 @@ -[buildpackage] -upstream-tag = %(version)s +[DEFAULT] debian-branch = debian +upstream-branch = upstream +pristine-tar = True +sign-tags = True + +[import-orig] +upstream-vcs-tag = v%(version)s [dch] -git-log = --first-parent customizations = /usr/share/doc/git-buildpackage/examples/wrap_cl.py +git-log = --first-parent \ No newline at end of file diff --git a/debian/stlink-lib-dev.install b/debian/libstlink-dev.install similarity index 100% rename from debian/stlink-lib-dev.install rename to debian/libstlink-dev.install diff --git a/debian/stlink-lib.install b/debian/libstlink1.install similarity index 100% rename from debian/stlink-lib.install rename to debian/libstlink1.install diff --git a/debian/rules b/debian/rules index 512bd533f..04a6aeb7b 100755 --- a/debian/rules +++ b/debian/rules @@ -10,12 +10,15 @@ include /usr/share/dpkg/default.mk # see FEATURE AREAS in dpkg-buildflags(1) export DEB_BUILD_MAINT_OPTIONS = hardening=+all +export deb_udevdir = $(shell pkg-config --variable=udevdir udev | sed s,^/,,) + %: dh $@ --buildsystem cmake override_dh_auto_configure: dh_auto_configure -- \ -DSTLINK_UDEV_RULES_DIR='/lib/udev/rules.d' + -DSTLINK_UDEV_RULES_DIR=/$(deb_udevdir)/rules.d override_dh_auto_install: dh_auto_install diff --git a/debian/stlink-lib.symbols b/debian/stlink-lib.symbols index 9fb371d64..7d77f3bbc 100644 --- a/debian/stlink-lib.symbols +++ b/debian/stlink-lib.symbols @@ -1,4 +1,4 @@ -stlink-lib.so.1 stlink-lib #MINVER# +libstlink.so.1 libstlink1 #MINVER# Md5Calculate@Base 1.6.1 Md5Finalise@Base 1.6.1 Md5Initialise@Base 1.6.1 @@ -62,13 +62,32 @@ stlink-lib.so.1 stlink-lib #MINVER# calculate_F7_sectornum@Base 1.5.0 calculate_H7_sectornum@Base 1.7.0 calculate_L4_page@Base 1.5.0 + check_file@Base 1.8.0 + check_flash_error@Base 1.8.0 + clear_flash_cr_pg@Base 1.8.0 + clear_flash_error@Base 1.8.0 + dump_a_chip@Base 1.8.0 + get_stm32l0_flash_base@Base 1.8.0 + init_chipids@Base 1.8.0 #MISSING: 1.7.0# is_bigendian@Base 1.5.0 + is_flash_busy@Base 1.8.0 + lock_flash@Base 1.8.0 + lock_flash_option@Base 1.8.0 + map_file@Base 1.8.0 + md5_calculate@Base 1.8.0 + process_chipfile@Base 1.8.0 + read_flash_cr@Base 1.8.0 + read_flash_sr@Base 1.8.0 read_uint16@Base 1.5.0 read_uint32@Base 1.5.0 send_recv@Base 1.5.0 send_usb_data_only@Base 1.5.0 send_usb_mass_storage_command@Base 1.5.0 stlink_calculate_pagesize@Base 1.5.0 + stlink_check_address_alignment@Base 1.8.0 + stlink_check_address_range_validity@Base 1.8.0 + stlink_check_address_range_validity_otp@Base 1.8.0 + stlink_checksum@Base 1.8.0 stlink_chip_id@Base 1.5.0 stlink_chipid_get_params@Base 1.5.0 stlink_close@Base 1.5.0 @@ -80,6 +99,7 @@ stlink-lib.so.1 stlink-lib #MINVER# stlink_enter_swd_mode@Base 1.5.0 stlink_erase_flash_mass@Base 1.5.0 stlink_erase_flash_page@Base 1.5.0 + stlink_erase_flash_section@Base 1.8.0 stlink_exit_debug_mode@Base 1.5.0 stlink_exit_dfu_mode@Base 1.5.0 stlink_fcheck_flash@Base 1.5.0 @@ -91,6 +111,7 @@ stlink-lib.so.1 stlink-lib #MINVER# stlink_flashloader_write@Base 1.7.0 stlink_force_debug@Base 1.5.0 stlink_fread@Base 1.5.0 + stlink_fwrite_finalize@Base 1.8.0 stlink_fwrite_flash@Base 1.5.0 stlink_fwrite_option_bytes@Base 1.6.0 #MISSING: 1.6.1# stlink_fwrite_option_bytes_32bit@Base 1.6.0 @@ -112,20 +133,24 @@ stlink-lib.so.1 stlink-lib #MINVER# stlink_read_debug32@Base 1.5.0 stlink_read_mem32@Base 1.5.0 stlink_read_option_bytes32@Base 1.6.1 - stlink_read_option_bytes_Gx@Base 1.6.1 +#MISSING: 1.8.0# stlink_read_option_bytes_Gx@Base 1.6.1 stlink_read_option_bytes_boot_add32@Base 1.7.0 stlink_read_option_bytes_boot_add_f7@Base 1.7.0 stlink_read_option_bytes_f2@Base 1.6.0 stlink_read_option_bytes_f4@Base 1.6.0 stlink_read_option_bytes_f7@Base 1.7.0 stlink_read_option_bytes_generic@Base 1.6.1 + stlink_read_option_bytes_gx@Base 1.8.0 stlink_read_option_control_register1_32@Base 1.7.0 stlink_read_option_control_register1_f7@Base 1.7.0 stlink_read_option_control_register32@Base 1.7.0 - stlink_read_option_control_register_Gx@Base 1.7.0 +#MISSING: 1.8.0# stlink_read_option_control_register_Gx@Base 1.7.0 + stlink_read_option_control_register_f0@Base 1.8.0 stlink_read_option_control_register_f2@Base 1.7.0 stlink_read_option_control_register_f4@Base 1.7.0 stlink_read_option_control_register_f7@Base 1.7.0 + stlink_read_option_control_register_gx@Base 1.8.0 + stlink_read_option_control_register_wb@Base 1.8.0 stlink_read_reg@Base 1.5.0 stlink_read_unsupported_reg@Base 1.5.0 stlink_reset@Base 1.5.0 @@ -140,9 +165,9 @@ stlink-lib.so.1 stlink-lib #MINVER# stlink_step@Base 1.5.0 stlink_target_connect@Base 1.7.0 stlink_target_voltage@Base 1.5.0 - stlink_trace_disable@Base 1.7.0 - stlink_trace_enable@Base 1.7.0 - stlink_trace_read@Base 1.7.0 +#MISSING: 1.8.0# stlink_trace_disable@Base 1.7.0 +#MISSING: 1.8.0# stlink_trace_enable@Base 1.7.0 +#MISSING: 1.8.0# stlink_trace_read@Base 1.7.0 stlink_v1_open@Base 1.5.0 stlink_v1_open_inner@Base 1.5.0 stlink_verify_write_flash@Base 1.5.0 @@ -157,6 +182,7 @@ stlink-lib.so.1 stlink-lib #MINVER# stlink_write_option_bytes_boot_add32@Base 1.7.0 stlink_write_option_control_register1_32@Base 1.7.0 stlink_write_option_control_register32@Base 1.7.0 + stlink_write_otp@Base 1.8.0 stlink_write_reg@Base 1.5.0 stlink_write_unsupported_reg@Base 1.5.0 stm32l1_write_half_pages@Base 1.5.0 @@ -164,6 +190,11 @@ stlink-lib.so.1 stlink-lib #MINVER# ugly_init@Base 1.5.0 ugly_libusb_log_level@Base 1.6.1 ugly_log@Base 1.5.0 + unlock_flash_if@Base 1.8.0 + unlock_flash_option_if@Base 1.8.0 + unmap_file@Base 1.8.0 + wait_flash_busy@Base 1.8.0 write_buffer_to_sram@Base 1.5.0 + write_flash_cr_psiz@Base 1.8.0 write_uint16@Base 1.5.0 - write_uint32@Base 1.5.0 + write_uint32@Base 1.5.0 \ No newline at end of file diff --git a/debian/stlink-tools.install b/debian/stlink-tools.install index ca875a0e6..7944d876d 100644 --- a/debian/stlink-tools.install +++ b/debian/stlink-tools.install @@ -1,3 +1,4 @@ /usr/bin/st-* -lib/udev/rules.d/*.rules +${env:deb_udevdir}/rules.d/*.rules etc/modprobe.d/*.conf +usr/share/stlink/chips \ No newline at end of file diff --git a/debian/stlink.pc.in b/debian/stlink.pc.in index b5f994bad..7fde2d968 100644 --- a/debian/stlink.pc.in +++ b/debian/stlink.pc.in @@ -3,7 +3,7 @@ includedir=${prefix}/include/stlink libdir=${prefix}/lib/@DEB_HOST_MULTIARCH@ Name: stlink -Description: Open source version of the STMicroelectronics STLINK Tools +Description: Open source version of the STMicroelectronics Stlink Tools Version: @VERSION@ Requires: libusb-1.0 Libs: -L${libdir} -lstlink diff --git a/debian/upstream/metadata b/debian/upstream/metadata new file mode 100644 index 000000000..0a49c27f4 --- /dev/null +++ b/debian/upstream/metadata @@ -0,0 +1,4 @@ +--- +Bug-Database: https://github.com/stlink-org/stlink/issues +Bug-Submit: https://github.com/stlink-org/stlink/issues/new +Repository-Browse: https://github.com/stlink-org/stlink \ No newline at end of file diff --git a/debian/watch b/debian/watch index 6eb6b78d6..e716b7a22 100644 --- a/debian/watch +++ b/debian/watch @@ -1,3 +1,3 @@ version=3 -opts=dversionmangle=s/\+ds$//,repacksuffix=+ds,filenamemangle=s/.+\/v?(\d\S+)\.tar\.gz/stlink-$1\.tar\.gz/ \ +opts=filenamemangle=s/.+\/v?(\d\S+)\.tar\.gz/stlink-$1\.tar\.gz/ \ https://github.com/stlink-org/stlink/tags .*/v?(\d\S+)\.tar\.gz From 1ee7f6b6c05e305112bb070ae571ebbe26c55946 Mon Sep 17 00:00:00 2001 From: nightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:10:46 +0100 Subject: [PATCH 06/15] Restored previous cmake policy (regression) (Closes #1374) (Closes #1375) --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3344e394..1fc979c41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ ### cmake_minimum_required(VERSION 3.10.2) -cmake_policy(SET CMP0153 NEW) +cmake_policy(SET CMP0042 NEW) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) From ece34efbce579ca7d367c58f903ffa6dc7bd96e6 Mon Sep 17 00:00:00 2001 From: nightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com> Date: Sat, 6 Apr 2024 18:17:30 +0200 Subject: [PATCH 07/15] Updated info on OS support. (Closes #1376) --- debian/stlink.pc.in | 2 +- doc/version_support.md | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/debian/stlink.pc.in b/debian/stlink.pc.in index 7fde2d968..3650b22c5 100644 --- a/debian/stlink.pc.in +++ b/debian/stlink.pc.in @@ -3,7 +3,7 @@ includedir=${prefix}/include/stlink libdir=${prefix}/lib/@DEB_HOST_MULTIARCH@ Name: stlink -Description: Open source version of the STMicroelectronics Stlink Tools +Description: Open source version of the STMicroelectronics ST-LINK Tools Version: @VERSION@ Requires: libusb-1.0 Libs: -L${libdir} -lstlink diff --git a/doc/version_support.md b/doc/version_support.md index c0c8389dd..d2a1c34fd 100644 --- a/doc/version_support.md +++ b/doc/version_support.md @@ -12,7 +12,7 @@ Up on compiling c-make will **automatically** download and install the latest co ### Linux-/Unix-based: -Maintained versions of: +Actively maintained versions of: - Debian - Ubuntu - Fedora @@ -27,10 +27,6 @@ Other Linux-/Unix-based Operating Systems: | Operating System | libusb | cmake | libgtk-dev | End of
OS-Support | | ------------------------ | ------------------------------ | ---------- | ----------- | ---------------------- | -| Debian Sid | 1.0.24 | 3.22.1 | 3.24.31 | | -| Debian 11 (Bullseye) | 1.0.24 | 3.**18.4** | 3.24.24 | | -| Debian 10 (Buster) | 1.0.**22** | 3.**13.4** | 3.24.**5** | Jun 2024 | -| | | | | | | Ubuntu 20.04 LTS (Focal) | 1.0.23 | 3.**16.3** | 3.24.**18** | May 2025 | | | | | | | | FreeBSD 13.x | 1.0.**16-18** (API 0x01000102) | 3.22.1 | 3.24.31 | | @@ -41,7 +37,6 @@ Other Linux-/Unix-based Operating Systems: | CentOS 9 Stream [x64] | 1.0.24 (`libusbx`) | 3.20.3 | 3.24.30 | | | CentOS 8 Stream [x64] | 1.0.23 (`libusbx`) | 3.20.2 | 3.**22.30** | May 2024 | | | | | | | -| ALT Linux Sisyphus | 1.0.24 | 3.22.1 | 3.24.31 | | | ALT Linux P10 | 1.0.24 | 3.20.5 | 3.24.31 | | | ALT Linux P9 | 1.0.**22** | 3.**16.3** | 3.24.29 | | | | | | | | @@ -59,6 +54,7 @@ Systems with highlighted versions remain compatible with this toolset. | Operating System | libusb | cmake | End of
OS-Support | | ---------------------------------------- | ------------------------------ | ---------- | ---------------------- | +| Debian 11 (Bullseye) | 1.0.**24** | 3.**18.4** | Jun 2024 (v1.7.0) | | FreeBSD 12.x | 1.0.**16-18** (API 0x01000102) | 3.**22.1** | Dec 2023 | | Alpine 3.15 | 1.0.**24** | 3.**21.3** | Nov 2023 | | Fedora 35 [x64] | 1.0.**24** | 3.**21.3** | Dec 2022 | @@ -84,6 +80,7 @@ Systems with highlighted versions remain compatible with this toolset. | Fedora 30 | 1.0.**22**(`libusbx`) | 3.**14.2** | May 2020 | | Ubuntu 19.10 (Eoan) | 1.0.**23** | 3.**13.4** | Jul 2020 | | Alpine 3.9 | 1.0.**22** | 3.**13.0** | Jan 2021 | +| Debian 10 (Buster) | 1.0.**22** | 3.**13.4** | Jun 2024 (v1.7.0) | | Ubuntu 18.04 LTS (Bionic) | 1.0.21 | 3.10.2 | Apr 2023 | | openSUSE Leap 15.1 [x64] | 1.0.21 | 3.10.2 | Jan 2021 | | Debian 9 (Stretch) | 1.0.21 | 3.7.2 | Jun 2022 | @@ -92,5 +89,3 @@ Systems with highlighted versions remain compatible with this toolset. | CentOS / Rocky Linux / AlmaLinux 7 [x64] | 1.0.21 (`libusbx`) | 2.8.12.2 | Jun 2024 | _All other operating systems which are not listed are unsupported._ - -Author: nightwalker-87 From feb7eb1d4409109582d74aee8087e895523bcebd Mon Sep 17 00:00:00 2001 From: bauen1 Date: Wed, 17 Apr 2024 12:26:08 +0200 Subject: [PATCH 08/15] st-util: supply osabi to gdb This tells gdb the osabi to use, which is especially useful if the osabi is not communicated to gdb by manually setting it, or by a special section in the ELF file loaded by gdb. --- src/st-util/gdb-server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/st-util/gdb-server.c b/src/st-util/gdb-server.c index 28e06231a..dfe71cbb0 100644 --- a/src/st-util/gdb-server.c +++ b/src/st-util/gdb-server.c @@ -285,6 +285,7 @@ static const char* const target_description = "" "" " arm" + " none" " " " " " " From 2fea7597a3ab9785963f83b873d9a84ed5e13263 Mon Sep 17 00:00:00 2001 From: florrant Sazerac Date: Thu, 25 Apr 2024 14:40:47 +0200 Subject: [PATCH 09/15] Add support for stlink-v3pwr --- config/udev/rules.d/49-stlinkv3.rules | 7 ++++++- src/stlink-lib/usb.c | 3 ++- src/stlink-lib/usb.h | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config/udev/rules.d/49-stlinkv3.rules b/config/udev/rules.d/49-stlinkv3.rules index 98c33eddf..71242d1e0 100644 --- a/config/udev/rules.d/49-stlinkv3.rules +++ b/config/udev/rules.d/49-stlinkv3.rules @@ -27,7 +27,12 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374e", \ SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374f", \ MODE:="0666", \ SYMLINK+="stlinkv3_%n" - + +# STLink V3PWR +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3757", \ + MODE:="0666", \ + SYMLINK+="stlinkv3_%n" + # If you share your linux system with other users, or just don't like the # idea of write permission for everybody, you can replace MODE:="0666" with # OWNER:="yourusername" to create the device owned by you, or with diff --git a/src/stlink-lib/usb.c b/src/stlink-lib/usb.c index 83e2652ea..1f8bf91bd 100644 --- a/src/stlink-lib/usb.c +++ b/src/stlink-lib/usb.c @@ -1256,7 +1256,8 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, enum connect_type connect, 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_NO_MSD_PID) { + desc.idProduct == STLINK_USB_PID_STLINK_V3_NO_MSD_PID || + desc.idProduct == STLINK_USB_PID_STLINK_V3P) { slu->ep_req = 1 /* ep req */ | LIBUSB_ENDPOINT_OUT; slu->ep_trace = 2 | LIBUSB_ENDPOINT_IN; } else { diff --git a/src/stlink-lib/usb.h b/src/stlink-lib/usb.h index 2ec7490ad..783144471 100644 --- a/src/stlink-lib/usb.h +++ b/src/stlink-lib/usb.h @@ -23,6 +23,7 @@ #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_USB_PID_STLINK_V3P 0x3757 #define STLINK_V1_USB_PID(pid) ((pid) == STLINK_USB_PID_STLINK) @@ -36,7 +37,8 @@ (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_NO_MSD_PID) + (pid) == STLINK_USB_PID_STLINK_V3_NO_MSD_PID || \ + (pid) == STLINK_USB_PID_STLINK_V3P) #define STLINK_SUPPORTED_USB_PID(pid) (STLINK_V1_USB_PID(pid) || \ STLINK_V2_USB_PID(pid) || \ From 44c02d9c8c1218fbb24804bb6486081361ec7243 Mon Sep 17 00:00:00 2001 From: Rocky04 Date: Thu, 2 May 2024 09:55:05 +0000 Subject: [PATCH 10/15] Dynamic SRAM size for F4 memory map - Instead of using a fixed size of 128 KB for the SRAM memory map for F4 chips it now uses the definied SRAM size from the chip configuration --- src/st-util/gdb-server.c | 3 ++- src/st-util/memory-map.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/st-util/gdb-server.c b/src/st-util/gdb-server.c index 28e06231a..d11c320bf 100644 --- a/src/st-util/gdb-server.c +++ b/src/st-util/gdb-server.c @@ -354,7 +354,8 @@ char* make_memory_map(stlink_t *sl) { if (sl->chip_id == STM32_CHIPID_F4 || sl->chip_id == STM32_CHIPID_F446 || sl->chip_id == STM32_CHIPID_F411xx) { - strcpy(map, memory_map_template_F4); + snprintf(map, sz, memory_map_template_F4, + sl->sram_size); } else if (sl->chip_id == STM32_CHIPID_F4_DE) { strcpy(map, memory_map_template_F4_DE); } else if (sl->core_id == STM32_CORE_ID_M7F_SWD) { diff --git a/src/st-util/memory-map.h b/src/st-util/memory-map.h index 6f34eedac..37acb62e8 100644 --- a/src/st-util/memory-map.h +++ b/src/st-util/memory-map.h @@ -8,7 +8,7 @@ static const char* const memory_map_template_F4 = "" " " // code = sram, bootrom or flash; flash is bigger " " // ccm ram - " " // sram + " " // sram " " // Sectors 0...3 " 0x4000" // 16 kB " " From 0cb07935fcaebe2375bd9e0ab81c5e5a95bc2e92 Mon Sep 17 00:00:00 2001 From: Ilgrim Date: Wed, 8 May 2024 21:53:48 +0200 Subject: [PATCH 11/15] Making some modifications for be able to build these tools in OpenBSD --- src/st-flash/flash_opts.c | 12 ++++++------ src/st-info/info.c | 2 +- src/st-util/gdb-server.c | 2 +- src/stlink-lib/chipid.c | 2 +- src/stlink-lib/common.c | 2 +- src/stlink-lib/flash_loader.c | 2 +- src/stlink-lib/map_file.c | 2 +- src/stlink-lib/usb.c | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/st-flash/flash_opts.c b/src/st-flash/flash_opts.c index e2d4154fe..2650d2ecb 100644 --- a/src/st-flash/flash_opts.c +++ b/src/st-flash/flash_opts.c @@ -17,7 +17,7 @@ #include static bool starts_with(const char * str, const char * prefix) { - uint32_t n = strlen(prefix); + uint32_t n = (uint32_t)strlen(prefix); if (strlen(str) < n) { return (false); } @@ -70,7 +70,7 @@ static int32_t get_integer_from_char_array (const char *const str, uint32_t *rea fprintf (stderr, "*** Error: Integer greater than UINT32_MAX, cannot convert to int32_t\n"); return (-1); } else { - *read_value = value; + *read_value = (uint32_t)value; return (0); } } @@ -199,7 +199,7 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) { if (result != 0) { return (bad_arg ("--flash")); } else { - o->flash_size = (size_t)flash_size; + o->flash_size = (uint32_t)flash_size; } } else if (strcmp(av[0], "--connect-under-reset") == 0) { o->connect = CONNECT_UNDER_RESET; @@ -259,7 +259,7 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) { if (result != 0) { return bad_arg ("size"); } else { - o->size = (size_t) size; + o->size = (uint32_t) size; } } @@ -283,7 +283,7 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) { if (result != 0) { return bad_arg ("size"); } else { - o->size = (size_t) size; + o->size = (uint32_t) size; } break; @@ -300,7 +300,7 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) { if (result != 0) { return bad_arg("option bytes read: invalid size"); } else { - o->size = (size_t) size; + o->size = (uint32_t) size; } } break; diff --git a/src/st-info/info.c b/src/st-info/info.c index ffdf521cc..31deeba45 100644 --- a/src/st-info/info.c +++ b/src/st-info/info.c @@ -55,7 +55,7 @@ static void stlink_probe(enum connect_type connect, int32_t freq) { stlink_t **stdevs; uint32_t size; - size = stlink_probe_usb(&stdevs, connect, freq); + size = (uint32_t)stlink_probe_usb(&stdevs, connect, freq); printf("Found %u stlink programmers\n", size); diff --git a/src/st-util/gdb-server.c b/src/st-util/gdb-server.c index 28e06231a..db743c0fa 100644 --- a/src/st-util/gdb-server.c +++ b/src/st-util/gdb-server.c @@ -1041,7 +1041,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) { params = separator + 1; } - uint32_t hex_len = strlen(params); + uint32_t hex_len = (uint32_t)strlen(params); uint32_t alloc_size = (hex_len / 2) + 1; uint32_t cmd_len; char *cmd = malloc(alloc_size); diff --git a/src/stlink-lib/chipid.c b/src/stlink-lib/chipid.c index c115089a4..4845859ec 100644 --- a/src/stlink-lib/chipid.c +++ b/src/stlink-lib/chipid.c @@ -224,7 +224,7 @@ void init_chipids(char *dir_to_scan) { if (d) { while ((dir = readdir(d)) != NULL) { - nl = strlen(dir->d_name); + nl = (uint32_t)strlen(dir->d_name); if (strcmp(dir->d_name + nl - 5, ".chip") == 0) { char buf[1024]; diff --git a/src/stlink-lib/common.c b/src/stlink-lib/common.c index 3e49a779d..3ce1dd688 100644 --- a/src/stlink-lib/common.c +++ b/src/stlink-lib/common.c @@ -913,7 +913,7 @@ int32_t stlink_parse_ihex(const char *path, uint8_t erased_pattern, uint8_t **me break; } - uint32_t l = strlen(line); + uint32_t l = (uint32_t)strlen(line); while (l > 0 && (line[l - 1] == '\n' || line[l - 1] == '\r')) { --l; diff --git a/src/stlink-lib/flash_loader.c b/src/stlink-lib/flash_loader.c index 16c717ca7..1caac8489 100644 --- a/src/stlink-lib/flash_loader.c +++ b/src/stlink-lib/flash_loader.c @@ -788,7 +788,7 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t if (stm32l1_write_half_pages(sl, fl, addr, base, len, pagesize)) { return (-1); } else { - off = (size_t)(len / pagesize) * pagesize; + off = (uint32_t)(len / pagesize) * pagesize; } } diff --git a/src/stlink-lib/map_file.c b/src/stlink-lib/map_file.c index 118c80d34..f75996be5 100644 --- a/src/stlink-lib/map_file.c +++ b/src/stlink-lib/map_file.c @@ -95,7 +95,7 @@ int32_t map_file(mapped_file_t *mf, const char *path) { goto on_error; } - mf->len = (size_t)st.st_size; + mf->len = (uint32_t)st.st_size; error = 0; // success on_error: diff --git a/src/stlink-lib/usb.c b/src/stlink-lib/usb.c index 83e2652ea..3708d1d6e 100644 --- a/src/stlink-lib/usb.c +++ b/src/stlink-lib/usb.c @@ -1172,7 +1172,7 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, enum connect_type connect, if (ret) { continue; } // could not open device - uint32_t serial_len = stlink_serial(handle, &desc, sl->serial); + uint32_t serial_len = (uint32_t)stlink_serial(handle, &desc, sl->serial); libusb_close(handle); @@ -1375,7 +1375,7 @@ static uint32_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[], break; } - uint32_t serial_len = stlink_serial(handle, &desc, serial); + uint32_t serial_len = (uint32_t)stlink_serial(handle, &desc, serial); libusb_close(handle); From 0c7259819319feedf5f272d9f3b1b6c66af82440 Mon Sep 17 00:00:00 2001 From: ratman528 Date: Sat, 11 May 2024 12:37:26 -0500 Subject: [PATCH 12/15] add a graceful way to terminate st-util --- src/st-util/gdb-server.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/st-util/gdb-server.c b/src/st-util/gdb-server.c index 28e06231a..41df1fb3e 100644 --- a/src/st-util/gdb-server.c +++ b/src/st-util/gdb-server.c @@ -92,7 +92,13 @@ static void _cleanup() { static void cleanup(int32_t signum) { printf("Receive signal %i. Exiting...\n", signum); _cleanup(); - exit(1); + // if asked to gracefully terminate + if(signum == SIGTERM){ + // return 0 + exit(0); + }else{ + exit(1); + } (void)signum; } From b67a6c33ca8314e9c366c68ef3d2a3fd6a7eac38 Mon Sep 17 00:00:00 2001 From: AJ528 Date: Mon, 13 May 2024 14:17:42 -0500 Subject: [PATCH 13/15] because signum is now being used, the line "(void)signum;" is no longer needed --- src/st-util/gdb-server.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/st-util/gdb-server.c b/src/st-util/gdb-server.c index 41df1fb3e..a3ee18a54 100644 --- a/src/st-util/gdb-server.c +++ b/src/st-util/gdb-server.c @@ -99,7 +99,6 @@ static void cleanup(int32_t signum) { }else{ exit(1); } - (void)signum; } #if defined(_WIN32) From 3655871f8dd97294bbee191c1c7341c8a129af2f Mon Sep 17 00:00:00 2001 From: nightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com> Date: Sun, 19 May 2024 00:04:17 +0200 Subject: [PATCH 14/15] General Project Update - Updated CONTRIBUTING.md - Updated list of supported devices (Closes #1398) --- CONTRIBUTING.md | 2 +- doc/supported_devices.md | 6 +++--- src/stlink-gui/gui.c | 5 +---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6c1842aca..4f842b51d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ Report a bug by [opening a new issue]() with one of the available templates. It' 1) If using a ST-Link-v2 programmer: Convince yourself that it is recognised as an USB device by your computer, thus reporting device and manufacturer ID. Use a diagnostic tool to probe for enumerated USB devices, e.g [`lsusb -v`](https://linux.die.net/man/8/lsusb) on unix-based systems. 2) **Use the [ST-Link firmware upgrade tool](https://www.st.com/en/development-tools/stsw-link007.html) based on Java to read out the current firmware version and update to the latest available version. This also works for _non-genuine_ ST programmers and boards.** 3) Try to make sure you have a working toolchain before starting to build. -4) **Update to the _latest_ release version or maybe even use the `develop` branch.** +4) **Update to the _latest_ release version or maybe even use the `testing` branch.** 5) Search for your problem in the available open issues, _before_ opening a new ticket. 6) Make sure to **use the available issue templates** to submit a bug-report or a feature-request. **Do not replace the prepared text, edit the placeholders instead. _Describe_ your problem.** 7) Avoid to add new comments to closed issues unless they confirm a solution already available. diff --git a/doc/supported_devices.md b/doc/supported_devices.md index b22b1c11a..f2895edba 100644 --- a/doc/supported_devices.md +++ b/doc/supported_devices.md @@ -34,9 +34,9 @@ More commonly these are: | STM32H7 | M7F | | | STM32WB | M4F | | | STM32WL | M4 | | -| STM32L5 | M33 | | -| STM32H5 | M33 | | -| STM32U5 | M33 | | +| STM32L5 | M33 | *preliminary, limited and partial support only!* | +| STM32H5 | M33 | *preliminary, limited and partial support only!* | +| STM32U5 | M33 | *preliminary, limited and partial support only!* | # Chinese Clone-Chips [may work, but without support!] diff --git a/src/stlink-gui/gui.c b/src/stlink-gui/gui.c index 51ee293e8..57dbe997a 100644 --- a/src/stlink-gui/gui.c +++ b/src/stlink-gui/gui.c @@ -271,10 +271,7 @@ static gpointer stlink_gui_populate_filemem_view(gpointer data) { int32_t res = stlink_parse_ihex(gui->filename, 0, &mem, &size, &begin); if (res == 0) { - if (gui->file_mem.memory) { - g_free(gui->file_mem.memory); - } - + if (gui->file_mem.memory) { g_free(gui->file_mem.memory); } gui->file_mem.size = size; gui->file_mem.memory = g_malloc(size); gui->file_mem.base = begin; From f47c69714ffc7fe00c061fb90b4cfbb1bd9c91e9 Mon Sep 17 00:00:00 2001 From: nightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com> Date: Wed, 29 May 2024 21:27:27 +0200 Subject: [PATCH 15/15] Changed data types to fixed width types & formatting fixes - stlink_serial( ) - stlink_probe_usb( ) --- inc/stm32.h | 34 +++++++------- inc/stm32flash.h | 42 +++++++++--------- src/st-flash/flash.c | 2 +- src/st-flash/flash_opts.c | 8 ++-- src/st-info/info.c | 2 +- src/st-trace/trace.c | 2 +- src/st-util/gdb-remote.c | 2 +- src/st-util/gdb-server.c | 56 +++++++++++------------ src/st-util/semihosting.c | 26 +++++------ src/stlink-gui/gui.c | 4 +- src/stlink-lib/calculate.c | 2 +- src/stlink-lib/chipid.c | 2 +- src/stlink-lib/common.c | 40 ++++++++--------- src/stlink-lib/common_flash.c | 10 ++--- src/stlink-lib/flash_loader.c | 8 ++-- src/stlink-lib/helper.c | 4 +- src/stlink-lib/lib_md5.c | 60 ++++++++++++------------- src/stlink-lib/map_file.c | 8 ++-- src/stlink-lib/md5.c | 4 +- src/stlink-lib/option_bytes.c | 6 +-- src/stlink-lib/read_write.c | 10 ++--- src/stlink-lib/sg.c | 4 +- src/stlink-lib/usb.c | 84 +++++++++++++++++------------------ src/stlink-lib/usb.h | 4 +- src/win32/mmap.c | 2 +- src/win32/sys_time.c | 4 +- tests/flash.c | 2 +- 27 files changed, 216 insertions(+), 216 deletions(-) diff --git a/inc/stm32.h b/inc/stm32.h index 615484ee3..928b03233 100644 --- a/inc/stm32.h +++ b/inc/stm32.h @@ -142,37 +142,37 @@ enum stm32_chipids { }; /* Constant STM32 option bytes base memory address */ -#define STM32_C0_OPTION_BYTES_BASE ((uint32_t)0x1fff7800) +#define STM32_C0_OPTION_BYTES_BASE ((uint32_t) 0x1fff7800) -#define STM32_F4_OPTION_BYTES_BASE ((uint32_t)0x40023c14) +#define STM32_F4_OPTION_BYTES_BASE ((uint32_t) 0x40023c14) -#define STM32_H7_OPTION_BYTES_BASE ((uint32_t)0x5200201c) +#define STM32_H7_OPTION_BYTES_BASE ((uint32_t) 0x5200201c) -#define STM32_L0_OPTION_BYTES_BASE ((uint32_t)0x1ff80000) -#define STM32_L1_OPTION_BYTES_BASE ((uint32_t)0x1ff80000) +#define STM32_L0_OPTION_BYTES_BASE ((uint32_t) 0x1ff80000) +#define STM32_L1_OPTION_BYTES_BASE ((uint32_t) 0x1ff80000) -#define STM32_F7_OPTION_BYTES_BASE ((uint32_t)0x1fff0000) +#define STM32_F7_OPTION_BYTES_BASE ((uint32_t) 0x1fff0000) -#define STM32_G0_OPTION_BYTES_BASE ((uint32_t)0x1fff7800) -#define STM32_L4_OPTION_BYTES_BASE ((uint32_t)0x1fff7800) +#define STM32_G0_OPTION_BYTES_BASE ((uint32_t) 0x1fff7800) +#define STM32_L4_OPTION_BYTES_BASE ((uint32_t) 0x1fff7800) -#define STM32_F2_OPTION_BYTES_BASE ((uint32_t)0x1fffc000) +#define STM32_F2_OPTION_BYTES_BASE ((uint32_t) 0x1fffc000) -#define STM32_F0_OPTION_BYTES_BASE ((uint32_t)0x1ffff800) -#define STM32_F1_OPTION_BYTES_BASE ((uint32_t)0x1ffff800) -#define STM32_F3_OPTION_BYTES_BASE ((uint32_t)0x1ffff800) -#define STM32_G4_OPTION_BYTES_BASE ((uint32_t)0x1ffff800) +#define STM32_F0_OPTION_BYTES_BASE ((uint32_t) 0x1ffff800) +#define STM32_F1_OPTION_BYTES_BASE ((uint32_t) 0x1ffff800) +#define STM32_F3_OPTION_BYTES_BASE ((uint32_t) 0x1ffff800) +#define STM32_G4_OPTION_BYTES_BASE ((uint32_t) 0x1ffff800) /* ============ */ /* Old defines from common.c are below */ /* ============ */ /* Constant STM32 memory address */ -#define STM32_SRAM_BASE ((uint32_t)0x20000000) -#define STM32_FLASH_BASE ((uint32_t)0x08000000) +#define STM32_SRAM_BASE ((uint32_t) 0x20000000) +#define STM32_FLASH_BASE ((uint32_t) 0x08000000) -#define STM32_F1_FLASH_BANK2_BASE ((uint32_t)0x08080000) -#define STM32_H7_FLASH_BANK2_BASE ((uint32_t)0x08100000) +#define STM32_F1_FLASH_BANK2_BASE ((uint32_t) 0x08080000) +#define STM32_H7_FLASH_BANK2_BASE ((uint32_t) 0x08100000) #define STM32F0_DBGMCU_CR 0xE0042004 #define STM32F0_DBGMCU_CR_IWDG_STOP 8 diff --git a/inc/stm32flash.h b/inc/stm32flash.h index a5081d694..96d44f751 100644 --- a/inc/stm32flash.h +++ b/inc/stm32flash.h @@ -48,19 +48,19 @@ #define FLASH_CR_OPTWRE 9 #define FLASH_CR_OBL_LAUNCH 13 -#define FLASH_ACR_OFF ((uint32_t)0x00) -#define FLASH_PECR_OFF ((uint32_t)0x04) -#define FLASH_PDKEYR_OFF ((uint32_t)0x08) -#define FLASH_PEKEYR_OFF ((uint32_t)0x0c) -#define FLASH_PRGKEYR_OFF ((uint32_t)0x10) -#define FLASH_OPTKEYR_OFF ((uint32_t)0x14) -#define FLASH_SR_OFF ((uint32_t)0x18) -#define FLASH_OBR_OFF ((uint32_t)0x1c) -#define FLASH_WRPR_OFF ((uint32_t)0x20) +#define FLASH_ACR_OFF ((uint32_t) 0x00) +#define FLASH_PECR_OFF ((uint32_t) 0x04) +#define FLASH_PDKEYR_OFF ((uint32_t) 0x08) +#define FLASH_PEKEYR_OFF ((uint32_t) 0x0c) +#define FLASH_PRGKEYR_OFF ((uint32_t) 0x10) +#define FLASH_OPTKEYR_OFF ((uint32_t) 0x14) +#define FLASH_SR_OFF ((uint32_t) 0x18) +#define FLASH_OBR_OFF ((uint32_t) 0x1c) +#define FLASH_WRPR_OFF ((uint32_t) 0x20) // == STM32C0 == (RM0490) // C0 Flash registers -#define FLASH_C0_REGS_ADDR ((uint32_t)0x40022000) +#define FLASH_C0_REGS_ADDR ((uint32_t) 0x40022000) #define FLASH_C0_KEYR (FLASH_C0_REGS_ADDR + 0x08) #define FLASH_C0_OPT_KEYR (FLASH_C0_REGS_ADDR + 0x0C) #define FLASH_C0_SR (FLASH_C0_REGS_ADDR + 0x10) @@ -87,7 +87,7 @@ #define FLASH_F0_OPTKEY2 0xcdef89ab // == STM32F2 == -#define FLASH_F2_REGS_ADDR ((uint32_t)0x40023c00) +#define FLASH_F2_REGS_ADDR ((uint32_t) 0x40023c00) #define FLASH_F2_KEYR (FLASH_F2_REGS_ADDR + 0x04) #define FLASH_F2_OPT_KEYR (FLASH_F2_REGS_ADDR + 0x08) #define FLASH_F2_SR (FLASH_F2_REGS_ADDR + 0x0c) @@ -107,7 +107,7 @@ // == STM32F4 == // F4 Flash registers -#define FLASH_F4_REGS_ADDR ((uint32_t)0x40023c00) +#define FLASH_F4_REGS_ADDR ((uint32_t) 0x40023c00) #define FLASH_F4_KEYR (FLASH_F4_REGS_ADDR + 0x04) #define FLASH_F4_OPT_KEYR (FLASH_F4_REGS_ADDR + 0x08) #define FLASH_F4_SR (FLASH_F4_REGS_ADDR + 0x0c) @@ -131,7 +131,7 @@ // == STM32F7 == // F7 Flash registers -#define FLASH_F7_REGS_ADDR ((uint32_t)0x40023c00) +#define FLASH_F7_REGS_ADDR ((uint32_t) 0x40023c00) #define FLASH_F7_KEYR (FLASH_F7_REGS_ADDR + 0x04) #define FLASH_F7_OPT_KEYR (FLASH_F7_REGS_ADDR + 0x08) #define FLASH_F7_SR (FLASH_F7_REGS_ADDR + 0x0c) @@ -165,7 +165,7 @@ // == STM32G0/G4 == // G0/G4 Flash registers (RM0440, p.146) -#define FLASH_Gx_REGS_ADDR ((uint32_t)0x40022000) +#define FLASH_Gx_REGS_ADDR ((uint32_t) 0x40022000) #define FLASH_Gx_ACR (FLASH_Gx_REGS_ADDR + 0x00) #define FLASH_Gx_KEYR (FLASH_Gx_REGS_ADDR + 0x08) #define FLASH_Gx_OPTKEYR (FLASH_Gx_REGS_ADDR + 0x0c) @@ -232,7 +232,7 @@ // == STM32H7 == // H7 Flash registers -#define FLASH_H7_REGS_ADDR ((uint32_t)0x52002000) +#define FLASH_H7_REGS_ADDR ((uint32_t) 0x52002000) #define FLASH_H7_KEYR1 (FLASH_H7_REGS_ADDR + 0x04) #define FLASH_H7_KEYR2 (FLASH_H7_REGS_ADDR + 0x104) #define FLASH_H7_OPT_KEYR (FLASH_H7_REGS_ADDR + 0x08) @@ -278,7 +278,7 @@ // == STM32L0/L1/L4/L5 == // Lx Flash registers -#define FLASH_Lx_REGS_ADDR ((uint32_t)0x40023c00) +#define FLASH_Lx_REGS_ADDR ((uint32_t) 0x40023c00) #define FLASH_Lx_ACR (FLASH_Lx_REGS_ADDR + 0x00) #define FLASH_Lx_PECR (FLASH_Lx_REGS_ADDR + 0x04) #define FLASH_Lx_PDKEYR (FLASH_Lx_REGS_ADDR + 0x08) @@ -300,7 +300,7 @@ #define FLASH_L0_OPTKEY1 0xFBEAD9C8 #define FLASH_L0_OPTKEY2 0x24252627 -#define FLASH_L0_REGS_ADDR ((uint32_t)0x40022000) +#define FLASH_L0_REGS_ADDR ((uint32_t) 0x40022000) #define FLASH_L0_PELOCK (0) #define FLASH_L0_OPTLOCK (2) @@ -352,16 +352,16 @@ #define FLASH_L4_CR_OBL_LAUNCH 27 /* Option bytes reload */ // Bits requesting flash operations (useful when we want to clear them) #define FLASH_L4_CR_OPBITS \ - (uint32_t)((1lu << FLASH_L4_CR_PG) | (1lu << FLASH_L4_CR_PER) | \ + (uint32_t) ((1lu << FLASH_L4_CR_PG) | (1lu << FLASH_L4_CR_PER) | \ (1lu << FLASH_L4_CR_MER1) | (1lu << FLASH_L4_CR_MER1)) // Page is fully specified by BKER and PNB -#define FLASH_L4_CR_PAGEMASK (uint32_t)(0x1fflu << FLASH_L4_CR_PNB) +#define FLASH_L4_CR_PAGEMASK (uint32_t) (0x1fflu << FLASH_L4_CR_PNB) #define FLASH_L4_OPTR_DUALBANK 21 // == STM32L5 == (RM0438, p.241) // L5 Flash registers -#define FLASH_L5_REGS_ADDR ((uint32_t)0x40022000) +#define FLASH_L5_REGS_ADDR ((uint32_t) 0x40022000) #define FLASH_L5_ACR (FLASH_L5_REGS_ADDR + 0x00) #define FLASH_L5_NSKEYR (FLASH_L5_REGS_ADDR + 0x08) #define FLASH_L5_OPTKEYR (FLASH_L5_REGS_ADDR + 0x10) @@ -399,7 +399,7 @@ // == STM32WB == (RM0434) // WB Flash registers -#define FLASH_WB_REGS_ADDR ((uint32_t)0x58004000) +#define FLASH_WB_REGS_ADDR ((uint32_t) 0x58004000) #define FLASH_WB_ACR (FLASH_WB_REGS_ADDR + 0x00) #define FLASH_WB_KEYR (FLASH_WB_REGS_ADDR + 0x08) #define FLASH_WB_OPT_KEYR (FLASH_WB_REGS_ADDR + 0x0c) diff --git a/src/st-flash/flash.c b/src/st-flash/flash.c index c6c8768e8..56556ee25 100644 --- a/src/st-flash/flash.c +++ b/src/st-flash/flash.c @@ -281,7 +281,7 @@ int32_t main(int32_t ac, char** av) { fprintf(stderr, "open(%s) == -1\n", o.filename); goto on_error; } - err = (uint32_t)write(fd, &option_byte, 4); + err = (uint32_t) write(fd, &option_byte, 4); if (err == -1) { printf("could not write buffer to file (%d)\n", err); goto on_error; diff --git a/src/st-flash/flash_opts.c b/src/st-flash/flash_opts.c index 4e2f11fde..9fe35cad8 100644 --- a/src/st-flash/flash_opts.c +++ b/src/st-flash/flash_opts.c @@ -17,7 +17,7 @@ #include static bool starts_with(const char * str, const char * prefix) { - uint32_t n = (uint32_t)strlen(prefix); + uint32_t n = (uint32_t) strlen(prefix); if (strlen(str) < n) { return (false); } @@ -70,7 +70,7 @@ static int32_t get_integer_from_char_array (const char *const str, uint32_t *rea fprintf (stderr, "*** Error: Integer greater than UINT32_MAX, cannot convert to int32_t\n"); return (-1); } else { - *read_value = (uint32_t)value; + *read_value = (uint32_t) value; return (0); } } @@ -201,7 +201,7 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) { if (result != 0) { return (bad_arg ("--flash")); } else { - o->flash_size = (uint32_t)flash_size; + o->flash_size = (uint32_t) flash_size; } } else if (strcmp(av[0], "--connect-under-reset") == 0) { o->connect = CONNECT_UNDER_RESET; @@ -372,7 +372,7 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) { if (result != 0) { return (bad_arg ("addr")); } else { - o->addr = (stm32_addr_t)addr; + o->addr = (stm32_addr_t) addr; } } else if (o->format == FLASH_FORMAT_IHEX) { // expect filename if (ac != 1) { return (invalid_args("write ")); } diff --git a/src/st-info/info.c b/src/st-info/info.c index 31deeba45..ffdf521cc 100644 --- a/src/st-info/info.c +++ b/src/st-info/info.c @@ -55,7 +55,7 @@ static void stlink_probe(enum connect_type connect, int32_t freq) { stlink_t **stdevs; uint32_t size; - size = (uint32_t)stlink_probe_usb(&stdevs, connect, freq); + size = stlink_probe_usb(&stdevs, connect, freq); printf("Found %u stlink programmers\n", size); diff --git a/src/st-trace/trace.c b/src/st-trace/trace.c index 591e29252..0be4e6342 100644 --- a/src/st-trace/trace.c +++ b/src/st-trace/trace.c @@ -158,7 +158,7 @@ static bool parse_frequency(char* text, uint32_t* result) { return false; } - *result = (uint32_t)value; + *result = (uint32_t) value; return true; } diff --git a/src/st-util/gdb-remote.c b/src/st-util/gdb-remote.c index 0e6c69e72..6ab9d1158 100644 --- a/src/st-util/gdb-remote.c +++ b/src/st-util/gdb-remote.c @@ -20,7 +20,7 @@ static const char hex[] = "0123456789abcdef"; int32_t gdb_send_packet(int32_t fd, char* data) { - uint32_t data_length = (uint32_t)strlen(data); + uint32_t data_length = (uint32_t) strlen(data); int32_t length = data_length + 4; char* packet = malloc(length); // '$' data (hex) '#' cksum (hex) diff --git a/src/st-util/gdb-server.c b/src/st-util/gdb-server.c index 3eadd974d..a2f735824 100644 --- a/src/st-util/gdb-server.c +++ b/src/st-util/gdb-server.c @@ -98,7 +98,7 @@ static void cleanup(int32_t signum) { #if defined(_WIN32) BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) { - printf("Receive signal %i. Exiting...\r\n", (int32_t)fdwCtrlType); + printf("Receive signal %i. Exiting...\r\n", (int32_t) fdwCtrlType); _cleanup(); return FALSE; } @@ -684,7 +684,7 @@ static int32_t flash_go(stlink_t *sl, st_state_t *st) { for (struct flash_block* fb = flash_root; fb; fb = fb->next) { ILOG("flash_erase: block %08x -> %04x\n", fb->addr, fb->length); - for (stm32_addr_t page = fb->addr; page < fb->addr + fb->length; page += (uint32_t)FLASH_PAGE) { + for (stm32_addr_t page = fb->addr; page < fb->addr + fb->length; page += (uint32_t) FLASH_PAGE) { // update FLASH_PAGE stlink_calculate_pagesize(sl, page); @@ -700,14 +700,14 @@ static int32_t flash_go(stlink_t *sl, st_state_t *st) { for (struct flash_block* fb = flash_root; fb; fb = fb->next) { ILOG("flash_do: block %08x -> %04x\n", fb->addr, fb->length); - for (stm32_addr_t page = fb->addr; page < fb->addr + fb->length; page += (uint32_t)FLASH_PAGE) { + for (stm32_addr_t page = fb->addr; page < fb->addr + fb->length; page += (uint32_t) FLASH_PAGE) { uint32_t length = fb->length - (page - fb->addr); // update FLASH_PAGE stlink_calculate_pagesize(sl, page); ILOG("flash_do: page %08x\n", page); - uint32_t len = (length > FLASH_PAGE) ? (uint32_t)FLASH_PAGE : length; + uint32_t len = (length > FLASH_PAGE) ? (uint32_t) FLASH_PAGE : length; ret = stlink_flashloader_write(sl, &fl, page, fb->data + (page - fb->addr), len); if (ret) { goto error; } } @@ -983,7 +983,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) { params = separator + 1; } - uint32_t queryNameLength = (uint32_t)(separator - &packet[1]); + uint32_t queryNameLength = (uint32_t) (separator - &packet[1]); char* queryName = calloc(queryNameLength + 1, 1); strncpy(queryName, &packet[1], queryNameLength); @@ -1002,8 +1002,8 @@ int32_t serve(stlink_t *sl, st_state_t *st) { __s_addr = strsep(&tok, ","); s_length = tok; - uint32_t addr = (uint32_t)strtoul(__s_addr, NULL, 16), - length = (uint32_t)strtoul(s_length, NULL, 16); + uint32_t addr = (uint32_t) strtoul(__s_addr, NULL, 16), + length = (uint32_t) strtoul(s_length, NULL, 16); DLOG("Xfer: type:%s;op:%s;annex:%s;addr:%d;length:%d\n", type, op, annex, addr, length); @@ -1020,7 +1020,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) { } if (data) { - uint32_t data_length = (uint32_t)strlen(data); + uint32_t data_length = (uint32_t) strlen(data); if (addr + length > data_length) { length = data_length - addr; } @@ -1043,7 +1043,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) { params = separator + 1; } - uint32_t hex_len = (uint32_t)strlen(params); + uint32_t hex_len = (uint32_t) strlen(params); uint32_t alloc_size = (hex_len / 2) + 1; uint32_t cmd_len; char *cmd = malloc(alloc_size); @@ -1163,8 +1163,8 @@ int32_t serve(stlink_t *sl, st_state_t *st) { __s_addr = strsep(&tok, ","); s_length = tok; - uint32_t addr = (uint32_t)strtoul(__s_addr, NULL, 16), - length = (uint32_t)strtoul(s_length, NULL, 16); + uint32_t addr = (uint32_t) strtoul(__s_addr, NULL, 16), + length = (uint32_t) strtoul(s_length, NULL, 16); DLOG("FlashErase: addr:%08x,len:%04x\n", addr, length); @@ -1181,8 +1181,8 @@ int32_t serve(stlink_t *sl, st_state_t *st) { __s_addr = strsep(&tok, ":"); data = tok; - uint32_t addr = (uint32_t)strtoul(__s_addr, NULL, 16); - uint32_t data_length = status - (uint32_t)(data - packet); + uint32_t addr = (uint32_t) strtoul(__s_addr, NULL, 16); + uint32_t data_length = status - (uint32_t) (data - packet); // Length of decoded data cannot be more than encoded, as escapes are removed. // Additional byte is reserved for alignment fix. @@ -1345,13 +1345,13 @@ int32_t serve(stlink_t *sl, st_state_t *st) { reply = calloc(8 * 16 + 1, 1); for (int32_t i = 0; i < 16; i++) { - sprintf(&reply[i * 8], "%08x", (uint32_t)htonl(regp.r[i])); + sprintf(&reply[i * 8], "%08x", (uint32_t) htonl(regp.r[i])); } break; case 'p': { - uint32_t id = (uint32_t)strtoul(&packet[1], NULL, 16); + uint32_t id = (uint32_t) strtoul(&packet[1], NULL, 16); uint32_t myreg = 0xDEADDEAD; if (id < 16) { @@ -1404,8 +1404,8 @@ int32_t serve(stlink_t *sl, st_state_t *st) { char* s_reg = &packet[1]; char* s_value = strstr(&packet[1], "=") + 1; - uint32_t reg = (uint32_t)strtoul(s_reg, NULL, 16); - uint32_t value = (uint32_t)strtoul(s_value, NULL, 16); + uint32_t reg = (uint32_t) strtoul(s_reg, NULL, 16); + uint32_t value = (uint32_t) strtoul(s_value, NULL, 16); if (reg < 16) { @@ -1445,7 +1445,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) { for (int32_t i = 0; i < 16; i++) { char str[9] = {0}; strncpy(str, &packet[1 + i * 8], 8); - uint32_t reg = (uint32_t)strtoul(str, NULL, 16); + uint32_t reg = (uint32_t) strtoul(str, NULL, 16); ret = stlink_write_reg(sl, ntohl(reg), i); if (ret) { DLOG("G packet: stlink_write_reg failed"); } @@ -1458,8 +1458,8 @@ int32_t serve(stlink_t *sl, st_state_t *st) { char* s_start = &packet[1]; char* s_count = strstr(&packet[1], ",") + 1; - stm32_addr_t start = (stm32_addr_t)strtoul(s_start, NULL, 16); - uint32_t count = (uint32_t)strtoul(s_count, NULL, 16); + stm32_addr_t start = (stm32_addr_t) strtoul(s_start, NULL, 16); + uint32_t count = (uint32_t) strtoul(s_count, NULL, 16); uint32_t adj_start = start % 4; uint32_t count_rnd = (count + adj_start + 4 - 1) / 4 * 4; @@ -1489,8 +1489,8 @@ int32_t serve(stlink_t *sl, st_state_t *st) { char* s_count = strstr(&packet[1], ",") + 1; char* hexdata = strstr(packet, ":") + 1; - stm32_addr_t start = (stm32_addr_t)strtoul(s_start, NULL, 16); - uint32_t count = (uint32_t)strtoul(s_count, NULL, 16); + stm32_addr_t start = (stm32_addr_t) strtoul(s_start, NULL, 16); + uint32_t count = (uint32_t) strtoul(s_count, NULL, 16); int32_t err = 0; if (start % 4) { @@ -1500,7 +1500,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) { for (uint32_t i = 0; i < align_count; i++) { char hextmp[3] = { hexdata[i * 2], hexdata[i * 2 + 1], 0 }; - uint8_t byte = (uint8_t)strtoul(hextmp, NULL, 16); + uint8_t byte = (uint8_t) strtoul(hextmp, NULL, 16); sl->q_buf[i] = byte; } @@ -1516,7 +1516,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) { for (uint32_t i = 0; i < aligned_count; i++) { char hextmp[3] = { hexdata[i * 2], hexdata[i * 2 + 1], 0 }; - uint8_t byte = (uint8_t)strtoul(hextmp, NULL, 16); + uint8_t byte = (uint8_t) strtoul(hextmp, NULL, 16); sl->q_buf[i] = byte; } @@ -1530,7 +1530,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) { if (count) { for (uint32_t i = 0; i < count; i++) { char hextmp[3] = { hexdata[i * 2], hexdata[i * 2 + 1], 0 }; - uint8_t byte = (uint8_t)strtoul(hextmp, NULL, 16); + uint8_t byte = (uint8_t) strtoul(hextmp, NULL, 16); sl->q_buf[i] = byte; } @@ -1544,8 +1544,8 @@ int32_t serve(stlink_t *sl, st_state_t *st) { case 'Z': { char *endptr; - stm32_addr_t addr = (stm32_addr_t)strtoul(&packet[3], &endptr, 16); - stm32_addr_t len = (stm32_addr_t)strtoul(&endptr[1], NULL, 16); + stm32_addr_t addr = (stm32_addr_t) strtoul(&packet[3], &endptr, 16); + stm32_addr_t len = (stm32_addr_t) strtoul(&endptr[1], NULL, 16); switch (packet[1]) { case '1': @@ -1587,7 +1587,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) { } case 'z': { char *endptr; - stm32_addr_t addr = (stm32_addr_t)strtoul(&packet[3], &endptr, 16); + stm32_addr_t addr = (stm32_addr_t) strtoul(&packet[3], &endptr, 16); // stm32_addr_t len = strtoul(&endptr[1], NULL, 16); switch (packet[1]) { diff --git a/src/st-util/semihosting.c b/src/st-util/semihosting.c index 8e9828ce8..4a86e4db2 100644 --- a/src/st-util/semihosting.c +++ b/src/st-util/semihosting.c @@ -191,7 +191,7 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { DLOG("Semihosting: open('%s', (SH open mode)%d, 0644)\n", name, mode); - *ret = (uint32_t)open(name, open_mode_flags[mode], 0644); + *ret = (uint32_t) open(name, open_mode_flags[mode], 0644); saved_errno = errno; DLOG("Semihosting: return %d\n", *ret); @@ -210,11 +210,11 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { return (-1); } - fd = (int32_t)args[0]; + fd = (int32_t) args[0]; DLOG("Semihosting: close(%d)\n", fd); - *ret = (uint32_t)close(fd); + *ret = (uint32_t) close(fd); saved_errno = errno; DLOG("Semihosting: return %d\n", *ret); @@ -234,7 +234,7 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { return (-1); } - fd = (int32_t)args[0]; + fd = (int32_t) args[0]; buffer_address = args[1]; buffer_len = args[2]; @@ -262,7 +262,7 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { DLOG("Semihosting: write(%d, target_addr:0x%08x, %u)\n", fd, buffer_address, buffer_len); - *ret = (uint32_t)write(fd, buffer, buffer_len); + *ret = (uint32_t) write(fd, buffer, buffer_len); saved_errno = errno; if (*ret == (uint32_t)-1) { @@ -290,7 +290,7 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { return (-1); } - fd = (int32_t)args[0]; + fd = (int32_t) args[0]; buffer_address = args[1]; buffer_len = args[2]; @@ -323,7 +323,7 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { *ret = buffer_len; return (-1); } else { - *ret = buffer_len - (uint32_t)read_result; + *ret = buffer_len - (uint32_t) read_result; } } @@ -333,7 +333,7 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { } case SEMIHOST_SYS_ERRNO: { - *ret = (uint32_t)saved_errno; + *ret = (uint32_t) saved_errno; DLOG("Semihosting: Errno return %d\n", *ret); break; } @@ -381,7 +381,7 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { } DLOG("Semihosting: unlink('%s')\n", name); - *ret = (uint32_t)unlink(name); + *ret = (uint32_t) unlink(name); saved_errno = errno; DLOG("Semihosting: return %d\n", *ret); free(name); @@ -399,11 +399,11 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { return (-1); } - fd = (int32_t)args[0]; - offset = (off_t)args[1]; + fd = (int32_t) args[0]; + offset = (off_t) args[1]; - DLOG("Semihosting: lseek(%d, %d, SEEK_SET)\n", fd, (int32_t)offset); - *ret = (uint32_t)lseek(fd, offset, SEEK_SET); + DLOG("Semihosting: lseek(%d, %d, SEEK_SET)\n", fd, (int32_t) offset); + *ret = (uint32_t) lseek(fd, offset, SEEK_SET); saved_errno = errno; if (*ret != (uint32_t)-1) { *ret = 0; /* Success */ } diff --git a/src/stlink-gui/gui.c b/src/stlink-gui/gui.c index 57dbe997a..bc24591e5 100644 --- a/src/stlink-gui/gui.c +++ b/src/stlink-gui/gui.c @@ -442,7 +442,7 @@ static gchar *dev_format_chip_id(guint32 chip_id) { } static gchar *dev_format_mem_size(gsize flash_size) { - return (g_strdup_printf("%u kB", (uint32_t)(flash_size / 1024))); + return (g_strdup_printf("%u kB", (uint32_t) (flash_size / 1024))); } @@ -594,7 +594,7 @@ static gpointer stlink_gui_write_flash(gpointer data) { g_return_val_if_fail((gui->filename != NULL), NULL); if (stlink_mwrite_flash( - gui->sl, gui->file_mem.memory, (uint32_t)gui->file_mem.size, gui->sl->flash_base) < 0) { + gui->sl, gui->file_mem.memory, (uint32_t) gui->file_mem.size, gui->sl->flash_base) < 0) { stlink_gui_set_info_error_message(gui, "Failed to write to flash"); } diff --git a/src/stlink-lib/calculate.c b/src/stlink-lib/calculate.c index 95a94143b..d214c7c03 100644 --- a/src/stlink-lib/calculate.c +++ b/src/stlink-lib/calculate.c @@ -65,7 +65,7 @@ uint32_t calculate_L4_page(stlink_t *sl, uint32_t flashaddr) { sl->chip_id == STM32_CHIPID_L496x_L4A6x || sl->chip_id == STM32_CHIPID_L4Rx) { // these chips use dual bank flash - if (flashopt & (uint32_t)(1lu << FLASH_L4_OPTR_DUALBANK)) { + if (flashopt & (uint32_t) (1lu << FLASH_L4_OPTR_DUALBANK)) { uint32_t banksize = sl->flash_size / 2; if (flashaddr >= banksize) { diff --git a/src/stlink-lib/chipid.c b/src/stlink-lib/chipid.c index c5ec08e6a..d20c5f58c 100644 --- a/src/stlink-lib/chipid.c +++ b/src/stlink-lib/chipid.c @@ -224,7 +224,7 @@ void init_chipids(char *dir_to_scan) { if (d) { while ((dir = readdir(d)) != NULL) { - nl = (uint32_t)strlen(dir->d_name); + nl = (uint32_t) strlen(dir->d_name); if (strcmp(dir->d_name + nl - 5, ".chip") == 0) { char buf[1024]; diff --git a/src/stlink-lib/common.c b/src/stlink-lib/common.c index 3ce1dd688..42209485d 100644 --- a/src/stlink-lib/common.c +++ b/src/stlink-lib/common.c @@ -620,7 +620,7 @@ void stlink_print_data(stlink_t *sl) { */ } // DLOG(" %02x", (uint32_t) sl->q_buf[i]); - fprintf(stderr, " %02x", (uint32_t)sl->q_buf[i]); + fprintf(stderr, " %02x", (uint32_t) sl->q_buf[i]); } // DLOG("\n\n"); fprintf(stderr, "\n"); @@ -669,12 +669,12 @@ int32_t stlink_mwrite_sram(stlink_t *sl, uint8_t *data, uint32_t length, stm32_a size += 2; } // round size if needed - stlink_write_mem32(sl, addr + off, (uint16_t)size); + stlink_write_mem32(sl, addr + off, (uint16_t) size); } if (length > len) { memcpy(sl->q_buf, data + len, length - len); - stlink_write_mem8(sl, addr + len, (uint16_t)(length - len)); + stlink_write_mem8(sl, addr + len, (uint16_t) (length - len)); } error = 0; // success @@ -737,12 +737,12 @@ int32_t stlink_fwrite_sram(stlink_t *sl, const char *path, stm32_addr_t addr) { size += 2; } // round size if needed - stlink_write_mem32(sl, addr + off, (uint16_t)size); + stlink_write_mem32(sl, addr + off, (uint16_t) size); } if (mf.len > len) { memcpy(sl->q_buf, mf.base + len, mf.len - len); - stlink_write_mem8(sl, addr + len, (uint16_t)(mf.len - len)); + stlink_write_mem8(sl, addr + len, (uint16_t) (mf.len - len)); } // check the file has been written @@ -913,7 +913,7 @@ int32_t stlink_parse_ihex(const char *path, uint8_t erased_pattern, uint8_t **me break; } - uint32_t l = (uint32_t)strlen(line); + uint32_t l = (uint32_t) strlen(line); while (l > 0 && (line[l - 1] == '\n' || line[l - 1] == '\r')) { --l; @@ -941,14 +941,14 @@ int32_t stlink_parse_ihex(const char *path, uint8_t erased_pattern, uint8_t **me uint8_t reclen = stlink_parse_hex(line + 1); - if (((uint32_t)reclen + 5) * 2 + 1 != l) { + if (((uint32_t) reclen + 5) * 2 + 1 != l) { ELOG("Wrong file format - record length mismatch\n"); res = -1; break; } - uint16_t offset = ((uint16_t)stlink_parse_hex(line + 3) << 8) | - ((uint16_t)stlink_parse_hex(line + 5)); + uint16_t offset = ((uint16_t) stlink_parse_hex(line + 3) << 8) | + ((uint16_t) stlink_parse_hex(line + 5)); uint8_t rectype = stlink_parse_hex(line + 7); switch (rectype) { @@ -986,8 +986,8 @@ int32_t stlink_parse_ihex(const char *path, uint8_t erased_pattern, uint8_t **me break; case 4: /* Extended Linear Address */ if (reclen == 2) { - lba = ((uint32_t)stlink_parse_hex(line + 9) << 24) | - ((uint32_t)stlink_parse_hex(line + 11) << 16); + lba = ((uint32_t) stlink_parse_hex(line + 9) << 24) | + ((uint32_t) stlink_parse_hex(line + 11) << 16); } else { ELOG("Wrong file format - wrong LBA length\n"); res = -1; @@ -1181,8 +1181,8 @@ void _parse_version(stlink_t *sl, stlink_version_t *slv) { slv->stlink_v = sl->q_buf[0]; slv->swim_v = sl->q_buf[1]; slv->jtag_v = sl->q_buf[2]; - slv->st_vid = (uint32_t)((sl->q_buf[9] << 8) | sl->q_buf[8]); - slv->stlink_pid = (uint32_t)((sl->q_buf[11] << 8) | sl->q_buf[10]); + slv->st_vid = (uint32_t) ((sl->q_buf[9] << 8) | sl->q_buf[8]); + slv->stlink_pid = (uint32_t) ((sl->q_buf[11] << 8) | sl->q_buf[10]); slv->jtag_api = STLINK_JTAG_API_V3; /* preferred API to get last R/W status */ sl->version.flags |= STLINK_F_HAS_GETLASTRWSTATUS2; @@ -1230,7 +1230,7 @@ static int32_t stlink_read(stlink_t *sl, stm32_addr_t addr, uint32_t size, save_ aligned_size = (cmp_size + 4) & ~(4 - 1); } - stlink_read_mem32(sl, addr + off, (uint16_t)aligned_size); + stlink_read_mem32(sl, addr + off, (uint16_t) aligned_size); if (!fn(fn_arg, sl->q_buf, aligned_size)) { goto on_error; @@ -1277,11 +1277,11 @@ static uint8_t stlink_parse_hex(const char *hex) { static bool stlink_fread_ihex_newsegment(struct stlink_fread_ihex_worker_arg *the_arg) { uint32_t addr = the_arg->addr; - uint8_t sum = 2 + 4 + (uint8_t)((addr & 0xFF000000) >> 24) + - (uint8_t)((addr & 0x00FF0000) >> 16); + uint8_t sum = 2 + 4 + (uint8_t) ((addr & 0xFF000000) >> 24) + + (uint8_t) ((addr & 0x00FF0000) >> 16); if (17 != fprintf(the_arg->file, ":02000004%04X%02X\r\n", - (addr & 0xFFFF0000) >> 16, (uint8_t)(0x100 - sum))) { + (addr & 0xFFFF0000) >> 16, (uint8_t) (0x100 - sum))) { return (false); } @@ -1304,8 +1304,8 @@ static bool stlink_fread_ihex_writeline(struct stlink_fread_ihex_worker_arg *the } } - uint8_t sum = count + (uint8_t)((addr & 0x0000FF00) >> 8) + - (uint8_t)(addr & 0x000000FF); + uint8_t sum = count + (uint8_t) ((addr & 0x0000FF00) >> 8) + + (uint8_t) (addr & 0x000000FF); if (9 != fprintf(the_arg->file, ":%02X%04X00", count, (addr & 0x0000FFFF))) { return (false); @@ -1320,7 +1320,7 @@ static bool stlink_fread_ihex_writeline(struct stlink_fread_ihex_worker_arg *the } } - if (4 != fprintf(the_arg->file, "%02X\r\n", (uint8_t)(0x100 - sum))) { + if (4 != fprintf(the_arg->file, "%02X\r\n", (uint8_t) (0x100 - sum))) { return (false); } diff --git a/src/stlink-lib/common_flash.c b/src/stlink-lib/common_flash.c index 73c77d090..663dd8132 100644 --- a/src/stlink-lib/common_flash.c +++ b/src/stlink-lib/common_flash.c @@ -885,7 +885,7 @@ static inline void write_flash_cr_bker_pnb(stlink_t *sl, uint32_t n) { x &= ~(1 << FLASH_L4_CR_MER1); x &= ~(1 << FLASH_L4_CR_MER2); x |= (n << FLASH_L4_CR_PNB); - x |= (uint32_t)(1lu << FLASH_L4_CR_PER); + x |= (uint32_t) (1lu << FLASH_L4_CR_PER); #if DEBUG_FLASH fprintf(stdout, "BKER:PNB:0x%x 0x%x\n", x, n); #endif @@ -1344,7 +1344,7 @@ int32_t stlink_fwrite_flash(stlink_t *sl, const char *path, stm32_addr_t addr) { stlink_checksum(&mf); if (sl->opt) { - idx = (uint32_t)mf.len; + idx = (uint32_t) mf.len; for (num_empty = 0; num_empty != mf.len; ++num_empty) { if (mf.base[--idx] != erased_pattern) { @@ -1370,10 +1370,10 @@ int32_t stlink_fwrite_flash(stlink_t *sl, const char *path, stm32_addr_t addr) { /* In case the address is within the OTP area we use a different flash method */ if(addr >= sl->otp_base && addr < sl->otp_base + sl->otp_size) { err = stlink_write_otp(sl, addr, mf.base, - (num_empty == mf.len) ? (uint32_t)mf.len : (uint32_t)mf.len - num_empty); + (num_empty == mf.len) ? (uint32_t) mf.len : (uint32_t) mf.len - num_empty); } else { err = stlink_write_flash(sl, addr, mf.base, - (num_empty == mf.len) ? (uint32_t)mf.len : (uint32_t)mf.len - num_empty, + (num_empty == mf.len) ? (uint32_t) mf.len : (uint32_t) mf.len - num_empty, num_empty == mf.len); } stlink_fwrite_finalize(sl, addr); @@ -1424,7 +1424,7 @@ int32_t stlink_verify_write_flash(stlink_t *sl, stm32_addr_t address, uint8_t *d aligned_size = (cmp_size + 4) & ~(4 - 1); } - stlink_read_mem32(sl, address + off, (uint16_t)aligned_size); + stlink_read_mem32(sl, address + off, (uint16_t) aligned_size); if (memcmp(sl->q_buf, data + off, cmp_size)) { ELOG("Verification of flash failed at offset: %u\n", off); diff --git a/src/stlink-lib/flash_loader.c b/src/stlink-lib/flash_loader.c index 503dcce37..34033a0f8 100644 --- a/src/stlink-lib/flash_loader.c +++ b/src/stlink-lib/flash_loader.c @@ -320,7 +320,7 @@ int32_t stlink_flash_loader_write_to_sram(stlink_t *sl, stm32_addr_t* addr, uint } memcpy(sl->q_buf, loader_code, loader_size); - int32_t ret = stlink_write_mem32(sl, sl->sram_base, (uint16_t)loader_size); + int32_t ret = stlink_write_mem32(sl, sl->sram_base, (uint16_t) loader_size); if (ret) { return (ret); } @@ -400,7 +400,7 @@ int32_t stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t t * several bytes garbage have been written due to the unaligned * firmware size. */ - if ((int32_t)rr.r[2] > 0 || (int32_t)rr.r[2] < -7) { + if ((int32_t) rr.r[2] > 0 || (int32_t) rr.r[2] < -7) { ELOG("Flash loader write error\n"); goto error; } @@ -460,7 +460,7 @@ int32_t stm32l1_write_half_pages(stlink_t *sl, flash_loader_t *fl, stm32_addr_t for (off = 0; off < pagesize && !ret; off += 64) { uint32_t chunk = (pagesize - off > 64) ? 64 : pagesize - off; memcpy(sl->q_buf, base + count * pagesize + off, chunk); - ret = stlink_write_mem32(sl, addr + count * pagesize + off, (uint16_t)chunk); + ret = stlink_write_mem32(sl, addr + count * pagesize + off, (uint16_t) chunk); } } @@ -788,7 +788,7 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t if (stm32l1_write_half_pages(sl, fl, addr, base, len, pagesize)) { return (-1); } else { - off = (uint32_t)(len / pagesize) * pagesize; + off = (uint32_t) (len / pagesize) * pagesize; } } diff --git a/src/stlink-lib/helper.c b/src/stlink-lib/helper.c index 1e756f1de..860d1b409 100644 --- a/src/stlink-lib/helper.c +++ b/src/stlink-lib/helper.c @@ -19,12 +19,12 @@ uint32_t time_ms() { struct timeval tv; gettimeofday(&tv, NULL); - return (uint32_t)(tv.tv_sec * 1000 + tv.tv_usec / 1000); + return (uint32_t) (tv.tv_sec * 1000 + tv.tv_usec / 1000); } int32_t arg_parse_freq(const char *str) { char *tail; - int32_t value = (int32_t)strtol(str, &tail, 10); + int32_t value = (int32_t) strtol(str, &tail, 10); if (tail[0] == 'M' && tail[1] == '\0') { value = value*1000; diff --git a/src/stlink-lib/lib_md5.c b/src/stlink-lib/lib_md5.c index 62e77252e..1f4a915af 100644 --- a/src/stlink-lib/lib_md5.c +++ b/src/stlink-lib/lib_md5.c @@ -46,10 +46,10 @@ static void* TransformFunction(Md5Context* ctx, void const* data, uintmax_t size uint32_t saved_d; #define GET(n) (ctx->block[(n)]) - #define SET(n) (ctx->block[(n)] = ((uint32_t)ptr[(n) * 4 + 0] << 0) | \ - ((uint32_t)ptr[(n) * 4 + 1] << 8) | \ - ((uint32_t)ptr[(n) * 4 + 2] << 16) | \ - ((uint32_t)ptr[(n) * 4 + 3] << 24)) + #define SET(n) (ctx->block[(n)] = ((uint32_t) ptr[(n) * 4 + 0] << 0) | \ + ((uint32_t) ptr[(n) * 4 + 1] << 8) | \ + ((uint32_t) ptr[(n) * 4 + 2] << 16) | \ + ((uint32_t) ptr[(n) * 4 + 3] << 24)) ptr = (uint8_t*)data; @@ -188,7 +188,7 @@ void Md5Update(Md5Context* Context /* [in out] */, void const* Buffer /* [in] */ Context->hi++; } - Context->hi += (uint32_t)(BufferSize >> 29); + Context->hi += (uint32_t) (BufferSize >> 29); used = saved_lo & 0x3f; @@ -207,7 +207,7 @@ void Md5Update(Md5Context* Context /* [in out] */, void const* Buffer /* [in] */ } if ( BufferSize >= 64 ) { - Buffer = TransformFunction( Context, Buffer, BufferSize & ~(uint32_t)0x3f ); + Buffer = TransformFunction( Context, Buffer, BufferSize & ~(uint32_t) 0x3f ); BufferSize &= 0x3f; } @@ -239,33 +239,33 @@ void Md5Finalise(Md5Context* Context /* [in out] */, MD5_HASH* Digest /* [in] */ memset( &Context->buffer[used], 0, free - 8 ); Context->lo <<= 3; - Context->buffer[56] = (uint8_t)(Context->lo); - Context->buffer[57] = (uint8_t)(Context->lo >> 8); - Context->buffer[58] = (uint8_t)(Context->lo >> 16); - Context->buffer[59] = (uint8_t)(Context->lo >> 24); - Context->buffer[60] = (uint8_t)(Context->hi); - Context->buffer[61] = (uint8_t)(Context->hi >> 8); - Context->buffer[62] = (uint8_t)(Context->hi >> 16); - Context->buffer[63] = (uint8_t)(Context->hi >> 24); + Context->buffer[56] = (uint8_t) (Context->lo); + Context->buffer[57] = (uint8_t) (Context->lo >> 8); + Context->buffer[58] = (uint8_t) (Context->lo >> 16); + Context->buffer[59] = (uint8_t) (Context->lo >> 24); + Context->buffer[60] = (uint8_t) (Context->hi); + Context->buffer[61] = (uint8_t) (Context->hi >> 8); + Context->buffer[62] = (uint8_t) (Context->hi >> 16); + Context->buffer[63] = (uint8_t) (Context->hi >> 24); TransformFunction( Context, Context->buffer, 64 ); - Digest->bytes[0] = (uint8_t)(Context->a); - Digest->bytes[1] = (uint8_t)(Context->a >> 8); - Digest->bytes[2] = (uint8_t)(Context->a >> 16); - Digest->bytes[3] = (uint8_t)(Context->a >> 24); - Digest->bytes[4] = (uint8_t)(Context->b); - Digest->bytes[5] = (uint8_t)(Context->b >> 8); - Digest->bytes[6] = (uint8_t)(Context->b >> 16); - Digest->bytes[7] = (uint8_t)(Context->b >> 24); - Digest->bytes[8] = (uint8_t)(Context->c); - Digest->bytes[9] = (uint8_t)(Context->c >> 8); - Digest->bytes[10] = (uint8_t)(Context->c >> 16); - Digest->bytes[11] = (uint8_t)(Context->c >> 24); - Digest->bytes[12] = (uint8_t)(Context->d); - Digest->bytes[13] = (uint8_t)(Context->d >> 8); - Digest->bytes[14] = (uint8_t)(Context->d >> 16); - Digest->bytes[15] = (uint8_t)(Context->d >> 24); + Digest->bytes[0] = (uint8_t) (Context->a); + Digest->bytes[1] = (uint8_t) (Context->a >> 8); + Digest->bytes[2] = (uint8_t) (Context->a >> 16); + Digest->bytes[3] = (uint8_t) (Context->a >> 24); + Digest->bytes[4] = (uint8_t) (Context->b); + Digest->bytes[5] = (uint8_t) (Context->b >> 8); + Digest->bytes[6] = (uint8_t) (Context->b >> 16); + Digest->bytes[7] = (uint8_t) (Context->b >> 24); + Digest->bytes[8] = (uint8_t) (Context->c); + Digest->bytes[9] = (uint8_t) (Context->c >> 8); + Digest->bytes[10] = (uint8_t) (Context->c >> 16); + Digest->bytes[11] = (uint8_t) (Context->c >> 24); + Digest->bytes[12] = (uint8_t) (Context->d); + Digest->bytes[13] = (uint8_t) (Context->d >> 8); + Digest->bytes[14] = (uint8_t) (Context->d >> 16); + Digest->bytes[15] = (uint8_t) (Context->d >> 24); } /* Md5Calculate diff --git a/src/stlink-lib/map_file.c b/src/stlink-lib/map_file.c index f75996be5..5dae9f27a 100644 --- a/src/stlink-lib/map_file.c +++ b/src/stlink-lib/map_file.c @@ -52,7 +52,7 @@ int32_t check_file(stlink_t *sl, mapped_file_t *mf, stm32_addr_t addr) { aligned_size = (cmp_size + 4) & ~(4 - 1); } - stlink_read_mem32(sl, addr + off, (uint16_t)aligned_size); + stlink_read_mem32(sl, addr + off, (uint16_t) aligned_size); if (memcmp(sl->q_buf, mf->base + off, cmp_size)) { return (-1); @@ -80,7 +80,7 @@ int32_t map_file(mapped_file_t *mf, const char *path) { if (sizeof(st.st_size) != sizeof(size_t)) { // on 32 bit systems, check if there is an overflow - if (st.st_size > (off_t)MAX_FILE_SIZE /*1 GB*/ ) { + if (st.st_size > (off_t) MAX_FILE_SIZE /*1 GB*/ ) { // limit file size to 1 GB fprintf(stderr, "mmap() uint32_t overflow for file %s\n", path); goto on_error; @@ -88,14 +88,14 @@ int32_t map_file(mapped_file_t *mf, const char *path) { } mf->base = - (uint8_t *)mmap(NULL, (size_t)(st.st_size), PROT_READ, MAP_SHARED, fd, 0); + (uint8_t *)mmap(NULL, (size_t) (st.st_size), PROT_READ, MAP_SHARED, fd, 0); if (mf->base == MAP_FAILED) { fprintf(stderr, "mmap() == MAP_FAILED for file %s\n", path); goto on_error; } - mf->len = (uint32_t)st.st_size; + mf->len = (uint32_t) st.st_size; error = 0; // success on_error: diff --git a/src/stlink-lib/md5.c b/src/stlink-lib/md5.c index a5347de59..271a01a20 100644 --- a/src/stlink-lib/md5.c +++ b/src/stlink-lib/md5.c @@ -18,11 +18,11 @@ void md5_calculate(mapped_file_t *mf) { Md5Context md5Context; MD5_HASH md5Hash; Md5Initialise(&md5Context); - Md5Update(&md5Context, mf->base, (uint32_t)mf->len); + Md5Update(&md5Context, mf->base, (uint32_t) mf->len); Md5Finalise(&md5Context, &md5Hash); printf("md5 checksum: "); - for (int32_t i = 0; i < (int32_t)sizeof(md5Hash); i++) { + for (int32_t i = 0; i < (int32_t) sizeof(md5Hash); i++) { printf("%x", md5Hash.bytes[i]); } diff --git a/src/stlink-lib/option_bytes.c b/src/stlink-lib/option_bytes.c index d49c346ef..a5f164506 100644 --- a/src/stlink-lib/option_bytes.c +++ b/src/stlink-lib/option_bytes.c @@ -211,7 +211,7 @@ static int32_t stlink_write_option_control_register_f0(stlink_t *sl, uint32_t op user_options = (option_cr >> option_offset >> 2) & 0xFFFF; user_data = (option_cr >> user_data_offset) & 0xFFFF; -#define VAL_WITH_COMPLEMENT(v) (uint16_t)(((v)&0xFF) | (((~(v))<<8)&0xFF00)) +#define VAL_WITH_COMPLEMENT(v) (uint16_t) (((v)&0xFF) | (((~(v))<<8)&0xFF00)) opt_val[0] = (option_cr & (1 << 1/*OPT_READOUT*/)) ? 0xFFFF : rdp; opt_val[1] = VAL_WITH_COMPLEMENT(user_options); @@ -330,7 +330,7 @@ int32_t stlink_read_option_bytes_f7(stlink_t *sl, uint32_t *option_byte) { return stlink_read_debug32( sl, - sl->option_base + (uint32_t)(sl->option_size / 4 - 1) * sizeof(uint32_t), + sl->option_base + (uint32_t) (sl->option_size / 4 - 1) * sizeof(uint32_t), option_byte); } @@ -919,7 +919,7 @@ int32_t stlink_fwrite_option_bytes(stlink_t *sl, const char *path, stm32_addr_t md5_calculate(&mf); stlink_checksum(&mf); - err = stlink_write_option_bytes(sl, addr, mf.base, (uint32_t)mf.len); + err = stlink_write_option_bytes(sl, addr, mf.base, (uint32_t) mf.len); stlink_fwrite_finalize(sl, addr); unmap_file(&mf); diff --git a/src/stlink-lib/read_write.c b/src/stlink-lib/read_write.c index 4e43d8aa5..877ab3b48 100644 --- a/src/stlink-lib/read_write.c +++ b/src/stlink-lib/read_write.c @@ -18,17 +18,17 @@ // These functions encode and decode little endian uint16 and uint32 values. uint16_t read_uint16(const unsigned char *c, const int32_t pt) { - return ((uint16_t)c[pt]) | ((uint16_t)c[pt + 1] << 8); + return ((uint16_t) c[pt]) | ((uint16_t) c[pt + 1] << 8); } void write_uint16(unsigned char *buf, uint16_t ui) { - buf[0] = (uint8_t)ui; - buf[1] = (uint8_t)(ui >> 8); + buf[0] = (uint8_t) ui; + buf[1] = (uint8_t) (ui >> 8); } uint32_t read_uint32(const unsigned char *c, const int32_t pt) { - return ((uint32_t)c[pt]) | ((uint32_t)c[pt + 1] << 8) | - ((uint32_t)c[pt + 2] << 16) | ((uint32_t)c[pt + 3] << 24); + return ((uint32_t) c[pt]) | ((uint32_t) c[pt + 1] << 8) | + ((uint32_t) c[pt + 2] << 16) | ((uint32_t) c[pt + 3] << 24); } void write_uint32(unsigned char *buf, uint32_t ui) { diff --git a/src/stlink-lib/sg.c b/src/stlink-lib/sg.c index b1d5d7689..c58e22b64 100644 --- a/src/stlink-lib/sg.c +++ b/src/stlink-lib/sg.c @@ -172,7 +172,7 @@ static int32_t dump_CDB_command(uint8_t *cdb, uint8_t cdb_len) { dbugp += sprintf(dbugp, "Sending CDB ["); for (uint8_t i = 0; i < cdb_len; i++) { - dbugp += sprintf(dbugp, " 0x%02x", (uint32_t)cdb[i]); + dbugp += sprintf(dbugp, " 0x%02x", (uint32_t) cdb[i]); } sprintf(dbugp, "]\n"); @@ -288,7 +288,7 @@ static void get_sense(libusb_device_handle *handle, uint8_t endpoint_in, uint8_t } if (transferred != sizeof(sense)) { - WLOG("received unexpected amount of sense: %d != %u\n", transferred, (uint32_t)sizeof(sense)); + WLOG("received unexpected amount of sense: %d != %u\n", transferred, (uint32_t) sizeof(sense)); } uint32_t received_tag; diff --git a/src/stlink-lib/usb.c b/src/stlink-lib/usb.c index e666101a1..e37b531ea 100644 --- a/src/stlink-lib/usb.c +++ b/src/stlink-lib/usb.c @@ -31,7 +31,7 @@ #include "register.h" static inline uint32_t le_to_h_u32(const uint8_t* buf) { - return ((uint32_t)((uint32_t)buf[0] | (uint32_t)buf[1] << 8 | (uint32_t)buf[2] << 16 | (uint32_t)buf[3] << 24)); + return ((uint32_t) ((uint32_t) buf[0] | (uint32_t) buf[1] << 8 | (uint32_t) buf[2] << 16 | (uint32_t) buf[3] << 24)); } static int32_t _stlink_match_speed_map(const uint32_t *map, uint32_t map_size, uint32_t khz) { @@ -98,17 +98,17 @@ ssize_t send_recv(struct stlink_libusb* handle, int32_t terminate, unsigned char while (1) { res = 0; - t = libusb_bulk_transfer(handle->usb_handle, handle->ep_req, txbuf, (int32_t)txsize, &res, 3000); + t = libusb_bulk_transfer(handle->usb_handle, handle->ep_req, txbuf, (int32_t) txsize, &res, 3000); if (t) { ELOG("%s send request failed: %s\n", cmd, libusb_error_name(t)); return (-1); - } else if ((size_t)res != txsize) { - ELOG("%s send request wrote %u bytes, instead of %u\n", cmd, (uint32_t)res, (uint32_t)txsize); + } else if ((size_t) res != txsize) { + ELOG("%s send request wrote %u bytes, instead of %u\n", cmd, (uint32_t) res, (uint32_t) txsize); } if (rxsize != 0) { - t = libusb_bulk_transfer(handle->usb_handle, handle->ep_rep, rxbuf, (int32_t)rxsize, &res, 3000); + t = libusb_bulk_transfer(handle->usb_handle, handle->ep_rep, rxbuf, (int32_t) rxsize, &res, 3000); if (t) { ELOG("%s read reply failed: %s\n", cmd, libusb_error_name(t)); @@ -143,7 +143,7 @@ ssize_t send_recv(struct stlink_libusb* handle, int32_t terminate, unsigned char return (-1); } - if (check_error == CMD_CHECK_REP_LEN && res != (int32_t)rxsize) { + if (check_error == CMD_CHECK_REP_LEN && res != (int32_t) rxsize) { ELOG("%s wrong reply length\n", cmd); res = -1; } @@ -169,7 +169,7 @@ ssize_t send_recv(struct stlink_libusb* handle, int32_t terminate, unsigned char static inline int32_t send_only(struct stlink_libusb* handle, int32_t terminate, unsigned char* txbuf, uint32_t txsize, const char *cmd) { - return ((int32_t)send_recv(handle, terminate, txbuf, txsize, NULL, 0, CMD_CHECK_NO, cmd)); + return ((int32_t) send_recv(handle, terminate, txbuf, txsize, NULL, 0, CMD_CHECK_NO, cmd)); } @@ -682,10 +682,10 @@ int32_t _stlink_usb_set_swdclk(stlink_t* sl, int32_t clk_freq) { cmd[i++] = STLINK_DEBUG_APIV3_SET_COM_FREQ; cmd[i++] = 0; // SWD mode cmd[i++] = 0; - cmd[i++] = (uint8_t)((map[speed_index] >> 0) & 0xFF); - cmd[i++] = (uint8_t)((map[speed_index] >> 8) & 0xFF); - cmd[i++] = (uint8_t)((map[speed_index] >> 16) & 0xFF); - cmd[i++] = (uint8_t)((map[speed_index] >> 24) & 0xFF); + cmd[i++] = (uint8_t) ((map[speed_index] >> 0) & 0xFF); + cmd[i++] = (uint8_t) ((map[speed_index] >> 8) & 0xFF); + cmd[i++] = (uint8_t) ((map[speed_index] >> 16) & 0xFF); + cmd[i++] = (uint8_t) ((map[speed_index] >> 24) & 0xFF); size = send_recv(slu, 1, cmd, slu->cmd_len, data, 8, CMD_CHECK_STATUS, "SET_COM_FREQ"); @@ -728,7 +728,7 @@ int32_t _stlink_usb_read_mem32(stlink_t *sl, uint32_t addr, uint16_t len) { return (-1); } - sl->q_len = (int32_t)size; + sl->q_len = (int32_t) size; stlink_print_data(sl); return (0); @@ -759,7 +759,7 @@ int32_t _stlink_usb_read_all_regs(stlink_t *sl, struct stlink_reg *regp) { /* V1: regs data from offset 0 */ /* V2: status at offset 0, regs data from offset 4 */ int32_t reg_offset = sl->version.jtag_api == STLINK_JTAG_API_V1 ? 0 : 4; - sl->q_len = (int32_t)size; + sl->q_len = (int32_t) size; stlink_print_data(sl); for (i = 0; i < 16; i++) regp->r[i] = read_uint32(sl->q_buf, reg_offset + i * 4); @@ -799,14 +799,14 @@ int32_t _stlink_usb_read_reg(stlink_t *sl, int32_t r_idx, struct stlink_reg *reg cmd[i++] = STLINK_DEBUG_APIV2_READREG; } - cmd[i++] = (uint8_t)r_idx; + cmd[i++] = (uint8_t) r_idx; size = send_recv(slu, 1, cmd, slu->cmd_len, data, rep_len, CMD_CHECK_RETRY, "READREG"); if (size < 0) { return (-1); } - sl->q_len = (int32_t)size; + sl->q_len = (int32_t) size; stlink_print_data(sl); r = read_uint32(sl->q_buf, reg_offset); DLOG("r_idx (%2d) = 0x%08x\n", r_idx, r); @@ -856,10 +856,10 @@ int32_t _stlink_usb_read_unsupported_reg(stlink_t *sl, int32_t r_idx, struct stl switch (r_idx) { case 0x14: - regp->primask = (uint8_t)(r & 0xFF); - regp->basepri = (uint8_t)((r >> 8) & 0xFF); - regp->faultmask = (uint8_t)((r >> 16) & 0xFF); - regp->control = (uint8_t)((r >> 24) & 0xFF); + regp->primask = (uint8_t) (r & 0xFF); + regp->basepri = (uint8_t) ((r >> 8) & 0xFF); + regp->faultmask = (uint8_t) ((r >> 16) & 0xFF); + regp->control = (uint8_t) ((r >> 24) & 0xFF); break; case 0x21: regp->fpscr = r; @@ -902,32 +902,32 @@ int32_t _stlink_usb_write_unsupported_reg(stlink_t *sl, uint32_t val, int32_t r_ if (ret == -1) { return (ret); } - val = (uint8_t)(val >> 24); + val = (uint8_t) (val >> 24); switch (r_idx) { case 0x1C: /* control */ - val = (((uint32_t)val) << 24) | - (((uint32_t)regp->faultmask) << 16) | - (((uint32_t)regp->basepri) << 8) | - ((uint32_t)regp->primask); + val = (((uint32_t) val) << 24) | + (((uint32_t) regp->faultmask) << 16) | + (((uint32_t) regp->basepri) << 8) | + ((uint32_t) regp->primask); break; case 0x1D: /* faultmask */ - val = (((uint32_t)regp->control) << 24) | - (((uint32_t)val) << 16) | - (((uint32_t)regp->basepri) << 8) | - ((uint32_t)regp->primask); + val = (((uint32_t) regp->control) << 24) | + (((uint32_t) val) << 16) | + (((uint32_t) regp->basepri) << 8) | + ((uint32_t) regp->primask); break; case 0x1E: /* basepri */ - val = (((uint32_t)regp->control) << 24) | - (((uint32_t)regp->faultmask) << 16) | - (((uint32_t)val) << 8) | - ((uint32_t)regp->primask); + val = (((uint32_t) regp->control) << 24) | + (((uint32_t) regp->faultmask) << 16) | + (((uint32_t) val) << 8) | + ((uint32_t) regp->primask); break; case 0x1F: /* primask */ - val = (((uint32_t)regp->control) << 24) | - (((uint32_t)regp->faultmask) << 16) | - (((uint32_t)regp->basepri) << 8) | - ((uint32_t)val); + val = (((uint32_t) regp->control) << 24) | + (((uint32_t) regp->faultmask) << 16) | + (((uint32_t) regp->basepri) << 8) | + ((uint32_t) val); break; } @@ -1026,7 +1026,7 @@ int32_t _stlink_usb_read_trace(stlink_t* sl, uint8_t* buf, uint32_t size) { if (send_size < 0) { return (-1); } else if (send_size != 2) { - ELOG("STLINK_DEBUG_APIV2_GET_TRACE_NB reply size %d\n", (int32_t)send_size); + ELOG("STLINK_DEBUG_APIV2_GET_TRACE_NB reply size %d\n", (int32_t) send_size); return (-1); } @@ -1041,7 +1041,7 @@ int32_t _stlink_usb_read_trace(stlink_t* sl, uint8_t* buf, uint32_t size) { int32_t res = 0; int32_t t = libusb_bulk_transfer(slu->usb_handle, slu->ep_trace, buf, trace_count, &res, 3000); - if (t || res != (int32_t)trace_count) { + if (t || res != (int32_t) trace_count) { ELOG("read_trace read error %d\n", t); return (-1); } @@ -1084,7 +1084,7 @@ static stlink_backend_t _stlink_usb_backend = { }; /* return the length of serial or (0) in case of errors */ -size_t stlink_serial(struct libusb_device_handle *handle, struct libusb_device_descriptor *desc, char *serial) { +uint32_t stlink_serial(struct libusb_device_handle *handle, struct libusb_device_descriptor *desc, char *serial) { unsigned char desc_serial[(STLINK_SERIAL_LENGTH) * 2]; /* truncate the string in the serial buffer */ @@ -1172,7 +1172,7 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, enum connect_type connect, if (ret) { continue; } // could not open device - uint32_t serial_len = (uint32_t)stlink_serial(handle, &desc, sl->serial); + uint32_t serial_len = stlink_serial(handle, &desc, sl->serial); libusb_close(handle); @@ -1376,7 +1376,7 @@ static uint32_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[], break; } - uint32_t serial_len = (uint32_t)stlink_serial(handle, &desc, serial); + uint32_t serial_len = stlink_serial(handle, &desc, serial); libusb_close(handle); @@ -1397,7 +1397,7 @@ static uint32_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[], return (slcur); } -size_t stlink_probe_usb(stlink_t **stdevs[], enum connect_type connect, int32_t freq) { +uint32_t stlink_probe_usb(stlink_t **stdevs[], enum connect_type connect, int32_t freq) { libusb_device **devs; stlink_t **sldevs; diff --git a/src/stlink-lib/usb.h b/src/stlink-lib/usb.h index 783144471..2a76182b0 100644 --- a/src/stlink-lib/usb.h +++ b/src/stlink-lib/usb.h @@ -102,10 +102,10 @@ int32_t _stlink_usb_read_trace(stlink_t* sl, uint8_t* buf, uint32_t size); // static stlink_backend_t _stlink_usb_backend = { }; -size_t stlink_serial(struct libusb_device_handle *handle, struct libusb_device_descriptor *desc, char *serial); +uint32_t stlink_serial(struct libusb_device_handle *handle, struct libusb_device_descriptor *desc, char *serial); stlink_t *stlink_open_usb(enum ugly_loglevel verbose, enum connect_type connect, char serial[STLINK_SERIAL_BUFFER_SIZE], int32_t freq); // static uint32_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[], enum connect_type connect, int32_t freq); -size_t stlink_probe_usb(stlink_t **stdevs[], enum connect_type connect, int32_t freq); +uint32_t stlink_probe_usb(stlink_t **stdevs[], enum connect_type connect, int32_t freq); void stlink_probe_usb_free(stlink_t **stdevs[], uint32_t size); #endif // USB_H diff --git a/src/win32/mmap.c b/src/win32/mmap.c index 8bddb5094..1e2f3c7d4 100644 --- a/src/win32/mmap.c +++ b/src/win32/mmap.c @@ -23,7 +23,7 @@ void *mmap (void *addr, uint32_t len, int32_t prot, int32_t flags, int32_t fd, i count = read(fd, buf, len); - if (count != (ssize_t)len) { + if (count != (ssize_t) len) { free (buf); return (MAP_FAILED); } diff --git a/src/win32/sys_time.c b/src/win32/sys_time.c index f1ebd63b9..7cdc51c17 100644 --- a/src/win32/sys_time.c +++ b/src/win32/sys_time.c @@ -17,8 +17,8 @@ int32_t gettimeofday(struct timeval *tv, struct timezone *tz) { ulint.LowPart = ftime.dwLowDateTime; ulint.HighPart = ftime.dwHighDateTime; - tv->tv_sec = (int32_t)(ulint.QuadPart / 10000000L); - tv->tv_usec = (int32_t)(ulint.QuadPart % 10000000L); + tv->tv_sec = (int32_t) (ulint.QuadPart / 10000000L); + tv->tv_usec = (int32_t) (ulint.QuadPart % 10000000L); } if (NULL != tz) { diff --git a/tests/flash.c b/tests/flash.c index 4d9ac5185..7c54221f5 100644 --- a/tests/flash.c +++ b/tests/flash.c @@ -49,7 +49,7 @@ static bool execute_test(const struct Test * test) { strcpy(cmd_line, test->cmd_line); for (char * tok = strtok(cmd_line, " "); tok; tok = strtok(NULL, " ")) { - if ((size_t)ac >= sizeof(av) / sizeof(av[0])) return (false); + if ((size_t) ac >= sizeof(av) / sizeof(av[0])) return (false); av[ac] = tok; ++ac;