Skip to content

Commit

Permalink
Move "bare-metal" flags to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Jun 19, 2018
1 parent b3ec774 commit 772ece5
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 50 deletions.
69 changes: 69 additions & 0 deletions builder/frameworks/_bare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2014-present PlatformIO <contact@platformio.org>
#
# 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", [])[:])
4 changes: 3 additions & 1 deletion builder/frameworks/arduino/mxchip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -145,7 +147,7 @@
])

env.Append(CPPPATH=inc_dirs)

env.Replace(
LIBS=["az_iot", "m", "wlan", "wifi", "libstsafe", "mbed-os", "stdc++", "gcc"],

Expand Down
2 changes: 2 additions & 0 deletions builder/frameworks/arduino/stm32duino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
2 changes: 2 additions & 0 deletions builder/frameworks/cmsis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion builder/frameworks/libopencm3
Submodule libopencm3 updated 1 files
+2 −1 libopencm3.py
5 changes: 4 additions & 1 deletion builder/frameworks/spl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
)
Expand Down
6 changes: 4 additions & 2 deletions builder/frameworks/stm32cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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",
Expand Down
48 changes: 3 additions & 45 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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([
Expand All @@ -118,6 +73,9 @@
)
)

if not env.get("PIOFRAMEWORK"):
env.SConscript("frameworks/_bare.py")

#
# Target: Build executable and linkable firmware
#
Expand Down

0 comments on commit 772ece5

Please sign in to comment.