diff --git a/builder/frameworks/base.py b/builder/frameworks/base.py index b43dc0b..4cef734 100644 --- a/builder/frameworks/base.py +++ b/builder/frameworks/base.py @@ -3,7 +3,7 @@ from os.path import join import click -from ltchiptool import Family +from ltchiptool import Family, get_version from platformio.platform.base import PlatformBase from platformio.platform.board import PlatformBoardConfig from SCons.Errors import UserError @@ -14,6 +14,12 @@ board: PlatformBoardConfig = env.BoardConfig() platform: PlatformBase = env.PioPlatform() family: Family = env["FAMILY_OBJ"] +# Print information about installed core versions +lt_version: str = env.ReadLTVersion(platform.get_dir(), platform.version) +print("PLATFORM VERSIONS:") +print(" - libretuya @", lt_version) +print(" - ltchiptool @", get_version()) + # TODO remove include path prepending ("!<...>") # Move common core sources (env.AddCoreSources()) and Arduino libs # below per-family sources (to maintain child families taking precedence) @@ -86,6 +92,12 @@ queue.AddExternalLibrary("ltchiptool") # uf2ota source code queue.AddExternalLibrary("flashdb") queue.AddExternalLibrary("printf") +# Find optimization level and add __OPTIMIZE_LEVEL__ macro +for flag in env["CCFLAGS"]: + if not flag.startswith("-O"): + continue + env.Append(CPPDEFINES=[("__OPTIMIZE_LEVEL__", flag[2])]) + # Non-SDK defines & linker options queue.AppendPublic( CCFLAGS=[ @@ -102,13 +114,13 @@ queue.AppendPublic( ], CPPDEFINES=[ ("LIBRETUYA", 1), - ("LT_VERSION", env.ReadLTVersion(platform.get_dir(), platform.version)), + ("LT_VERSION", lt_version), ("LT_BOARD", "${VARIANT}"), ("LT_VARIANT_H", r"\"${VARIANT}.h\""), ("F_CPU", board.get("build.f_cpu")), ("MCU", "${MCU}"), ("MCULC", "${MCULC}"), - ("FAMILY", "F_${FAMILY}"), + ("FAMILY", "F_${FAMILY_SHORT_NAME}"), # Add flash layout defines created in env.AddFlashLayout() *env["FLASH_DEFINES"].items(), ], diff --git a/builder/utils/ltchiptool.py b/builder/utils/ltchiptool.py index 3af3238..dc8ac5e 100644 --- a/builder/utils/ltchiptool.py +++ b/builder/utils/ltchiptool.py @@ -26,26 +26,24 @@ def env_uf2ota(env: Environment, *args, **kwargs): project_name, project_version, "${VARIANT}", - "${FAMILY}", + "${MCULC}", f"lt{lt_version}", ] output = "_".join(output) + ".uf2" if platform.custom("fw_output"): output = platform.custom("fw_output") - output = join("${BUILD_DIR}", output) - output_copy_1 = join("${BUILD_DIR}", "firmware.uf2") - output_copy_2 = join("${BUILD_DIR}", "firmware.bin") - - env["UF2OUT"] = output - env["UF2OUT_BASE"] = basename(output) + outputs = [ + join("${BUILD_DIR}", output), + join("${BUILD_DIR}", "firmware.uf2"), + join("${BUILD_DIR}", "firmware.bin"), + ] + output_opts = [f'--output "{output}"' for output in outputs] cmd = [ "@${LTCHIPTOOL} uf2 write", - f'--output "{output}"', - f'--output-copy "{output_copy_1}"', - f'--output-copy "{output_copy_2}"', - "--family ${FAMILY}", + *output_opts, + "--family ${FAMILY_SHORT_NAME}", "--board ${VARIANT}", f"--lt-version {lt_version}", f'--fw "{project_name}:{project_version}"', @@ -53,10 +51,9 @@ def env_uf2ota(env: Environment, *args, **kwargs): *env["UF2OTA"], ] - print(f"|-- {basename(env.subst(output))}") + for output in outputs: + print(f"|-- {basename(env.subst(output))}") env.Execute(" ".join(cmd)) - print(f"|-- {basename(env.subst(output_copy_1))}") - print(f"|-- {basename(env.subst(output_copy_2))}") def env_flash_write(env: Environment): diff --git a/cores/common/base/libretuya.h b/cores/common/base/libretuya.h index f6a557e..0cf8b50 100644 --- a/cores/common/base/libretuya.h +++ b/cores/common/base/libretuya.h @@ -27,16 +27,12 @@ #define LT_BOARD_STR STRINGIFY_MACRO(LT_BOARD) #define GCC_VERSION_STR \ STRINGIFY_MACRO(__GNUC__) "." STRINGIFY_MACRO(__GNUC_MINOR__) "." STRINGIFY_MACRO(__GNUC_PATCHLEVEL__) +#define LT_BANNER_STR \ + "LibreTuya v" LT_VERSION_STR " on " LT_BOARD_STR ", compiled at " __DATE__ " " __TIME__ ", GCC " GCC_VERSION_STR \ + " (-O" STRINGIFY_MACRO(__OPTIMIZE_LEVEL__) ")" // Functional macros -#define LT_BANNER() \ - LT_LOG( \ - LT_LEVEL_INFO, \ - __FUNCTION__, \ - __LINE__, \ - "LibreTuya v" LT_VERSION_STR " on " LT_BOARD_STR ", compiled at " __DATE__ " " __TIME__ \ - ", GCC " GCC_VERSION_STR \ - ) +#define LT_BANNER() LT_LOG(LT_LEVEL_INFO, __FUNCTION__, __LINE__, LT_BANNER_STR) // Types & macros #include "lt_config.h" // platform configuration options