You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
KED/env/python/ked.py

159 lines
5.6 KiB

'''
KED Main Script
'''
import sys
import os
import shutil
import subprocess
import flasher
####################################################################################################
# FUTURE ACTIONS
####################################################################################################
# TODO: KeY 14_02_2023 -> Automatically generate project, if empty.
# TODO: KeY 14_02_2023 -> Give the possibility to generate different example projects.
####################################################################################################
####################################################################################################
# MODIFICATIONS
####################################################################################################
# KeY 14_02_2023 : Some comments for code separation added :
# FUTURE ACTIONS, MODIFICATIONS, FUNCTIONS and MAIN EXECUTION Delimiters
#
# KeY 14_02_2023 : Modified some Print's for user guidance and apearance changes
# KeY 14_02_2023 : Gave a response to CSL_TO_USE question from Edwin
####################################################################################################
####################################################################################################
# FUNCTIONS
####################################################################################################
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"
# KeY 14_02_2023 RESPONSE:
# CSL_TO_USE is the "folder name" given to CMAKE
# so that CMAKE gets the correct "file path" under the csl directory.
# Like so: csl/<CSL_TO_USE> | Real example: csl/stm32f042
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!')
'''
####################################################################################################
####################################################################################################
# MAIN EXECUTION
####################################################################################################
scriptDirectory = os.getcwd()
projectDirectory = os.path.join(scriptDirectory, '..')
buildDirectory = os.path.join(projectDirectory, 'ked_build')
#projectDirectory = scriptDirectory + '\\..'
#buildDirectory = projectDirectory + '\\ked_build'
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
# KeY 14_02_2023 : Could not help my self wiht some pimping
if sys.argv[1] in ('-ls', '-lt', '-lst', '-lsd'):
print('----------------------------')
print('| Available Traget Devices |')
print('----------------------------')
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
# KeY : 14_02_2023 : Jsut changed the text a little bit and gave some guidance to the user.
if sys.argv[1] not in targetDevList:
print('debug: Invalid Target Device')
print(' |-> To list the availabe target devices pass -ls as argument')
print(' |-> python ked.py -ls')
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)