示例#1
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
示例#2
0
def updateCore():
    for serie in stm32_list:
        cube_name = repo_generic_name + serie
        cube_path = repo_local_path / cube_name
        core_path = repo_local_path / repo_core_name
        core_HAL_version = core_HAL_versions[serie]
        cube_HAL_version = cube_HAL_versions[serie]
        core_CMSIS_version = core_CMSIS_versions[serie]
        cube_CMSIS_version = 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_version, 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_version, cube_version, "add" if upargs.add else "update"
        )
        wrapper_commit_msg = "core: {}: {} wrapped files".format(
            serie, "add" if upargs.add else "update"
        )

        # Update HAL part if needed
        if version.parse(core_HAL_version) < version.parse(cube_HAL_version):
            if upargs.add:
                print("Adding {} HAL version {}...".format(serie, cube_HAL_version))
            else:
                print(
                    "Updating {} HAL from version {} to {}...".format(
                        serie, core_HAL_version, cube_HAL_version
                    )
                )
            # First delete old HAL version
            HAL_serie_core_path = hal_dest_path / "STM32{}xx_HAL_Driver".format(serie)
            deleteFolder(HAL_serie_core_path)
            # Copy new one
            HAL_serie_cube_path = (
                cube_path / hal_src_path / "STM32{}xx_HAL_Driver".format(serie)
            )
            copyFolder(HAL_serie_cube_path, HAL_serie_core_path, {"*.chm"})
            # Update MD file
            updateMDFile(md_HAL_path, serie, cube_HAL_version)
            # Commit all HAL files
            commitFiles(core_path, hal_commit_msg)
            HAL_updated = True

        if version.parse(core_CMSIS_version) < version.parse(cube_CMSIS_version):
            if upargs.add:
                print("Adding {} CMSIS version {}...".format(serie, cube_CMSIS_version))
            else:
                print(
                    "Updating {} CMSIS from version {} to {}...".format(
                        serie, core_CMSIS_version, cube_CMSIS_version
                    )
                )
            # First delete CMSIS folder
            CMSIS_serie_dest_path = cmsis_dest_path / "STM32{}xx".format(serie)
            deleteFolder(CMSIS_serie_dest_path)
            # Copy new one
            CMSIS_serie_cube_path = (
                cube_path / cmsis_src_path / "STM32{}xx".format(serie)
            )
            copyFolder(CMSIS_serie_cube_path, CMSIS_serie_dest_path, {"iar", "arm"})
            # Update MD file
            updateMDFile(md_CMSIS_path, serie, cube_CMSIS_version)
            # Commit all CMSIS files
            commitFiles(core_path, cmsis_commit_msg)
            CMSIS_updated = True

        if upargs.add:
            system_commit_msg = (
                "system: {0}: add STM32{0}xx system source files".format(serie)
            )
            update_hal_conf_commit_msg = (
                "system: {0}: update STM32{0}xx hal default config".format(serie)
            )
            update_stm32_def_commit_msg = "core: {0}: add top HAL include".format(serie)
            # 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(
                "\tredefinable in the stm32{}xx_hal_conf_default.h".format(
                    serie.lower()
                )
            )
            # 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(
                "{} {} wrapped files...".format(
                    "Adding" if upargs.add else "Updating", serie
                )
            )
            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)
示例#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 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
示例#4
0
def updateCore():
    for serie in stm32_list:
        cube_name = repo_generic_name + serie
        cube_path = os.path.join(repo_local_path, cube_name)
        core_path = os.path.join(repo_local_path, repo_core_name)
        core_HAL_version = core_HAL_versions[serie]
        cube_HAL_version = cube_HAL_versions[serie]
        core_CMSIS_version = core_CMSIS_versions[serie]
        cube_CMSIS_version = cube_CMSIS_versions[serie]
        cube_version = cube_versions[serie]
        regexmd = re.compile(rf"(STM32{serie}:\s+)\d+.\d+.\d+")
        HAL_updated = False
        CMSIS_updated = False
        hal_commit_msg = """[{0}] Update STM32{0}xx HAL Drivers to v{1}

Included in STM32Cube{0} FW {2}""".format(serie, cube_HAL_version,
                                          cube_version)
        cmsis_commit_msg = """[{0}] Update STM32{0}xx CMSIS Drivers to v{1}

Included in STM32Cube{0} FW {2}""".format(serie, cube_CMSIS_version,
                                          cube_version)
        wrapper_commit_msg = "[{}] Update wrapped files".format(serie)

        # Update HAL part if needed
        if version.parse(core_HAL_version) < version.parse(cube_HAL_version):
            print("Update " + serie + " HAL from version " + core_HAL_version +
                  " to " + cube_HAL_version)
            # First delete old HAL version
            HAL_serie_core_path = os.path.join(
                core_path, hal_dest_path, "STM32{}xx_HAL_Driver".format(serie))
            deleteFolder(HAL_serie_core_path)
            # Copy new one
            HAL_serie_cube_path = os.path.join(
                cube_path, hal_src_path, "STM32{}xx_HAL_Driver".format(serie))
            copyFolder(HAL_serie_cube_path, HAL_serie_core_path, {"*.chm"})
            # Update MD file
            for line in fileinput.input(md_HAL_path, inplace=True):
                line = regexmd.sub(rf"\g<1>{cube_HAL_version}", line)
                print(line, end="")
            # Commit all HAL files
            commitFiles(core_path, hal_commit_msg)
            HAL_updated = True

        if version.parse(core_CMSIS_version) < version.parse(
                cube_CMSIS_version):
            print("Update " + serie + " CMSIS from version " +
                  core_CMSIS_version + " to " + cube_CMSIS_version)
            # First delete CMSIS folder
            CMSIS_serie_dest_path = os.path.join(
                core_path, cmsis_dest_path, "STM32{}xx".format(serie.upper()))
            deleteFolder(CMSIS_serie_dest_path)
            # Copy new one
            CMSIS_serie_cube_path = os.path.join(
                cube_path, cmsis_src_path, "STM32{}xx".format(serie.upper()))
            copyFolder(CMSIS_serie_cube_path, CMSIS_serie_dest_path,
                       {"iar", "arm"})
            # Update MD file
            for line in fileinput.input(md_CMSIS_path, inplace=True):
                line = regexmd.sub(rf"\g<1>{cube_CMSIS_version}", line)
                print(line, end="")
            # Commit all CMSIS files
            commitFiles(core_path, cmsis_commit_msg)
            CMSIS_updated = True

        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("Update {} wrapped files".format(serie))
            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)