add support for LOG=2

LOGGER=rtt is not tested since jlink doesn't support rp2040 just yet
This commit is contained in:
hathach
2021-01-29 11:24:05 +07:00
parent 4fef2ddb4c
commit ba69da1d8f
4 changed files with 81 additions and 14 deletions
+37 -3
View File
@@ -76,6 +76,38 @@ bool __no_inline_not_in_flash_func(get_bootsel_button)() {
}
#endif
//------------- Segger RTT retarget -------------//
#if defined(LOGGER_RTT)
// Logging with RTT
#include "pico/stdio/driver.h"
#include "SEGGER_RTT.h"
static void stdio_rtt_write (const char *buf, int length)
{
SEGGER_RTT_Write(0, buf, length);
}
static int stdio_rtt_read (char *buf, int len)
{
return SEGGER_RTT_Read(0, buf, len);
}
static stdio_driver_t stdio_rtt =
{
.out_chars = stdio_rtt_write,
.out_flush = NULL,
.in_chars = stdio_rtt_read
};
void stdio_rtt_init(void)
{
stdio_set_driver_enabled(&stdio_rtt, true);
}
#endif
void board_init(void)
{
gpio_init(LED_PIN);
@@ -86,9 +118,11 @@ void board_init(void)
#endif
#ifdef UART_DEV
uart_init(UART_DEV, CFG_BOARD_UART_BAUDRATE);
gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART);
gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART);
stdio_uart_init_full(UART_DEV, CFG_BOARD_UART_BAUDRATE, UART_TX_PIN, UART_RX_PIN);
#endif
#if defined(LOGGER_RTT)
stdio_rtt_init();
#endif
// todo probably set up device mode?
+23
View File
@@ -31,3 +31,26 @@ target_include_directories(${PROJECT} PUBLIC
target_compile_definitions(${PROJECT} PUBLIC
CFG_TUSB_MCU=OPT_MCU_RP2040
)
if(DEFINED LOG)
target_compile_definitions(${PROJECT} PUBLIC CFG_TUSB_DEBUG=${LOG} )
pico_enable_stdio_uart(${PROJECT} 1)
endif()
if(LOGGER STREQUAL "rtt")
pico_enable_stdio_uart(${PROJECT} 0)
target_compile_definitions(${PROJECT} PUBLIC
LOGGER_RTT
SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
)
target_sources(${PROJECT} PUBLIC
${TOP}/lib/SEGGER_RTT/RTT/SEGGER_RTT.c
)
target_include_directories(${PROJECT} PUBLIC
${TOP}/lib/SEGGER_RTT/RTT
)
endif()