Пример #1
0
def main():
    global stm32_list
    # check config have to be done first
    checkConfig()
    updateCoreRepo()
    stm32_list = genSTM32List(hal_dest_path, upargs.serie)
    updateSTRepo()

    if upargs.check:
        printVersion()
    else:
        updateCore()
Пример #2
0
def main():
    global stm32_list
    # check config have to be done first
    checkConfig()
    updateCoreRepo()
    stm32_list = genSTM32List(hal_dest_path, upargs.serie)
    if upargs.add:
        if upargs.add.upper() not in stm32_list:
            stm32_list = [upargs.add.upper()]
        else:
            print(upargs.add + " can't be added as it already exists!")
            exit(1)
    updateSTRepo()
    if upargs.check:
        printVersion()
    else:
        updateCore()
Пример #3
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
Пример #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 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