Zoltan Hudak / QtCreator_Support
Revision:
0:e5c84595673c
Child:
5:ace99c9d0e4e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bat	Fri Aug 14 06:02:57 2020 +0000
@@ -0,0 +1,151 @@
+#!/bin/bash
+
+echo off
+
+MBED_SYS_PATH=~/src/arm/sys
+LIB_PATH=~/src/arm/lib
+OS=6
+PROF=DEBUG
+PROJ_NAME=${PWD##*/}
+PORT=/dev/ttyACM0
+
+#MCU="$1"
+#shift # past argument
+
+MACROS=()
+SRC_LIB_PATH=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+    all)
+    FLASH='-f'
+    shift # past argument
+    ;;
+    -f)
+    FLASH='-f'
+    shift # past argument
+    ;;
+    -c|clean)
+    CLEAN='-c'
+    shift # past argument
+    ;;
+    -D|--macro)
+    MACROS+=('-D '$2)
+    shift # past argument
+    shift # past value
+    ;;
+    -l)
+    SRC_LIB_PATH+=' --source '${LIB_PATH}/$2
+    shift # past argument
+    shift # past value
+    ;;
+    -m)
+    MCU="$2"
+    shift # past argument
+    shift # past value
+    ;;
+    -os)
+    OS="$2"
+    shift # past argument
+    shift # past value
+    ;;
+    -p|--port)
+    PORT="$2"
+    shift # past argument
+    shift # past value
+    ;;
+    -r|--release)
+    PROF=RELEASE
+    shift # past argument
+    ;;
+    *)    # additional args
+    ARGS+=("$key $2")
+    shift # past argument
+    ;;
+esac
+done
+
+if [ ${OS} == 2 ]
+then
+	GCC_ARM_PATH=/opt/gcc-arm-none-eabi-6-2017-q2-update
+	MBED_OS_PATH=${MBED_SYS_PATH}/mbed
+	CUSTOM_TARGETS_PATH=${MBED_SYS_PATH}/custom_targets/mbed
+	PROFILE=debug
+	if [ ${PROF} == RELEASE ]
+	then
+		PROFILE=release
+	fi
+else
+	GCC_ARM_PATH=/opt/gcc-arm-none-eabi-9-2019-q4-major
+	MBED_OS_PATH=${MBED_SYS_PATH}/mbed-os
+	CUSTOM_TARGETS_PATH=${MBED_SYS_PATH}/custom_targets/mbed-os
+	PROFILE=${MBED_SYS_PATH}/mbed-os/tools/profiles/debug.json
+	if [ ${PROF} == RELEASE ]
+	then
+		PROFILE=${MBED_SYS_PATH}/mbed-os/tools/profiles/release.json
+	fi
+fi
+
+mbed config -G GCC_ARM_PATH ${GCC_ARM_PATH}/bin
+mbed config -G MBED_OS_DIR ${MBED_OS_PATH}
+if ! [ -f ./.mbed ]
+then
+    mbed new .
+fi
+mbed export -i qtcreator -m ${MCU} --source . --source ${CUSTOM_TARGETS_PATH} --source ${MBED_OS_PATH} --source ${GCC_ARM_PATH}/arm-none-eabi/include ${SRC_LIB_PATH}
+#mbed export -i vscode_gcc_arm -m ${MCU} --source . --source ${CUSTOM_TARGETS_PATH} --source ${MBED_OS_PATH} --source ${GCC_ARM_PATH}/arm-none-eabi/include ${SRC_LIB_PATH}
+mbed compile -t GCC_ARM -m ${MCU} ${ARGS} --source . --source ${CUSTOM_TARGETS_PATH} --source ${MBED_OS_PATH} ${SRC_LIB_PATH} $CLEAN --profile ${PROFILE}
+
+#if [ "${MCU}" == "LPC1768X" ]
+#then
+#	${GCC_ARM_PATH}/bin/arm-none-eabi-objcopy -I binary -O ihex ./BUILD/${MCU}/GCC_ARM-${PROF}/${PROJ_NAME}.bin ./BUILD/${MCU}/GCC_ARM-${PROF}/${PROJ_NAME}.hex
+#fi
+
+if [ "${FLASH}" == "-f" ]
+then
+	case ${MCU} in
+    	LPC1768)
+    		MCU_CFG="pyOCD"
+    		;;
+    	LPC1768X)
+    		MCU_CFG="pyOCD"
+    		;;
+    	BLUEPILL|MAPLE_MINI|NUCLEO_F103RB|STM32F103RC|STM32F103VE)
+    		MCU_CFG="/usr/local/share/openocd/scripts/board/st_nucleo_f103rb.cfg"
+    		;;
+    	NUCLEO_F446RE|STM32F407VE)
+    		MCU_CFG="/usr/local/share/openocd/scripts/board/st_nucleo_f4.cfg"
+    		;;
+    	NUCLEO_F767ZI)
+    		MCU_CFG="/usr/local/share/openocd/scripts/board/stm32f7discovery.cfg"
+    		;;
+    	*)
+    		MCU_CFG="not_supported" 
+    		echo "No support to flash "${MCU}
+    		;;
+	esac
+	if [ "$MCU_CFG" != "not_supported" ]
+	then
+		echo "Flashing the "${MCU}" ..."
+		case ${MCU_CFG} in
+			pyOCD)
+				if [ "$PORT" == "/dev/ttyACM0" ]
+				then
+    				~/.local/bin/pyocd-flashtool -t lpc1768 ./BUILD/${MCU}/GCC_ARM-${PROF}/${PROJ_NAME}.bin
+    				#~/.local/bin/pyocd-flashtool -t lpc1768 ./BUILD/${MCU}/GCC_ARM-${PROF}/${PROJ_NAME}.bin > /dev/null 2>&1
+    			else
+    				lpc21isp -bin ./BUILD/${MCU}/GCC_ARM-${PROF}/${PROJ_NAME}.bin ${PORT} 115200 96000
+    			fi
+    			;;
+			*)
+  				openocd -f ${MCU_CFG} -c """program ./BUILD/${MCU}/GCC_ARM-${PROF}/${PROJ_NAME}.elf verify reset exit"""
+  				#openocd -f ${MCU_CFG} -c """program ./BUILD/${MCU}/GCC_ARM-${PROF}/${PROJ_NAME}.elf verify reset exit""" > /dev/null 2>&1
+  				;;
+  		esac
+  		echo "Done"
+  	fi
+fi
+
+