Skip to content
Snippets Groups Projects
Commit 81abfd9f authored by moon2's avatar moon2 :speech_balloon:
Browse files

enable gdb build flag

how to:
(1) idf.py menuconfig -> Component config -> debug config -> usb gdb mode
(2) rm -r build ; idf.py app-flash
(3) OPENOCD_COMMANDS="-f board/esp32s3-builtin.cfg" idf.py openocd
(4) (in another terminal) idf.py gdb
parent 59392016
Branches
Tags
No related merge requests found
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
#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);
......@@ -144,3 +167,24 @@ void tud_suspend_cb(bool remote_wakeup_en) {
st3m_usb_cdc_detached();
}
}
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(" |___|");
}
......@@ -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);
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment