Skip to content

[esp32_ble] Enable CONFIG_BT_RELEASE_IRAM on ESP32-C2#14109

Merged
bdraco merged 2 commits intodevfrom
esp32c2-ble-release-iram
Feb 19, 2026
Merged

[esp32_ble] Enable CONFIG_BT_RELEASE_IRAM on ESP32-C2#14109
bdraco merged 2 commits intodevfrom
esp32c2-ble-release-iram

Conversation

@bdraco
Copy link
Member

@bdraco bdraco commented Feb 19, 2026

What does this implement/fix?

Enable CONFIG_BT_RELEASE_IRAM automatically when BLE is used on ESP32-C2 variants.

https://docs.espressif.com/projects/esp-idf/en/v5.2/esp32c2/api-guides/performance/ram-usage.html

The ESP32-C2 has very limited RAM (~272KB). Without this sdkconfig option, esp_bt_controller_init fails with ESP_ERR_NO_MEM, making BLE completely non-functional on C2 chips.

On ESP32-C2, enabling CONFIG_BT_RELEASE_IRAM disables CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT, which changes the memory partitioning so IRAM and DRAM share space more flexibly. This gives the BT controller enough contiguous memory to initialize without OOM. The option also enables releasing ~21KB of BT IRAM via esp_bt_mem_release() after Bluetooth is no longer needed, but ESPHome keeps BLE running continuously (for proxy, improv, etc.) so that function is never called. The benefit here is purely from the compile-time memory layout change.

This is automatically applied during final validation when the ESP32-C2 variant is detected, so users no longer need to manually add it to their sdkconfig_options.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Developer breaking change (an API change that could break external components)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

Pull request in esphome-docs with documentation (if applicable):

  • N/A (no user-facing configuration changes)

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx
  • LN882x
  • nRF52840

Example entry for config.yaml:

# No changes needed - CONFIG_BT_RELEASE_IRAM is now set automatically on ESP32-C2
# Previously users had to manually add:
#   esp32:
#     framework:
#       type: esp-idf
#       sdkconfig_options:
#         CONFIG_BT_RELEASE_IRAM: y

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

The ESP32-C2 has very limited RAM (~272KB) and BLE initialization
fails with ESP_ERR_NO_MEM without this option. CONFIG_BT_RELEASE_IRAM
frees ~21KB of IRAM by merging BT text/data/bss into heap, which is
enough for BLE to work on the memory-constrained C2.

Closes #13516

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 19, 2026 16:55
@bdraco bdraco requested a review from jesserockz as a code owner February 19, 2026 16:55
@github-actions
Copy link
Contributor

👋 Hi there! This PR modifies 1 file(s) with codeowners.

@jesserockz, @Rapsssito - As codeowner(s) of the affected files, your review would be appreciated! 🙏

Note: Automatic review request may have failed, but you're still welcome to review.

@github-actions
Copy link
Contributor

To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file:

external_components:
  - source: github://pr#14109
    components: [esp32_ble]
    refresh: 1h

(Added by the PR bot)

@codecov-commenter
Copy link

codecov-commenter commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.11%. Comparing base (bd50b80) to head (859b434).
⚠️ Report is 4 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev   #14109   +/-   ##
=======================================
  Coverage   74.11%   74.11%           
=======================================
  Files          55       55           
  Lines       11590    11590           
  Branches     1578     1578           
=======================================
  Hits         8590     8590           
  Misses       2598     2598           
  Partials      402      402           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

swoboda1337
swoboda1337 previously approved these changes Feb 19, 2026
@swoboda1337 swoboda1337 added this to the 2026.2.1 milestone Feb 19, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes BLE functionality on ESP32-C2 devices by automatically enabling the CONFIG_BT_RELEASE_IRAM sdkconfig option. The ESP32-C2 has limited RAM (~272KB), and without this option, esp_bt_controller_init fails with ESP_ERR_NO_MEM. The fix enables this option automatically during final validation when the ESP32-C2 variant is detected, eliminating the need for users to manually configure it.

Changes:

  • Added automatic CONFIG_BT_RELEASE_IRAM configuration for ESP32-C2 to free ~21KB of IRAM required for BLE operation
  • Added test coverage for ESP32-C2 BLE functionality

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/components/esp32_ble/test.esp32-c2-idf.yaml New test file for ESP32-C2 BLE functionality following the established test pattern
esphome/components/esp32_ble/init.py Added import of VARIANT_ESP32C2 constant and conditional sdkconfig option setting in final_validation

@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2026

Memory Impact Analysis

Components: esp32_ble
Platform: esp32-idf

Metric Target Branch This PR Change
RAM 33,500 bytes 33,500 bytes ➡️ +0 bytes (0.00%)
Flash 573,911 bytes 573,911 bytes ➡️ +0 bytes (0.00%)

Note: This analysis measures static RAM and Flash usage only (compile-time allocation).
Dynamic memory (heap) cannot be measured automatically.
⚠️ You must test this PR on a real device to measure free heap and ensure no runtime memory issues.

This analysis runs automatically when components change. Memory usage is measured from a representative test configuration.

@bdraco
Copy link
Member Author

bdraco commented Feb 19, 2026

thanks

@bdraco bdraco enabled auto-merge (squash) February 19, 2026 17:09
@bdraco
Copy link
Member Author

bdraco commented Feb 19, 2026

oops. I reset instead of pushing the CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT change on top

CONFIG_BT_RELEASE_IRAM requires CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT to
be disabled, otherwise ESP-IDF raises a compile-time error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bdraco
Copy link
Member Author

bdraco commented Feb 19, 2026

should have just let claude do it :)

@bdraco
Copy link
Member Author

bdraco commented Feb 19, 2026

all good now

Wrote 0xa58c0 bytes to file '/Users/bdraco/esphome/tests/test_build_components/build/.esphome/build/componenttestesp32c2idf/.pioenvs/componenttestesp32c2idf/firmware.factory.bin', ready to flash to offset 0x0.
Successfully created /Users/bdraco/esphome/tests/test_build_components/build/.esphome/build/componenttestesp32c2idf/.pioenvs/componenttestesp32c2idf/firmware.factory.bin
esp32_copy_ota_bin([".pioenvs/componenttestesp32c2idf/firmware.bin"], [".pioenvs/componenttestesp32c2idf/firmware.elf"])
Copied firmware to /Users/bdraco/esphome/tests/test_build_components/build/.esphome/build/componenttestesp32c2idf/.pioenvs/componenttestesp32c2idf/firmware.ota.bin
==================================================================================================== [SUCCESS] Took 23.46 seconds ====================================================================================================
INFO Build Info: config_hash=0x59987129 build_time_str=2026-02-19 11:18:43 -0600

@bdraco bdraco merged commit 7a5c3ce into dev Feb 19, 2026
26 checks passed
@bdraco bdraco deleted the esp32c2-ble-release-iram branch February 19, 2026 17:41
swoboda1337 pushed a commit that referenced this pull request Feb 20, 2026
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@swoboda1337 swoboda1337 mentioned this pull request Feb 20, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BLE not working with ESP32C2

4 participants