Skip to content

Commit 4beb22e

Browse files
committed
debugging
1 parent 2086e25 commit 4beb22e

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ uint8_t value_out = 0;
116116
#include "shared-module/os/__init__.h"
117117
#endif
118118

119+
#include "esp_log.h"
120+
static const char *TAG = "main";
121+
119122
static void reset_devices(void) {
120123
#if CIRCUITPY_BLEIO_HCI
121124
bleio_reset();
@@ -154,6 +157,7 @@ static uint8_t *_allocate_memory(safe_mode_t safe_mode, const char *env_key, siz
154157
#endif
155158

156159
static void start_mp(safe_mode_t safe_mode) {
160+
ESP_LOGI(TAG, "start_mp");
157161
supervisor_workflow_reset();
158162

159163
// Stack limit should be less than real stack size, so we have a chance
@@ -210,6 +214,7 @@ static void start_mp(safe_mode_t safe_mode) {
210214
}
211215

212216
static void stop_mp(void) {
217+
ESP_LOGI(TAG, "stop_mp");
213218
#if MICROPY_VFS
214219
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
215220

@@ -421,6 +426,7 @@ static void print_code_py_status_message(safe_mode_t safe_mode) {
421426
}
422427

423428
static bool __attribute__((noinline)) run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
429+
ESP_LOGI(TAG, "run_code_py");
424430
bool serial_connected_at_start = serial_connected();
425431
bool printed_safe_mode_message = false;
426432
#if CIRCUITPY_AUTORELOAD_DELAY_MS > 0

ports/espressif/boards/espressif_esp32c6_devkitc_1_n8/sdkconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
# Component config
66
#
77
#
8-
# LWIP
8+
# ESP-Driver:GPTimer Configurations
99
#
10-
# end of LWIP
10+
CONFIG_GPTIMER_ISR_CACHE_SAFE=y
11+
# end of ESP-Driver:GPTimer Configurations
1112

1213
# end of Component config
1314

ports/espressif/common-hal/digitalio/DigitalInOut.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "driver/gpio.h"
1111
#include "hal/gpio_hal.h"
1212

13+
#include "esp_log.h"
14+
static const char *TAG = "digitalio";
15+
1316
static bool _pin_is_input(uint8_t pin_number) {
1417
gpio_io_config_t config;
1518
if (gpio_get_io_config((gpio_num_t)pin_number, &config) != ESP_OK) {
@@ -87,6 +90,7 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
8790

8891
void common_hal_digitalio_digitalinout_set_value(
8992
digitalio_digitalinout_obj_t *self, bool value) {
93+
ESP_LOGI(TAG, "Setting value to %d", value);
9094
self->output_value = value;
9195
gpio_set_level(self->pin->number, value);
9296
}

ports/espressif/supervisor/port.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ void reset_to_bootloader(void) {
417417
}
418418

419419
void reset_cpu(void) {
420+
ESP_LOGI(TAG, "Resetting CPU");
420421
#if CIRCUITPY_DEBUG
421422
esp_backtrace_print(100);
422423
#endif

ports/espressif/supervisor/usb_serial_jtag.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "esp_intr_alloc.h"
1616
#include "soc/periph_defs.h"
1717

18+
#include "esp_log.h"
19+
static const char *TAG = "usb_serial_jtag";
1820

1921
#define USB_SERIAL_JTAG_BUF_SIZE (64)
2022

@@ -33,6 +35,7 @@ static void _copy_out_of_fifo(void) {
3335
if (req_len == 0) {
3436
// Disable the interrupt so that CircuitPython can run and process the ringbuf. It will
3537
// re-enable the interrupt once the ringbuf is empty.
38+
ESP_EARLY_LOGW(TAG, "Disable interrupt");
3639
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT);
3740
}
3841
if (req_len > USB_SERIAL_JTAG_BUF_SIZE) {
@@ -42,9 +45,15 @@ static void _copy_out_of_fifo(void) {
4245

4346
// Read up to req_len bytes. Does not block.
4447
size_t len = usb_serial_jtag_ll_read_rxfifo(rx_buf, req_len);
48+
if (len == req_len) {
49+
ESP_EARLY_LOGW(TAG, "Buffer full");
50+
} else if (len > 0) {
51+
ESP_EARLY_LOGW(TAG, "Read %d bytes", len);
52+
}
4553

4654
for (size_t i = 0; i < len; ++i) {
4755
if (rx_buf[i] == mp_interrupt_char) {
56+
ESP_LOGI(TAG, "usb_serial_jtag_read_char: interrupt char received");
4857
mp_sched_keyboard_interrupt();
4958
ringbuf_clear(&ringbuf);
5059
} else {
@@ -72,10 +81,20 @@ static void usb_serial_jtag_isr_handler(void *arg) {
7281
_copy_out_of_fifo();
7382
port_wake_main_task_from_isr();
7483
}
84+
85+
// Clear everything else
86+
usb_serial_jtag_ll_clr_intsts_mask(~(USB_SERIAL_JTAG_INTR_SOF | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_TOKEN_REC_IN_EP1));
7587
}
7688

7789
void usb_serial_jtag_init(void) {
7890
ringbuf_init(&ringbuf, buf, sizeof(buf));
91+
#ifdef USB_SERIAL_JTAG_USB_UART_CHIP_RST_DIS
92+
// Disable UART triggered reset because the host may set the serial lines.
93+
USB_SERIAL_JTAG.chip_rst.usb_uart_chip_rst_dis = 1;
94+
ESP_LOGI(TAG, "UART reset disabled");
95+
#else
96+
#error "USB_SERIAL_JTAG_USB_UART_CHIP_RST_DIS must be defined"
97+
#endif
7998
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SOF | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_TOKEN_REC_IN_EP1);
8099
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SOF | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_TOKEN_REC_IN_EP1);
81100
ESP_ERROR_CHECK(esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, ESP_INTR_FLAG_LEVEL1,
@@ -90,6 +109,7 @@ char usb_serial_jtag_read_char(void) {
90109
uint32_t num_filled = ringbuf_num_filled(&ringbuf);
91110

92111
if (num_filled == 0 && !usb_serial_jtag_ll_rxfifo_data_available()) {
112+
ESP_LOGI(TAG, "usb_serial_jtag_read_char: no data available");
93113
return -1;
94114
}
95115
char c = -1;
@@ -113,6 +133,7 @@ char usb_serial_jtag_read_char(void) {
113133
}
114134
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT);
115135
}
136+
ESP_LOGI(TAG, "c: %c", c);
116137
return c;
117138
}
118139

@@ -121,13 +142,15 @@ uint32_t usb_serial_jtag_bytes_available(void) {
121142
common_hal_mcu_disable_interrupts();
122143
const uint32_t count = ringbuf_num_filled(&ringbuf) + usb_serial_jtag_ll_rxfifo_data_available();
123144
common_hal_mcu_enable_interrupts();
145+
ESP_LOGI(TAG, "usb_serial_jtag_bytes_available: %d", count);
124146
return count;
125147
}
126148

127149
void usb_serial_jtag_write(const char *text, uint32_t length) {
128150
if (!usb_serial_jtag_connected()) {
129151
return;
130152
}
153+
ESP_LOGI(TAG, "Writing '%s'", text);
131154
size_t total_written = 0;
132155
while (total_written < length) {
133156
uint32_t start_time = supervisor_ticks_ms32();
@@ -144,4 +167,5 @@ void usb_serial_jtag_write(const char *text, uint32_t length) {
144167
RUN_BACKGROUND_TASKS;
145168
}
146169
usb_serial_jtag_ll_txfifo_flush();
170+
ESP_LOGI(TAG, "Written %d bytes", total_written);
147171
}

0 commit comments

Comments
 (0)