From 772ece542c6075a03cabaa347a637482c20c207c Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 20 Jun 2018 00:58:22 +0300 Subject: [PATCH] Move "bare-metal" flags to a separate file --- builder/frameworks/_bare.py | 69 ++++++++++++++++++++++++ builder/frameworks/arduino/mxchip.py | 4 +- builder/frameworks/arduino/stm32duino.py | 2 + builder/frameworks/cmsis.py | 2 + builder/frameworks/libopencm3 | 2 +- builder/frameworks/spl.py | 5 +- builder/frameworks/stm32cube.py | 6 ++- builder/main.py | 48 ++--------------- 8 files changed, 88 insertions(+), 50 deletions(-) create mode 100644 builder/frameworks/_bare.py diff --git a/builder/frameworks/_bare.py b/builder/frameworks/_bare.py new file mode 100644 index 00000000..8e70f0f1 --- /dev/null +++ b/builder/frameworks/_bare.py @@ -0,0 +1,69 @@ +# Copyright 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# Default flags for bare-metal programming (without any framework layers) +# + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() + +env.Append( + ASFLAGS=["-x", "assembler-with-cpp"], + + CCFLAGS=[ + "-Os", # optimize for size + "-ffunction-sections", # place each function in its own section + "-fdata-sections", + "-Wall", + "-mthumb", + "-nostdlib" + ], + + CXXFLAGS=[ + "-fno-rtti", + "-fno-exceptions" + ], + + CPPDEFINES=[ + ("F_CPU", "$BOARD_F_CPU") + ], + + LINKFLAGS=[ + "-Os", + "-Wl,--gc-sections,--relax", + "-mthumb", + "-nostartfiles", + "-nostdlib" + ], + + LIBS=["c", "gcc", "m", "stdc++", "nosys"] +) + +if "BOARD" in env: + env.Append( + CCFLAGS=[ + "-mcpu=%s" % env.BoardConfig().get("build.cpu") + ], + CPPDEFINES=[ + env.BoardConfig().get("build.variant", "").upper() + ], + LINKFLAGS=[ + "-mcpu=%s" % env.BoardConfig().get("build.cpu") + ] + ) + +# copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode) +env.Append(ASFLAGS=env.get("CCFLAGS", [])[:]) diff --git a/builder/frameworks/arduino/mxchip.py b/builder/frameworks/arduino/mxchip.py index 576fcf58..fc2bc8b6 100644 --- a/builder/frameworks/arduino/mxchip.py +++ b/builder/frameworks/arduino/mxchip.py @@ -30,6 +30,8 @@ platform = env.PioPlatform() board = env.BoardConfig() +env.SConscript("../_bare.py") + FRAMEWORK_DIR = platform.get_package_dir("framework-arduinostm32mxchip") FRAMEWORK_VERSION = platform.get_package_version( "framework-arduinostm32mxchip") @@ -145,7 +147,7 @@ ]) env.Append(CPPPATH=inc_dirs) - + env.Replace( LIBS=["az_iot", "m", "wlan", "wifi", "libstsafe", "mbed-os", "stdc++", "gcc"], diff --git a/builder/frameworks/arduino/stm32duino.py b/builder/frameworks/arduino/stm32duino.py index 6317c4ad..7034b789 100644 --- a/builder/frameworks/arduino/stm32duino.py +++ b/builder/frameworks/arduino/stm32duino.py @@ -26,6 +26,8 @@ env = DefaultEnvironment() +env.SConscript("../_bare.py") + if "stm32f1" in env.BoardConfig().get("build.variant"): env.SConscript("maple/stm32f1.py") elif "stm32f4" in env.BoardConfig().get("build.variant"): diff --git a/builder/frameworks/cmsis.py b/builder/frameworks/cmsis.py index e81b0f11..fa0ad76f 100644 --- a/builder/frameworks/cmsis.py +++ b/builder/frameworks/cmsis.py @@ -33,6 +33,8 @@ env = DefaultEnvironment() platform = env.PioPlatform() +env.SConscript("_bare.py") + FRAMEWORK_DIR = platform.get_package_dir("framework-cmsis") assert isdir(FRAMEWORK_DIR) diff --git a/builder/frameworks/libopencm3 b/builder/frameworks/libopencm3 index d848e6f4..5ae4c353 160000 --- a/builder/frameworks/libopencm3 +++ b/builder/frameworks/libopencm3 @@ -1 +1 @@ -Subproject commit d848e6f4ebde1c7d3770e472d30407519652fa3a +Subproject commit 5ae4c3536a2596b967538ab859beb1e49309ccdf diff --git a/builder/frameworks/spl.py b/builder/frameworks/spl.py index 989341b5..51b478c9 100644 --- a/builder/frameworks/spl.py +++ b/builder/frameworks/spl.py @@ -31,9 +31,12 @@ env = DefaultEnvironment() platform = env.PioPlatform() +env.SConscript("_bare.py") + FRAMEWORK_DIR = platform.get_package_dir("framework-spl") assert isdir(FRAMEWORK_DIR) + def get_linker_script(mcu): ldscript = join(FRAMEWORK_DIR, "platformio", "ldscripts", mcu[0:11].upper() + "_FLASH.ld") @@ -58,7 +61,7 @@ def get_linker_script(mcu): with open(template_file) as fp: data = Template(fp.read()) content = data.substitute( - stack=hex(0x20000000 + ram), # 0x20000000 - start address for RAM + stack=hex(0x20000000 + ram), # 0x20000000 - start address for RAM ram=str(int(ram/1024)) + "K", flash=str(int(flash/1024)) + "K" ) diff --git a/builder/frameworks/stm32cube.py b/builder/frameworks/stm32cube.py index a7560e65..11988386 100644 --- a/builder/frameworks/stm32cube.py +++ b/builder/frameworks/stm32cube.py @@ -33,6 +33,8 @@ env = DefaultEnvironment() platform = env.PioPlatform() +env.SConscript("_bare.py") + FRAMEWORK_DIR = platform.get_package_dir("framework-stm32cube") assert isdir(FRAMEWORK_DIR) @@ -105,7 +107,7 @@ def get_linker_script(mcu): with open(template_file) as fp: data = Template(fp.read()) content = data.substitute( - stack=hex(0x20000000 + ram), # 0x20000000 - start address for RAM + stack=hex(0x20000000 + ram), # 0x20000000 - start address for RAM ram=str(int(ram/1024)) + "K", flash=str(int(flash/1024)) + "K" ) @@ -135,7 +137,7 @@ def generate_hal_config_file(mcu): env.Replace( AS="$CC", ASCOM="$ASPPCOM", LDSCRIPT_PATH=get_linker_script(env.BoardConfig().get("build.mcu")), - CPPDEFINES=["USE_HAL_DRIVER"], + CPPDEFINES=["USE_HAL_DRIVER"], LINKFLAGS=[ "-Os", "-Wl,--gc-sections,--relax", diff --git a/builder/main.py b/builder/main.py index 2c941164..a4e852ea 100644 --- a/builder/main.py +++ b/builder/main.py @@ -34,36 +34,6 @@ ARFLAGS=["rc"], - ASFLAGS=["-x", "assembler-with-cpp"], - - CCFLAGS=[ - "-Os", # optimize for size - "-ffunction-sections", # place each function in its own section - "-fdata-sections", - "-Wall", - "-mthumb", - "-nostdlib" - ], - - CXXFLAGS=[ - "-fno-rtti", - "-fno-exceptions" - ], - - CPPDEFINES=[ - ("F_CPU", "$BOARD_F_CPU") - ], - - LINKFLAGS=[ - "-Os", - "-Wl,--gc-sections,--relax", - "-mthumb", - "-nostartfiles", - "-nostdlib" - ], - - LIBS=["c", "gcc", "m", "stdc++", "nosys"], - SIZEPROGREGEXP=r"^(?:\.text|\.data|\.rodata|\.text.align|\.ARM.exidx)\s+(\d+).*", SIZEDATAREGEXP=r"^(?:\.data|\.bss|\.noinit)\s+(\d+).*", SIZECHECKCMD="$SIZETOOL -A -d $SOURCES", @@ -76,22 +46,7 @@ if env.get("PROGNAME", "program") == "program": env.Replace(PROGNAME="firmware") -if "BOARD" in env: - env.Append( - CCFLAGS=[ - "-mcpu=%s" % env.BoardConfig().get("build.cpu") - ], - CPPDEFINES=[ - env.BoardConfig().get("build.variant", "").upper() - ], - LINKFLAGS=[ - "-mcpu=%s" % env.BoardConfig().get("build.cpu") - ] - ) - env.Append( - ASFLAGS=env.get("CCFLAGS", [])[:], - BUILDERS=dict( ElfToBin=Builder( action=env.VerboseAction(" ".join([ @@ -118,6 +73,9 @@ ) ) +if not env.get("PIOFRAMEWORK"): + env.SConscript("frameworks/_bare.py") + # # Target: Build executable and linkable firmware #