Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to -Os for all 4MB builds #9207

Merged
merged 7 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 377 files
10 changes: 5 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ STATIC void stop_mp(void) {

background_callback_reset();

#if CIRCUITPY_USB
#if CIRCUITPY_TINYUSB
usb_background();
#endif

Expand Down Expand Up @@ -466,7 +466,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {

start_mp(safe_mode);

#if CIRCUITPY_USB
#if CIRCUITPY_USB_DEVICE
usb_setup_with_vm();
#endif

Expand Down Expand Up @@ -845,7 +845,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {

start_mp(safe_mode);

#if CIRCUITPY_USB
#if CIRCUITPY_USB_DEVICE
// Set up default USB values after boot.py VM starts but before running boot.py.
usb_set_defaults();
#endif
Expand Down Expand Up @@ -930,7 +930,7 @@ STATIC int run_repl(safe_mode_t safe_mode) {

start_mp(safe_mode);

#if CIRCUITPY_USB
#if CIRCUITPY_USB_DEVICE
usb_setup_with_vm();
#endif

Expand Down Expand Up @@ -1078,7 +1078,7 @@ int __attribute__((used)) main(void) {
// By default our internal flash is readonly to local python code and
// writable over USB. Set it here so that safemode.py or boot.py can change it.
filesystem_set_internal_concurrent_write_protection(true);
filesystem_set_internal_writable_by_usb(CIRCUITPY_USB == 1);
filesystem_set_internal_writable_by_usb(CIRCUITPY_USB_DEVICE == 1);

#if CIRCUITPY_SAFEMODE_PY
// Run safemode.py if we ARE in safe mode.
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/common-hal/microcontroller/Pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void reset_all_pins(void) {
uint32_t pin_mask[PORT_COUNT] = PORT_OUT_IMPLEMENTED;

// Do not full reset USB lines.
#if CIRCUITPY_USB
#if CIRCUITPY_USB_DEVICE
pin_mask[0] &= ~(PORT_PA24 | PORT_PA25);
#endif

Expand Down
26 changes: 19 additions & 7 deletions ports/espressif/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,34 @@ LIBS += -lm
endif

# TinyUSB defines
ifeq ($(CIRCUITPY_USB),1)
ifeq ($(IDF_TARGET),esp32s2)
# Always add these because we might be doing host.
ifeq ($(IDF_TARGET),esp32)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32
else ifeq ($(IDF_TARGET),esp32c3)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32C3
else ifeq ($(IDF_TARGET),esp32c6)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32C6
else ifeq ($(IDF_TARGET),esp32h2)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32H2
else ifeq ($(IDF_TARGET),esp32s2)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S2
else ifeq ($(IDF_TARGET),esp32s3)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S3
endif
ifeq ($(CIRCUITPY_TINYUSB),1)
CFLAGS += \
-DCFG_TUSB_OS=OPT_OS_FREERTOS \
-DCFG_TUD_TASK_QUEUE_SZ=32
endif
ifeq ($(CIRCUITPY_USB_DEVICE),1)
CFLAGS += \
-DCFG_TUD_CDC_RX_BUFSIZE=1024 \
-DCFG_TUD_CDC_TX_BUFSIZE=1024 \
-DCFG_TUD_MSC_BUFSIZE=4096 \
-DCFG_TUD_MIDI_RX_BUFSIZE=128 \
-DCFG_TUD_MIDI_TX_BUFSIZE=128 \
-DCFG_TUD_VENDOR_RX_BUFSIZE=128 \
-DCFG_TUD_VENDOR_TX_BUFSIZE=128 \
-DCFG_TUD_TASK_QUEUE_SZ=32
-DCFG_TUD_VENDOR_TX_BUFSIZE=128
endif

######################################
Expand Down Expand Up @@ -303,7 +315,7 @@ ifneq ($(CIRCUITPY_TOUCHIO_USE_NATIVE),0)
SRC_C += peripherals/touch.c
endif

ifneq ($(CIRCUITPY_USB),0)
ifneq ($(CIRCUITPY_USB_DEVICE),0)
SRC_C += lib/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c
endif

Expand Down Expand Up @@ -390,7 +402,7 @@ TARGET_SDKCONFIG = esp-idf-config/sdkconfig-$(IDF_TARGET).defaults
ifeq ($(CIRCUITPY_ESP_FLASH_SIZE), 2MB)
FLASH_SIZE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_SIZE)-no-ota-no-uf2.defaults
else
UF2_BOOTLOADER ?= $(CIRCUITPY_USB)
UF2_BOOTLOADER ?= $(CIRCUITPY_USB_DEVICE)
ifeq ($(UF2_BOOTLOADER), 1)
FLASH_SIZE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_SIZE).defaults
else
Expand Down Expand Up @@ -503,7 +515,7 @@ endif
ifneq ($(CIRCUITPY_PARALLELDISPLAYBUS),0)
ESP_IDF_COMPONENTS_LINK += esp_lcd
endif
ifneq ($(CIRCUITPY_USB),0)
ifneq ($(CIRCUITPY_USB_DEVICE),0)
ESP_IDF_COMPONENTS_LINK += usb
endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ CIRCUITPY_ONEWIREIO = 0
CIRCUITPY_PARALLELDISPLAYBUS = 0
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_ROTARYIO = 0

OPTIMIZATION_FLAGS = -Os
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ CIRCUITPY_ESP_PSRAM_FREQ = 80m

CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_PARALLELDISPLAYBUS = 0

OPTIMIZATION_FLAGS = -Os
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB

OPTIMIZATION_FLAGS = -Os
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_PARALLELDISPLAYBUS = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ CIRCUITPY_ESP_PSRAM_SIZE = 2MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 80m

OPTIMIZATION_FLAGS = -Os
CIRCUITPY_ESPCAMERA = 0
# Not enough pins.
CIRCUITPY_PARALLELDISPLAYBUS = 0
2 changes: 0 additions & 2 deletions ports/espressif/boards/deneyap_kart_1a_v2/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_BITMAPFILTER = 0
CIRCUITPY_CODEOP = 0
CIRCUITPY_PARALLELDISPLAYBUS = 0

OPTIMIZATION_FLAGS = -Os
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ IDF_TARGET = esp32s3

# This board doesn't have USB by default, it
# instead uses a CP2102 USB-to-Serial chip
CIRCUITPY_USB = 0
CIRCUITPY_USB_DEVICE = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0

CIRCUITPY_ESP_FLASH_MODE = qio
Expand Down
1 change: 0 additions & 1 deletion ports/espressif/boards/lolin_s3/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ CIRCUITPY_ESP_PSRAM_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_MODE = opi
CIRCUITPY_ESP_PSRAM_FREQ = 80m

OPTIMIZATION_FLAGS = -Os
CIRCUITPY_ESPCAMERA = 0
1 change: 0 additions & 1 deletion ports/espressif/boards/lolin_s3_mini/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ CIRCUITPY_ESP_PSRAM_SIZE = 2MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 80m

OPTIMIZATION_FLAGS = -Os
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_BITMAPFILTER = 0
CIRCUITPY_CODEOP = 0
Expand Down
1 change: 0 additions & 1 deletion ports/espressif/boards/lolin_s3_pro/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ CIRCUITPY_ESP_PSRAM_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_MODE = opi
CIRCUITPY_ESP_PSRAM_FREQ = 80m

OPTIMIZATION_FLAGS = -Os
CIRCUITPY_ESPCAMERA = 0
2 changes: 1 addition & 1 deletion ports/espressif/boards/makerfabs_tft7/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CIRCUITPY_DOTCLOCKFRAMEBUFFER = 1
# To build with USB disabled allowing access to I2S pins
#CIRCUITPY_CREATOR_ID = 0x1A000000
#CIRCUITPY_CREATION_ID = 0x005381BF
#CIRCUITPY_USB=0
#CIRCUITPY_USB_DEVICE=0
#CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
#UF2_BOOTLOADER = 1
#CIRCUITPY_WIFI=1
Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/boards/makerfabs_tft7/pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_GPIO19), MP_ROM_PTR(&pin_GPIO19) },

// I2S pins are shared with USB D+/D-, these are only useful if USB is disabled
#if CIRCUITPY_USB == 0
#if CIRCUITPY_USB_DEVICE == 0
{ MP_ROM_QSTR(MP_QSTR_I2S_BIT_CLOCK), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_I2S_WORD_SELECT), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_I2S_DATA), MP_ROM_PTR(&pin_GPIO19) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CIRCUITPY_CREATION_ID = 0x00AA0004

# This board doesn't have USB by default, it
# instead uses a CH340C USB-to-Serial chip
CIRCUITPY_USB = 0
CIRCUITPY_USB_DEVICE = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0

IDF_TARGET = esp32s3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CIRCUITPY_CREATION_ID = 0x00AB0001

# This board doesn't have USB by default, it
# instead uses a CH340C USB-to-Serial chip
CIRCUITPY_USB = 0
CIRCUITPY_USB_DEVICE = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0

IDF_TARGET = esp32s3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ CIRCUITPY_ESP_PSRAM_SIZE = 2MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 80m

OPTIMIZATION_FLAGS = -Os
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_BITMAPFILTER = 0
CIRCUITPY_CODEOP = 0
Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/common-hal/microcontroller/Pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static const uint64_t pin_mask_reset_forbidden =
#endif // ESP32H2

#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
#if CIRCUITPY_USB
#if CIRCUITPY_USB_DEVICE
// Never ever reset USB pins.
GPIO_SEL_19 | // USB D-
GPIO_SEL_20 | // USB D+
Expand Down
14 changes: 9 additions & 5 deletions ports/espressif/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ CIRCUITPY_FRAMEBUFFERIO ?= 1
CIRCUITPY_FREQUENCYIO ?= 1
CIRCUITPY_HASHLIB ?= 1
CIRCUITPY_I2CTARGET ?= 0
CIRCUITPY_MAX3421E ?= 1
CIRCUITPY_MEMORYMAP ?= 1
CIRCUITPY_NVM ?= 1
CIRCUITPY_PARALLELDISPLAYBUS ?= 1
Expand All @@ -51,7 +52,7 @@ ifeq ($(IDF_TARGET),esp32)
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_BLEIO = 0
# Features
CIRCUITPY_USB = 0
CIRCUITPY_USB_DEVICE = 0

else ifeq ($(IDF_TARGET),esp32c3)
# Modules
Expand All @@ -72,7 +73,7 @@ CIRCUITPY_ROTARYIO = 0
CIRCUITPY_TOUCHIO ?= 1
CIRCUITPY_TOUCHIO_USE_NATIVE = 0
# Features
CIRCUITPY_USB = 0
CIRCUITPY_USB_DEVICE = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1

else ifeq ($(IDF_TARGET),esp32c6)
Expand All @@ -93,7 +94,7 @@ CIRCUITPY_PARALLELDISPLAYBUS = 0
CIRCUITPY_TOUCHIO ?= 1
CIRCUITPY_TOUCHIO_USE_NATIVE = 0
# Features
CIRCUITPY_USB = 0
CIRCUITPY_USB_DEVICE = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1

else ifeq ($(IDF_TARGET),esp32h2)
Expand All @@ -112,10 +113,12 @@ CIRCUITPY_TOUCHIO ?= 1
CIRCUITPY_TOUCHIO_USE_NATIVE = 0
CIRCUITPY_HASHLIB_MBEDTLS_ONLY = 0
# Features
CIRCUITPY_USB = 0
CIRCUITPY_USB_DEVICE = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1
CIRCUITPY_WIFI = 0

CIRCUITPY_MAX3421E = 0

else ifeq ($(IDF_TARGET),esp32s2)
# Modules
# No BLE in hw
Expand All @@ -139,6 +142,7 @@ endif
# bitmapfilter does not fit on 4MB boards unless they are set up as camera boards
ifeq ($(CIRCUITPY_ESP_FLASH_SIZE),4MB)
CIRCUITPY_BITMAPFILTER ?= 0
OPTIMIZATION_FLAGS ?= -Os
endif

# No room for dualbank on boards with 2MB flash
Expand All @@ -154,7 +158,7 @@ CIRCUITPY_JPEGIO ?= $(CIRCUITPY_DISPLAYIO)
CIRCUITPY_QRIO ?= $(CIRCUITPY_ESPCAMERA)

# Features dependent on other features
ifneq ($(CIRCUITPY_USB),0)
ifneq ($(CIRCUITPY_USB_DEVICE),0)
CIRCUITPY_BUILD_EXTENSIONS ?= bin,uf2
else
CIRCUITPY_BUILD_EXTENSIONS ?= bin
Expand Down
44 changes: 24 additions & 20 deletions ports/espressif/supervisor/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#include "tusb.h"

#if CIRCUITPY_USB_DEVICE
#ifdef CFG_TUSB_DEBUG
#define USBD_STACK_SIZE (3 * configMINIMAL_STACK_SIZE)
#else
Expand Down Expand Up @@ -80,26 +81,6 @@ STATIC void usb_device_task(void *param) {
}
}

