-
Notifications
You must be signed in to change notification settings - Fork 7.8k
-
Board
any
Device Description
esp32s3 dev module
Hardware Configuration
no connections except UART0 and power
Version
latest stable Release (if not listed below)
Type
Bug
IDE Name
Arduino IDE
Operating System
Windows 10
Flash frequency
80
PSRAM enabled
yes
Upload speed
115200
Description
class EspClass of Arduino Core (Esp.cpp) has getters for heap size/free size/etc, which for some reason return values of internal memory only. In particular, on my esp32s3 these return values below 300kb, while malloc() can allocate up to 8MB.
Proposed fix is extremely simple:
Replace MALLOC_CAP_INTERNAL with MALLOC_CAP_DEFAULT in functions:
[code]
uint32_t EspClass::getHeapSize(void) {
return heap_caps_get_total_size(MALLOC_CAP_INTERNAL);
}
uint32_t EspClass::getFreeHeap(void) {
return heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
}
uint32_t EspClass::getMinFreeHeap(void) {
return heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL);
}
uint32_t EspClass::getMaxAllocHeap(void) {
return heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL);
}
[/code]
It would be better if we can get real sizes with ::getFreeHeap(). For rare cases when we need to know INTERNAL memory sizes, we can use specific queries, like uint32_t EspClass::getSRAMSize(void)
Sketch
uint32_t size1 = ESP.getHeapSize(); uint32_t size2 = heap_caps_get_total_size(MALLOC_CAP_DEFAULT); if (size2 != size1) Serial.printf("size1=%lu, size2=%lu\r\n",size1,size2)
Debug Message
none
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
There are different reasons why this is so:
- Historically this API shows only internal memory stats
- If you have available PSRAM memory, but no internal one, you are in trouble.
- There are getters for PSRAM stats
- PSRAM used to not be available through malloc
Beta Was this translation helpful? Give feedback.
All reactions
-
But now SPIRAM is available to malloc, so may be it is good idea to update these getters?
How I see this: user calls getter function to query memory size and then calls malloc() or new(). In this case it is safe to replace _INTERNAL to _DEFAULT - getter will return values larger than before so it should not break any existing code.
It is also seems right to hide all these internal/spi/etc things from the class user. If it is heap - it is heap and we should return actual size. For those rare cases when user requires INTERNAL memory (for DMA buffers for example) - he/she will likely use heap_caps_malloc().
Since SPIRAM is under malloc()/MALLOC_CAPS_DEFAULT now, may be it is worth to remove ...Psram() functions entirely, from class ESP: it will make programming more transparent. Users don't have to think about SPI/INTERNAL RAM at all. They just call getHeapSize() or getHeapFreeSize() and then do (or don't) allocations.
Just an opinion.
Beta Was this translation helpful? Give feedback.