-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
esp32: control the python heap size via NVS variables #6785
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,8 @@ | |
#include "modesp32.h" | ||
|
||
// These private includes are needed for idf_heap_info. | ||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0) | ||
#define MULTI_HEAP_FREERTOS | ||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0) | ||
#define MULTI_HEAP_FREERTOS // see esp-idf/components/heap/component.mk | ||
#include "../multi_heap_platform.h" | ||
#endif | ||
#include "../heap_private.h" | ||
|
@@ -190,6 +190,7 @@ STATIC const mp_rom_map_elem_t esp32_module_globals_table[] = { | |
{ MP_ROM_QSTR(MP_QSTR_Partition), MP_ROM_PTR(&esp32_partition_type) }, | ||
{ MP_ROM_QSTR(MP_QSTR_RMT), MP_ROM_PTR(&esp32_rmt_type) }, | ||
{ MP_ROM_QSTR(MP_QSTR_ULP), MP_ROM_PTR(&esp32_ulp_type) }, | ||
{ MP_ROM_QSTR(MP_QSTR_NVS), MP_ROM_PTR(&esp32_nvs_type) }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
|
||
{ MP_ROM_QSTR(MP_QSTR_WAKEUP_ALL_LOW), MP_ROM_FALSE }, | ||
{ MP_ROM_QSTR(MP_QSTR_WAKEUP_ANY_HIGH), MP_ROM_TRUE }, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,6 @@ extern const mp_obj_type_t esp32_nvs_type; | |
extern const mp_obj_type_t esp32_partition_type; | ||
extern const mp_obj_type_t esp32_rmt_type; | ||
extern const mp_obj_type_t esp32_ulp_type; | ||
extern const mp_obj_type_t esp32_nvs_type; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
|
||
#endif // MICROPY_INCLUDED_ESP32_MODESP32_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Test MicroPython heap limits on the esp32. | ||
# This test requires resetting the device and thus does not simply run in run-tests. | ||
# You can run this test manually using pyboard and hitting ctrl-c after each reset and rerunning | ||
# the script. It will cycle through the various settings. | ||
import gc | ||
import machine | ||
from esp32 import NVS, idf_heap_info, HEAP_DATA | ||
|
||
nvs = NVS("micropython") | ||
try: | ||
min_idf = nvs.get_i32("min_idf_heap") | ||
except OSError: | ||
min_idf = 0 | ||
try: | ||
max_mp = nvs.get_i32("max_mp_heap") | ||
except OSError: | ||
max_mp = None | ||
|
||
mp_total = gc.mem_alloc() + gc.mem_free() | ||
print("MP heap:", mp_total) | ||
idf_free = sum([h[2] for h in idf_heap_info(HEAP_DATA)]) | ||
print("IDF heap free:", idf_free) | ||
|
||
if min_idf == 0: | ||
nvs.set_i32("min_idf_heap", 100000) | ||
nvs.commit() | ||
print("IDF MIN heap changed to 100000") | ||
machine.reset() | ||
elif max_mp is None: | ||
nvs.set_i32("max_mp_heap", 50000) | ||
nvs.commit() | ||
print("MAX heap changed to 50000") | ||
machine.reset() | ||
else: | ||
try: | ||
nvs.erase_key("min_idf_heap") | ||
except OSError: | ||
pass | ||
try: | ||
nvs.erase_key("max_mp_heap") | ||
except OSError: | ||
pass | ||
print("Everything reset to default") | ||
machine.reset() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it should not print anything here. The user can programatically inspect the heap sizes and print their own message if needed.