''' KED Main Script ''' import sys import os import shutil import subprocess import flasher class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKCYAN = '\033[96m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' def getTargetDeviceList(): os.chdir(os.path.join(os.getcwd(), 'csl')) # get top level folder names in csl which represent all available target devices return next(os.walk('.'))[1] def build(TARGET_DEVICE): # TODO: ask Kerem what he wanted to to with "CSL_TO_USE" #CSL_TO_USE = 1 print('building project with cmake...') print(bcolors.OKGREEN) os.system('cmake -S . -B '+ buildDirectory + ' -DCSL_USED=' + TARGET_DEVICE) print(bcolors.ENDC) print('...done!') print('Compiling Project with Make...') os.chdir(buildDirectory) print(bcolors.OKGREEN) os.system('make -j4') print(bcolors.ENDC) print('...done!') ''' def flash(TARGET_DEVICE): # find out what platform the build is done (e.g. linux, win32, etc.) if sys.platform == 'linux': os.system('st-flash write' + TARGET_DEVICE + '.bin 0x08000000') if sys.platform == 'win32': # https://www.youtube.com/watch?v=AcrbUOhApd0 os.chdir('C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin') subprocess.Popen("STM32_Programmer_CLI.exe") os.chdir(buildDirectory) print('this platform is not supported by KED!') ''' ########################################################################################################################### scriptDirectory = os.getcwd() projectDirectory = os.path.join(scriptDirectory, '..') buildDirectory = os.path.join(projectDirectory, 'ked_build') #projectDirectory = scriptDirectory + '\\..' #buildDirectory = projectDirectory + '\\ked_build' print(scriptDirectory) print(projectDirectory) print(buildDirectory) os.chdir(scriptDirectory) # exit if no argument was passed argvLen = len(sys.argv) if argvLen < 2: print('target device missing as argument!') sys.exit() # obtain list of all available targets in KED targetDevList = getTargetDeviceList() # user requests help if sys.argv[1] in ('-h', '-help'): print('HELP -> TODO!') sys.exit() # user request to remove build folder if sys.argv[1] in ('-rm', '-rmb'): if os.path.exists(buildDirectory): shutil.rmtree(buildDirectory) sys.exit() # user requests listing of all available target devices if sys.argv[1] in ('-ls', '-lt', '-lst', '-lsd'): print('listing all availabel targets...') for targetDev in targetDevList: print(targetDev) sys.exit() # user requests to clean project by erasing build if sys.argv[1] in ('-clean', '-c', '-db'): if os.path.exists(buildDirectory): shutil.rmtree(buildDirectory) os.mkdir(buildDirectory) print('build cleaned!') sys.exit() if sys.argv[1] in ('-dox', '-doxygen', '-gd'): print('TODO: Implement doxygen generation') sys.exit() if sys.argv[1] in ('-opendox', '-od'): print('TODO: Implement open doxygen in browser') sys.exit() ########################################################################################################################### # check if requested target device is supported by KED if sys.argv[1] not in targetDevList: print('debug: targt not valid') sys.exit() print('building for target device ['+ bcolors.OKGREEN + sys.argv[1] + bcolors.ENDC + ']...') #create build directory if missing if not os.path.exists(buildDirectory): os.mkdir(buildDirectory) CSL_TO_USE = sys.argv[1] build(CSL_TO_USE) #flasher.flash(CSL_TO_USE,buildDirectory)