From ca649505031f77a02ee3f7473fc7c14d131e0fb4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 28 Jun 2022 18:32:08 -0400 Subject: [PATCH] wip fixes --- ports/espressif/Makefile | 5 +++-- .../boards/adafruit_feather_esp32_v2/mpconfigboard.h | 3 +++ .../espressif/boards/adafruit_feather_esp32_v2/sdkconfig | 8 +------- ports/espressif/common-hal/alarm/touch/TouchAlarm.c | 4 ++-- ports/espressif/common-hal/microcontroller/Pin.c | 9 ++++++++- ports/espressif/esp-idf-config/partitions-8MB-no-uf2.csv | 4 ++-- ports/espressif/modules/esp32_pico_mini_02.c | 7 +++---- ports/espressif/tools/build_memory_info.py | 9 ++++++--- 8 files changed, 28 insertions(+), 21 deletions(-) diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index f713e942e6..3280ffa105 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -388,8 +388,9 @@ BINARY_BLOBS += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a ESP_IDF_COMPONENTS_EXPANDED += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a endif +# BOOTLOADER_OFFSET is determined by chip type, based on the ROM bootloader, and is not changeable. ifeq ($(IDF_TARGET),esp32) -BOOTLOADER_OFFSET = 0x0 +BOOTLOADER_OFFSET = 0x1000 else ifeq ($(IDF_TARGET),esp32c3) BOOTLOADER_OFFSET = 0x0 else ifeq ($(IDF_TARGET),esp32s3) @@ -412,7 +413,7 @@ ESP_AUTOGEN_LD = $(BUILD)/esp-idf/esp-idf/$(IDF_TARGET)/$(IDF_TARGET)_out.ld $(B FLASH_FLAGS = --flash_mode $(CIRCUITPY_ESP_FLASH_MODE) --flash_freq $(CIRCUITPY_ESP_FLASH_FREQ) --flash_size $(CIRCUITPY_ESP_FLASH_SIZE) -ESPTOOL_FLAGS ?= --before=default_reset --after=no_reset +ESPTOOL_FLAGS ?= --before=default_reset --after=no_reset --baud 460800 ifeq ($(UF2_BOOTLOADER),1) all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2 diff --git a/ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h b/ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h index 886963028b..5a010cb5c7 100644 --- a/ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h +++ b/ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h @@ -46,3 +46,6 @@ // Explanation of how a user got into safe mode #define BOARD_USER_SAFE_MODE_ACTION translate("pressing SW38 button at start up.\n") + +#define CIRCUITPY_DEBUG_UART_TX (&pin_GPIO8) +#define CIRCUITPY_DEBUG_UART_RX (&pin_GPIO7) diff --git a/ports/espressif/boards/adafruit_feather_esp32_v2/sdkconfig b/ports/espressif/boards/adafruit_feather_esp32_v2/sdkconfig index 94333353af..731ea37c4d 100644 --- a/ports/espressif/boards/adafruit_feather_esp32_v2/sdkconfig +++ b/ports/espressif/boards/adafruit_feather_esp32_v2/sdkconfig @@ -33,7 +33,7 @@ CONFIG_PARTITION_TABLE_FILENAME="esp-idf-config/partitions-8MB-no-uf2.csv" # # ESP32-specific # -# CONFIG_ESP32_SPIRAM_SUPPORT is not set +CONFIG_ESP32_SPIRAM_SUPPORT=y # end of ESP32-specific # @@ -43,9 +43,3 @@ CONFIG_LWIP_LOCAL_HOSTNAME="Adafruit-Feather-ESP32-V2" # end of LWIP # end of Component config - -# -# Deprecated options for backward compatibility -# -# CONFIG_SPIRAM_SUPPORT is not set -# end of Deprecated options for backward compatibility diff --git a/ports/espressif/common-hal/alarm/touch/TouchAlarm.c b/ports/espressif/common-hal/alarm/touch/TouchAlarm.c index 0caeeea915..02f176cbf7 100644 --- a/ports/espressif/common-hal/alarm/touch/TouchAlarm.c +++ b/ports/espressif/common-hal/alarm/touch/TouchAlarm.c @@ -132,11 +132,11 @@ void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alar #if defined(CONFIG_IDF_TARGET_ESP32) uint16_t touch_value; touch_pad_read(touch_channel, &touch_value); - touch_pad_set_thresh(touch_channel, touch_value * 0.1); // 10% + touch_pad_set_thresh(touch_channel, touch_value / 10); // 10% #else uint32_t touch_value; touch_pad_read_benchmark(touch_channel, &touch_value); - touch_pad_set_threshold(touch_channel, touch_value * 0.1); // 10% + touch_pad_set_thresh(touch_channel, touch_value / 10); // 10% #endif } } diff --git a/ports/espressif/common-hal/microcontroller/Pin.c b/ports/espressif/common-hal/microcontroller/Pin.c index 957ddd3492..995c281611 100644 --- a/ports/espressif/common-hal/microcontroller/Pin.c +++ b/ports/espressif/common-hal/microcontroller/Pin.c @@ -33,6 +33,10 @@ #include "components/driver/include/driver/gpio.h" #include "components/hal/include/hal/gpio_hal.h" +#include "esp_log.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + STATIC uint32_t never_reset_pins[2]; STATIC uint32_t in_use[2]; @@ -57,7 +61,7 @@ MP_WEAK bool espressif_board_reset_pin_number(gpio_num_t pin_number) { STATIC void _reset_pin(gpio_num_t pin_number) { // Never ever reset pins used for flash and RAM. #if defined(CONFIG_IDF_TARGET_ESP32) - if (pin_number == 6 || pin_number == 11 || pin_number == 9 || pin_number == 10) { + if (pin_number == 1 || pin_number == 6 || pin_number == 11 || pin_number == 9 || pin_number == 10 || pin_number == 17 || pin_number == 23) { return; } #elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) @@ -129,12 +133,15 @@ void common_hal_reset_pin(const mcu_pin_obj_t *pin) { } void reset_all_pins(void) { + ESP_LOGI("Pin.c", "reset_all_pins"); for (uint8_t i = 0; i < GPIO_PIN_COUNT; i++) { uint32_t iomux_address = GPIO_PIN_MUX_REG[i]; if (iomux_address == 0 || (never_reset_pins[i / 32] & (1 << i % 32)) != 0) { continue; } + ESP_LOGI("Pin.c", "about to reset pin %d", i); + vTaskDelay(100); _reset_pin(i); } in_use[0] = never_reset_pins[0]; diff --git a/ports/espressif/esp-idf-config/partitions-8MB-no-uf2.csv b/ports/espressif/esp-idf-config/partitions-8MB-no-uf2.csv index e7bfe0c51f..ba92d9fc73 100644 --- a/ports/espressif/esp-idf-config/partitions-8MB-no-uf2.csv +++ b/ports/espressif/esp-idf-config/partitions-8MB-no-uf2.csv @@ -4,6 +4,6 @@ # partition table,, 0x8000, 4K nvs, data, nvs, 0x9000, 20K, otadata, data, ota, 0xe000, 8K, -ota_0, 0, ota_0, 0x10000, 2048K, -ota_1, 0, ota_1, 0x210000, 2048K, +ota_0, app, ota_0, 0x10000, 2048K, +ota_1, app, ota_1, 0x210000, 2048K, user_fs, data, fat, 0x410000, 4032K, diff --git a/ports/espressif/modules/esp32_pico_mini_02.c b/ports/espressif/modules/esp32_pico_mini_02.c index e115ca27e0..e94c22dd0b 100644 --- a/ports/espressif/modules/esp32_pico_mini_02.c +++ b/ports/espressif/modules/esp32_pico_mini_02.c @@ -27,11 +27,10 @@ #include "modules/module.h" void never_reset_module_internal_pins(void) { - // SPI Flash + // SPI Flash and PSRAM common_hal_never_reset_pin(&pin_GPIO6); - common_hal_never_reset_pin(&pin_GPIO11); - - // PSRAM common_hal_never_reset_pin(&pin_GPIO9); common_hal_never_reset_pin(&pin_GPIO10); + common_hal_never_reset_pin(&pin_GPIO11); + } diff --git a/ports/espressif/tools/build_memory_info.py b/ports/espressif/tools/build_memory_info.py index 4f5304a288..df9d6a801e 100644 --- a/ports/espressif/tools/build_memory_info.py +++ b/ports/espressif/tools/build_memory_info.py @@ -82,9 +82,12 @@ with open(sys.argv[2], "r") as f: elif subtype == "ota_0": ota = partition[4].strip() size = app if ota is None else ota - if size[-1] not in ("k", "K"): - raise RuntimeError("Unhandled partition size suffix") - firmware_region = int(size[:-1]) * 1024 + if size[-1] in ("k", "K"): + firmware_region = int(size[:-1]) * 1024 + elif size[-1] in ("m", "M"): + firmware_region = int(size[:-1]) * 1024 * 1024 + else: + raise RuntimeError("Unhandled partition size suffix:", size[-1]) regions = dict((name, 0) for name, _, _ in internal_memory[target])