import os import sys import rtconfig if os.getenv('RTT_ROOT'): RTT_ROOT = os.getenv('RTT_ROOT') else: RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..') sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] from building import * TARGET = 'rtthread.' + rtconfig.TARGET_EXT AddOption('--run', dest = 'run', type='string', nargs=1, action = 'store', default = "", help = 'Upload or debug application using openocd') DefaultEnvironment(tools=[]) env = Environment(tools = ['mingw'], AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS, AR = rtconfig.AR, ARFLAGS = '-rc', LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) env.PrependENVPath('PATH', rtconfig.EXEC_PATH) env['ASCOM'] = env['ASPPCOM'] Export('RTT_ROOT') Export('rtconfig') GDB = rtconfig.GDB nuclei_sdk_root = rtconfig.NUCLEI_SDK_ROOT openocd_cfg = rtconfig.OPENOCD_CFG.replace('\\', '/') # prepare building environment objs = PrepareBuilding(env, RTT_ROOT) # include libraries objs.extend(SConscript(os.path.join(nuclei_sdk_root, 'SConscript'))) # make a building DoBuilding(TARGET, objs) # Run upload or debug if --run=upload or --upload=debug run_target = GetOption('run') SUPPORT_RUN_TARGETS = ["upload", "debug"] if run_target in SUPPORT_RUN_TARGETS: if os.path.isfile(TARGET): if run_target == "upload": upload_cmd = '{} {} -ex "set remotetimeout 240" \ -ex "target remote | openocd --pipe -f {}" \ --batch -ex "monitor halt" -ex "monitor flash protect 0 0 last off" -ex "load" \ -ex "monitor resume" -ex "monitor shutdown" -ex "quit"'.format(GDB, TARGET, openocd_cfg) print("Upload application {} using openocd and gdb".format(TARGET)) print(upload_cmd) os.system(upload_cmd) elif run_target == "debug": debug_cmd = '{} {} -ex "set remotetimeout 240" \ -ex "target remote | openocd --pipe -f {}"'.format(GDB, TARGET, openocd_cfg) print("Debug application {} using openocd and gdb".format(TARGET)) print(debug_cmd) os.system(debug_cmd) else: print(TARGET + ' not exist, please run scons first!!') exit(0)