fysetc_STM32S6.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from os.path import join
  2. Import("env", "projenv")
  3. import os,shutil
  4. from SCons.Script import DefaultEnvironment
  5. from platformio import util
  6. env = DefaultEnvironment()
  7. platform = env.PioPlatform()
  8. board = env.BoardConfig()
  9. FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoststm32")
  10. #FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoststm32@3.10500.190327")
  11. CMSIS_DIR = os.path.join(FRAMEWORK_DIR, "CMSIS", "CMSIS")
  12. assert os.path.isdir(FRAMEWORK_DIR)
  13. assert os.path.isdir(CMSIS_DIR)
  14. assert os.path.isdir("buildroot/share/PlatformIO/variants")
  15. mcu_type = board.get("build.mcu")[:-2]
  16. variant = board.get("build.variant")
  17. series = mcu_type[:7].upper() + "xx"
  18. variant_dir = os.path.join(FRAMEWORK_DIR, "variants", variant)
  19. source_dir = os.path.join("buildroot/share/PlatformIO/variants", variant)
  20. assert os.path.isdir(source_dir)
  21. if not os.path.isdir(variant_dir):
  22. os.mkdir(variant_dir)
  23. for file_name in os.listdir(source_dir):
  24. full_file_name = os.path.join(source_dir, file_name)
  25. if os.path.isfile(full_file_name):
  26. shutil.copy(full_file_name, variant_dir)
  27. # Relocate firmware from 0x08000000 to 0x08002000
  28. #import marlin
  29. #marlin.relocate_firmware("0x08010000")
  30. #env.Replace(LDSCRIPT_PATH="buildroot/share/PlatformIO/ldscripts/fysetc_aio_ii.ld")
  31. # Custom HEX from ELF
  32. env.AddPostAction(
  33. "$BUILD_DIR/${PROGNAME}.elf",
  34. env.VerboseAction(" ".join([
  35. "$OBJCOPY",
  36. "-O",
  37. "ihex",
  38. "$BUILD_DIR/${PROGNAME}.elf",
  39. "$BUILD_DIR/${PROGNAME}.hex"
  40. ]), "Building $TARGET"))
  41. # In-line command with arguments
  42. env.Replace(
  43. UPLOADER=platform.get_package_dir("tool-stm32duino") + '/stm32flash/stm32flash',
  44. UPLOADCMD='"${UPLOADER}" -v -i rts,-dtr,dtr,-rts -R -b 115200 -g 0x8000000 -w "${BUILD_DIR}/${PROGNAME}.hex" ${UPLOAD_PORT}'
  45. )