From 84c5da36bab8be29c2e42002995bd2b5ba2d0f53 Mon Sep 17 00:00:00 2001 From: Erin Shepherd Date: Sun, 23 Apr 2023 23:18:58 +0200 Subject: [PATCH] Setup stdio to use RTT for debug purposes --- .gitmodules | 3 +++ CMakeLists.txt | 6 ++++++ lib/rtt | 1 + shell.nix | 2 +- src/main.c | 8 ++++++-- src/stdio_rtt.c | 20 ++++++++++++++++++++ src/stdio_rtt.h | 8 ++++++++ 7 files changed, 45 insertions(+), 3 deletions(-) create mode 160000 lib/rtt create mode 100644 src/stdio_rtt.c create mode 100644 src/stdio_rtt.h diff --git a/.gitmodules b/.gitmodules index 97478eb..aa70eb1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "lib/pico-sdk"] path = lib/pico-sdk url = https://github.com/raspberrypi/pico-sdk +[submodule "lib/rtt"] + path = lib/rtt + url = https://github.com/adfernandes/segger-rtt diff --git a/CMakeLists.txt b/CMakeLists.txt index ce9aac0..a86bed1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,13 @@ project(vibe-check) pico_sdk_init() +include_directories( + ${CMAKE_SOURCE_DIR}/lib/rtt/RTT +) + add_executable(vibe-check + lib/rtt/RTT/SEGGER_RTT.c + src/stdio_rtt.c src/main.c ) diff --git a/lib/rtt b/lib/rtt new file mode 160000 index 0000000..660fa25 --- /dev/null +++ b/lib/rtt @@ -0,0 +1 @@ +Subproject commit 660fa2589a67cc87c9a112e405531c53b77504ad diff --git a/shell.nix b/shell.nix index 90b9e68..8f45b57 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,7 @@ { pkgs ? import {} }: pkgs.mkShell { buildInputs = with pkgs; [ - cmake ninja python3 gcc-arm-embedded + cmake cmakeCurses ninja python3 gcc-arm-embedded picotool ]; } diff --git a/src/main.c b/src/main.c index 0ec3f09..8326976 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,9 @@ #include #include "pico/stdlib.h" #include "pico/cyw43_arch.h" -#include "btstack.h" +#include "stdio_rtt.h" + +// #include "btstack.h" #ifndef CYW43_WL_GPIO_LED_PIN #error no WiFi LED on board, wrong -DPICO_BOARD? @@ -11,7 +13,9 @@ // https://github.com/buttplugio/buttplug/blob/master/buttplug/src/server/device/protocol/sakuraneko.rs int main() { - stdio_init_all(); + // stdio_init_all(); + stdio_rtt_init(); + if (cyw43_arch_init()) { printf("WiFi init failed"); return -1; diff --git a/src/stdio_rtt.c b/src/stdio_rtt.c new file mode 100644 index 0000000..8cbb060 --- /dev/null +++ b/src/stdio_rtt.c @@ -0,0 +1,20 @@ +#include "pico/stdio/driver.h" +#include "stdio_rtt.h" +#include "SEGGER_RTT.h" + +void stdio_rtt_init(void) { + stdio_set_driver_enabled(&stdio_rtt, true); +} + +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, +}; diff --git a/src/stdio_rtt.h b/src/stdio_rtt.h new file mode 100644 index 0000000..f3fd837 --- /dev/null +++ b/src/stdio_rtt.h @@ -0,0 +1,8 @@ +#ifndef STDIO_RTT_H +#define STDIO_RTT_H +#include "pico/stdio.h" + +extern stdio_driver_t stdio_rtt; +void stdio_rtt_init(void); + +#endif