def main(): # check config have to be done first check_config() if args.clean: deleteFolder(root_output_dir) load_core_config() if args.list != "sketch": find_board() if args.list == "board": for board in board_fqbn: print(board) print(f"{len(board_fqbn)} board(s) available") quit() manage_inos() if args.list == "sketch": for sketch in sketch_list: print(sketch) print(f"{len(sketch_list)} sketches found") quit() if core_config: parse_core_config() createFolder(build_output_dir) createFolder(output_dir) build_all() deleteFolder(build_output_dir) sys.exit(nb_build_failed)
def train(self, message): print(message) m = json.loads(message) intervals = m["keystrokes"] user = m["user"] newUser = m["newUser"] if newUser: utils.deleteFolder(user) utils.singleTrain(intervals, user, newUser) classes, prob = utils.singleTest(intervals, user) utils.save_stat(user, intervals, classes[0], prob, newUser) returnMessage = "CREATED" Y = 1 else: classes, prob = utils.singleTest(intervals, user) utils.save_stat(user, intervals, classes[0], prob, newUser) if classes[0] == 1: # utils.singleTrain(intervals,user,newUser) returnMessage = "VALID" Y = 1 else: returnMessage = "INVALID" Y = 0 utils.saveIntervals(intervals, Y, user, newUser) back = {'stat': utils.get_stat(user), 'message': returnMessage} return back
def build_all(): create_output_log_tree() wrapper = textwrap.TextWrapper(width=76) if args.dry: print("Performing a dry run (no build)") build = dry_build else: build = real_build for sketch_nb, sketch in enumerate(sketch_list, start=1): boardKo = [] boardSkipped = [] print(f"\n{build_separator}") print("| {:^85} |".format( f"Sketch \033[34m{sketch.name}\033[0m ({sketch_nb}/{len(sketch_list)})" )) wrapped_path_ = wrapper.wrap(text=str(sketch.parent)) for line in wrapped_path_: print("| {:^76} |".format(f"{line}")) print(build_separator) print((build_format_header).format("Num", "Board", "Result", "Time")) print(build_separator) build_conf_list = build_config(sketch, boardSkipped) nb_build_conf = len(build_conf_list) with concurrent.futures.ProcessPoolExecutor(os.cpu_count() - 1) as executor: for build_conf, res in zip(build_conf_list, executor.map(build, build_conf_list)): check_status(res, build_conf, boardKo, nb_build_conf) log_sketch_build_result(sketch, boardKo, boardSkipped) # Ensure no cache issue deleteFolder(build_output_cache_dir) log_final_result()
def updateOpenAmp(): print("Updating OpenAmp Middleware") repo_path = repo_local_path / repo_core_name if upargs.local: cube_path = local_cube_path else: cube_name = f"{repo_generic_name}MP1" cube_path = repo_local_path / cube_name OpenAmp_cube_path = cube_path / "Middlewares" / "Third_Party" / "OpenAMP" OpenAmp_core_path = repo_path / "system" / "Middlewares" / "OpenAMP" # First delete old HAL version deleteFolder(OpenAmp_core_path) # Copy new one copyFolder(OpenAmp_cube_path, OpenAmp_core_path)
def installApp(REPO_URL, manifest, APP_ROOT='/apps'): import upip_utarfile as tarfile import uzlib, os, gc from upip import url_open gc.collect() oled.fill(0) oled.text('Installing...', 0, 0, 1) oled.text(manifest['name'], 0, 8, 1) oled.text(manifest['version'], 0, 16, 1) oled.show() count = 0 try: s1 = url_open(REPO_URL + manifest['url']) f2 = uzlib.DecompIO(s1, 30) t3 = tarfile.TarFile(fileobj=f2) for x in t3: print(x) count += 1 oled.fill_rect(0, 32, 128, 16, 0) oled.hctext('File #%d' % count, 32, 1) oled.hctext(x.name[-16:], 40, 1) oled.show() if x.type == tarfile.DIRTYPE: # a dir FOLDER_PATH = APP_ROOT + '/' + x.name[:-1] print(FOLDER_PATH) if x.name[:-1] in os.listdir(APP_ROOT): deleteFolder(FOLDER_PATH) # delete if exists os.mkdir(FOLDER_PATH) else: # a file f4 = open(APP_ROOT + '/' + x.name, 'wb') f4.write(t3.extractfile(x).read()) f4.close() finally: s1.close() rebuildAppsIndex(APP_ROOT) oled.text('Done :) Reboot!', 0, 56, 1) oled.show() sleep_ms(500) import machine machine.reset()
def updateCore(): for serie in stm32_list: if upargs.local: cube_path = local_cube_path else: cube_name = f"{repo_generic_name}{serie}" cube_path = repo_local_path / cube_name core_path = repo_local_path / repo_core_name core_HAL_ver = core_HAL_versions[serie] cube_HAL_ver = cube_HAL_versions[serie] core_CMSIS_ver = core_CMSIS_versions[serie] cube_CMSIS_ver = cube_CMSIS_versions[serie] cube_version = cube_versions[serie] HAL_updated = False CMSIS_updated = False hal_commit_msg = """system({0}) {3} STM32{0}xx HAL Drivers to v{1} Included in STM32Cube{0} FW {2}""".format(serie, cube_HAL_ver, cube_version, "add" if upargs.add else "update") cmsis_commit_msg = """system({0}): {3} STM32{0}xx CMSIS Drivers to v{1} Included in STM32Cube{0} FW {2}""".format(serie, cube_CMSIS_ver, cube_version, "add" if upargs.add else "update") wrapper_commit_msg = ( f"core({serie}): {'add' if upargs.add else 'update'} wrapped files" ) # Update HAL part if needed if version.parse(core_HAL_ver) < version.parse(cube_HAL_ver): if upargs.add: print(f"Adding {serie} HAL version {cube_HAL_ver}...") else: print( f"Updating {serie} HAL from version {core_HAL_ver} to {cube_HAL_ver}..." ) # First delete old HAL version HAL_serie_core_path = hal_dest_path / f"STM32{serie}xx_HAL_Driver" deleteFolder(HAL_serie_core_path) # Copy new one HAL_serie_cube_path = (cube_path / hal_src_path / f"STM32{serie}xx_HAL_Driver") copyFolder(HAL_serie_cube_path, HAL_serie_core_path, {"*.chm"}) # Update MD file updateMDFile(md_HAL_path, serie, cube_HAL_ver) # Commit all HAL files commitFiles(core_path, hal_commit_msg) HAL_updated = True if version.parse(core_CMSIS_ver) < version.parse(cube_CMSIS_ver): if upargs.add: print(f"Adding {serie} CMSIS version {cube_CMSIS_ver}...") else: print( f"Updating {serie} CMSIS from version {core_CMSIS_ver} to {cube_CMSIS_ver}..." ) # First delete CMSIS folder CMSIS_serie_dest_path = cmsis_dest_path / f"STM32{serie}xx" deleteFolder(CMSIS_serie_dest_path) # Copy new one CMSIS_serie_cube_path = cube_path / cmsis_src_path / f"STM32{serie}xx" copyFolder(CMSIS_serie_cube_path, CMSIS_serie_dest_path, {"iar", "arm"}) # Update MD file updateMDFile(md_CMSIS_path, serie, cube_CMSIS_ver) # Commit all CMSIS files commitFiles(core_path, cmsis_commit_msg) CMSIS_updated = True if upargs.add: system_commit_msg = ( f"system({serie}): add STM32{serie}xx system source files") update_hal_conf_commit_msg = ( f"system({serie}): update STM32{serie}xx hal default config") update_stm32_def_commit_msg = f"core({serie}): add top HAL include" # Create system files createSystemFiles(serie) # Commit all system files commitFiles(core_path, system_commit_msg) # Update default HAL configuration updateHalConfDefault(serie) commitFiles(core_path, update_hal_conf_commit_msg) print("\tPlease, review carefully all the system files added!") print("\tAdd #ifndef/#endif to all definitions which should be") print( f"\tredefinable in the stm32{serie.lower()}xx_hal_conf_default.h" ) # Update stm32_def to add top HAL include updateStm32Def(serie) commitFiles(core_path, update_stm32_def_commit_msg) if HAL_updated or CMSIS_updated: # Generate all wrapper files # Assuming the ArduinoModule-CMSIS repo available # at the same root level than the core print( f"{'Adding' if upargs.add else 'Updating'} {serie} wrapped files..." ) if stm32wrapper.wrap(core_path, None, False) == 0: commitFiles(core_path, wrapper_commit_msg) # Apply all related patch if any applyPatch(serie, HAL_updated, CMSIS_updated, core_path) if serie == "MP1": print( f"Updating {serie} OpenAmp Middleware to Cube {cube_version} ..." ) updateOpenAmp() openAmp_commit_msg = ( f"Update OpenAmp Middleware to MP1 Cube version {cube_version}" ) commitFiles(core_path, openAmp_commit_msg) print( "WARNING: OpenAmp MW has been updated, please check whether Arduino implementation:" ) print(" * cores/arduino/stm32/OpenAMP/mbox_ipcc.h") print(" * cores/arduino/stm32/OpenAMP/mbox_ipcc.c") print(" * cores/arduino/stm32/OpenAMP/rsc_table.h") print(" * cores/arduino/stm32/OpenAMP/rsc_table.c") print(" * cores/arduino/stm32/OpenAMP/openamp.h") print(" * cores/arduino/stm32/OpenAMP/openamp.c") print(" * cores/arduino/stm32/OpenAMP/openamp_conf.h") print(" should be updated from Cube project:") print( " --> Projects/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo" ) if serie == "WB": updateBle()
def wrap(arg_core, arg_cmsis, log): global stm32_series # check config have to be done first checkConfig(arg_core, arg_cmsis) stm32_series = genSTM32List(HALDrivers_path, "") # Remove old file deleteFolder(HALoutSrc_path) createFolder(HALoutSrc_path) deleteFolder(LLoutSrc_path) createFolder(LLoutSrc_path) deleteFolder(LLoutInc_path) createFolder(LLoutInc_path) if CMSIS_Startupfile.is_file(): CMSIS_Startupfile.unlink() all_ll_h_list = [] # key: peripheral, value: serie list ll_h_dict = {} ll_c_dict = {} hal_c_dict = {} # Search all files for each series for serie in stm32_series: src = HALDrivers_path / f"STM32{serie}xx_HAL_Driver" / "Src" inc = HALDrivers_path / f"STM32{serie}xx_HAL_Driver" / "Inc" if src.exists(): if log: print(f"Generating for {serie}...") lower = serie.lower() # Search stm32yyxx_[hal|ll]*.c file filelist = src.glob(f"**/stm32{lower}xx_*.c") for fp in filelist: legacy = True if fp.parent.name == "Legacy" else False # File name fn = fp.name found = peripheral_c_regex.match(fn) if "_template" in fn: continue peripheral = found.group(1) if found else "hal" if "_ll_" in fn: if peripheral in ll_c_dict: if legacy: # Change legacy value if exists current_list = ll_c_dict.pop(peripheral) if current_list[-1][0] == lower: current_list.pop() current_list.append((lower, legacy)) ll_c_dict[peripheral] = current_list else: ll_c_dict[peripheral].append((lower, legacy)) else: ll_c_dict[peripheral] = [(lower, legacy)] else: if peripheral in hal_c_dict: if legacy: # Change legacy value if exists current_list = hal_c_dict.pop(peripheral) if current_list[-1][0] == lower: current_list.pop() current_list.append((lower, legacy)) hal_c_dict[peripheral] = current_list else: hal_c_dict[peripheral].append((lower, legacy)) else: hal_c_dict[peripheral] = [(lower, legacy)] # Search stm32yyxx_ll_*.h file filelist = inc.glob(f"stm32{lower}xx_ll_*.h") for fp in filelist: # File name fn = fp.name found = peripheral_h_regex.match(fn) if not found: continue peripheral = found.group(1) # Amend all LL header list all_ll_h_list.append(fn.replace(lower, "yy")) if peripheral in ll_h_dict: ll_h_dict[peripheral].append(lower) else: ll_h_dict[peripheral] = [lower] # Generate stm32yyxx_hal_*.c file for key, value in hal_c_dict.items(): if key == "hal": filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace( "_ppp", "") else: filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace( "ppp", key) out_file = open(filepath, "w", newline="\n") out_file.write( c_file_template.render(periph=key, type="hal", serieslist=value)) out_file.close() # Generate stm32yyxx_ll_*.c file for key, value in ll_c_dict.items(): filepath = LLoutSrc_path / c_file.replace("zz", "ll").replace( "ppp", key) out_file = open(filepath, "w", newline="\n") out_file.write( c_file_template.render(periph=key, type="ll", serieslist=value)) out_file.close() # Generate stm32yyxx_ll_*.h file for key, value in ll_h_dict.items(): filepath = LLoutInc_path / ll_h_file.replace("ppp", key) out_file = open(filepath, "w", newline="\n") out_file.write(ll_h_file_template.render(periph=key, serieslist=value)) out_file.close() if log: print("done") # Filter all LL header file all_ll_h_list = sorted(set(all_ll_h_list)) # Generate the all LL header file all_ll_file = open(LLoutInc_path / all_ll_h_file, "w", newline="\n") all_ll_file.write( all_ll_header_file_template.render(ll_header_list=all_ll_h_list)) all_ll_file.close() # CMSIS startup files printCMSISStartup(log) # system stm32 files printSystemSTM32(log) # CMSIS DSP C source file if not CMSIS_path.is_dir(): print(f"Could not find {CMSIS_path}") print("CMSIS DSP generation skipped.") else: # Delete all subfolders deleteFolder(CMSIS_DSP_outSrc_path / "*") dirlist = [] for path_object in CMSIS_DSPSrc_path.glob("**/*"): if path_object.is_file(): if path_object.name.endswith(".c"): dirlist.append(path_object.parent.name) dirlist = sorted(set(dirlist)) for dn in dirlist: fdn = CMSIS_DSP_outSrc_path / dn if not fdn.is_dir(): createFolder(fdn) out_file = open(fdn / (f"{dn}.c"), "w", newline="\n") all_ll_file.write(dsp_file_template.render(dsp_path=dn)) out_file.close() return 0
def cleanUp(mw): dist_path = mw.txtDistPath.text() if mw.txtDistPath.text() else os.path.join(source_path, "dist") work_path = mw.txtWorkPath.text() if mw.txtWorkPath.text() else os.path.join(source_path, "build") utils.deleteFolder(dist_path) utils.deleteFolder(work_path)