From 38d923b35969e4debe11348f312c8a86d0b59aa1 Mon Sep 17 00:00:00 2001 From: Jacob Abrams Date: Mon, 10 Jun 2024 11:07:40 -0700 Subject: [PATCH] Let firmware info be optional to save RAM Many projects already have another mechanism for getting firmware info or want to save RAM and do not need firmware info of CmBacktrace. With this change user can pass NULL for name and version after setting the define CMB_NOT_USING_FIRMWARE_INFO. --- cm_backtrace/cm_backtrace.c | 15 ++++++++++++--- cm_backtrace/cmb_cfg.h | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cm_backtrace/cm_backtrace.c b/cm_backtrace/cm_backtrace.c index 8390803..aa50f51 100644 --- a/cm_backtrace/cm_backtrace.c +++ b/cm_backtrace/cm_backtrace.c @@ -119,9 +119,14 @@ static const char * const print_info[] = { #endif }; -static char fw_name[CMB_NAME_MAX + 1] = {0}; -static char hw_ver[CMB_NAME_MAX + 1] = {0}; -static char sw_ver[CMB_NAME_MAX + 1] = {0}; +#ifdef CMB_NOT_USING_FIRMWARE_INFO + static const char * const fw_name = "x"; +#else + static char fw_name[CMB_NAME_MAX + 1] = {0}; + static char hw_ver[CMB_NAME_MAX + 1] = {0}; + static char sw_ver[CMB_NAME_MAX + 1] = {0}; +#endif + static uint32_t main_stack_start_addr = 0; static size_t main_stack_size = 0; static uint32_t code_start_addr = 0; @@ -143,9 +148,11 @@ static bool on_thread_before_fault = false; * library initialize */ void cm_backtrace_init(const char *firmware_name, const char *hardware_ver, const char *software_ver) { +#ifndef CMB_NOT_USING_FIRMWARE_INFO strncpy(fw_name, firmware_name, CMB_NAME_MAX); strncpy(hw_ver, hardware_ver, CMB_NAME_MAX); strncpy(sw_ver, software_ver, CMB_NAME_MAX); +#endif #if defined(__ARMCC_VERSION) main_stack_start_addr = (uint32_t)&CSTACK_BLOCK_START(CMB_CSTACK_BLOCK_NAME); @@ -178,7 +185,9 @@ void cm_backtrace_init(const char *firmware_name, const char *hardware_ver, cons * print firmware information, such as: firmware name, hardware version, software version */ void cm_backtrace_firmware_info(void) { +#ifndef CMB_NOT_USING_FIRMWARE_INFO cmb_println(print_info[PRINT_FIRMWARE_INFO], fw_name, hw_ver, sw_ver); +#endif } #ifdef CMB_USING_OS_PLATFORM diff --git a/cm_backtrace/cmb_cfg.h b/cm_backtrace/cmb_cfg.h index b9a0b09..e3476ba 100644 --- a/cm_backtrace/cmb_cfg.h +++ b/cm_backtrace/cmb_cfg.h @@ -46,6 +46,8 @@ /* #define CMB_USING_DUMP_STACK_INFO */ /* language of print information */ /* #define CMB_PRINT_LANGUAGE CMB_PRINT_LANGUAGE_ENGLISH(default) or CMB_PRINT_LANGUAGE_CHINESE or CMB_PRINT_LANGUAGE_CHINESE_UTF8 */ +/* disable storing and printing firmware information */ +/* #define CMB_NOT_USING_FIRMWARE_INFO */ #endif #endif /* _CMB_CFG_H_ */