void init_usb_hardware(void) {
// Configure USB PHY
usb_phy_config_t phy_conf = {
.controller = USB_PHY_CTRL_OTG,
.otg_mode = USB_OTG_MODE_DEVICE,
};
usb_new_phy(&phy_conf, &phy_hdl);

// Pin the USB task to the same core as CircuitPython. This way we leave
// the other core for networking.
(void)xTaskCreateStaticPinnedToCore(usb_device_task,
"usbd",
USBD_STACK_SIZE,
NULL,
5,
usb_device_stack,
&usb_device_taskdef,
xPortGetCoreID());
}

/**
* Callback invoked when received an "wanted" char.
* @param itf Interface index (for multiple cdc interfaces)
Expand All @@ -124,3 +105,26 @@ void tud_cdc_rx_cb(uint8_t itf) {
// Wake main task when any key is pressed.
port_wake_main_task();
}
#endif // CIRCUITPY_USB_DEVICE

void init_usb_hardware(void) {
#if CIRCUITPY_USB_DEVICE
// Configure USB PHY
usb_phy_config_t phy_conf = {
.controller = USB_PHY_CTRL_OTG,
.otg_mode = USB_OTG_MODE_DEVICE,
};
usb_new_phy(&phy_conf, &phy_hdl);

// Pin the USB task to the same core as CircuitPython. This way we leave
// the other core for networking.
(void)xTaskCreateStaticPinnedToCore(usb_device_task,
"usbd",
USBD_STACK_SIZE,
NULL,
5,
usb_device_stack,
&usb_device_taskdef,
xPortGetCoreID());
#endif
}
4 changes: 2 additions & 2 deletions ports/litex/supervisor/internal_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n
uint32_t src = lba2addr(block);
memcpy(dest, (uint8_t *)src, FILESYSTEM_BLOCK_SIZE * num_blocks);

#if CIRCUITPY_USB
#if CIRCUITPY_USB_DEVICE
usb_background();
#endif

Expand Down Expand Up @@ -347,7 +347,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
src += count * FILESYSTEM_BLOCK_SIZE;
num_blocks -= count;

#if CIRCUITPY_USB
#if CIRCUITPY_USB_DEVICE
usb_background();
#endif
}
Expand Down
Loading