From 20cef63d324af83f1ab4bc8920262a74c897fb8f Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 20 May 2021 13:05:18 -0700 Subject: [PATCH] Lua on f407, try again (#2725) * lua on f4 * move perf trace to efifeatures * check that it's defined * cypress and kinetis * it would help to define the correct thing * disable buffer if not used * we can work with 2k * turn off ramdisk on mre qc * wow strncpy is useless for truncated strings * turn off for bootloader * lto bootloader * memory * memory --- firmware/bootloader/src/Makefile | 4 ++-- firmware/config/boards/hellen/cypress/chconf.h | 4 ---- firmware/config/boards/hellen/cypress/efifeatures.h | 1 + firmware/config/boards/kinetis/chconf.h | 4 ---- firmware/config/boards/kinetis/efifeatures.h | 1 + .../compile_mre_f4_hardware_QC_special_build.sh | 2 +- firmware/config/stm32f4ems/efifeatures.h | 11 ++++++++--- firmware/config/stm32f7ems/efifeatures.h | 4 ++-- firmware/config/stm32h7ems/efifeatures.h | 4 ++-- firmware/controllers/engine_controller.cpp | 2 +- firmware/controllers/lua/lua.cpp | 3 ++- firmware/development/perf_trace.cpp | 9 +++++++++ firmware/hw_layer/ports/chconf_common.h | 5 ----- 13 files changed, 29 insertions(+), 25 deletions(-) diff --git a/firmware/bootloader/src/Makefile b/firmware/bootloader/src/Makefile index 8d6d9e5404..b36d4ca1f9 100644 --- a/firmware/bootloader/src/Makefile +++ b/firmware/bootloader/src/Makefile @@ -14,7 +14,7 @@ endif # disable some modules to shrink bootloader binary DDEFS += -DEFI_BOOTLOADER -DDEFS += -DHAL_USE_EXT=FALSE -DHAL_USE_ICU=FALSE -DHAL_USE_PWM=FALSE -DHAL_USE_RTC=FALSE +DDEFS += -DHAL_USE_EXT=FALSE -DHAL_USE_ICU=FALSE -DHAL_USE_PWM=FALSE -DHAL_USE_RTC=FALSE -DEF_LUA=FALSE #disable ChibiOS flsah driver and prevent header from include DDEFS += -DHAL_USE_FLASH=FALSE @@ -62,7 +62,7 @@ endif # Enable this if you want link time optimizations (LTO) ifeq ($(USE_LTO),) - USE_LTO = no + USE_LTO = yes endif # If enabled, this option allows to compile the application in THUMB mode. diff --git a/firmware/config/boards/hellen/cypress/chconf.h b/firmware/config/boards/hellen/cypress/chconf.h index d4c83a8b44..301537cac1 100644 --- a/firmware/config/boards/hellen/cypress/chconf.h +++ b/firmware/config/boards/hellen/cypress/chconf.h @@ -740,10 +740,6 @@ /* Port-specific settings (override port settings defaulted in chcore.h). */ /*===========================================================================*/ -#undef ENABLE_PERF_TRACE -#define ENABLE_PERF_TRACE FALSE -#define TRACE_BUFFER_LENGTH 1 - #endif /* CHCONF_H */ /** @} */ diff --git a/firmware/config/boards/hellen/cypress/efifeatures.h b/firmware/config/boards/hellen/cypress/efifeatures.h index 8c965cfd09..f1c6b02ab9 100644 --- a/firmware/config/boards/hellen/cypress/efifeatures.h +++ b/firmware/config/boards/hellen/cypress/efifeatures.h @@ -377,6 +377,7 @@ #define EFI_UART_ECHO_TEST_MODE FALSE #define EXTREME_TERM_LOGGING FALSE #define EFI_PRINTF_FUEL_DETAILS FALSE +#define ENABLE_PERF_TRACE FALSE #define RAM_UNUSED_SIZE 1 #define CCM_UNUSED_SIZE 1 diff --git a/firmware/config/boards/kinetis/chconf.h b/firmware/config/boards/kinetis/chconf.h index beb7dd8fba..5f12d029c9 100644 --- a/firmware/config/boards/kinetis/chconf.h +++ b/firmware/config/boards/kinetis/chconf.h @@ -741,10 +741,6 @@ /* Port-specific settings (override port settings defaulted in chcore.h). */ /*===========================================================================*/ -#undef ENABLE_PERF_TRACE -#define ENABLE_PERF_TRACE FALSE -#define TRACE_BUFFER_LENGTH 1 - #endif /* CHCONF_H */ /** @} */ diff --git a/firmware/config/boards/kinetis/efifeatures.h b/firmware/config/boards/kinetis/efifeatures.h index 7e19cc8ba2..a1e1d334d6 100644 --- a/firmware/config/boards/kinetis/efifeatures.h +++ b/firmware/config/boards/kinetis/efifeatures.h @@ -343,6 +343,7 @@ #define EFI_UART_ECHO_TEST_MODE FALSE #define EXTREME_TERM_LOGGING FALSE #define EFI_PRINTF_FUEL_DETAILS FALSE +#define ENABLE_PERF_TRACE FALSE #define RAM_UNUSED_SIZE 1 #define CCM_UNUSED_SIZE 1 diff --git a/firmware/config/boards/microrusefi/compile_mre_f4_hardware_QC_special_build.sh b/firmware/config/boards/microrusefi/compile_mre_f4_hardware_QC_special_build.sh index 10b9864e50..636edc6975 100644 --- a/firmware/config/boards/microrusefi/compile_mre_f4_hardware_QC_special_build.sh +++ b/firmware/config/boards/microrusefi/compile_mre_f4_hardware_QC_special_build.sh @@ -2,7 +2,7 @@ export PROJECT_BOARD=microrusefi export PROJECT_CPU=ARCH_STM32F4 -export EXTRA_PARAMS="-DHW_CHECK_MODE=TRUE -DANALOG_HW_CHECK_MODE=TRUE -DHW_CHECK_ALAWAYS_STIMULATE=TRUE -DSHORT_BOARD_NAME=mre_f4" +export EXTRA_PARAMS="-DHW_CHECK_MODE=TRUE -DANALOG_HW_CHECK_MODE=TRUE -DHW_CHECK_ALAWAYS_STIMULATE=TRUE -DSHORT_BOARD_NAME=mre_f4 -DRAMDISK_INVALID" export DEFAULT_ENGINE_TYPE=-DDEFAULT_ENGINE_TYPE=MRE_BOARD_NEW_TEST diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index f02e2e9fe5..81bd85956d 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -264,12 +264,17 @@ // F42x has more memory, so we can: // - use compressed USB MSD image (requires 32k of memory) -// - use Lua interpreter (requires ~20k of memory) +// - use perf trace (requires ~16k of memory) #ifdef EFI_IS_F42x #define EFI_USE_COMPRESSED_INI_MSD - #define EFI_LUA TRUE + #define ENABLE_PERF_TRACE TRUE #else - #define EFI_LUA FALSE + // small memory F40x can't fit perf trace + #define ENABLE_PERF_TRACE FALSE +#endif + +#ifndef EFI_LUA +#define EFI_LUA TRUE #endif #ifndef EFI_ENGINE_SNIFFER diff --git a/firmware/config/stm32f7ems/efifeatures.h b/firmware/config/stm32f7ems/efifeatures.h index b7d8540fb1..8bc8166ded 100644 --- a/firmware/config/stm32f7ems/efifeatures.h +++ b/firmware/config/stm32f7ems/efifeatures.h @@ -53,5 +53,5 @@ #define EFI_USE_COMPRESSED_INI_MSD -#undef EFI_LUA -#define EFI_LUA TRUE +#undef ENABLE_PERF_TRACE +#define ENABLE_PERF_TRACE TRUE diff --git a/firmware/config/stm32h7ems/efifeatures.h b/firmware/config/stm32h7ems/efifeatures.h index 51e423fd2b..386a9ecf3f 100644 --- a/firmware/config/stm32h7ems/efifeatures.h +++ b/firmware/config/stm32h7ems/efifeatures.h @@ -32,5 +32,5 @@ // H7 has dual bank, so flash on its own (low priority) thread so as to not block any other operations #define EFI_FLASH_WRITE_THREAD TRUE -#undef EFI_LUA -#define EFI_LUA TRUE +#undef ENABLE_PERF_TRACE +#define ENABLE_PERF_TRACE TRUE diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 701dfec136..a73fe51004 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -702,7 +702,7 @@ void initEngineContoller(DECLARE_ENGINE_PARAMETER_SUFFIX) { * UNUSED_SIZE constants. */ #ifndef RAM_UNUSED_SIZE -#define RAM_UNUSED_SIZE 5900 +#define RAM_UNUSED_SIZE 1800 #endif #ifndef CCM_UNUSED_SIZE #define CCM_UNUSED_SIZE 300 diff --git a/firmware/controllers/lua/lua.cpp b/firmware/controllers/lua/lua.cpp index 24b8a15da2..ddb2b1ead6 100644 --- a/firmware/controllers/lua/lua.cpp +++ b/firmware/controllers/lua/lua.cpp @@ -276,7 +276,8 @@ void startLua() { return; } - strncpy(interactiveCmd, str, sizeof(interactiveCmd)); + strncpy(interactiveCmd, str, sizeof(interactiveCmd) - 1); + interactiveCmd[sizeof(interactiveCmd) - 1] = '\0'; interactivePending = true; }); diff --git a/firmware/development/perf_trace.cpp b/firmware/development/perf_trace.cpp index 350bc9ac11..a7bea6e020 100644 --- a/firmware/development/perf_trace.cpp +++ b/firmware/development/perf_trace.cpp @@ -12,11 +12,20 @@ #include "efitime.h" #include "os_util.h" +#ifndef ENABLE_PERF_TRACE +#error ENABLE_PERF_TRACE must be defined! +#endif #ifndef TRACE_BUFFER_LENGTH #define TRACE_BUFFER_LENGTH 2048 #endif /* TRACE_BUFFER_LENGTH */ +// Disable the buffer if we're not enabled at all +#if !ENABLE_PERF_TRACE +#undef TRACE_BUFFER_LENGTH +#define TRACE_BUFFER_LENGTH 1 +#endif + enum class EPhase : char { Start, diff --git a/firmware/hw_layer/ports/chconf_common.h b/firmware/hw_layer/ports/chconf_common.h index 9586adea53..1b9f868c1a 100644 --- a/firmware/hw_layer/ports/chconf_common.h +++ b/firmware/hw_layer/ports/chconf_common.h @@ -16,11 +16,6 @@ #define CHPRINTF_USE_FLOAT TRUE -#if !defined(ENABLE_PERF_TRACE) || defined(__DOXYGEN__) -// looks like this value could not be defined in efifeatures.h - please define either externally or just change the value here - #define ENABLE_PERF_TRACE TRUE -#endif /* ENABLE_PERF_TRACE */ - #if !defined(_FROM_ASM_) #include "obd_error_codes.h" #endif /* _FROM_ASM_ */