STM32F1_create_variant.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #
  2. # STM32F1_create_variant.py
  3. #
  4. import pioutil
  5. if pioutil.is_pio_build():
  6. from pathlib import Path
  7. source_root_str = "buildroot/share/PlatformIO/variants"
  8. source_root = Path(source_root_str)
  9. assert source_root.is_dir()
  10. env = pioutil.env
  11. board = env.BoardConfig()
  12. variant = board.get("build.variant")
  13. source_dir = source_root / variant
  14. assert source_dir.is_dir()
  15. if True:
  16. # Copying to the platform folder is still needed by STM32F1 (Maple).
  17. # The alternative code below comes close. See if you can solve it!
  18. platform = env.PioPlatform()
  19. FRAMEWORK_DIR = Path(platform.get_package_dir("framework-arduinoststm32-maple"))
  20. assert FRAMEWORK_DIR.is_dir()
  21. variant_dir = FRAMEWORK_DIR / "STM32F1/variants" / variant
  22. if variant_dir.is_dir():
  23. import shutil
  24. shutil.rmtree(variant_dir)
  25. if not variant_dir.is_dir():
  26. variant_dir.mkdir()
  27. import marlin
  28. marlin.copytree(source_dir, variant_dir)
  29. else:
  30. # The following almost works, but __start__ (from wirish/start.S) is not seen by common.inc
  31. board.update("build.variants_dir", source_root_str);
  32. src = str(source_dir)
  33. env.Append(BUILD_FLAGS=[f"-I{src}", f"-L{src}/ld"]) # Add include path for variant