From 431fa84ffba76c6832a1af15c3c6e2f262cd9b27 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 12 Jan 2025 00:38:19 +0100 Subject: [PATCH] Merge develop into main (#161) - Fix CoreS3 boot failure (I2C now returns bool instead of err_result_t) - Flashing scripts now erase before flashing (to ensure it's a clean install) - M5Stack Core2 and CoreS3: Experimental SPI speed increase --- Boards/M5stackCoreS3/Source/InitBoot.cpp | 10 +++++----- Boards/M5stackCoreS3/Source/hal/CoreS3Display.cpp | 2 +- Buildscripts/Flashing/flash.ps1 | 2 ++ Buildscripts/Flashing/flash.sh | 1 + Documentation/ideas.md | 1 + sdkconfig.board.m5stack-core2 | 5 ++++- sdkconfig.board.m5stack-cores3 | 7 +++++-- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Boards/M5stackCoreS3/Source/InitBoot.cpp b/Boards/M5stackCoreS3/Source/InitBoot.cpp index 699ff0d2..9cb32dd4 100644 --- a/Boards/M5stackCoreS3/Source/InitBoot.cpp +++ b/Boards/M5stackCoreS3/Source/InitBoot.cpp @@ -58,12 +58,12 @@ bool initGpioExpander() { // SD card aw9523_P0 |= (1 << 4); - if (tt::hal::i2c::masterWrite(I2C_NUM_0, AW9523_ADDRESS, 0x02, &aw9523_P0, 1, 1000) != ESP_OK) { + if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AW9523_ADDRESS, 0x02, &aw9523_P0, 1, 1000)) { TT_LOG_E(TAG, "Failed to enable LCD"); return false; } - if (tt::hal::i2c::masterWrite(I2C_NUM_0, AW9523_ADDRESS, 0x03, &aw9523_P1, 1, 1000) != ESP_OK) { + if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AW9523_ADDRESS, 0x03, &aw9523_P1, 1, 1000)) { TT_LOG_E(TAG, "Failed to enable touch"); return false; } @@ -76,21 +76,21 @@ bool initPowerControl() { uint8_t sdcard_3v3 = 0b00011100; // TODO: Refactor to use Axp2101 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L62 - if (tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x95, &sdcard_3v3, 1, 1000) != ESP_OK) { + if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x95, &sdcard_3v3, 1, 1000)) { TT_LOG_E(TAG, "Failed to enable SD card"); return false; } // TODO: Refactor to use Axp2102 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42 uint8_t axp_dld01_enable = 0xBF; // For backlight - if (tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x90, &axp_dld01_enable, 1, 1000) != ESP_OK) { + if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x90, &axp_dld01_enable, 1, 1000)) { TT_LOG_E(TAG, "Failed to enable display backlight"); return false; } // TODO: Refactor to use Axp2101 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L62 uint8_t axp_dld01_voltage = 0b00011000; // For backlight - if (tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &axp_dld01_voltage, 1, 1000) != ESP_OK) { + if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &axp_dld01_voltage, 1, 1000)) { TT_LOG_E(TAG, "Failed to set display backlight voltage"); return false; } diff --git a/Boards/M5stackCoreS3/Source/hal/CoreS3Display.cpp b/Boards/M5stackCoreS3/Source/hal/CoreS3Display.cpp index 6b90c005..d47b00d9 100644 --- a/Boards/M5stackCoreS3/Source/hal/CoreS3Display.cpp +++ b/Boards/M5stackCoreS3/Source/hal/CoreS3Display.cpp @@ -175,7 +175,7 @@ void CoreS3Display::setGammaCurve(uint8_t index) { void CoreS3Display::setBacklightDuty(uint8_t backlightDuty) { const uint8_t voltage = 20 + ((8 * backlightDuty) / 255); // [0b00000, 0b11100] - under 20 is too dark // TODO: Refactor to use Axp2102 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42 - if (tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &voltage, 1, 1000) != ESP_OK) { + if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &voltage, 1, 1000)) { TT_LOG_E(TAG, "Failed to set display backlight voltage"); } } diff --git a/Buildscripts/Flashing/flash.ps1 b/Buildscripts/Flashing/flash.ps1 index 2303f153..13eb8c31 100644 --- a/Buildscripts/Flashing/flash.ps1 +++ b/Buildscripts/Flashing/flash.ps1 @@ -13,6 +13,8 @@ $jsonClean = $json.flash_files -replace '[\{\}\@\;]', '' $jsonClean = $jsonClean -replace '[\=]', ' ' cd Binaries +$command = "esptool --port $port erase_flash" +Invoke-Expression $command $command = "esptool --port $port -b 460800 write_flash $jsonClean" Invoke-Expression $command cd .. diff --git a/Buildscripts/Flashing/flash.sh b/Buildscripts/Flashing/flash.sh index 33919268..a9c26265 100755 --- a/Buildscripts/Flashing/flash.sh +++ b/Buildscripts/Flashing/flash.sh @@ -38,4 +38,5 @@ fi cd Binaries # Create flash command based on partitions KEY_VALUES=`jq -r '.flash_files | keys[] as $k | "\($k) \(.[$k])"' flasher_args.json | tr "\n" " "` +esptool.py --port $1 erase_flash esptool.py --port $1 --connect-attempts 10 -b 460800 write_flash $KEY_VALUES diff --git a/Documentation/ideas.md b/Documentation/ideas.md index 6421f131..56804e08 100644 --- a/Documentation/ideas.md +++ b/Documentation/ideas.md @@ -14,6 +14,7 @@ - Consistently use either ESP_TARGET or ESP_PLATFORM - tt_check() failure during app argument bundle nullptr check seems to trigger SIGSEGV - Fix bug in T-Deck/etc: esp_lvgl_port settings has a large stack size (~9kB) to fix an issue where the T-Deck would get a stackoverflow. This sometimes happens when WiFi is auto-enabled and you open the app while it is still connecting. +- M5Stack Core only shows 4MB of SPIRAM in use # TODOs - Make a ledger for setting CPU affinity of various services and tasks diff --git a/sdkconfig.board.m5stack-core2 b/sdkconfig.board.m5stack-core2 index 508494e3..1872fff6 100644 --- a/sdkconfig.board.m5stack-core2 +++ b/sdkconfig.board.m5stack-core2 @@ -29,15 +29,18 @@ CONFIG_FATFS_LFN_HEAP=y CONFIG_FATFS_VOLUME_COUNT=3 # Hardware: Main +CONFIG_IDF_EXPERIMENTAL_FEATURES=y CONFIG_TT_BOARD_M5STACK_CORE2=y CONFIG_IDF_TARGET="esp32" CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y +CONFIG_ESPTOOLPY_FLASHFREQ_80M=y CONFIG_FLASHMODE_QIO=y # Hardware: SPI RAM +CONFIG_ESP32_SPIRAM_SUPPORT=y CONFIG_SPIRAM=y -CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_MODE_QUAD=y CONFIG_SPIRAM_SPEED_80M=y CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y # LVGL diff --git a/sdkconfig.board.m5stack-cores3 b/sdkconfig.board.m5stack-cores3 index da65dc52..0de20431 100644 --- a/sdkconfig.board.m5stack-cores3 +++ b/sdkconfig.board.m5stack-cores3 @@ -29,6 +29,7 @@ CONFIG_FATFS_LFN_HEAP=y CONFIG_FATFS_VOLUME_COUNT=3 # Hardware: Main +CONFIG_IDF_EXPERIMENTAL_FEATURES=y CONFIG_TT_BOARD_M5STACK_CORES3=y CONFIG_IDF_TARGET="esp32s3" CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y @@ -41,11 +42,13 @@ CONFIG_SPIRAM_MODE_QUAD=y CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y CONFIG_SPIRAM_CLK_IO=30 CONFIG_SPIRAM_CS_IO=26 -CONFIG_SPIRAM_SPEED_40M=y -CONFIG_SPIRAM_SPEED=40 +CONFIG_SPIRAM_SPEED_120M=y +CONFIG_SPIRAM_SPEED=120 CONFIG_SPIRAM_BOOT_INIT=y CONFIG_SPIRAM_USE_MALLOC=y CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y +# SPI Flash (can set back to 80MHz after ESP-IDF bug is resolved) +CONFIG_ESPTOOLPY_FLASHFREQ_120M=y # LVGL CONFIG_LV_DISP_DEF_REFR_PERIOD=17 CONFIG_LV_INDEV_DEF_READ_PERIOD=17