示例#1
0
def createSystemFiles(serie):
    print("Creating system files for {}...".format(serie))
    system_serie = system_dest_path / ("STM32{}xx".format(serie))
    createFolder(system_serie)
    # Generate stm32yyxx_hal_conf_file.h
    stm32_hal_conf_file = system_serie / stm32yyxx_hal_conf_file.replace(
        "yy", serie.lower())
    out_file = open(stm32_hal_conf_file, "w", newline="\n")
    out_file.write(stm32yyxx_hal_conf_file_template.render(serie=serie))
    out_file.close()
    # Copy system_stm32*.c file from CMSIS device template
    system_stm32_path = (cmsis_dest_path / "STM32{}xx".format(serie) /
                         "Source" / "Templates")
    filelist = sorted(system_stm32_path.glob("system_stm32*.c"))
    file_number = len(filelist)
    if file_number:
        if file_number == 1:
            file_number = 0
        else:
            menu_list = "Several system stm32 files exist:\n"
            for index, fp in enumerate(filelist):
                menu_list += "{}. {}\n".format(index, fp.name)
            menu_list += "Your choice: "
            while file_number >= len(filelist):
                file_number = int(input(menu_list))
        copyFile(filelist[file_number], system_serie)
    else:
        print("No system files found!")
    # Copy stm32yyxx_hal_conf_default.h file
    hal_conf_base = "stm32{}xx_hal_conf".format(serie.lower())
    hal_serie_path = hal_dest_path / "STM32{}xx_HAL_Driver".format(serie)
    hal_conf_file = hal_serie_path / "Inc" / (hal_conf_base + "_template.h")
    hal_conf_default = system_serie / (hal_conf_base + "_default.h")
    copyFile(hal_conf_file, hal_conf_default)
示例#2
0
def checkConfig():
    global repo_local_path
    global hal_dest_path
    global cmsis_dest_path
    global system_dest_path
    global md_HAL_path
    global md_CMSIS_path
    global stm32_def

    config_file_path = script_path / path_config_filename
    if config_file_path.is_file():
        try:
            config_file = open(config_file_path, "r")
            path_config = json.load(config_file)
            # Common path
            repo_local_path = Path(path_config["REPO_LOCAL_PATH"])
            config_file.close()
            hal_dest_path = repo_local_path / repo_core_name / hal_dest_path
            md_HAL_path = hal_dest_path / md_HAL_path
            cmsis_dest_path = repo_local_path / repo_core_name / cmsis_dest_path
            system_dest_path = repo_local_path / repo_core_name / system_dest_path
            md_CMSIS_path = cmsis_dest_path / md_CMSIS_path
            stm32_def = (
                repo_local_path
                / repo_core_name
                / "cores"
                / "arduino"
                / "stm32"
                / stm32_def
            )
        except IOError:
            print("Failed to open {}!".format(config_file))
    else:
        create_config()
    createFolder(repo_local_path)
示例#3
0
def checkConfig():
    global repo_local_path
    global hal_dest_path
    global cmsis_dest_path
    global md_HAL_path
    global md_CMSIS_path
    if os.path.isfile(os.path.join(script_path, path_config_filename)):
        try:
            path_config_file = open(
                os.path.join(script_path, path_config_filename), "r")
            path_config = json.load(path_config_file)
            # Common path
            repo_local_path = path_config["REPO_LOCAL_PATH"]
            path_config_file.close()
            hal_dest_path = os.path.join(repo_local_path, repo_core_name,
                                         hal_dest_path)
            md_HAL_path = os.path.join(hal_dest_path, md_HAL_path)
            cmsis_dest_path = os.path.join(repo_local_path, repo_core_name,
                                           cmsis_dest_path)
            md_CMSIS_path = os.path.join(cmsis_dest_path, md_CMSIS_path)
        except IOError:
            print("Failed to open " + path_config_file)
    else:
        create_config()
    createFolder(repo_local_path)
