diff --git a/stm32CubeProg.sh b/stm32CubeProg.sh index 403d1a425..9e8a0bb38 100644 --- a/stm32CubeProg.sh +++ b/stm32CubeProg.sh @@ -2,6 +2,7 @@ set -o nounset # Treat unset variables as an error # set -o xtrace # Print command traces before executing command. +UNAME_OS="$(uname -s)" STM32CP_CLI= INTERFACE= PORT= @@ -55,11 +56,21 @@ aborting() { # 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 -fi - +case "${UNAME_OS}" in + Darwin*) + echo "Warning: long options not supported due to getopt from FreeBSD usage." + if ! options=$(getopt hi:ef:o:c:r:d:v:p: "$@"); then + echo "Terminating..." >&2 + exit 1 + fi + ;; + *) + 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 + ;; +esac eval set -- "$options" while true; do @@ -109,10 +120,13 @@ 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)" +# Check STM32CubeProgrammer cli availability case "${UNAME_OS}" in Linux*) STM32CP_CLI=STM32_Programmer.sh