diff options
| author | hathach <[email protected]> | 2021-01-29 11:24:05 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2021-01-29 11:24:05 +0700 |
| commit | ba69da1d8f93af91685e691e5441cd3bca5c71b0 (patch) | |
| tree | 4c06ddb901d0182fea7f1696c53350406dd126a0 /hw | |
| parent | 4fef2ddb4c500f23115781aa87afd1f83b049b9d (diff) | |
add support for LOG=2
LOGGER=rtt is not tested since jlink doesn't support rp2040 just yet
Diffstat (limited to 'hw')
| -rw-r--r-- | hw/bsp/rp2040/family.c | 40 | ||||
| -rw-r--r-- | hw/bsp/rp2040/family.cmake | 23 |
2 files changed, 60 insertions, 3 deletions
diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c index e0dc47b39..452e4771a 100644 --- a/hw/bsp/rp2040/family.c +++ b/hw/bsp/rp2040/family.c @@ -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? diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index edd57a39b..e936fbb24 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -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() + |
