Skip to content

Conversation

projectgus
Copy link
Contributor

@projectgus projectgus commented Aug 27, 2025

Summary

  • ESP32-C6 binary size has been getting close to the 2MB partition limit.
  • In general ESP32 RISC-V binaries are larger than Xtensa binaries, due to architecture differences (also true for ARM Thumb-2 vs RISC-V Compact).

This PR switches all esp32 RISC-V boards to optimise for size (-0s) instead of performance (-O2). This also reduces the static D/IRAM usage, which translates to more free RAM at runtime.

Size Before After Delta
C2 Total Binary 1680384 1494224 -186160
C2 D/IRAM Usage 83710 79080 -4630
C3 Total Binary 1833328 1636624 -196704
C3 D/IRAM Usage 139608 131896 -7712
C6 Total Binary 2024432 1813216 -211216
C6 D/IRAM Usage 167187 148584 -18603

On ESP32-C6 this PR also switches to using the SPI flash driver from ROM, which saves about an extra 10KB of flash. There is some risk of a regression due to this change, but we already use this option on ESP32-C2 so it should be safe enough.

Testing

  • Ran the basic unit tests on all three boards, noted no new failures.

Trade-offs and Alternatives

  • Could make the app partition larger for C6, but this requires a full re-flash of C6 boards and may not run any faster (due to cache overhead from larger binary size).

Reduces ESP32_GENERIC_C6 application flash size from 2024432 to
1813216 (206KB smaller).

Also has benefit of reducing D/IRAM size, increasing free memory at
runtime (167187 to 148584, -18603 bytes).

Most of this savings comes from building with -Os instead of -O2,
but about 10KB comes from using the SPI flash functions from the ROM.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Same optimisation that was applied to C6 in the parent commit, now applied
to all RISC-V boards.

+------------+------------+------------+------------+
| Size       | Before     | After      | Delta      |
+------------+------------+------------+------------+
| C2 Binary  | 1680384    | 1494224    | -186160    |
| C2 D/IRAM  |   83710    |   79080    |   -4630    |
| C3 Binary  | 1833328    | 1636624    | -196704    |
| C3 D/IRAM  |  139608    |  131896    |   -7712    |
+------------+------------+------------+------------+

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much! This is a very simple and good solution to the problem where the C6 is running out of flash.

The ESP32_GENERIC_C6 firmware now has 218416 bytes available, which should be plenty enough for the medium term future (as long as IDF updates don't grow it too much).

Tested ESP32_GENERIC_C6, didn't see any regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants