Skip to content

Conversation

@AdrianSoundy
Copy link
Member

@AdrianSoundy AdrianSoundy commented Dec 12, 2024

Description

Since upgrading to IDF 5.2.3 the available native memory has been reduced for ESP32_S3 devices without psram
This change increases native memory to give about the same as before upgrade.

Motivation and Context

Discord discussion

How Has This Been Tested?

Locally run with supplied test program

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

Summary by CodeRabbit

  • New Features
    • Introduced support for the ESP32S3 target with a defined minimum free memory requirement of 130 KB.
  • Bug Fixes
    • No changes to existing memory allocation logic or error handling mechanisms; functionality remains consistent.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes in this pull request introduce a new conditional compilation directive for the ESP32S3 target in the Memory.cpp file, defining a minimum free memory requirement of 130 KB for the IDF. This addition complements existing definitions for other ESP32 targets, which have their own specified minimum memory requirements. The overall memory allocation logic, error handling, and control flow remain unchanged, ensuring that the new configuration integrates seamlessly with the existing framework.

Changes

File Path Change Summary
targets/ESP32/_nanoCLR/Memory.cpp Added a new constant definition #define MINIMUM_FREE_MEMORY_FOR_IDF (130 * 1024) for ESP32S3 target. Existing memory allocation logic remains unchanged.

Possibly related PRs

Suggested labels

Platform: ESP32, Series: ESP32C6


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
targets/ESP32/_nanoCLR/Memory.cpp (1)

28-29: Document the memory requirement change

Consider adding a comment explaining why ESP32S3 requires 130KB of minimum free memory, particularly since it's higher than other variants. This will help future maintenance and prevent accidental modifications.

 #elif defined(CONFIG_IDF_TARGET_ESP32S3)
+// ESP32S3 requires more minimum free memory after IDF 5.2.3 upgrade when PSRAM is not used
 #define MINIMUM_FREE_MEMORY_FOR_IDF (130 * 1024)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 08e9931 and aa730d8.

📒 Files selected for processing (1)
  • targets/ESP32/_nanoCLR/Memory.cpp (1 hunks)
🔇 Additional comments (2)
targets/ESP32/_nanoCLR/Memory.cpp (2)

28-29: Verify the 130KB minimum memory requirement for ESP32S3

The increase to 130KB for ESP32S3 is notably higher than other variants (ESP32H2: 20KB, ESP32C6: 90KB, Others: 100KB). While this aligns with addressing the memory reduction after IDF 5.2.3 upgrade, we should verify this value.

✅ Verification successful

From the search results, I can see that the memory configuration for ESP32S3 is part of a well-structured memory management system where different ESP32 variants have different minimum memory requirements based on their capabilities and constraints. The increase to 130KB for ESP32S3 is justified by the following findings:

  1. The memory configuration is target-specific with clear progression:

    • ESP32H2: 20KB
    • ESP32C6: 90KB
    • ESP32S3: 130KB
    • Others: 100KB
  2. The value is used as MINIMUM_FREE_MEMORY_FOR_IDF which is the minimum memory needed for IDF (native code) operation.

  3. The implementation includes additional safeguards:

    • Extra memory reservations for BLE (30KB) and Thread (20KB) if enabled
    • Internal RAM allocation considerations with INTERNAL_RAM_LEAVE_FREE_FOR_ALLOCATION
  4. The memory management system has built-in flexibility to handle both SPIRAM and internal RAM scenarios with appropriate fallback mechanisms.

Memory requirement of 130KB for ESP32S3 is appropriate

The increased memory requirement aligns with the IDF 5.2.3 upgrade needs and follows the established pattern of target-specific memory allocations. The implementation includes proper memory management safeguards and fallback mechanisms.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing memory-related tests or configurations specific to ESP32S3
rg -l "ESP32S3.*memory|memory.*ESP32S3" --type cpp --type h

# Look for any related discussions or configurations in build files
rg -l "ESP32S3.*KB|KB.*ESP32S3" --type cmake --type make

Length of output: 120


Script:

#!/bin/bash
# Let's try a broader search for memory configurations in ESP32 targets
rg -l "MINIMUM_FREE_MEMORY_FOR_IDF" --type cpp --type h

# Search for ESP32S3 related configurations
rg "ESP32S3" --type cpp --type h -C 2

# Look for memory-related configurations in ESP32 target
fd Memory.cpp -t f --exec cat {} \;

Length of output: 66178


28-29: Verify memory availability with BLE and Thread features

Since ESP32S3 now requires 130KB minimum free memory, and additional memory is required for BLE (+30KB) and Thread (+20KB) features, we should verify that there's sufficient memory when these features are enabled.

✅ Verification successful

Memory requirements are properly handled for ESP32S3 with BLE and Thread features

The code correctly handles memory requirements by dynamically adding BLE (30KB) and Thread (20KB) memory reserves on top of the base 130KB for ESP32S3. The memory allocation is properly managed through conditional compilation:

  • Base ESP32S3 memory requirement: 130KB
  • Additional for BLE if enabled: +30KB
  • Additional for Thread if enabled: +20KB
  • Maximum total when all features enabled: 180KB

This implementation ensures sufficient memory allocation regardless of which features are enabled.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for BLE and Thread configurations with ESP32S3
rg "CONFIG_IDF_TARGET_ESP32S3.*HAL_USE_BLE|HAL_USE_THREAD" --type cmake --type cpp

# Look for any memory-related test cases combining these features
rg "TEST.*ESP32S3.*(BLE|THREAD)" --type cpp

Length of output: 1566


Script:

#!/bin/bash
# Check for ESP32S3 specific memory configurations and BLE/Thread related memory adjustments
rg "MINIMUM_FREE_MEMORY|HAL_USE_BLE|HAL_USE_THREAD" targets/ESP32/_nanoCLR/Memory.cpp -A 2

# Check for ESP32S3 specific BLE configurations
rg "CONFIG_IDF_TARGET_ESP32S3.*BLE|HAL_USE_BLE.*ESP32S3" --type cmake

# Check for memory configurations in ESP32S3 platform files
fd "ESP32S3" --type f --exec rg "MINIMUM_FREE_MEMORY|CONFIG_SPIRAM|HAL_USE_BLE|HAL_USE_THREAD" {}

Length of output: 804


Script:

#!/bin/bash
# Check for BLE and Thread memory reserve definitions
rg "BLE_EXTRA_IDF_MEMORY_RESERVE|THREAD_EXTRA_IDF_MEMORY_RESERVE" targets/ESP32/

# Check for SPIRAM configurations for ESP32S3
rg "CONFIG_SPIRAM.*ESP32S3|ESP32S3.*SPIRAM" --type cmake

Length of output: 501

@AdrianSoundy
Copy link
Member Author

Simple change just merging

@AdrianSoundy AdrianSoundy merged commit 770af05 into nanoframework:main Dec 12, 2024
18 checks passed
Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

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

@AdrianSoundy considering that we're tweaking this for pretty much all series and that this is deep in the code, I was thinking that this should go back to cmakepresets to expose it and make it adjustable at build time without having to touch the code.

@AdrianSoundy AdrianSoundy deleted the memory_increase branch December 12, 2024 09:38
@AdrianSoundy
Copy link
Member Author

@josesimoes This is just changing the default value for ESP32_S3 running without psram. So really just for the firmware ESP3_S3. The value still can be set in the build if required.

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.

3 participants