示例#4
0
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 / ("STM32" + serie + "xx_HAL_Driver") / "Src"
        inc = HALDrivers_path / ("STM32" + serie + "xx_HAL_Driver") / "Inc"

        if src.exists():
            if log:
                print("Generating for " + serie + "...")
            lower = serie.lower()

            # Search stm32yyxx_[hal|ll]*.c file
            filelist = src.glob("stm32" + lower + "xx_*.c")
            for fp in filelist:
                # 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:
                        ll_c_dict[peripheral].append(lower)
                    else:
                        ll_c_dict[peripheral] = [lower]
                else:
                    if peripheral in hal_c_dict:
                        hal_c_dict[peripheral].append(lower)
                    else:
                        hal_c_dict[peripheral] = [lower]

            # Search stm32yyxx_ll_*.h file
            filelist = inc.glob("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("Could not find {}".format(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 / (dn + ".c"), "w", newline="\n")
                all_ll_file.write(dsp_file_template.render(dsp_path=dn))
                out_file.close()
    return 0
示例#5
0
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 os.path.isfile(CMSIS_Startupfile):
        os.remove(CMSIS_Startupfile)
    full_ll_list = []
    # Search all files for each series
    for serie in stm32_series:
        src = os.path.join(HALDrivers_path, "STM32" + serie + "xx_HAL_Driver", "Src")
        inc = os.path.join(HALDrivers_path, "STM32" + serie + "xx_HAL_Driver", "Inc")

        if os.path.exists(src):
            if log:
                print("Generating for " + serie + "...")
            lower = serie.lower()
            # Generate stm32yyxx_[hal|ll]*.c file
            filelist = glob.glob(os.path.join(src, "stm32" + lower + "xx_*.c"))
            for fp in filelist:
                if "_template" in fp:
                    continue
                outp = HALoutSrc_path
                # File name
                fn = os.path.basename(fp)
                if "_ll_" in fn:
                    outp = LLoutSrc_path
                # Compute generic file name with path
                gp = os.path.join(outp, fn.replace(lower, "yy"))
                out_file = open(gp, "a", newline="\n")
                # Amend file name under serie switch
                out_file.write("#ifdef STM32" + serie + "xx\n")
                out_file.write('  #include "' + fn + '"\n')
                out_file.write("#endif\n")
                out_file.close()
            # Generate stm32yyxx_ll_*.h file
            filelist = glob.glob(os.path.join(inc, "stm32" + lower + "xx_ll_*.h"))
            for fp in filelist:
                outp = LLoutInc_path
                # File name
                fn = os.path.basename(fp)
                # Compute generic file name
                gn = fn.replace(lower, "yy")
                # with path
                gp = os.path.join(outp, gn)
                out_file = open(gp, "a", newline="\n")
                if os.path.getsize(gp) == 0:
                    print_LL_header(out_file, gn)
                # Amend full LL header file
                full_ll_list.append(gn)
                # Amend file name under serie switch
                out_file.write("#ifdef STM32" + serie + "xx\n")
                out_file.write('  #include "' + fn + '"\n')
                out_file.write("#endif\n")
                out_file.close()
            if log:
                print("done")

    # Filter full LL header file
    full_ll_file = open(os.path.join(LLoutInc_path, all_LL_file), "w", newline="\n")
    print_LL_header(full_ll_file, all_LL_file)
    full_ll_file.write("/* Include Low Layers drivers */\n")
    full_ll_list = sorted(set(full_ll_list))
    for hn in full_ll_list:
        full_ll_file.write('#include "' + hn + '"\n')
    full_ll_file.close()

    # Search all LL header files to end guard
    filelist = glob.glob(os.path.join(LLoutInc_path, "stm32yyxx_ll*.h"))
    for fp in filelist:
        out_file = open(fp, "a", newline="\n")
        upper = os.path.basename(fp).upper().replace(".", "_")
        out_file.write("#pragma GCC diagnostic pop\n")
        out_file.write("#endif /* _" + upper + "_ */\n")
        out_file.close()

    # CMSIS startup files
    printCMSISStartup(log)

    # CMSIS DSP C source file
    if not os.path.isdir(CMSIS_path):
        print("Could not find " + CMSIS_path)
        print("CMSIS DSP generation skipped.")
    else:
        # Delete all subfolders
        deleteFolder(os.path.join(CMSIS_DSP_outSrc_path, "*"))
        dirlist = []
        for root, dirs, files in os.walk(CMSIS_DSPSrc_path):
            for file in files:
                if file.endswith(".c"):
                    dirlist.append(root.replace(CMSIS_DSPSrc_path, "")[1:])
        dirlist = sorted(set(dirlist))
        for dn in dirlist:
            fdn = os.path.join(CMSIS_DSP_outSrc_path, dn)
            if not os.path.isdir(fdn):
                createFolder(fdn)
                out_file = open(os.path.join(fdn, dn + ".c"), "w", newline="\n")
                out_file.write('#include "../Source/{0}/{0}.c"\n'.format(dn))
                out_file.close()
    return 0