From 156871d55efc1b53a8efceafb64318198d819252 Mon Sep 17 00:00:00 2001 From: WRR <-@-> Date: Mon, 12 Aug 2019 11:37:00 -0700 Subject: [PATCH 1/6] Add support for STM32G031 and STM32G041 chips. Including the 8-pin STM32G031J6 :D --- include/stlink/chipid.h | 3 ++- src/chipid.c | 13 ++++++++++++- src/common.c | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/stlink/chipid.h b/include/stlink/chipid.h index a4f4be4c0..9ff8c814f 100644 --- a/include/stlink/chipid.h +++ b/include/stlink/chipid.h @@ -71,7 +71,8 @@ enum stlink_stm32_chipids { STLINK_CHIPID_STM32_F410 = 0x458, STLINK_CHIPID_STM32_F413 = 0x463, STLINK_CHIPID_STM32_L4RX = 0x470, // taken from the STM32L4R9I-DISCO board - STLINK_CHIPID_STM32_G0X1 = 0x460, + STLINK_CHIPID_STM32_G0_CAT1 = 0x466, // G031/041 + STLINK_CHIPID_STM32_G0_CAT2 = 0x460, // G071/081 STLINK_CHIPID_STM32_WB55 = 0x495 }; diff --git a/src/chipid.c b/src/chipid.c index d627849a3..7b7bc88d0 100644 --- a/src/chipid.c +++ b/src/chipid.c @@ -521,9 +521,20 @@ static const struct stlink_chipid_params devices[] = { .bootrom_base = 0x1ff00000, .bootrom_size = 0x2000 }, + { + // STM32G031/041 (from RM0444) + .chip_id = STLINK_CHIPID_STM32_G0_CAT1, + .description = "G031/G041 device", + .flash_type = STLINK_FLASH_TYPE_G0, + .flash_size_reg = 0x1FFF75E0, // Section 38.2 + .flash_pagesize = 0x800, // 2K (sec 3.2) + .sram_size = 0x2000, // 8K (sec 2.3) + .bootrom_base = 0x1fff0000, + .bootrom_size = 0x7800 // 30K (table 3) + }, { // STM32G071/081 (from RM0444) - .chip_id = STLINK_CHIPID_STM32_G0X1, + .chip_id = STLINK_CHIPID_STM32_G0_CAT2, .description = "G071/G081 device", .flash_type = STLINK_FLASH_TYPE_G0, .flash_size_reg = 0x1FFF75E0, // Section 38.2 diff --git a/src/common.c b/src/common.c index b4741a585..f974d77ab 100644 --- a/src/common.c +++ b/src/common.c @@ -2520,7 +2520,7 @@ int stlink_write_option_bytes(stlink_t *sl, stm32_addr_t addr, uint8_t* base, ui stlink_core_id(sl); /* Check if chip is supported and for correct address */ - if((sl->chip_id != STLINK_CHIPID_STM32_G0X1) || (addr != STM32_G0_OPTION_BYTES_BASE)) { + if((sl->chip_id != STLINK_CHIPID_STM32_G0_CAT2 && sl->chip_id != STLINK_CHIPID_STM32_G0_CAT1) || (addr != STM32_G0_OPTION_BYTES_BASE)) { ELOG("Option bytes writing is currently only supported for the STM32G0\n"); return -1; } From 5a5c3d71d7568070bc108e7501ff977ad94d653c Mon Sep 17 00:00:00 2001 From: Oleksiy Slyshyk Date: Fri, 21 Feb 2020 06:53:28 +0200 Subject: [PATCH 2/6] --- --- src/common.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/common.c b/src/common.c index bef3a5e3d..018e01c4c 100644 --- a/src/common.c +++ b/src/common.c @@ -2631,15 +2631,6 @@ static int stlink_write_option_bytes_g0x(stlink_t *sl, uint8_t* base, uint32_t l return -1; } - // Make sure we've loaded the context with the chip details - stlink_core_id(sl); - - /* Check if chip is supported and for correct address */ - if((sl->chip_id != STLINK_CHIPID_STM32_G0_CAT2 && sl->chip_id != STLINK_CHIPID_STM32_G0_CAT1) || (addr != STM32_G0_OPTION_BYTES_BASE)) { - ELOG("Option bytes writing is currently only supported for the STM32G0\n"); - return -1; - } - /* Unlock flash if necessary (ref manuel page 52) */ stlink_read_debug32(sl, STM32Gx_FLASH_CR, &val); if ((val & (1u << STM32Gx_FLASH_CR_LOCK))) { From 83a31a09b358021a3b6b65962f7ea4c6550f0289 Mon Sep 17 00:00:00 2001 From: Slyshyk Oleksiy Date: Sat, 29 Feb 2020 16:23:22 +0200 Subject: [PATCH 3/6] Add win32 travis build (#2) * add mingw64 build to travis CI * Make .travis-lin-mingw.sh executable * .travis-lin-mingw.sh: make build dir * show $PWD in travis-lin-mingw * update .travis-lin-mingw.sh * --- * update .travis-lin-mingw.sh * update p7zip cmd * fix sign/unsign comparioson in usb.c * revert call .travis.sh * clean up .travis-lin-mingw.sh --- .travis-lin-mingw.sh | 14 ++++++++++++++ .travis.yml | 3 +++ cmake/modules/FindLibUSB.cmake | 3 ++- src/usb.c | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100755 .travis-lin-mingw.sh diff --git a/.travis-lin-mingw.sh b/.travis-lin-mingw.sh new file mode 100755 index 000000000..0422a06f6 --- /dev/null +++ b/.travis-lin-mingw.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +DIR=$PWD + +if [ "$TRAVIS_OS_NAME" == "linux" ]; then + echo "WORK DIR:$DIR" + mkdir -p $DIR/build/linux-mingw32-release + cd $DIR/build/linux-mingw32-release + echo "cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$PWD/_install $DIR" + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$PWD/_install $DIR + echo "make" + make +fi + diff --git a/.travis.yml b/.travis.yml index b0f985012..b1832d57f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,9 +18,12 @@ addons: - g++-6 - gcc-6 - libusb-1.0.0-dev + - p7zip + - mingw-w64 script: - git fetch --tags - printenv - cmake --version - ./.travis.sh + - ./.travis-lin-mingw.sh diff --git a/cmake/modules/FindLibUSB.cmake b/cmake/modules/FindLibUSB.cmake index 5233e489d..2ad35b3d8 100644 --- a/cmake/modules/FindLibUSB.cmake +++ b/cmake/modules/FindLibUSB.cmake @@ -84,7 +84,8 @@ if(NOT LIBUSB_FOUND) file(MAKE_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER}) if(${ZIP_EXECUTABLE} MATCHES "p7zip") - execute_process(COMMAND ${ZIP_EXECUTABLE} -d --keep -f ${LIBUSB_WIN_ARCHIVE_PATH} WORKING_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER}) + #execute_process(COMMAND ${ZIP_EXECUTABLE} -d --keep -f ${LIBUSB_WIN_ARCHIVE_PATH} WORKING_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER}) + execute_process(COMMAND ${ZIP_EXECUTABLE} -d ${LIBUSB_WIN_ARCHIVE_PATH} WORKING_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER}) else() execute_process(COMMAND ${ZIP_EXECUTABLE} x -y ${LIBUSB_WIN_ARCHIVE_PATH} -o${LIBUSB_WIN_OUTPUT_FOLDER}) endif() diff --git a/src/usb.c b/src/usb.c index 9df9d7296..81bd7ae2c 100644 --- a/src/usb.c +++ b/src/usb.c @@ -189,7 +189,7 @@ int _stlink_usb_version(stlink_t *sl) { cmd[i++] = STLINK_APIV3_GET_VERSION_EX; size = send_recv(slu, 1, cmd, slu->cmd_len, data, rep_len); - if (size != rep_len) { + if (size != (ssize_t)rep_len) { printf("[!] send_recv STLINK_APIV3_GET_VERSION_EX\n"); return (int) size; } From 4d55b6b3bf2bfecab3251fbe966c86eaad4e027a Mon Sep 17 00:00:00 2001 From: Oleksiy Slyshyk Date: Sun, 1 Mar 2020 18:47:59 +0200 Subject: [PATCH 4/6] make Version.cmake more error-resistant. fix #772 --- cmake/Version.cmake | 103 +++++++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 34 deletions(-) diff --git a/cmake/Version.cmake b/cmake/Version.cmake index e74d775d6..e5ce9f4c6 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -1,7 +1,11 @@ # Determine project version # * Using Git # * Local .version file -find_package (Git QUIET) + +set(__detect_version 0) + +find_package (Git) + if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") # Working off a git repo, using git versioning # Check if HEAD is pointing to a tag @@ -9,43 +13,74 @@ if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") COMMAND "${GIT_EXECUTABLE}" describe --always --tag WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" OUTPUT_VARIABLE PROJECT_VERSION + RESULT_VARIABLE GIT_DESCRIBE_RESULT + ERROR_VARIABLE GIT_DESCRIBE_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE) - # If the sources have been changed locally, add -dirty to the version. - execute_process ( - COMMAND "${GIT_EXECUTABLE}" diff --quiet - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" - RESULT_VARIABLE res) - - if (res EQUAL 1) - set (PROJECT_VERSION "${PROJECT_VERSION}-dirty") - endif() - - # strip a leading v off of the version as proceeding code expectes just the version numbering. - string(REGEX REPLACE "^v" "" PROJECT_VERSION ${PROJECT_VERSION}) - - string(REGEX REPLACE "^(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$" - "\\1;\\2;\\3" PROJECT_VERSION_LIST ${PROJECT_VERSION}) - list(LENGTH PROJECT_VERSION_LIST len) - if(len EQUAL 3) - list(GET PROJECT_VERSION_LIST 0 PROJECT_VERSION_MAJOR) - list(GET PROJECT_VERSION_LIST 1 PROJECT_VERSION_MINOR) - list(GET PROJECT_VERSION_LIST 2 PROJECT_VERSION_PATCH) - endif() -elseif(EXISTS ${PROJECT_SOURCE_DIR}/.version) - # If git is not available (e.g. when building from source package) - # we can extract the package version from .version file. - file (STRINGS .version PROJECT_VERSION) - - # TODO create function to extract semver from file or string and check if it is correct instead of copy-pasting - string(REGEX REPLACE "^(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$" - "\\1;\\2;\\3" PROJECT_VERSION_LIST ${PROJECT_VERSION}) - list(GET PROJECT_VERSION_LIST 0 PROJECT_VERSION_MAJOR) - list(GET PROJECT_VERSION_LIST 1 PROJECT_VERSION_MINOR) - list(GET PROJECT_VERSION_LIST 2 PROJECT_VERSION_PATCH) + if(GIT_DESCRIBE_RESULT EQUAL 0) + # If the sources have been changed locally, add -dirty to the version. + execute_process ( + COMMAND "${GIT_EXECUTABLE}" diff --quiet + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + RESULT_VARIABLE res) + + if (res EQUAL 1) + set (PROJECT_VERSION "${PROJECT_VERSION}-dirty") + endif() + + # strip a leading v off of the version as proceeding code expectes just the version numbering. + string(REGEX REPLACE "^v" "" PROJECT_VERSION ${PROJECT_VERSION}) + + string(REGEX REPLACE "^(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$" + "\\1;\\2;\\3" PROJECT_VERSION_LIST ${PROJECT_VERSION}) + list(LENGTH PROJECT_VERSION_LIST len) + if(len EQUAL 3) + list(GET PROJECT_VERSION_LIST 0 PROJECT_VERSION_MAJOR) + list(GET PROJECT_VERSION_LIST 1 PROJECT_VERSION_MINOR) + list(GET PROJECT_VERSION_LIST 2 PROJECT_VERSION_PATCH) + set(__detect_version 1) + else() + message(STATUS "Fail to extract version's parts from \"${PROJECT_VERSION}\"") + endif() + + else(GIT_DESCRIBE_RESULT EQUAL 0) + message(WARNING "git describe failed.") + message(WARNING "${GIT_DESCRIBE_ERROR}") + endif(GIT_DESCRIBE_RESULT EQUAL 0) else() - message(FATAL_ERROR "Unable to determine project version") + message(STATUS "Git or repo not found.") endif() + + +if(NOT __detect_version) + message(STATUS "Try to detect version from \"${PROJECT_SOURCE_DIR}/.version\" file.") + if(EXISTS ${PROJECT_SOURCE_DIR}/.version) + # If git is not available (e.g. when building from source package) + # we can extract the package version from .version file. + file (STRINGS .version PROJECT_VERSION) + + # TODO create function to extract semver from file or string and check if it is correct instead of copy-pasting + string(REGEX REPLACE "^(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$" + "\\1;\\2;\\3" PROJECT_VERSION_LIST ${PROJECT_VERSION}) + list(LENGTH PROJECT_VERSION_LIST len) + if(len EQUAL 3) + list(GET PROJECT_VERSION_LIST 0 PROJECT_VERSION_MAJOR) + list(GET PROJECT_VERSION_LIST 1 PROJECT_VERSION_MINOR) + list(GET PROJECT_VERSION_LIST 2 PROJECT_VERSION_PATCH) + set(__detect_version 1) + else() + message(STATUS "Fail to extract version's parts from \"${PROJECT_VERSION}\"") + endif() + else() + message(STATUS "File \"${PROJECT_SOURCE_DIR}/.version\" did not exists.") + endif() +endif() + +if(NOT __detect_version) + message(FATAL_ERROR "Unable to determine project version") +endif() + + message(STATUS "stlink version: ${PROJECT_VERSION}") message(STATUS " Major ${PROJECT_VERSION_MAJOR} Minor ${PROJECT_VERSION_MINOR} Patch ${PROJECT_VERSION_PATCH}") From ecf86c735bdcdb82b098de52b5656c0d8ca94302 Mon Sep 17 00:00:00 2001 From: Oleksiy Slyshyk Date: Sun, 1 Mar 2020 22:39:43 +0200 Subject: [PATCH 5/6] compare git version with .version --- .version | 2 +- cmake/Version.cmake | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.version b/.version index dc1e644a1..ce6a70b9d 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.6.0 +1.6.0 \ No newline at end of file diff --git a/cmake/Version.cmake b/cmake/Version.cmake index e5ce9f4c6..2ca1c0ff8 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -39,6 +39,15 @@ if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") list(GET PROJECT_VERSION_LIST 1 PROJECT_VERSION_MINOR) list(GET PROJECT_VERSION_LIST 2 PROJECT_VERSION_PATCH) set(__detect_version 1) + set(__version_str "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") + if(EXISTS "${PROJECT_SOURCE_DIR}/.version") + file(READ "${PROJECT_SOURCE_DIR}/.version" __version_file) + if(NOT __version_str STREQUAL __version_file) + message(STATUS "Rewrite ${PROJECT_SOURCE_DIR}/.version with ${__version_str}") + endif() + else() + file(WRITE "${PROJECT_SOURCE_DIR}/.version" ${__version_str}) + endif() else() message(STATUS "Fail to extract version's parts from \"${PROJECT_VERSION}\"") endif() From e49ad2770ede3377cd4865210c6f88a42ce48378 Mon Sep 17 00:00:00 2001 From: Oleksiy Slyshyk Date: Sat, 21 Mar 2020 21:31:12 +0200 Subject: [PATCH 6/6] fix intendation in Version.cmake --- cmake/Version.cmake | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmake/Version.cmake b/cmake/Version.cmake index 2ca1c0ff8..71859015c 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -7,15 +7,15 @@ set(__detect_version 0) find_package (Git) if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") - # Working off a git repo, using git versioning - # Check if HEAD is pointing to a tag - execute_process ( - COMMAND "${GIT_EXECUTABLE}" describe --always --tag - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" - OUTPUT_VARIABLE PROJECT_VERSION + # Working off a git repo, using git versioning + # Check if HEAD is pointing to a tag + execute_process ( + COMMAND "${GIT_EXECUTABLE}" describe --always --tag + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + OUTPUT_VARIABLE PROJECT_VERSION RESULT_VARIABLE GIT_DESCRIBE_RESULT ERROR_VARIABLE GIT_DESCRIBE_ERROR - OUTPUT_STRIP_TRAILING_WHITESPACE) + OUTPUT_STRIP_TRAILING_WHITESPACE) if(GIT_DESCRIBE_RESULT EQUAL 0) # If the sources have been changed locally, add -dirty to the version.