Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(stm32cubeprog): add address and start options #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions stm32CubeProg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ STM32CP_CLI=
INTERFACE=
PORT=
FILEPATH=
ADDRESS=0x8000000
OFFSET=0x0
# Optional
ADDRESS=0x8000000
START=0x8000000
MODE=UR
ERASE=
# Optional for Serial
RTS=
Expand All @@ -28,7 +30,10 @@ usage() {
-i, --interface <'swd'/'dfu'/'serial'/'jlink'> interface identifier: 'swd', 'dfu', 'serial' or 'jlink'
-f, --file <path> file path to be downloaded: bin or hex
Optional options:
-a, --address <hex value> flash base address. Default: $ADDRESS
-e, --erase erase all sectors before flashing
-m, --mode connection mode: UR (default), HOTPLUG, POWERDOWN or hwRstPulse
-s, --start <hex value> start address after flashing. Default: $START
-o, --offset <hex value> offset from flash base ($ADDRESS) where flashing should start

Specific options for Serial protocol:
Expand Down Expand Up @@ -118,7 +123,7 @@ if [ -n "${GNU_GETOPT}" ]; then
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
if ! options=$(getopt -a -o a:hi:m:ef:o:c:r:s:d:v:p: --long address:,help,interface:,mode:,erase,file:,start:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then
echo "Terminating..." >&2
exit 1
fi
Expand All @@ -136,6 +141,18 @@ while true; do
echo "Selected interface: $INTERFACE"
shift 2
;;
-m | --mode)
MODE=$2
shift 2
;;
-a | --address)
ADDRESS=$2
shift 2
;;
-s | --start)
START=$2
shift 2
;;
-e | --erase)
ERASE="--erase all"
shift 1
Expand All @@ -146,7 +163,6 @@ while true; do
;;
-o | --offset)
OFFSET=$2
ADDRESS=$(printf "0x%x" $((ADDRESS + OFFSET)))
shift 2
;;
-c | --com)
Expand Down Expand Up @@ -180,6 +196,8 @@ while true; do
esac
done

ADDRESS=$(printf "0x%x" $((ADDRESS + OFFSET)))

# Check mandatory options
if [ -z "${INTERFACE}" ]; then
echo "Error missing interface!" >&2
Expand All @@ -196,14 +214,14 @@ fi

case "${INTERFACE}" in
swd)
${STM32CP_CLI} --connect port=SWD mode=UR "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${ADDRESS}"
${STM32CP_CLI} --connect port=SWD mode="${MODE}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${START}"
;;
dfu)
if [ -z "${VID}" ] || [ -z "${PID}" ]; then
echo "Missing mandatory arguments for DFU mode (VID/PID)!" >&2
exit 1
fi
${STM32CP_CLI} --connect port=usb1 VID="${VID}" PID="${PID}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${ADDRESS}"
${STM32CP_CLI} --connect port=usb1 VID="${VID}" PID="${PID}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${START}"
;;
serial)
if [ -z "${PORT}" ]; then
Expand All @@ -222,10 +240,10 @@ case "${INTERFACE}" in
exit 1
fi
fi
${STM32CP_CLI} --connect port="${PORT}" "${RTS}" "${DTR}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${ADDRESS}"
${STM32CP_CLI} --connect port="${PORT}" "${RTS}" "${DTR}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${START}"
;;
jlink)
${STM32CP_CLI} --connect port=JLINK ap=0 "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${ADDRESS}"
${STM32CP_CLI} --connect port=JLINK ap=0 "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${START}"
;;
*)
echo "Protocol unknown!" >&2
Expand Down