From 8de264f850219658a742b235035da05784695d81 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Mon, 1 Jul 2024 15:36:57 +0200 Subject: [PATCH 1/2] fix(stm32CubeProg): fallback to BSD getopt for MacOS By default, MacOS uses getopt from FreeBSD and not the GNU-based one. Then "-o" and long options are not supported except if gnu-getopt is installed. Fixes #99 Signed-off-by: Frederic Pillon --- stm32CubeProg.sh | 119 ++++++++++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 48 deletions(-) diff --git a/stm32CubeProg.sh b/stm32CubeProg.sh index 403d1a425..56ac9921b 100644 --- a/stm32CubeProg.sh +++ b/stm32CubeProg.sh @@ -2,6 +2,8 @@ set -o nounset # Treat unset variables as an error # set -o xtrace # Print command traces before executing command. +UNAME_OS="$(uname -s)" +GNU_GETOPT= STM32CP_CLI= INTERFACE= PORT= @@ -53,11 +55,73 @@ aborting() { exit 1 } +# Check STM32CubeProgrammer cli availability and getopt version +case "${UNAME_OS}" in + Linux*) + STM32CP_CLI=STM32_Programmer.sh + if ! command -v $STM32CP_CLI >/dev/null 2>&1; then + export PATH="$HOME/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin":"$PATH" + fi + if ! command -v $STM32CP_CLI >/dev/null 2>&1; then + export PATH="/opt/stm32cubeprog/bin":"$PATH" + fi + if ! command -v $STM32CP_CLI >/dev/null 2>&1; then + aborting + fi + ;; + Darwin*) + STM32CP_CLI=STM32_Programmer_CLI + if ! command -v $STM32CP_CLI >/dev/null 2>&1; then + export PATH="/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin":"$PATH" + fi + if ! command -v $STM32CP_CLI >/dev/null 2>&1; then + aborting + fi + if ! command -v /usr/local/opt/gnu-getopt/bin/getopt >/dev/null 2>&1; then + if ! command -v /opt/homebrew/opt/gnu-getopt/bin/getopt >/dev/null 2>&1; then + echo "Warning: long options not supported due to getopt from FreeBSD usage." + GNU_GETOPT=n + else + export PATH="/opt/homebrew/opt/gnu-getopt/bin":"$PATH" + fi + else + export PATH="/usr/local/opt/gnu-getopt/bin":"$PATH" + fi + ;; + Windows*) + STM32CP_CLI=STM32_Programmer_CLI.exe + if ! command -v $STM32CP_CLI >/dev/null 2>&1; then + if [ -n "${PROGRAMFILES+x}" ]; then + STM32CP86=${PROGRAMFILES}/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin + export PATH="${STM32CP86}":"$PATH" + fi + if [ -n "${PROGRAMW6432+x}" ]; then + STM32CP=${PROGRAMW6432}/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin + export PATH="${STM32CP}":"$PATH" + fi + if ! command -v $STM32CP_CLI >/dev/null 2>&1; then + aborting + fi + fi + ;; + *) + echo "Unknown host OS: ${UNAME_OS}." >&2 + exit 1 + ;; +esac + # parse command line arguments # options may be followed by one colon to indicate they have a required arg -if ! options=$(getopt -a -o hi:ef:o:c:r:d:v:p: --long help,interface:,erase,file:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then - echo "Terminating..." >&2 - exit 1 +if [ -n "${GNU_GETOPT}" ]; then + if ! options=$(getopt hi:ef:o:c:r:d:v:p: "$@"); then + echo "Terminating..." >&2 + exit 1 + fi +else + if ! options=$(getopt -a -o hi:ef:o:c:r:d:v:p: --long help,interface:,erase,file:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then + echo "Terminating..." >&2 + exit 1 + fi fi eval set -- "$options" @@ -109,53 +173,12 @@ while true; do shift break ;; + *) + echo "Unknown option $1" + usage 1 + ;; esac done -# Check STM32CubeProgrammer cli availability, fallback to dfu-util if protocol dfu -UNAME_OS="$(uname -s)" -case "${UNAME_OS}" in - Linux*) - STM32CP_CLI=STM32_Programmer.sh - if ! command -v $STM32CP_CLI >/dev/null 2>&1; then - export PATH="$HOME/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin":"$PATH" - fi - if ! command -v $STM32CP_CLI >/dev/null 2>&1; then - export PATH="/opt/stm32cubeprog/bin":"$PATH" - fi - if ! command -v $STM32CP_CLI >/dev/null 2>&1; then - aborting - fi - ;; - Darwin*) - STM32CP_CLI=STM32_Programmer_CLI - if ! command -v $STM32CP_CLI >/dev/null 2>&1; then - export PATH="/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin":"$PATH" - fi - if ! command -v $STM32CP_CLI >/dev/null 2>&1; then - aborting - fi - ;; - Windows*) - STM32CP_CLI=STM32_Programmer_CLI.exe - if ! command -v $STM32CP_CLI >/dev/null 2>&1; then - if [ -n "${PROGRAMFILES+x}" ]; then - STM32CP86=${PROGRAMFILES}/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin - export PATH="${STM32CP86}":"$PATH" - fi - if [ -n "${PROGRAMW6432+x}" ]; then - STM32CP=${PROGRAMW6432}/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin - export PATH="${STM32CP}":"$PATH" - fi - if ! command -v $STM32CP_CLI >/dev/null 2>&1; then - aborting - fi - fi - ;; - *) - echo "Unknown host OS: ${UNAME_OS}." >&2 - exit 1 - ;; -esac # Check mandatory options if [ -z "${INTERFACE}" ]; then From 74f9e5031b85256ad28c04962c6420a5acbf666d Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 18 Jul 2024 16:30:57 +0200 Subject: [PATCH 2/2] doc: update badge version to 2.2.3 Signed-off-by: Frederic Pillon --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bcaf6d2bc..1d9efc916 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Arduino_Tools [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Tools.svg)](https://github.com/stm32duino/Arduino_Tools/releases/latest) -[![GitHub commits](https://img.shields.io/github/commits-since/stm32duino/Arduino_Tools/2.2.2.svg)](https://github.com/stm32duino/Arduino_Tools/compare/2.2.2...master) +[![GitHub commits](https://img.shields.io/github/commits-since/stm32duino/Arduino_Tools/2.2.3.svg)](https://github.com/stm32duino/Arduino_Tools/compare/2.2.3...master) Contains upload tools for STM32 based boards and some other usefull scripts.