|
| 1 | +# Copyright 2023 Waybyte Solutions |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | +# |
| 5 | + |
| 6 | +""" |
| 7 | +Arduino |
| 8 | +
|
| 9 | +Arduino Wiring-based Framework allows writing cross-platform software to |
| 10 | +control devices attached to a wide range of Arduino boards to create all |
| 11 | +kinds of creative coding, interactive objects, spaces or physical experiences. |
| 12 | +
|
| 13 | +http://arduino.cc/en/Reference/HomePage |
| 14 | +""" |
| 15 | + |
| 16 | +from os.path import isdir, isfile, join |
| 17 | +from shutil import copyfile |
| 18 | +from asrutils import gen_release_file, gen_fota_file |
| 19 | +from platformio.util import get_systype |
| 20 | + |
| 21 | +from SCons.Script import DefaultEnvironment |
| 22 | + |
| 23 | +env = DefaultEnvironment() |
| 24 | +platform = env.PioPlatform() |
| 25 | +board = env.BoardConfig() |
| 26 | + |
| 27 | +FRAMEWORK_DIR = platform.get_package_dir("framework-logicromarduino") |
| 28 | +assert isdir(FRAMEWORK_DIR) |
| 29 | + |
| 30 | +LOGICROMSDK_DIR = join(FRAMEWORK_DIR, "cores", board.get("build.core"), "logicromsdk") |
| 31 | +assert isdir(LOGICROMSDK_DIR) |
| 32 | + |
| 33 | +# RDA Tools |
| 34 | +if "windows" in get_systype(): |
| 35 | + systype = "win32" |
| 36 | +else: |
| 37 | + systype = "linux" |
| 38 | + |
| 39 | +# Generate linker script |
| 40 | +linker_script = env.Command( |
| 41 | + join("$BUILD_DIR", "linkerscript_out.ld"), |
| 42 | + join( |
| 43 | + LOGICROMSDK_DIR, "lib", "asr160x", "app_linker.ld" |
| 44 | + ), |
| 45 | + env.VerboseAction( |
| 46 | + '$CC -I"' + join(LOGICROMSDK_DIR, "lib", "asr160x") + '" -DFLASHSZ_' + board.get("build.flashsz") + ' -P -x c -E $SOURCE -o $TARGET', |
| 47 | + "Generating LD script $TARGET", |
| 48 | + ), |
| 49 | +) |
| 50 | +env.Depends(join("$BUILD_DIR", "$PROGNAME" + "$PROGSUFFIX"), linker_script) |
| 51 | +env.Replace(LDSCRIPT_PATH="linkerscript_out.ld") |
| 52 | + |
| 53 | + |
| 54 | +def gen_zip_file(target, source, env): |
| 55 | + (target_firm, ) = target |
| 56 | + (source_elf, ) = source |
| 57 | + imagepath = join(LOGICROMSDK_DIR, "lib", "asr160x", "pack") |
| 58 | + gen_release_file(target_firm, source_elf, imagepath, env) |
| 59 | + |
| 60 | + |
| 61 | +# Setup ENV |
| 62 | +env.Append( |
| 63 | + ASFLAGS=["-x", "assembler-with-cpp"], |
| 64 | + |
| 65 | + CCFLAGS=[ |
| 66 | + "-Os", # optimize for size |
| 67 | + "-g", |
| 68 | + "-fmessage-length=0", |
| 69 | + "-ffunction-sections", # place each function in its own section |
| 70 | + "-fdata-sections", |
| 71 | + "-fsigned-char", |
| 72 | + "-fno-strict-aliasing", |
| 73 | + "-Wall", |
| 74 | + "-mthumb", |
| 75 | + "-mthumb-interwork", |
| 76 | + "-mcpu=cortex-r4", |
| 77 | + "-march=armv7-r", |
| 78 | + "-mfloat-abi=soft", |
| 79 | + "-mno-unaligned-access", |
| 80 | + ], |
| 81 | + |
| 82 | + CFLAGS=[ |
| 83 | + "-std=gnu11" |
| 84 | + ], |
| 85 | + |
| 86 | + CXXFLAGS=[ |
| 87 | + "-std=gnu++11", |
| 88 | + "-fno-rtti", |
| 89 | + "-fno-exceptions", |
| 90 | + "-fno-use-cxa-atexit", |
| 91 | + "-fno-threadsafe-statics", |
| 92 | + ], |
| 93 | + |
| 94 | + CPPDEFINES=[ |
| 95 | + ("__BUFSIZ__", "512"), |
| 96 | + ("__FILENAME_MAX__", "256"), |
| 97 | + ("F_CPU", "$BOARD_F_CPU"), |
| 98 | + ("ARDUINO", 10816), |
| 99 | + "ARDUINO_ARCH_ARM", |
| 100 | + ("ARDUINO_VARIANT", '\\"%s\\"' % board.get("build.variant").replace('"', "")), |
| 101 | + ("ARDUINO_BOARD", '\\"%s\\"' % board.get("name").replace('"', "")), |
| 102 | + ], |
| 103 | + |
| 104 | + CPPPATH=[ |
| 105 | + join(LOGICROMSDK_DIR, "include"), |
| 106 | + join(LOGICROMSDK_DIR, "include", "ril"), |
| 107 | + join(FRAMEWORK_DIR, "cores", board.get("build.core")), |
| 108 | + ], |
| 109 | + |
| 110 | + LINKFLAGS=[ |
| 111 | + "-mthumb", |
| 112 | + "-mthumb-interwork", |
| 113 | + "-mcpu=cortex-r4", |
| 114 | + "-march=armv7-r", |
| 115 | + "-mfloat-abi=soft", |
| 116 | + "-mno-unaligned-access", |
| 117 | + "-Os", |
| 118 | + "-Wl,--gc-sections,--relax", |
| 119 | + "-nostartfiles", |
| 120 | + "-nostdlib", |
| 121 | + "-nostartfiles", |
| 122 | + "-nodefaultlibs", |
| 123 | + "-u", "main", |
| 124 | + ], |
| 125 | + |
| 126 | + LIBS=["logicromasr", "c", "gcc", "m", "stdc++"], |
| 127 | + |
| 128 | + LIBPATH=[ |
| 129 | + join(LOGICROMSDK_DIR, "lib"), |
| 130 | + join(LOGICROMSDK_DIR, "lib", "asr160x"), |
| 131 | + ], |
| 132 | + |
| 133 | + LIBSOURCE_DIRS=[join(FRAMEWORK_DIR, "libraries")], |
| 134 | + |
| 135 | + BUILDERS=dict( |
| 136 | + ElfToBin=Builder( |
| 137 | + action=env.VerboseAction(gen_zip_file, "Generating $TARGET"), |
| 138 | + suffix=".zip" |
| 139 | + ), |
| 140 | + BinToFOTA=Builder( |
| 141 | + action=env.VerboseAction(gen_fota_file, "Generating FOTA firmware $TARGET"), |
| 142 | + suffix=".bin" |
| 143 | + ) |
| 144 | + ) |
| 145 | +) |
| 146 | + |
| 147 | +# copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode) |
| 148 | +env.Append(ASFLAGS=env.get("CCFLAGS", [])[:]) |
| 149 | + |
| 150 | + |
| 151 | +def load_logicrom_debug(): |
| 152 | + for i, libs in enumerate(env["LIBS"]): |
| 153 | + if libs.startswith("logicrom"): |
| 154 | + env["LIBS"][i] = libs + "_debug" |
| 155 | + |
| 156 | + |
| 157 | +if board.get("build.logicromtype") == "debug": |
| 158 | + load_logicrom_debug() |
| 159 | + |
| 160 | +if env.GetBuildType() == "debug": |
| 161 | + load_logicrom_debug() |
| 162 | + |
| 163 | +# |
| 164 | +# Target: Build Core Library |
| 165 | +# |
| 166 | + |
| 167 | +libs = [] |
| 168 | + |
| 169 | +if "build.variant" in env.BoardConfig(): |
| 170 | + env.Append( |
| 171 | + CPPPATH=[ |
| 172 | + join(FRAMEWORK_DIR, "variants", env.BoardConfig().get("build.variant")) |
| 173 | + ] |
| 174 | + ) |
| 175 | + libs.append(env.BuildLibrary( |
| 176 | + join("$BUILD_DIR", "FrameworkArduinoVariant"), |
| 177 | + join(FRAMEWORK_DIR, "variants", board.get("build.variant")) |
| 178 | + )) |
| 179 | + |
| 180 | +envsafe = env.Clone() |
| 181 | + |
| 182 | +libs.append(envsafe.BuildLibrary( |
| 183 | + join("$BUILD_DIR", "FrameworkArduino"), |
| 184 | + join(FRAMEWORK_DIR, "cores", board.get("build.core")) |
| 185 | +)) |
| 186 | + |
| 187 | +env.Prepend(LIBS=libs) |
0 commit comments