Skip to content
Snippets Groups Projects
Unverified Commit 0996a9e3 authored by Andrew Fernandes's avatar Andrew Fernandes Committed by GitHub
Browse files

Add support for SEGGER RTT STDIO (updated) (#1411)

parent c93c3f49
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,7 @@ if (NOT PICO_BARE_METAL)
pico_add_subdirectory(pico_stdio)
pico_add_subdirectory(pico_stdio_semihosting)
pico_add_subdirectory(pico_stdio_uart)
pico_add_subdirectory(pico_stdio_rtt)
pico_add_subdirectory(cmsis)
pico_add_subdirectory(tinyusb)
......
......@@ -51,14 +51,14 @@ typedef struct stdio_driver stdio_driver_t;
/*! \brief Initialize all of the present standard stdio types that are linked into the binary.
* \ingroup pico_stdio
*
* Call this method once you have set up your clocks to enable the stdio support for UART, USB
* and semihosting based on the presence of the respective libraries in the binary.
* Call this method once you have set up your clocks to enable the stdio support for UART, USB,
* semihosting, and RTT based on the presence of the respective libraries in the binary.
*
* When stdio_usb is configured, this method can be optionally made to block, waiting for a connection
* via the variables specified in \ref stdio_usb_init (i.e. \ref PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS)
*
* \return true if at least one output was successfully initialized, false otherwise.
* \see stdio_uart, stdio_usb, stdio_semihosting
* \see stdio_uart, stdio_usb, stdio_semihosting, stdio_rtt
*/
bool stdio_init_all(void);
......
......@@ -32,6 +32,10 @@
#include "pico/stdio_semihosting.h"
#endif
#if LIB_PICO_STDIO_RTT
#include "pico/stdio_rtt.h"
#endif
#define STDIO_HANDLE_STDIN 0
#define STDIO_HANDLE_STDOUT 1
#define STDIO_HANDLE_STDERR 2
......@@ -295,6 +299,11 @@ bool stdio_init_all(void) {
rc = true;
#endif
#if LIB_PICO_STDIO_RTT
stdio_rtt_init();
rc = true;
#endif
#if LIB_PICO_STDIO_USB
rc |= stdio_usb_init();
#endif
......
pico_add_library(pico_stdio_rtt)
target_sources(pico_stdio_rtt INTERFACE
${CMAKE_CURRENT_LIST_DIR}/stdio_rtt.c
${CMAKE_CURRENT_LIST_DIR}/SEGGER/RTT/SEGGER_RTT.c)
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/SEGGER/RTT/SEGGER_RTT.c
PROPERTIES COMPILE_OPTIONS "-Wno-cast-qual;-Wno-cast-align")
target_include_directories(pico_stdio_rtt_headers INTERFACE
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/SEGGER/RTT
${CMAKE_CURRENT_LIST_DIR}/SEGGER/Config)
pico_mirrored_target_link_libraries(pico_stdio_rtt INTERFACE pico_stdio)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _PICO_STDIO_RTT_H
#define _PICO_STDIO_RTT_H
#include "pico/stdio.h"
/** \brief Support for stdin/stdout using SEGGER RTT
* \defgroup pico_stdio_rtt pico_stdio_rtt
* \ingroup pico_stdio
*
* Linking this library or calling `pico_enable_stdio_rtt(TARGET)` in the CMake (which
* achieves the same thing) will add RTT to the drivers used for standard output
*/
// PICO_CONFIG: PICO_STDIO_RTT_DEFAULT_CRLF, Default state of CR/LF translation for rtt output, type=bool, default=PICO_STDIO_DEFAULT_CRLF, group=pico_stdio_rtt
#ifndef PICO_STDIO_RTT_DEFAULT_CRLF
#define PICO_STDIO_RTT_DEFAULT_CRLF PICO_STDIO_DEFAULT_CRLF
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern stdio_driver_t stdio_rtt;
/*! \brief Explicitly initialize stdin/stdout over RTT and add it to the current set of stdin/stdout drivers
* \ingroup pico_stdio_rtt
*
* \note this method is automatically called by \ref stdio_init_all() if `pico_stdio_rtt` is included in the build
*/
void stdio_rtt_init(void);
#ifdef __cplusplus
}
#endif
#endif
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "pico/binary_info.h"
#include "pico/stdio/driver.h"
#include "pico/stdio_rtt.h"
#include "SEGGER_RTT.h"
#if PICO_NO_BI_STDIO_RTT
#define stdio_bi_decl_if_func_used(x)
#else
#define stdio_bi_decl_if_func_used bi_decl_if_func_used
#endif
void stdio_rtt_init(void) {
SEGGER_RTT_Init();
stdio_set_driver_enabled(&stdio_rtt, true);
stdio_bi_decl_if_func_used(bi_program_feature("RTT stdin / stdout"));
}
static void stdio_rtt_out_chars(const char *buf, int length) {
SEGGER_RTT_Write(0, buf, length);
}
static int stdio_rtt_in_chars(char *buf, int length) {
return SEGGER_RTT_Read(0, buf, length);
}
stdio_driver_t stdio_rtt = {
.out_chars = stdio_rtt_out_chars,
.in_chars = stdio_rtt_in_chars,
#if PICO_STDIO_ENABLE_CRLF_SUPPORT
.crlf_enabled = PICO_STDIO_RTT_DEFAULT_CRLF
#endif
};
......@@ -4,6 +4,8 @@ option(PICO_STDIO_UART "Globally enable stdio UART" 1)
option(PICO_STDIO_USB "Globally enable stdio USB" 0)
# PICO_CMAKE_CONFIG: PICO_STDIO_SEMIHOSTING, OPTION: Globally enable stdio semihosting, type=bool, default=0, group=pico_stdlib
option(PICO_STDIO_SEMIHOSTING "Globally enable stdio semi-hosting" 0)
# PICO_CMAKE_CONFIG: PICO_STDIO_RTT, OPTION: Globally enable stdio RTT, type=bool, default=0, group=pico_stdlib
option(PICO_STDIO_RTT "Globally enable stdio RTT" 0)
if (NOT TARGET pico_stdlib)
pico_add_impl_library(pico_stdlib)
......@@ -33,6 +35,10 @@ if (NOT TARGET pico_stdlib)
set_target_properties(${TARGET} PROPERTIES PICO_TARGET_STDIO_SEMIHOSTING ${ENABLED})
endfunction()
function(pico_enable_stdio_rtt TARGET ENABLED)
set_target_properties(${TARGET} PROPERTIES PICO_TARGET_STDIO_RTT ${ENABLED})
endfunction()
if (TARGET pico_stdio_uart)
target_link_libraries(pico_stdlib INTERFACE $<IF:$<BOOL:$<IF:$<STREQUAL:$<TARGET_PROPERTY:PICO_TARGET_STDIO_UART>,>,${PICO_STDIO_UART},$<TARGET_PROPERTY:PICO_TARGET_STDIO_UART>>>,pico_stdio_uart,>)
target_link_libraries(pico_stdlib_headers INTERFACE $<IF:$<BOOL:$<IF:$<STREQUAL:$<TARGET_PROPERTY:PICO_TARGET_STDIO_UART>,>,${PICO_STDIO_UART},$<TARGET_PROPERTY:PICO_TARGET_STDIO_UART>>>,pico_stdio_uart_headers,>)
......@@ -48,4 +54,9 @@ if (NOT TARGET pico_stdlib)
target_link_libraries(pico_stdlib_headers INTERFACE $<IF:$<BOOL:$<IF:$<STREQUAL:$<TARGET_PROPERTY:PICO_TARGET_STDIO_SEMIHOSTING>,>,${PICO_STDIO_SEMIHOSTING},$<TARGET_PROPERTY:PICO_TARGET_STDIO_SEMIHOSTING>>>,pico_stdio_semihosting_headers,>)
endif()
if (TARGET pico_stdio_rtt)
target_link_libraries(pico_stdlib INTERFACE $<IF:$<BOOL:$<IF:$<STREQUAL:$<TARGET_PROPERTY:PICO_TARGET_STDIO_RTT>,>,${PICO_STDIO_RTT},$<TARGET_PROPERTY:PICO_TARGET_STDIO_RTT>>>,pico_stdio_rtt,>)
target_link_libraries(pico_stdlib_headers INTERFACE $<IF:$<BOOL:$<IF:$<STREQUAL:$<TARGET_PROPERTY:PICO_TARGET_STDIO_RTT>,>,${PICO_STDIO_RTT},$<TARGET_PROPERTY:PICO_TARGET_STDIO_RTT>>>,pico_stdio_rtt_headers,>)
endif()
endif()
......@@ -4,13 +4,21 @@ if (NOT PICO_TIME_NO_ALARM_SUPPORT)
pico_add_extra_outputs(pico_stdio_test_uart)
pico_enable_stdio_uart(pico_stdio_test_uart 1)
pico_enable_stdio_usb(pico_stdio_test_uart 0)
pico_enable_stdio_rtt(pico_stdio_test_uart 0)
add_executable(pico_stdio_test_rtt pico_stdio_test.c)
target_link_libraries(pico_stdio_test_rtt PRIVATE pico_stdlib pico_test pico_multicore)
pico_add_extra_outputs(pico_stdio_test_rtt)
pico_enable_stdio_uart(pico_stdio_test_rtt 0)
pico_enable_stdio_usb(pico_stdio_test_rtt 0)
pico_enable_stdio_rtt(pico_stdio_test_rtt 1)
add_executable(pico_stdio_test_usb pico_stdio_test.c)
target_link_libraries(pico_stdio_test_usb PRIVATE pico_stdlib pico_test pico_multicore)
target_compile_definitions(pico_stdio_test_usb PRIVATE
PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS=-1) # wait for USB connect
pico_add_extra_outputs(pico_stdio_test_usb)
pico_enable_stdio_uart(pico_stdio_test_usb 0)
pico_enable_stdio_usb(pico_stdio_test_usb 1)
pico_enable_stdio_rtt(pico_stdio_test_usb 0)
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment