Skip to content

Commit d634481

Browse files
committed
Lots of web workflow, C3 and title bar fixes
* Fixes #6221 - C3 hang on `import wifi`. Enabling the WiFi PHY was disabling USB. Now boards that use it set CONFIG_ESP_PHY_ENABLE_USB explicitly. * Fixes #6655 - Allows pasting into the web serial page. Fixes reading more than 0xf bytes at a time. * Fixes #6653 - Fixes web socket encoding of payloads >125 bytes. Can happen when printing a long string. * Fixes C3 responsiveness when waiting for key to enter REPL. (It now correctly stops sleeping.) * Disables title bar updates when in raw REPL. Related to #6548. * Adds version to title bar.
1 parent c4c1520 commit d634481

File tree

19 files changed

+262
-71
lines changed

19 files changed

+262
-71
lines changed

main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "supervisor/shared/stack.h"
5858
#include "supervisor/shared/status_leds.h"
5959
#include "supervisor/shared/tick.h"
60+
#include "supervisor/shared/title_bar.h"
6061
#include "supervisor/shared/traceback.h"
6162
#include "supervisor/shared/translate/translate.h"
6263
#include "supervisor/shared/workflow.h"
@@ -822,7 +823,9 @@ STATIC int run_repl(bool first_run) {
822823
status_led_deinit();
823824
#endif
824825
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
826+
supervisor_title_bar_suspend();
825827
exit_code = pyexec_raw_repl();
828+
supervisor_title_bar_resume();
826829
} else {
827830
exit_code = pyexec_friendly_repl();
828831
}
@@ -914,6 +917,7 @@ int __attribute__((used)) main(void) {
914917
run_boot_py(safe_mode);
915918

916919
supervisor_workflow_start();
920+
supervisor_title_bar_start();
917921

918922
// Boot script is finished, so now go into REPL or run code.py.
919923
int exit_code = PYEXEC_FORCED_EXIT;

ports/espressif/boards/adafruit_qtpy_esp32c3/sdkconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ CONFIG_PARTITION_TABLE_FILENAME="esp-idf-config/partitions-4MB-no-uf2.csv"
3030
#
3131
# Component config
3232
#
33+
#
34+
35+
#
36+
# PHY
37+
#
38+
CONFIG_ESP_PHY_ENABLE_USB=y
39+
# end of PHY
40+
3341
#
3442
# ESP System Settings
3543
#

ports/espressif/boards/beetle-esp32-c3/sdkconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#
2+
# PHY
3+
#
4+
CONFIG_ESP_PHY_ENABLE_USB=y
5+
# end of PHY
6+
17
#
28
# LWIP
39
#

ports/espressif/boards/lolin_c3_mini/sdkconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#
2+
# PHY
3+
#
4+
CONFIG_ESP_PHY_ENABLE_USB=y
5+
# end of PHY
6+
17
#
28
# LWIP
39
#

ports/espressif/common-hal/wifi/__init__.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ wifi_radio_obj_t common_hal_wifi_radio_obj;
4444
#include "components/log/include/esp_log.h"
4545

4646
#include "supervisor/port.h"
47+
#include "supervisor/shared/title_bar.h"
4748
#include "supervisor/workflow.h"
4849

4950
#include "esp_ipc.h"
@@ -55,7 +56,7 @@ wifi_radio_obj_t common_hal_wifi_radio_obj;
5556
static const char *TAG = "CP wifi";
5657

5758
STATIC void schedule_background_on_cp_core(void *arg) {
58-
supervisor_workflow_request_background();
59+
supervisor_title_bar_request_update(false);
5960

6061
// CircuitPython's VM is run in a separate FreeRTOS task from wifi callbacks. So, we have to
6162
// notify the main task every time in case it's waiting for us.

ports/espressif/esp-idf

ports/espressif/supervisor/port.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "supervisor/board.h"
3131
#include "supervisor/port.h"
3232
#include "py/runtime.h"
33-
#include "supervisor/esp_port.h"
3433

3534
#include "freertos/FreeRTOS.h"
3635
#include "freertos/task.h"
@@ -390,6 +389,14 @@ void port_wake_main_task() {
390389
xTaskNotifyGive(circuitpython_task);
391390
}
392391

392+
void port_wake_main_task_from_isr() {
393+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
394+
vTaskNotifyGiveFromISR(circuitpython_task, &xHigherPriorityTaskWoken);
395+
if (xHigherPriorityTaskWoken == pdTRUE) {
396+
portYIELD_FROM_ISR();
397+
}
398+
}
399+
393400
void sleep_timer_cb(void *arg) {
394401
port_wake_main_task();
395402
}

ports/espressif/supervisor/usb_serial_jtag.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@
2828
#include "py/ringbuf.h"
2929
#include "py/runtime.h"
3030
#include "py/mphal.h"
31-
#include "usb_serial_jtag.h"
31+
#include "supervisor/port.h"
32+
#include "supervisor/usb_serial_jtag.h"
3233

3334
#include "hal/usb_serial_jtag_ll.h"
3435
#include "esp_intr_alloc.h"
3536
#include "soc/periph_defs.h"
3637

37-
#include "supervisor/esp_port.h"
3838

3939
#define USB_SERIAL_JTAG_BUF_SIZE (64)
4040

4141
STATIC ringbuf_t ringbuf;
4242
STATIC uint8_t buf[128];
43-
STATIC bool connected;
43+
STATIC volatile bool connected;
44+
45+
#if CIRCUITPY_ESP_USB_SERIAL_JTAG && !CONFIG_ESP_PHY_ENABLE_USB
46+
#error "CONFIG_ESP_PHY_ENABLE_USB must be enabled in sdkconfig"
47+
#endif
4448

4549
static void usb_serial_jtag_isr_handler(void *arg) {
4650
uint32_t flags = usb_serial_jtag_ll_get_intsts_mask();
@@ -49,6 +53,11 @@ static void usb_serial_jtag_isr_handler(void *arg) {
4953
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SOF);
5054
}
5155

56+
if (flags & USB_SERIAL_JTAG_INTR_TOKEN_REC_IN_EP1) {
57+
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_TOKEN_REC_IN_EP1);
58+
connected = true;
59+
}
60+
5261
if (flags & USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT) {
5362
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT);
5463
size_t req_len = ringbuf_num_empty(&ringbuf);
@@ -64,25 +73,19 @@ static void usb_serial_jtag_isr_handler(void *arg) {
6473
ringbuf_put(&ringbuf, rx_buf[i]);
6574
}
6675
}
67-
vTaskNotifyGiveFromISR(circuitpython_task, NULL);
76+
port_wake_main_task_from_isr();
6877
}
6978
}
7079

7180
void usb_serial_jtag_init(void) {
7281
ringbuf_init(&ringbuf, buf, sizeof(buf));
73-
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SOF | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT);
74-
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SOF | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT);
82+
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);
83+
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);
7584
ESP_ERROR_CHECK(esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, ESP_INTR_FLAG_LEVEL1,
7685
usb_serial_jtag_isr_handler, NULL, NULL));
7786
}
7887

7988
bool usb_serial_jtag_connected(void) {
80-
// Make connected sticky. Otherwise we'll be disconnected every time the SOF
81-
// index is 0. (It's only ~15 bits so it wraps around frequently.)
82-
if (connected) {
83-
return true;
84-
}
85-
connected = USB_SERIAL_JTAG.fram_num.sof_frame_index > 0;
8689
return connected;
8790
}
8891

supervisor/port.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@ void port_background_task(void);
9999
void port_start_background_task(void);
100100
void port_finish_background_task(void);
101101

102-
// Some ports need special handling to wake the main task from an interrupt
103-
// context or other task. The port must implement the necessary code in this
104-
// function. A default weak implementation is provided that does nothing.
102+
// Some ports need special handling to wake the main task from another task. The
103+
// port must implement the necessary code in this function. A default weak
104+
// implementation is provided that does nothing.
105105
void port_wake_main_task(void);
106+
107+
// Some ports need special handling to wake the main task from an interrupt
108+
// context. The port must implement the necessary code in this function. A
109+
// default weak implementation is provided that does nothing.
110+
void port_wake_main_task_from_isr(void);
111+
106112
#endif // MICROPY_INCLUDED_SUPERVISOR_PORT_H

ports/espressif/supervisor/esp_port.h renamed to supervisor/shared/port.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
6+
* Copyright (c) 2022 Scott Shawcroft for Adafruit Industries
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -24,12 +24,10 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_ESPRESSIF_SUPERVISOR_PORT_H
28-
#define MICROPY_INCLUDED_ESPRESSIF_SUPERVISOR_PORT_H
27+
#include "supervisor/port.h"
2928

30-
#include "freertos/FreeRTOS.h"
31-
#include "freertos/task.h"
29+
MP_WEAK void port_wake_main_task(void) {
30+
}
3231

33-
extern TaskHandle_t circuitpython_task;
34-
35-
#endif // MICROPY_INCLUDED_ESPRESSIF_SUPERVISOR_PORT_H
32+
MP_WEAK void port_wake_main_task_from_isr(void) {
33+
}

0 commit comments

Comments
 (0)