Merge branch 'bugfix-2.0.x' into CrealityDwin2.0_Bleeding

This commit is contained in:
InsanityAutomation
2021-04-03 12:43:14 -04:00
872 changed files with 25867 additions and 12110 deletions
@@ -0,0 +1,19 @@
#
# SAMD51_grandcentral_m4.py
# Customizations for env:SAMD51_grandcentral_m4
#
from os.path import join, isfile
import shutil
from pprint import pprint
Import("env")
mf = env["MARLIN_FEATURES"]
rxBuf = mf["RX_BUFFER_SIZE"] if "RX_BUFFER_SIZE" in mf else "0"
txBuf = mf["TX_BUFFER_SIZE"] if "TX_BUFFER_SIZE" in mf else "0"
serialBuf = str(max(int(rxBuf), int(txBuf), 350))
build_flags = env.get('BUILD_FLAGS')
build_flags.append("-DSERIAL_BUFFER_SIZE=" + serialBuf)
env.Replace(BUILD_FLAGS=build_flags)
@@ -1,3 +1,6 @@
#
# STM32F103RC_MEEB_3DP.py
#
try:
import configparser
except ImportError:
@@ -1,3 +1,6 @@
#
# STM32F103RC_SKR_MINI.py
#
import os
Import("env")
@@ -1,3 +1,6 @@
#
# STM32F103RC_fysetc.py
#
import os
from os.path import join
from os.path import expandvars
@@ -1,3 +1,6 @@
#
# STM32F103RET6_creality.py
#
import os
Import("env")
@@ -1,3 +1,6 @@
#
# STM32F103RE_SKR_E3_DIP.py
#
import os
Import("env")
@@ -1,3 +1,7 @@
#
# STM32F103VE_longer.py
# Customizations for env:STM32F103VE_longer
#
import os
Import("env")
@@ -14,7 +18,6 @@ for i, flag in enumerate(env["LINKFLAGS"]):
elif flag == "-T":
env["LINKFLAGS"][i + 1] = custom_ld_script
# Rename ${PROGNAME}.bin and save it as 'project.bin' (No encryption on the Longer3D)
def encrypt(source, target, env):
firmware = open(target[0].path, "rb")
@@ -1,3 +1,6 @@
#
# STM32F1_create_variant.py
#
import os,shutil
from SCons.Script import DefaultEnvironment
from platformio import util
@@ -17,12 +20,14 @@ board = env.BoardConfig()
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoststm32-maple")
assert os.path.isdir(FRAMEWORK_DIR)
assert os.path.isdir("buildroot/share/PlatformIO/variants")
source_root = os.path.join("buildroot", "share", "PlatformIO", "variants")
assert os.path.isdir(source_root)
variant = board.get("build.variant")
variant_dir = os.path.join(FRAMEWORK_DIR, "STM32F1", "variants", variant)
source_dir = os.path.join("buildroot/share/PlatformIO/variants", variant)
source_dir = os.path.join(source_root, variant)
assert os.path.isdir(source_dir)
if os.path.isdir(variant_dir):
@@ -1,3 +1,7 @@
#
# STM32F401VE_STEVAL.py
# Customizations for env:STM32F401VE_STEVAL
#
import os
Import("env")
@@ -1,2 +1,5 @@
#
# add_nanolib.py
#
Import("env")
env.Append(LINKFLAGS=["--specs=nano.specs"])
@@ -1,8 +1,9 @@
#
# chitu_crypt.py
# Customizations for Chitu boards
#
Import("env")
import os
import random
import struct
import uuid
import os,random,struct,uuid
# Relocate firmware from 0x08000000 to 0x08008800
env['CPPDEFINES'].remove(("VECT_TAB_ADDR", "0x8000000"))
@@ -11,15 +11,27 @@ env.Append(CXXFLAGS=[
#"-Wno-sign-compare"
])
#
# Add CPU frequency as a compile time constant instead of a runtime variable
#
def add_cpu_freq():
if 'BOARD_F_CPU' in env:
env['BUILD_FLAGS'].append('-DBOARD_F_CPU=' + env['BOARD_F_CPU'])
# Useful for JTAG debugging
#
# It will separe release and debug build folders.
# It useful when we need keep two live versions: one debug, for debugging,
# other release, for flashing.
# Without this, PIO will recompile everything twice for any small change.
#
if env.GetBuildType() == "debug":
# It will separate release and debug build folders.
# It useful to keep two live versions: a debug version for debugging and another for
# release, for flashing when upload is not done automatically by jlink/stlink.
# Without this, PIO needs to recompile everything twice for any small change.
if env.GetBuildType() == "debug" and env.get('UPLOAD_PROTOCOL') not in ['jlink', 'stlink']:
env['BUILD_DIR'] = '$PROJECT_BUILD_DIR/$PIOENV/debug'
env_name = str(env["PIOENV"])
env.Replace(PROGNAME="%s_DW7.2" % (env_name))
env.Replace(PROGNAME="%s_DW7.3" % (env_name))
print("Environment: %s" % (env_name))
# On some platform, F_CPU is a runtime variable. Since it's used to convert from ns
# to CPU cycles, this adds overhead preventing small delay (in the order of less than
# 30 cycles) to be generated correctly. By using a compile time constant instead
# the compiler will perform the computation and this overhead will be avoided
add_cpu_freq()
@@ -26,8 +26,6 @@
* Used by common-dependencies.py
*/
#define NUM_SERIAL 1 // Normally provided by HAL/HAL.h
#include "../../../../Marlin/src/inc/MarlinConfig.h"
//
@@ -69,9 +67,6 @@
#if ENABLED(CANCEL_OBJECTS)
#define HAS_MENU_CANCELOBJECT
#endif
#if ENABLED(CUSTOM_USER_MENUS)
#define HAS_MENU_CUSTOM
#endif
#if EITHER(DELTA_CALIBRATION_MENU, DELTA_AUTO_CALIBRATION)
#define HAS_MENU_DELTA_CALIBRATE
#endif
@@ -2,19 +2,7 @@
# common-dependencies.py
# Convenience script to check dependencies and add libs and sources for Marlin Enabled Features
#
import subprocess
import os
import re
try:
import configparser
except ImportError:
import ConfigParser as configparser
try:
# PIO < 4.4
from platformio.managers.package import PackageManager
except ImportError:
# PIO >= 4.4
from platformio.package.meta import PackageSpec as PackageManager
import subprocess,os,re
PIO_VERSION_MIN = (5, 0, 3)
try:
@@ -40,6 +28,9 @@ except SystemExit:
except:
print("Can't detect PlatformIO Version")
from platformio.package.meta import PackageSpec
from platformio.project.config import ProjectConfig
Import("env")
#print(env.Dump())
@@ -53,13 +44,6 @@ def blab(str):
if verbose:
print(str)
def parse_pkg_uri(spec):
if PackageManager.__name__ == 'PackageSpec':
return PackageManager(spec).name
else:
name, _, _ = PackageManager.parse_pkg_uri(spec)
return name
FEATURE_CONFIG = {}
def add_to_feat_cnf(feature, flines):
@@ -88,9 +72,7 @@ def add_to_feat_cnf(feature, flines):
feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep]
def load_config():
config = configparser.ConfigParser()
config.read("platformio.ini")
items = config.items('features')
items = ProjectConfig().items('features')
for key in items:
feature = key[0].upper()
if not feature in FEATURE_CONFIG:
@@ -116,16 +98,14 @@ def get_all_known_libs():
if not 'lib_deps' in feat:
continue
for dep in feat['lib_deps']:
name = parse_pkg_uri(dep)
known_libs.append(name)
known_libs.append(PackageSpec(dep).name)
return known_libs
def get_all_env_libs():
env_libs = []
lib_deps = env.GetProjectOption('lib_deps')
for dep in lib_deps:
name = parse_pkg_uri(dep)
env_libs.append(name)
env_libs.append(PackageSpec(dep).name)
return env_libs
def set_env_field(field, value):
@@ -156,20 +136,19 @@ def apply_features_config():
# feat to add
deps_to_add = {}
for dep in feat['lib_deps']:
name = parse_pkg_uri(dep)
deps_to_add[name] = dep
deps_to_add[PackageSpec(dep).name] = dep
# Does the env already have the dependency?
deps = env.GetProjectOption('lib_deps')
for dep in deps:
name = parse_pkg_uri(dep)
name = PackageSpec(dep).name
if name in deps_to_add:
del deps_to_add[name]
# Are there any libraries that should be ignored?
lib_ignore = env.GetProjectOption('lib_ignore')
for dep in deps:
name = parse_pkg_uri(dep)
name = PackageSpec(dep).name
if name in deps_to_add:
del deps_to_add[name]
@@ -312,16 +291,6 @@ def MarlinFeatureIsEnabled(env, feature):
return some_on
#
# Check for Configfiles in two common incorrect places
#
def check_configfile_locations():
for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
for f in [ "Configuration.h", "Configuration_adv.h" ]:
if os.path.isfile(os.path.join(p, f)):
err = 'ERROR: Config files found in directory ' + str(p) + '. Please move them into the Marlin subdirectory.'
raise SystemExit(err)
#
# Add a method for other PIO scripts to query enabled features
#
@@ -330,6 +299,5 @@ env.AddMethod(MarlinFeatureIsEnabled)
#
# Add dependencies for enabled Marlin features
#
check_configfile_locations()
apply_features_config()
force_ignore_unused_libs()
@@ -1,19 +1,10 @@
#
# copy_marlin_variant_to_framework.py
#
import os,shutil
from SCons.Script import DefaultEnvironment
from platformio import util
try:
# PIO < 4.4
from platformio.managers.package import PackageManager
except ImportError:
# PIO >= 4.4
from platformio.package.meta import PackageSpec as PackageManager
def parse_pkg_uri(spec):
if PackageManager.__name__ == 'PackageSpec':
return PackageManager(spec).name
else:
name, _, _ = PackageManager.parse_pkg_uri(spec)
return name
from platformio.package.meta import PackageSpec
def copytree(src, dst, symlinks=False, ignore=None):
for item in os.listdir(src):
@@ -38,7 +29,7 @@ framewords = {
if len(platform_packages) == 0:
platform_name = framewords[platform.__class__.__name__]
else:
platform_name = parse_pkg_uri(platform_packages[0])
platform_name = PackageSpec(platform_packages[0]).name
FRAMEWORK_DIR = platform.get_package_dir(platform_name)
assert os.path.isdir(FRAMEWORK_DIR)
@@ -1,9 +1,8 @@
#
# download_mks_assets.py
#
Import("env")
import os
import requests
import zipfile
import tempfile
import shutil
import os,requests,zipfile,tempfile,shutil
url = "https://github.com/makerbase-mks/Mks-Robin-Nano-Marlin2.0-Firmware/archive/master.zip"
zip_path = os.path.join(env.Dictionary("PROJECT_LIBDEPS_DIR"), "mks-assets.zip")
+104
View File
@@ -0,0 +1,104 @@
/* *****************************************************************************
* The MIT License
*
* Copyright (c) 2010 Perry Hung.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* ****************************************************************************/
# On an exception, push a fake stack thread mode stack frame and redirect
# thread execution to a thread mode error handler
# From RM008:
# The SP is decremented by eight words by the completion of the stack push.
# Figure 5-1 shows the contents of the stack after an exception pre-empts the
# current program flow.
#
# Old SP--> <previous>
# xPSR
# PC
# LR
# r12
# r3
# r2
# r1
# SP--> r0
.text
.globl __exc_nmi
.weak __exc_nmi
.globl __exc_hardfault
.weak __exc_hardfault
.globl __exc_memmanage
.weak __exc_memmanage
.globl __exc_busfault
.weak __exc_busfault
.globl __exc_usagefault
.weak __exc_usagefault
.code 16
.thumb_func
__exc_nmi:
mov r0, #1
b __default_exc
.thumb_func
__exc_hardfault:
mov r0, #2
b __default_exc
.thumb_func
__exc_memmanage:
mov r0, #3
b __default_exc
.thumb_func
__exc_busfault:
mov r0, #4
b __default_exc
.thumb_func
__exc_usagefault:
mov r0, #5
b __default_exc
.thumb_func
__default_exc:
ldr r2, NVIC_CCR @ Enable returning to thread mode even if there are
mov r1 ,#1 @ pending exceptions. See flag NONEBASETHRDENA.
str r1, [r2]
cpsid i @ Disable global interrupts
ldr r2, SYSTICK_CSR @ Disable systick handler
mov r1, #0
str r1, [r2]
ldr r1, CPSR_MASK @ Set default CPSR
push {r1}
ldr r1, TARGET_PC @ Set target pc
push {r1}
sub sp, sp, #24 @ Don't care
ldr r1, EXC_RETURN @ Return to thread mode
mov lr, r1
bx lr @ Exception exit
.align 4
CPSR_MASK: .word 0x61000000
EXC_RETURN: .word 0xFFFFFFF9
TARGET_PC: .word __error
NVIC_CCR: .word 0xE000ED14 @ NVIC configuration control register
SYSTICK_CSR: .word 0xE000E010 @ Systick control register
@@ -0,0 +1,44 @@
#
# fix_framework_weakness.py
#
from os.path import join, isfile
import shutil
from pprint import pprint
Import("env")
if env.MarlinFeatureIsEnabled("POSTMORTEM_DEBUGGING"):
FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple")
patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done")
# patch file only if we didn't do it before
if not isfile(patchflag_path):
print("Patching libmaple exception handlers")
original_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S")
backup_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S.bak")
src_file = join("buildroot", "share", "PlatformIO", "scripts", "exc.S")
assert isfile(original_file) and isfile(src_file)
shutil.copyfile(original_file, backup_file)
shutil.copyfile(src_file, original_file);
def _touch(path):
with open(path, "w") as fp:
fp.write("")
env.Execute(lambda *args, **kwargs: _touch(patchflag_path))
print("Done patching exception handler")
print("Libmaple modified and ready for post mortem debugging")
mf = env["MARLIN_FEATURES"]
rxBuf = mf["RX_BUFFER_SIZE"] if "RX_BUFFER_SIZE" in mf else "0"
txBuf = mf["TX_BUFFER_SIZE"] if "TX_BUFFER_SIZE" in mf else "0"
if int(rxBuf) < 64:
rxBuf = "64"
if int(txBuf) < 64:
txBuf = "64"
build_flags = env.get('BUILD_FLAGS')
build_flags.append("-DUSART_RX_BUF_SIZE=" + rxBuf + " -DUSART_TX_BUF_SIZE=" + txBuf)
env.Replace(BUILD_FLAGS=build_flags)
@@ -1,3 +1,7 @@
#
# fly_mini.py
# Customizations for env:FLY_MINI
#
import os
Import("env")
@@ -1,3 +1,7 @@
#
# STM32F401VE_STEVAL.py
# Customizations for env:STM32F401VE_STEVAL
#
import os
Import("env")
@@ -1,3 +1,7 @@
#
# lerdge.py
# Customizations for Lerdge build environments
#
import os,sys
Import("env")
@@ -1,5 +1,6 @@
# Generate the firmware as OpenBLT needs
#
# Convert the ELF to an SREC file suitable for some bootloaders
#
import os,sys
from os.path import join
@@ -10,5 +11,5 @@ env.AddPostAction(
env.VerboseAction(" ".join([
"$OBJCOPY", "-O", "srec",
"\"$BUILD_DIR/${PROGNAME}.elf\"", "\"$BUILD_DIR/${PROGNAME}.srec\""
]), "Building " + join("$BUILD_DIR","${PROGNAME}.srec"))
]), "Building " + join("$BUILD_DIR", "${PROGNAME}.srec"))
)
@@ -0,0 +1,75 @@
#
# preflight-checks.py
# Check for common issues prior to compiling
#
import os,re,sys
Import("env")
def get_envs_for_board(board):
with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file:
if sys.platform == 'win32':
envregex = r"(?:env|win):"
elif sys.platform == 'darwin':
envregex = r"(?:env|mac|uni):"
elif sys.platform == 'linux':
envregex = r"(?:env|lin|uni):"
else:
envregex = r"(?:env):"
r = re.compile(r"if\s+MB\((.+)\)")
if board.startswith("BOARD_"):
board = board[6:]
for line in file:
mbs = r.findall(line)
if mbs and board in re.split(r",\s*", mbs[0]):
line = file.readline()
found_envs = re.match(r"\s*#include .+" + envregex, line)
if found_envs:
envlist = re.findall(envregex + r"(\w+)", line)
return [ "env:"+s for s in envlist ]
return []
def check_envs(build_env, board_envs, config):
if build_env in board_envs:
return True
ext = config.get(build_env, 'extends', default=None)
if ext:
if isinstance(ext, str):
return check_envs(ext, board_envs, config)
elif isinstance(ext, list):
for ext_env in ext:
if check_envs(ext_env, board_envs, config):
return True
return False
# Sanity checks:
if 'PIOENV' not in env:
raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO")
if 'MARLIN_FEATURES' not in env:
raise SystemExit("Error: this script should be used after common Marlin scripts")
if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
build_env = env['PIOENV']
motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
board_envs = get_envs_for_board(motherboard)
config = env.GetProjectConfig()
result = check_envs("env:"+build_env, board_envs, config)
if not result:
err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) )
raise SystemExit(err)
#
# Check for Config files in two common incorrect places
#
for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
for f in [ "Configuration.h", "Configuration_adv.h" ]:
if os.path.isfile(os.path.join(p, f)):
err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
raise SystemExit(err)
@@ -1,3 +1,7 @@
#
# random-bin.py
# Set a unique firmware name based on current date and time
#
Import("env")
from datetime import datetime
@@ -1,21 +1,34 @@
#
# stm32_bootloader.py
#
import os,sys,shutil
Import("env")
from SCons.Script import DefaultEnvironment
board = DefaultEnvironment().BoardConfig()
#
# Copy the firmware.bin file to build.firmware, no encryption
#
def noencrypt(source, target, env):
firmware = os.path.join(target[0].dir.path, board.get("build.firmware"))
shutil.copy(target[0].path, firmware)
#
# For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
#
if 'offset' in board.get("build").keys():
LD_FLASH_OFFSET = board.get("build.offset")
# Remove an existing VECT_TAB_OFFSET from CPPDEFINES
for define in env['CPPDEFINES']:
if define[0] == "VECT_TAB_OFFSET":
env['CPPDEFINES'].remove(define)
# Replace VECT_TAB_OFFSET with our LD_FLASH_OFFSET
env['CPPDEFINES'].append(("VECT_TAB_OFFSET", LD_FLASH_OFFSET))
# Get upload.maximum_ram_size (defined by /buildroot/share/PlatformIO/boards/VARIOUS.json)
maximum_ram_size = board.get("upload.maximum_ram_size")
for i, flag in enumerate(env["LINKFLAGS"]):
@@ -24,7 +37,9 @@ if 'offset' in board.get("build").keys():
if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag:
env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40)
#
# Only copy the file if there's no encrypt
#
board_keys = board.get("build").keys()
# Only copy file if there's no encryptation
if 'firmware' in board_keys and not 'encrypt' in board_keys:
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", noencrypt)