Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve memory exhaustion warnings/errors #4886

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

Sophist-UK
Copy link

Firmware typically pre-allocates RAM memory where it can, and then remaining memory is used for dynamic allocation and the stack.

Currently excessive RAM usage is only a warning and not an error, which means that you are not alerted by a build failure but instead need to scan the PIO RUN output to see whether RAM usage is too high for the build. But in any case, typically firmware requires a certain amount of RAM to be available after the pre-allocation that is calculated by PIO, and you need to alerted when the remaining memory falls below this required free-memory amount.

This PR does two things:

  1. RAM pre-allocation greater than available memory is now treated as an error and not a warning.
  2. It introduces a RAMFREE option that can be used to define a minimum amount of memory required to remain free (for dynamic allocation and stack usage) after pre-allocation, with an error if pre-allocation results in less than this amount free.

@CLAassistant
Copy link

CLAassistant commented Mar 26, 2024

CLA assistant check
All committers have signed the CLA.

@Sophist-UK
Copy link
Author

P.S. This simple PR has been coded on Github and I have not tested it. Sorry - but I don't have the skills or time to create a local dev environment and test it.

@ivankravets
Copy link
Member

ivankravets commented Mar 26, 2024

ram_free

You can override this value via board_upload.maximum_ram_size (RAM) and board_upload.maximum_size (Flash)

@Sophist-UK
Copy link
Author

Sophist-UK commented Mar 26, 2024

@ivankravets said:

You can override this value via board_upload_maximum_ram_size (RAM)

  1. I am not sure how to provide this. In the platformio.ini [env] section?
  2. Since I have automated builds for a couple of different boards with different amounts of memory from the same source code, if I am specifying maximum ram size I need to be able to set this dynamicaly - any advice here would also be useful.

(P.S. Flash is all or nothing - it is RAM which is more nuanced.)

@Sophist-UK
Copy link
Author

In the platformio.ini [env] section?

I tried this and it didn't work.

@ivankravets
Copy link
Member

Could you provide your INI file on how you declared these lines?

@Sophist-UK
Copy link
Author

platformio.ini.txt

@ivankravets
Copy link
Member

Sorry, this is a my typo. See updated #4886 (comment)

The JSON path must be split with . dot. https://github.com/platformio/platform-atmelavr/blob/develop/boards/megaatmega2560.json#L33

@Sophist-UK
Copy link
Author

Sophist-UK commented Mar 26, 2024

@ivankravets I tried the dotted parameter name in the same place in the ini file and it didn't reduce the target ram size from 8k to 6.5K as it should have. Sorry.

The documentation page is here and it says exactly what you suggested, so it should have worked. {Sigh}

Edit: I moved it from a sub-[env] section to the main [env] section and it worked. 👍 Thanks for pointing this out and helping me get there.

However whilst it is a potential second class alternative, it does not meet the use case of this PR.

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

Successfully merging this pull request may close these issues.

None yet

3 participants