diff --git a/components/st3m/Kconfig b/components/st3m/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..65526b7af789fdadc293e78bd169324f2233ea2a --- /dev/null +++ b/components/st3m/Kconfig @@ -0,0 +1,10 @@ +menu "debug config" + choice DEBUG_GDB + prompt "gdb or tinyusb/mass storage" + default DEBUG_GDB_DISABLED + config DEBUG_GDB_DISABLED + bool "tinyusb/mass storage mode, no gdb" + config DEBUG_GDB_ENABLED + bool "usb gdb mode, no tinyusb/mass storage" + endchoice +endmenu diff --git a/components/st3m/st3m_usb.c b/components/st3m/st3m_usb.c index f3bd48275882f6d2767779661733b206a88df6e0..283e2bb0411f2ad9ef98c7386f624e2b2f10e5c9 100644 --- a/components/st3m/st3m_usb.c +++ b/components/st3m/st3m_usb.c @@ -1,4 +1,14 @@ #include "st3m_usb.h" +#ifndef CONFIG_DEBUG_GDB_ENABLED +#ifndef CONFIG_DEBUG_GDB_DISABLED +#error "st3m: no debug flags" +#endif +#endif +#ifdef CONFIG_DEBUG_GDB_ENABLED +#ifdef CONFIG_DEBUG_GDB_DISABLED +#error "st3m: invalid debug flags" +#endif +#endif static const char *TAG = "st3m-usb"; @@ -11,6 +21,8 @@ static const char *TAG = "st3m-usb"; #include "esp_private/usb_phy.h" #include "tusb.h" +#include "st3m_console.h" + static SemaphoreHandle_t _mu = NULL; static st3m_usb_mode_kind_t _mode = st3m_usb_mode_kind_disabled; static usb_phy_handle_t phy_hdl; @@ -45,12 +57,16 @@ static void _generate_serial(void) { } void st3m_usb_init(void) { +#ifdef CONFIG_DEBUG_GDB_ENABLED + return; +#endif assert(_mu == NULL); _mu = xSemaphoreCreateMutex(); assert(_mu != NULL); _mode = st3m_usb_mode_kind_disabled; _generate_serial(); +#ifndef CONFIG_DEBUG_GDB_ENABLED st3m_usb_cdc_init(); usb_phy_config_t phy_conf = { .controller = USB_PHY_CTRL_OTG, @@ -68,9 +84,13 @@ void st3m_usb_init(void) { xTaskCreate(_usb_task, "usb", 4096, NULL, 5, NULL); ESP_LOGI(TAG, "USB stack started"); +#endif } void st3m_usb_mode_switch(st3m_usb_mode_t *mode) { +#ifdef CONFIG_DEBUG_GDB_ENABLED + return; +#endif xSemaphoreTake(_mu, portMAX_DELAY); bool running = false; @@ -120,6 +140,9 @@ void st3m_usb_mode_switch(st3m_usb_mode_t *mode) { } bool st3m_usb_connected(void) { +#ifdef CONFIG_DEBUG_GDB_ENABLED + return false; +#endif xSemaphoreTake(_mu, portMAX_DELAY); bool res = _connected; xSemaphoreGive(_mu); @@ -143,4 +166,25 @@ void tud_suspend_cb(bool remote_wakeup_en) { if (mode == st3m_usb_mode_kind_app) { st3m_usb_cdc_detached(); } -} \ No newline at end of file +} + +void st3m_usb_startup() { +#ifdef CONFIG_DEBUG_GDB_ENABLED + return; +#endif + st3m_usb_app_conf_t app = { + .fn_rx = st3m_console_cdc_on_rx, + .fn_txpoll = st3m_console_cdc_on_txpoll, + .fn_detach = st3m_console_cdc_on_detach, + }; + st3m_usb_mode_t usb_mode = { + .kind = st3m_usb_mode_kind_app, + .app = &app, + }; + st3m_usb_mode_switch(&usb_mode); + puts(" ___ _ ___ _ _"); + puts("| _| |___ _ _ _|_ |___| |_ ___ _| |___ ___"); + puts("| _| | . | | | |_ | _| . | .'| . | . | -_|"); + puts("|_| |_|___|_____|___|_| |___|__,|___|_ |___|"); + puts(" |___|"); +} diff --git a/components/st3m/st3m_usb.h b/components/st3m/st3m_usb.h index 72e8f2e150a1093b674ad36a6556b3e7c171fbd2..5aa726d77c9ea3dc1749f9c19a1a56ee5a1933c7 100644 --- a/components/st3m/st3m_usb.h +++ b/components/st3m/st3m_usb.h @@ -38,6 +38,7 @@ #include <stdbool.h> #include <stddef.h> #include <stdint.h> +#include "sdkconfig.h" typedef enum { // Device should not enumerate. @@ -106,6 +107,8 @@ void st3m_usb_mode_switch(st3m_usb_mode_t *target); // Initialize the subsystem. Must be called, bad things will happen otherwise. void st3m_usb_init(); +void st3m_usb_startup(); + // Return true if the badge is connected to a host. bool st3m_usb_connected(void); diff --git a/main/main.c b/main/main.c index ade4f7c08f18225f1ec090b03cbf5f5f515e9ca7..440f7bf91d6ec8129b4034cdc3029932b20c89cd 100644 --- a/main/main.c +++ b/main/main.c @@ -57,21 +57,7 @@ static QueueHandle_t _core1_init_done_q; void _init_core1(void *unused) { st3m_usb_init(); st3m_console_init(); - st3m_usb_app_conf_t app = { - .fn_rx = st3m_console_cdc_on_rx, - .fn_txpoll = st3m_console_cdc_on_txpoll, - .fn_detach = st3m_console_cdc_on_detach, - }; - st3m_usb_mode_t usb_mode = { - .kind = st3m_usb_mode_kind_app, - .app = &app, - }; - st3m_usb_mode_switch(&usb_mode); - puts(" ___ _ ___ _ _"); - puts("| _| |___ _ _ _|_ |___| |_ ___ _| |___ ___"); - puts("| _| | . | | | |_ | _| . | .'| . | . | -_|"); - puts("|_| |_|___|_____|___|_| |___|__,|___|_ |___|"); - puts(" |___|"); + st3m_usb_startup(); // Load bearing delay. USB crashes otherwise? // TODO(q3k): debug this