Skip to content

Commit

Permalink
Let firmware info be optional to save RAM
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
satur9nine committed Jul 3, 2024
1 parent 6013293 commit 60cf01a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cm_backtrace/cm_backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -174,12 +181,14 @@ void cm_backtrace_init(const char *firmware_name, const char *hardware_ver, cons
init_ok = true;
}

#ifndef CMB_NOT_USING_FIRMWARE_INFO
/**
* print firmware information, such as: firmware name, hardware version, software version
*/
void cm_backtrace_firmware_info(void) {
cmb_println(print_info[PRINT_FIRMWARE_INFO], fw_name, hw_ver, sw_ver);
}
#endif /* CMB_NOT_USING_FIRMWARE_INFO */

#ifdef CMB_USING_OS_PLATFORM
/**
Expand Down
2 changes: 2 additions & 0 deletions cm_backtrace/cmb_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */

0 comments on commit 60cf01a

Please sign in to comment.