Просмотр исходного кода

🔨 Simplify generic variants, update DFU tool (#27502)

Scott Lahteine 4 месяцев назад
Родитель
Сommit
08717d3f60

+ 1 - 1
buildroot/share/PlatformIO/boards/marlin_CREALITY_STM32F401RE.json → buildroot/share/PlatformIO/boards/marlin_STM32F401RE_creality.json

@@ -16,7 +16,7 @@
     ],
     "ldscript": "ldscript.ld",
     "mcu": "stm32f401ret6",
-    "variant": "MARLIN_CREALITY_STM32F401RE"
+    "variant": "MARLIN_F401RE_CREALITY"
   },
   "debug": {
     "jlink_device": "STM32F401RE",

+ 1 - 1
buildroot/share/PlatformIO/boards/marlin_STM32F401RE_freeruns.json

@@ -16,7 +16,7 @@
     ],
     "ldscript": "ldscript.ld",
     "mcu": "stm32f401ret6",
-    "variant": "MARLIN_STM32F401RE_FREERUNS"
+    "variant": "MARLIN_F401RE_FREERUNS"
   },
   "debug": {
     "jlink_device": "STM32F401RE",

+ 27 - 14
buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py

@@ -3,28 +3,41 @@
 #
 import pioutil
 if pioutil.is_pio_build():
-    import shutil, marlin
     from pathlib import Path
-    env = pioutil.env
-    platform = env.PioPlatform()
-    board = env.BoardConfig()
-
-    FRAMEWORK_DIR = Path(platform.get_package_dir("framework-arduinoststm32-maple"))
-    assert FRAMEWORK_DIR.is_dir()
 
-    source_root = Path("buildroot/share/PlatformIO/variants")
+    source_root_str = "buildroot/share/PlatformIO/variants"
+    source_root = Path(source_root_str)
     assert source_root.is_dir()
 
+    env = pioutil.env
+    board = env.BoardConfig()
     variant = board.get("build.variant")
-    variant_dir = FRAMEWORK_DIR / "STM32F1/variants" / variant
 
     source_dir = source_root / variant
     assert source_dir.is_dir()
 
-    if variant_dir.is_dir():
-        shutil.rmtree(variant_dir)
+    if True:
+        # Copying to the platform folder is still needed by STM32F1 (Maple).
+        # The alternative code below comes close. See if you can solve it!
+        platform = env.PioPlatform()
+        FRAMEWORK_DIR = Path(platform.get_package_dir("framework-arduinoststm32-maple"))
+        assert FRAMEWORK_DIR.is_dir()
+
+        variant_dir = FRAMEWORK_DIR / "STM32F1/variants" / variant
+
+        if variant_dir.is_dir():
+            import shutil
+            shutil.rmtree(variant_dir)
+
+        if not variant_dir.is_dir():
+            variant_dir.mkdir()
+
+        import marlin
+        marlin.copytree(source_dir, variant_dir)
 
-    if not variant_dir.is_dir():
-        variant_dir.mkdir()
+    else:
 
-    marlin.copytree(source_dir, variant_dir)
+        # The following almost works, but __start__ (from wirish/start.S) is not seen by common.inc
+        board.update("build.variants_dir", source_root_str);
+        src = str(source_dir)
+        env.Append(BUILD_FLAGS=[f"-I{src}", f"-L{src}/ld"])  # Add include path for variant

+ 61 - 63
buildroot/share/PlatformIO/scripts/common-dependencies.py

@@ -188,77 +188,75 @@ if pioutil.is_pio_build():
                 set_env_field('lib_ignore', lib_ignore)
 
         build_src_filter = ""
-        if True:
-            # Build the actual equivalent build_src_filter list based on the inclusions by the features.
-            # PlatformIO doesn't do it this way, but maybe in the future....
-            cur_srcs = set()
-            # Remove the references to the same folder
-            my_srcs = re.findall(r'([+-]<.*?>)', build_filters)
-            for d in my_srcs:
-                # Assume normalized relative paths
-                plain = d[2:-1]
-                if d[0] == '+':
-                    def addentry(fullpath, info=None):
-                        relp = os.path.relpath(fullpath, marlinbasedir)
-                        if srcfilepattern.match(relp):
-                            if info:
-                                blab("Added src file %s (%s)" % (relp, str(info)), 3)
-                            else:
-                                blab("Added src file %s " % relp, 3)
-                            cur_srcs.add(relp)
-                    # Special rule: If a direct folder is specified add all files within.
-                    fullplain = os.path.join(marlinbasedir, plain)
-                    if os.path.isdir(fullplain):
-                        blab("Directory content addition for %s " % plain, 3)
-                        gpattern = os.path.join(fullplain, "**")
-                        for fname in glob.glob(gpattern, recursive=True):
-                            addentry(fname, "dca")
-                    else:
-                        # Add all the things from the pattern by GLOB.
-                        def srepl(matchi):
-                            g0 = matchi.group(0)
-                            return r"**" + g0[1:]
-                        gpattern = re.sub(r'[*]($|[^*])', srepl, plain)
-                        gpattern = os.path.join(marlinbasedir, gpattern)
-
-                        for fname in glob.glob(gpattern, recursive=True):
-                            addentry(fname)
-                else:
-                    # Special rule: If a direct folder is specified then remove all files within.
-                    def onremove(relp, info=None):
+
+        # Build the actual equivalent build_src_filter list based on the inclusions by the features.
+        # PlatformIO doesn't do it this way, but maybe in the future....
+        cur_srcs = set()
+        # Remove the references to the same folder
+        my_srcs = re.findall(r'([+-]<.*?>)', build_filters)
+        for d in my_srcs:
+            # Assume normalized relative paths
+            plain = d[2:-1]
+            if d[0] == '+':
+                def addentry(fullpath, info=None):
+                    relp = os.path.relpath(fullpath, marlinbasedir)
+                    if srcfilepattern.match(relp):
                         if info:
-                            blab("Removed src file %s (%s)" % (relp, str(info)), 3)
+                            blab("Added src file %s (%s)" % (relp, str(info)), 3)
                         else:
-                            blab("Removed src file %s " % relp, 3)
-                    fullplain = os.path.join(marlinbasedir, plain)
-                    if os.path.isdir(fullplain):
-                        blab("Directory content removal for %s " % plain, 2)
-                        def filt(x):
-                            common = os.path.commonpath([plain, x])
-                            if not common == os.path.normpath(plain): return True
-                            onremove(x, "dcr")
-                            return False
-                        cur_srcs = set(filter(filt, cur_srcs))
+                            blab("Added src file %s " % relp, 3)
+                        cur_srcs.add(relp)
+                # Special rule: If a direct folder is specified add all files within.
+                fullplain = os.path.join(marlinbasedir, plain)
+                if os.path.isdir(fullplain):
+                    blab("Directory content addition for %s " % plain, 3)
+                    gpattern = os.path.join(fullplain, "**")
+                    for fname in glob.glob(gpattern, recursive=True):
+                        addentry(fname, "dca")
+                else:
+                    # Add all the things from the pattern by GLOB.
+                    def srepl(matchi):
+                        g0 = matchi.group(0)
+                        return r"**" + g0[1:]
+                    gpattern = re.sub(r'[*]($|[^*])', srepl, plain)
+                    gpattern = os.path.join(marlinbasedir, gpattern)
+
+                    for fname in glob.glob(gpattern, recursive=True):
+                        addentry(fname)
+            else:
+                # Special rule: If a direct folder is specified then remove all files within.
+                def onremove(relp, info=None):
+                    if info:
+                        blab("Removed src file %s (%s)" % (relp, str(info)), 3)
                     else:
-                        # Remove matching source entries.
-                        def filt(x):
-                            if not fnmatch.fnmatch(x, plain): return True
-                            onremove(x)
-                            return False
-                        cur_srcs = set(filter(filt, cur_srcs))
-            # Transform the resulting set into a string.
-            for x in cur_srcs:
-                if build_src_filter != "": build_src_filter += ' '
-                build_src_filter += "+<" + x + ">"
-
-            #blab("Final build_src_filter: " + build_src_filter, 3)
-        else:
-            build_src_filter = build_filters
+                        blab("Removed src file %s " % relp, 3)
+                fullplain = os.path.join(marlinbasedir, plain)
+                if os.path.isdir(fullplain):
+                    blab("Directory content removal for %s " % plain, 2)
+                    def filt(x):
+                        common = os.path.commonpath([plain, x])
+                        if not common == os.path.normpath(plain): return True
+                        onremove(x, "dcr")
+                        return False
+                    cur_srcs = set(filter(filt, cur_srcs))
+                else:
+                    # Remove matching source entries.
+                    def filt(x):
+                        if not fnmatch.fnmatch(x, plain): return True
+                        onremove(x)
+                        return False
+                    cur_srcs = set(filter(filt, cur_srcs))
+        # Transform the resulting set into a string.
+        for x in cur_srcs:
+            if build_src_filter != "": build_src_filter += ' '
+            build_src_filter += "+<" + x + ">"
 
         # Update in PlatformIO
         set_env_field('build_src_filter', [build_src_filter])
         env.Replace(SRC_FILTER=build_src_filter)
 
+        #blab("Final build_src_filter: " + build_src_filter, 3)
+
     #
     # Use the compiler to get a list of all enabled features
     #

+ 7 - 16
buildroot/share/PlatformIO/scripts/generic_create_variant.py

@@ -40,26 +40,17 @@ if pioutil.is_pio_build():
     FRAMEWORK_DIR = Path(platform.get_package_dir(platform_name))
     assert FRAMEWORK_DIR.is_dir()
 
+    #
+    # Point variants_dir to our variant folder when board_build.variant
+    # is provided and the variant name begins with "marlin_".
+    #
     board = env.BoardConfig()
-
-    #mcu_type = board.get("build.mcu")[:-2]
     variant = board.get("build.variant")
+    #mcu_type = board.get("build.mcu")[:-2]
     #series = mcu_type[:7].upper() + "xx"
 
-    # Only prepare a new variant if the PlatformIO configuration provides it (board_build.variant).
-    # This check is important to avoid deleting official board config variants.
+    # Make sure the local variant sub-folder exists
     if marlin_variant_pattern.match(str(variant).lower()):
-        # Prepare a new empty folder at the destination
-        variant_dir = FRAMEWORK_DIR / "variants" / variant
-        if variant_dir.is_dir():
-            shutil.rmtree(variant_dir)
-        if not variant_dir.is_dir():
-            variant_dir.mkdir()
-
-        # Source dir is a local variant sub-folder
         source_dir = Path("buildroot/share/PlatformIO/variants", variant)
         assert source_dir.is_dir()
-
-        print("Copying variant " + str(variant) + " to framework directory...")
-
-        marlin.copytree(source_dir, variant_dir)
+        board.update("build.variants_dir", "buildroot/share/PlatformIO/variants");

+ 0 - 0
buildroot/share/PlatformIO/variants/MARLIN_CREALITY_STM32F401RC/PeripheralPins.c → buildroot/share/PlatformIO/variants/MARLIN_F401RC_CREALITY/PeripheralPins.c


+ 0 - 0
buildroot/share/PlatformIO/variants/MARLIN_CREALITY_STM32F401RC/PinNamesVar.h → buildroot/share/PlatformIO/variants/MARLIN_F401RC_CREALITY/PinNamesVar.h


+ 0 - 0
buildroot/share/PlatformIO/variants/MARLIN_CREALITY_STM32F401RC/hal_conf_custom.h → buildroot/share/PlatformIO/variants/MARLIN_F401RC_CREALITY/hal_conf_custom.h


+ 0 - 0
buildroot/share/PlatformIO/variants/MARLIN_CREALITY_STM32F401RC/ldscript.ld → buildroot/share/PlatformIO/variants/MARLIN_F401RC_CREALITY/ldscript.ld


+ 0 - 0
buildroot/share/PlatformIO/variants/MARLIN_CREALITY_STM32F401RC/variant.cpp → buildroot/share/PlatformIO/variants/MARLIN_F401RC_CREALITY/variant.cpp


Некоторые файлы не были показаны из-за большого количества измененных файлов