Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use alternative printf() in bootloader #5380

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions radio/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,13 @@ add_dependencies(firmware ${RADIO_DEPENDENCIES})
set_target_properties(firmware PROPERTIES EXCLUDE_FROM_ALL TRUE)

if(DEBUG)
target_compile_definitions(board PRIVATE -DDEBUG)
target_compile_definitions(firmware PRIVATE -DDEBUG)
target_compile_definitions(stm32_drivers_w_dbg_fw PRIVATE -DDEBUG)
endif()

add_subdirectory(thirdparty/printf)

target_link_options(firmware PRIVATE
-lm -T${LINKER_DIR}/firmware.ld
-Wl,-Map=firmware.map,--cref,--no-warn-mismatch,--gc-sections
Expand Down
2 changes: 1 addition & 1 deletion radio/src/boards/generic_stm32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(MINIMAL_BOARD_LIB_SRC
boards/generic_stm32/inputs.cpp
boards/generic_stm32/i2c_bus.cpp
boards/generic_stm32/bl_keys.cpp
boards/generic_stm32/aux_ports.cpp
)

# Dependencies only used in firmware
Expand All @@ -25,7 +26,6 @@ set(BOARD_LIB_SRC

boards/generic_stm32/module_ports.cpp
boards/generic_stm32/trainer_ports.cpp
boards/generic_stm32/aux_ports.cpp
boards/generic_stm32/sport_update.cpp
boards/generic_stm32/intmodule_heartbeat.cpp
boards/generic_stm32/analog_inputs.cpp
Expand Down
13 changes: 13 additions & 0 deletions radio/src/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "hal/serial_port.h"
#include "hal/usb_driver.h"
#include "printf/printf.h"

#if defined(CONFIGURABLE_MODULE_PORT) and !defined(BOOT)
#include "hal/module_port.h"
Expand Down Expand Up @@ -74,6 +75,11 @@ void dbgSerialSetSendCb(void* ctx, void (*cb)(void*, uint8_t))

#if defined(DEBUG_SEGGER_RTT)

extern "C" void putchar_(char c)
{
SEGGER_RTT_Write(0, (const void *)&c, 1);
}

extern "C" void dbgSerialPutc(char c)
{
SEGGER_RTT_Write(0, (const void *)&c, 1);
Expand All @@ -96,6 +102,13 @@ extern "C" void dbgSerialPrintf(const char * format, ...)
}
#else

extern "C" void putchar_(char c)
{
auto _putc = dbg_serial_putc;
auto _ctx = dbg_serial_ctx;
if (_putc) _putc(_ctx, c);
}

extern "C" void dbgSerialPutc(char c)
{
auto _putc = dbg_serial_putc;
Expand Down
8 changes: 2 additions & 6 deletions radio/src/targets/common/arm/stm32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,12 @@ if(NOT NATIVE_BUILD)
# HAL/LL drivers using TRACE
add_library(stm32_drivers_w_dbg_fw OBJECT EXCLUDE_FROM_ALL
${STM32_DRIVER_DIR}/sdcard_spi.cpp
${STM32_DRIVER_DIR}/diskio_sdio.cpp
)
add_library(stm32_drivers_w_dbg_bl OBJECT EXCLUDE_FROM_ALL
${STM32_DRIVER_DIR}/sdcard_spi.cpp
)

if(NOT PCB STREQUAL PL18)
target_sources(stm32_drivers PUBLIC
${STM32_DRIVER_DIR}/diskio_sdio.cpp
)
endif()
)

set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32_drivers>)
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32_drivers_w_dbg_fw>)
Expand Down
10 changes: 9 additions & 1 deletion radio/src/targets/common/arm/stm32/bootloader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if(NOT NO_LTO)
target_compile_options(stm32usb_device_bl PRIVATE -flto)
target_compile_options(stm32usb_device_fw PRIVATE -flto)
target_compile_options(stm32_drivers PRIVATE -flto)
target_compile_options(stm32_drivers_w_dbg_fw PRIVATE -flto)
target_compile_options(stm32_drivers_w_dbg_bl PRIVATE -flto)
endif()

Expand Down Expand Up @@ -66,7 +67,14 @@ if (DEFINED TARGET_SDRAM_SIZE)
endif()

if (ENABLE_BOOTLOADER_DEBUG)
target_compile_definitions(bootloader PUBLIC -DDEBUG)
target_sources(bootloader PRIVATE $<TARGET_OBJECTS:printf>)
target_compile_options(board_bl PRIVATE -fno-builtin-printf)
target_compile_options(bootloader PRIVATE -fno-builtin-printf)
target_compile_definitions(board_bl PRIVATE DEBUG)
target_compile_definitions(bootloader PRIVATE DEBUG)
target_sources(bootloader PRIVATE
${RADIO_SRC_DIR}/serial.cpp
)
# uncomment to enable TRACE in drivers
# target_compile_definitions(stm32_drivers_w_dbg_bl PRIVATE -DDEBUG)
endif()
Expand Down
2 changes: 1 addition & 1 deletion radio/src/targets/common/arm/stm32/diskio_sdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "hal.h"


#if !defined(SD_SPI)
#if defined(STORAGE_USE_SDIO)

// #include "delays_driver.h"
#include "debug.h"
Expand Down
7 changes: 7 additions & 0 deletions radio/src/thirdparty/printf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

add_library(printf OBJECT EXCLUDE_FROM_ALL
printf.c
)

target_compile_options(printf PUBLIC -fno-builtin-printf)
target_compile_options(printf PRIVATE -DPRINTF_INCLUDE_CONFIG_H=1)
Loading