Skip to content

Commit b983e0c

Browse files
authored
Merge pull request #4 from erhankur/fix/log_macro_usage
change: remove STUB_LOG_ENABLE macro from the library usage
2 parents e8ff7a0 + 7b03ba7 commit b983e0c

File tree

27 files changed

+466
-61
lines changed

27 files changed

+466
-61
lines changed

CMakeLists.txt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1+
if(NOT DEFINED ESP_TARGET)
2+
message(FATAL_ERROR "ESP_TARGET not defined. Please specify -DESP_TARGET=<target>")
3+
endif()
4+
5+
if(NOT ESP_STUB_LIB)
6+
set(ESP_STUB_LIB esp-stub-lib)
7+
endif()
8+
9+
if(NOT ESP_TARGET_LIB)
10+
set(ESP_TARGET_LIB ${ESP_TARGET})
11+
endif()
112

213
set(srcs
314
src/log.c
415
src/flash.c
516
)
617

7-
add_library(esp-stub-lib STATIC ${srcs})
18+
add_library(${ESP_STUB_LIB} STATIC ${srcs})
819

9-
target_include_directories(esp-stub-lib
20+
target_include_directories(${ESP_STUB_LIB}
1021
PUBLIC include
1122
PRIVATE include/esp-stub-lib
1223
)
1324

14-
add_subdirectory(src/${ESP_TARGET})
25+
# STUB_COMPILE_DEFS is optional definitions coming from the parent CMakeLists.txt
26+
target_compile_definitions(${ESP_STUB_LIB} PRIVATE ${STUB_COMPILE_DEFS})
27+
28+
add_subdirectory(src/${ESP_TARGET} ${ESP_TARGET_LIB})
1529

16-
target_link_libraries(esp-stub-lib PUBLIC ${ESP_TARGET})
30+
target_link_libraries(${ESP_STUB_LIB} PUBLIC ${ESP_TARGET_LIB})

example/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if(${ESP_TARGET} STREQUAL "esp8266")
3838
target_link_options(${PROJECT_NAME} PRIVATE -Wl,--entry=stub_main_esp8266)
3939
endif()
4040

41-
target_compile_definitions(${PROJECT_NAME} PRIVATE asm=__asm__ STUB_LOG_ENABLE)
41+
target_compile_definitions(${PROJECT_NAME} PRIVATE asm=__asm__ STUB_LOG_ENABLED)
4242

4343
set(MAP_FILE ${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.map)
4444
target_link_options(${PROJECT_NAME} PRIVATE -Wl,-Map=${MAP_FILE})

example/stub_main.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,24 @@ 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+
2533
static __attribute__((unused)) int handle_test1(va_list ap)
2634
{
2735
(void)ap;
2836

29-
STUB_LIB_LOG("test1\n");
37+
STUB_LOG("stub command test:%d\n", 1);
38+
STUB_LOG("stub command test:%d\n", -1);
39+
STUB_LOG("stub command test:0x%x\n", 0x4080393C);
40+
STUB_LOG("stub command test:%s\n", "test");
41+
STUB_LOG("stub command test:%c\n", 'A');
42+
STUB_LOG("stub command test:%l\n", 10); // not supported
3043

3144
return 0;
3245
}
@@ -35,7 +48,7 @@ static __attribute__((unused)) int handle_test2(va_list ap)
3548
{
3649
(void)ap;
3750

38-
STUB_LIB_LOG("test2\n");
51+
STUB_LOG("test2\n");
3952

4053
return 0;
4154
}
@@ -71,22 +84,22 @@ int stub_main(int cmd, ...)
7184

7285
va_start(ap, cmd);
7386

74-
stub_lib_log_init(0, 115200);
87+
STUB_LOG_INIT(0, 115200);
7588

7689
stub_lib_flash_init(&flash_state);
7790

7891
const struct stub_cmd_handler *handler = cmd_handlers;
7992
while (handler->handler) {
8093
if (handler->cmd == cmd) {
81-
STUB_LIB_LOG("Executing command: %s\n", handler->name);
94+
STUB_LOG("Executing command: %s\n", handler->name);
8295
ret = handler->handler(ap);
8396
break;
8497
}
8598
handler++;
8699
}
87100

88101
if (!handler->handler) {
89-
STUB_LIB_LOG("Unknown command!\n");
102+
STUB_LOG("Unknown command!\n");
90103
}
91104

92105
va_end(ap);

include/esp-stub-lib/log.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,5 @@
88

99
#include <stdint.h>
1010

11-
extern void ets_printf(const char *fmt, ...);
12-
1311
void stub_lib_log_init(uint8_t uart_num, uint32_t baudrate);
14-
15-
#ifdef STUB_LOG_ENABLE
16-
17-
#define STUB_LIB_LOG(format, ...) ets_printf(format, ## __VA_ARGS__);
18-
19-
#else
20-
21-
#define STUB_LIB_LOG(format, ...) do {} while (0)
22-
23-
#endif
12+
void stub_lib_log_printf(const char *fmt, ...);

src/esp32/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ set(srcs
44
src/flash.c
55
)
66

7-
add_library(${ESP_TARGET} STATIC ${srcs})
7+
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
88

9-
target_include_directories(${ESP_TARGET}
9+
target_include_directories(${ESP_TARGET_LIB}
1010
PUBLIC include
1111
PRIVATE include/target
1212
)
1313

14-
target_link_options(${ESP_TARGET} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32.rom.ld)
14+
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32.rom.ld)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#define ESP_ROM_HAS_CRC_LE (1) // ROM CRC library supports Little Endian
10+
#define ESP_ROM_HAS_CRC_BE (1) // ROM CRC library supports Big Endian
11+
#define ESP_ROM_HAS_MZ_CRC32 (1) // ROM has mz_crc32 function
12+
#define ESP_ROM_HAS_JPEG_DECODE (1) // ROM has JPEG decode library
13+
#define ESP_ROM_HAS_UART_BUF_SWITCH (1) // ROM has exported the uart buffer switch function
14+
#define ESP_ROM_NEEDS_SWSETUP_WORKAROUND (1) // ROM uses 32-bit time_t. A workaround is required to prevent printf functions from crashing
15+
#define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included
16+
#define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano version of formatting functions
17+
#define ESP_ROM_HAS_NEWLIB_32BIT_TIME (1) // ROM was compiled with 32 bit time_t
18+
#define ESP_ROM_HAS_SW_FLOAT (1) // ROM has libgcc software floating point emulation functions
19+
#define ESP_ROM_USB_OTG_NUM (-1) // No USB_OTG CDC in the ROM, set -1 for Kconfig usage.
20+
#define ESP_ROM_USB_SERIAL_DEVICE_NUM (-1) // No USB_SERIAL_JTAG in the ROM, set -1 for Kconfig usage.
21+
#define ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB (1) // ROM supports the HP core to jump to the RTC memory to execute stub code after waking up from deepsleep.
22+
#define ESP_ROM_HAS_OUTPUT_PUTC_FUNC (1) // ROM has esp_rom_output_putc (or ets_write_char_uart)

src/esp32c2/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ set(srcs
33
src/flash.c
44
)
55

6-
add_library(${ESP_TARGET} STATIC ${srcs})
6+
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
77

8-
target_include_directories(${ESP_TARGET}
8+
target_include_directories(${ESP_TARGET_LIB}
99
PUBLIC include
1010
PRIVATE include/target
1111
)
1212

13-
target_link_options(${ESP_TARGET} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c2.rom.ld)
13+
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c2.rom.ld)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#define ESP_ROM_HAS_CRC_LE (1) // ROM CRC library supports Little Endian
10+
#define ESP_ROM_HAS_CRC_BE (1) // ROM CRC library supports Big Endian
11+
#define ESP_ROM_UART_CLK_IS_XTAL (1) // UART clock source is selected to XTAL in ROM
12+
#define ESP_ROM_HAS_RETARGETABLE_LOCKING (1) // ROM was built with retargetable locking
13+
#define ESP_ROM_GET_CLK_FREQ (1) // Get clk frequency with rom function `ets_get_cpu_frequency`
14+
#define ESP_ROM_HAS_RVFPLIB (1) // ROM has the rvfplib
15+
#define ESP_ROM_HAS_HAL_WDT (1) // ROM has the implementation of Watchdog HAL driver
16+
#define ESP_ROM_HAS_HAL_SYSTIMER (1) // ROM has the implementation of Systimer HAL driver
17+
#define ESP_ROM_HAS_HEAP_TLSF (1) // ROM has the implementation of the tlsf and multi-heap library
18+
#define ESP_ROM_TLSF_CHECK_PATCH (1) // ROM does not contain the patch of tlsf_check_pool()
19+
#define ESP_ROM_MULTI_HEAP_WALK_PATCH (1) // ROM does not contain the patch of multi_heap_walk()
20+
#define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table
21+
#define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver
22+
#define ESP_ROM_HAS_SPI_FLASH_MMAP (1) // ROM has the implementation of SPI Flash mmap driver
23+
#define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included
24+
#define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano version of formatting functions
25+
#define ESP_ROM_NEEDS_SET_CACHE_MMU_SIZE (1) // ROM needs to set cache MMU size according to instruction and rodata for flash mmap
26+
#define ESP_ROM_RAM_APP_NEEDS_MMU_INIT (1) // ROM doesn't init cache MMU when it's a RAM APP, needs MMU hal to init
27+
#define ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB (1) // ROM has the mbedtls crypto algorithm lib
28+
#define ESP_ROM_HAS_SW_FLOAT (1) // ROM has libgcc software floating point emulation functions
29+
#define ESP_ROM_USB_OTG_NUM (-1) // No USB_OTG CDC in the ROM, set -1 for Kconfig usage.
30+
#define ESP_ROM_USB_SERIAL_DEVICE_NUM (-1) // No USB_SERIAL_JTAG in the ROM, set -1 for Kconfig usage.
31+
#define ESP_ROM_HAS_VERSION (1) // ROM has version/eco information
32+
#define ESP_ROM_HAS_VPRINTF_FUNC (1) // ROM has ets_vprintf
33+
#define ESP_ROM_HAS_OUTPUT_PUTC_FUNC (1) // ROM has esp_rom_output_putc (or ets_write_char_uart)
34+
#define ESP_ROM_CONSOLE_OUTPUT_SECONDARY (1) // The console output functions will also output to the USB-serial secondary console
35+
#define ESP_ROM_HAS_SUBOPTIMAL_NEWLIB_ON_MISALIGNED_MEMORY (1) // ROM mem/str functions are not optimized well for misaligned memory access.

src/esp32c3/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ set(srcs
33
src/flash.c
44
)
55

6-
add_library(${ESP_TARGET} STATIC ${srcs})
6+
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
77

8-
target_include_directories(${ESP_TARGET}
8+
target_include_directories(${ESP_TARGET_LIB}
99
PUBLIC include
1010
PRIVATE include/target
1111
)
1212

13-
target_link_options(${ESP_TARGET} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c3.rom.ld)
13+
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c3.rom.ld)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#define ESP_ROM_HAS_CRC_LE (1) // ROM CRC library supports Little Endian
10+
#define ESP_ROM_HAS_CRC_BE (1) // ROM CRC library supports Big Endian
11+
#define ESP_ROM_HAS_MZ_CRC32 (1) // ROM has mz_crc32 function
12+
#define ESP_ROM_HAS_JPEG_DECODE (1) // ROM has JPEG decode library
13+
#define ESP_ROM_UART_CLK_IS_XTAL (1) // UART clock source is selected to XTAL in ROM
14+
#define ESP_ROM_USB_SERIAL_DEVICE_NUM (3) // UART uses USB_SERIAL_JTAG port in ROM.
15+
#define ESP_ROM_HAS_RETARGETABLE_LOCKING (1) // ROM was built with retargetable locking
16+
#define ESP_ROM_HAS_ERASE_0_REGION_BUG (1) // ROM has esp_flash_erase_region(size=0) bug
17+
#define ESP_ROM_HAS_ENCRYPTED_WRITES_USING_LEGACY_DRV (1) // `esp_flash_write_encrypted` in ROM has bug.
18+
#define ESP_ROM_GET_CLK_FREQ (1) // Get clk frequency with rom function `ets_get_cpu_frequency`
19+
#define ESP_ROM_NEEDS_SWSETUP_WORKAROUND (1) // ROM uses 32-bit time_t. A workaround is required to prevent printf functions from crashing
20+
#define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table
21+
#define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver
22+
#define ESP_ROM_HAS_SPI_FLASH_MMAP (1) // ROM has the implementation of SPI Flash mmap driver
23+
#define ESP_ROM_HAS_ETS_PRINTF_BUG (1) // ROM has ets_printf bug when disable the ROM log either by eFuse or RTC storage register
24+
#define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included
25+
#define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano version of formatting functions
26+
#define ESP_ROM_HAS_NEWLIB_32BIT_TIME (1) // ROM was compiled with 32 bit time_t
27+
#define ESP_ROM_NEEDS_SET_CACHE_MMU_SIZE (1) // ROM needs to set cache MMU size according to instruction and rodata for flash mmap
28+
#define ESP_ROM_RAM_APP_NEEDS_MMU_INIT (1) // ROM doesn't init cache MMU when it's a RAM APP, needs MMU hal to init
29+
#define ESP_ROM_HAS_SW_FLOAT (1) // ROM has libgcc software floating point emulation functions
30+
#define ESP_ROM_USB_OTG_NUM (-1) // No USB_OTG CDC in the ROM, set -1 for Kconfig usage.
31+
#define ESP_ROM_HAS_VERSION (1) // ROM has version/eco information
32+
#define ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB (1) // ROM supports the HP core to jump to the RTC memory to execute stub code after waking up from deepsleep.
33+
#define ESP_ROM_CONSOLE_OUTPUT_SECONDARY (1) // The console output functions will also output to the USB-serial secondary console
34+
#define ESP_ROM_HAS_SUBOPTIMAL_NEWLIB_ON_MISALIGNED_MEMORY (1) // ROM mem/str functions are not optimized well for misaligned memory access.

0 commit comments

Comments
 (0)