Skip to content

Commit 456586a

Browse files
committed
logger: add logging to a RAM buffer
1 parent e36a73f commit 456586a

File tree

16 files changed

+83
-36
lines changed

16 files changed

+83
-36
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ if(NOT ESP_TARGET_LIB)
1010
set(ESP_TARGET_LIB ${ESP_TARGET})
1111
endif()
1212

13+
set(STUB_LIB_SHORT_INC "${CMAKE_CURRENT_SOURCE_DIR}/include/esp-stub-lib")
14+
1315
set(srcs
1416
src/log.c
1517
src/flash.c
@@ -18,8 +20,8 @@ set(srcs
1820
add_library(${ESP_STUB_LIB} STATIC ${srcs})
1921

2022
target_include_directories(${ESP_STUB_LIB}
21-
PUBLIC include
22-
PRIVATE include/esp-stub-lib
23+
INTERFACE include
24+
PRIVATE ${STUB_LIB_SHORT_INC}
2325
)
2426

2527
# STUB_COMPILE_DEFS is optional definitions coming from the parent CMakeLists.txt

example/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
5151
)
5252

5353
get_filename_component(PROJECT_ROOT ${CMAKE_CURRENT_LIST_DIR}/.. ABSOLUTE)
54+
set(STUB_COMPILE_DEFS "STUB_LOG_ENABLED;STUB_LIB_LOG_BUF;STUB_LIB_LOG_BUF_SIZE=2048")
5455
add_subdirectory(${PROJECT_ROOT} esp-stub-lib)
5556
target_link_libraries(${PROJECT_NAME} PRIVATE esp-stub-lib)

example/stub_main.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ struct stub_cmd_handler {
2222
int (*handler)(va_list ap);
2323
};
2424

25-
#ifdef STUB_LOG_ENABLED
26-
#define STUB_LOG_INIT(uart_num, baudrate) stub_lib_log_init(uart_num, baudrate)
27-
#define STUB_LOG(fmt, ...) stub_lib_log_printf(fmt, ##__VA_ARGS__)
28-
#else
29-
#define STUB_LOG_INIT(uart_num, baudrate)
30-
#define STUB_LOG(fmt, ...)
31-
#endif
32-
3325
static __attribute__((unused)) int handle_test1(va_list ap)
3426
{
3527
(void)ap;
@@ -84,7 +76,7 @@ int stub_main(int cmd, ...)
8476

8577
va_start(ap, cmd);
8678

87-
STUB_LOG_INIT(0, 115200);
79+
STUB_LOG_INIT();
8880

8981
stub_lib_flash_init(&flash_state);
9082

include/esp-stub-lib/log.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,42 @@
66

77
#pragma once
88

9+
#if defined(STUB_LOG_ENABLED)
10+
11+
#if !defined(STUB_LIB_LOG_BUF) && !defined(STUB_LIB_LOG_UART)
12+
#define STUB_LIB_LOG_BUF
13+
#endif
14+
15+
#if defined(STUB_LIB_LOG_BUF)
916
#include <stdint.h>
1017

18+
#if !defined(STUB_LIB_LOG_BUF_SIZE)
19+
#define STUB_LIB_LOG_BUF_SIZE 4096
20+
#endif
21+
22+
struct stub_lib_log_buf {
23+
uint32_t count;
24+
char buf[STUB_LIB_LOG_BUF_SIZE];
25+
};
26+
#endif // defined(STUB_LIB_LOG_BUF)
27+
1128
#ifdef __cplusplus
1229
extern "C" {
1330
#endif // __cplusplus
1431

15-
void stub_lib_log_init(uint8_t uart_num, uint32_t baudrate);
32+
void stub_lib_log_init();
1633
void stub_lib_log_printf(const char *fmt, ...);
1734

1835
#ifdef __cplusplus
1936
}
2037
#endif // __cplusplus
38+
39+
#define STUB_LOG_INIT() stub_lib_log_init()
40+
#define STUB_LOG(fmt, ...) stub_lib_log_printf(fmt, ##__VA_ARGS__)
41+
42+
#else // defined(STUB_LOG_ENABLED)
43+
44+
#define STUB_LOG_INIT()
45+
#define STUB_LOG(fmt, ...)
46+
47+
#endif // defined(STUB_LOG_ENABLED)

src/esp32/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ add_library(${ESP_TARGET_LIB} STATIC ${srcs})
88

99
target_include_directories(${ESP_TARGET_LIB}
1010
PUBLIC include
11-
PRIVATE include/target
11+
PRIVATE include/target ${STUB_LIB_SHORT_INC}
1212
)
13-
13+
target_compile_definitions(${ESP_TARGET_LIB} PRIVATE ${STUB_COMPILE_DEFS})
1414
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32.rom.ld)

src/esp32c2/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_library(${ESP_TARGET_LIB} STATIC ${srcs})
77

88
target_include_directories(${ESP_TARGET_LIB}
99
PUBLIC include
10-
PRIVATE include/target
10+
PRIVATE include/target ${STUB_LIB_SHORT_INC}
1111
)
12-
12+
target_compile_definitions(${ESP_TARGET_LIB} PRIVATE ${STUB_COMPILE_DEFS})
1313
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c2.rom.ld)

src/esp32c3/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_library(${ESP_TARGET_LIB} STATIC ${srcs})
77

88
target_include_directories(${ESP_TARGET_LIB}
99
PUBLIC include
10-
PRIVATE include/target
10+
PRIVATE include/target ${STUB_LIB_SHORT_INC}
1111
)
12-
12+
target_compile_definitions(${ESP_TARGET_LIB} PRIVATE ${STUB_COMPILE_DEFS})
1313
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c3.rom.ld)

src/esp32c5/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_library(${ESP_TARGET_LIB} STATIC ${srcs})
77

88
target_include_directories(${ESP_TARGET_LIB}
99
PUBLIC include
10-
PRIVATE include/target
10+
PRIVATE include/target ${STUB_LIB_SHORT_INC}
1111
)
12-
12+
target_compile_definitions(${ESP_TARGET_LIB} PRIVATE ${STUB_COMPILE_DEFS})
1313
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c5.rom.ld)

src/esp32c6/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_library(${ESP_TARGET_LIB} STATIC ${srcs})
77

88
target_include_directories(${ESP_TARGET_LIB}
99
PUBLIC include
10-
PRIVATE include/target
10+
PRIVATE include/target ${STUB_LIB_SHORT_INC}
1111
)
12-
12+
target_compile_definitions(${ESP_TARGET_LIB} PRIVATE ${STUB_COMPILE_DEFS})
1313
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c6.rom.ld)

src/esp32c61/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_library(${ESP_TARGET_LIB} STATIC ${srcs})
77

88
target_include_directories(${ESP_TARGET_LIB}
99
PUBLIC include
10-
PRIVATE include/target
10+
PRIVATE include/target ${STUB_LIB_SHORT_INC}
1111
)
12-
12+
target_compile_definitions(${ESP_TARGET_LIB} PRIVATE ${STUB_COMPILE_DEFS})
1313
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c61.rom.ld)

0 commit comments

Comments
 (0)