-
Notifications
You must be signed in to change notification settings - Fork 13.3k
16KB cache + 48KB IRAM (IRAM) doesn't seem to make extra RAM available #9033
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
Comments
Looking at
I think the exception handling overhead of non-32-bit data accesses to iRAM may play a big role in performance or lack of.
That option does not create a 2nd heap (At least, as it is defined with Arduino IDE). You have 48k of iRAM no/Heap. This was intended for those who just needed a bigger iRAM space for code and did not want any extra code space used for handling a 2nd Heap. |
I did want to have more memory and since the 2nd heap isn't working as stable as I would like, I wanted to try the 48k option, but I don't see more available free memory when this is enabled. So is this option intended to have more available memory? Edit: |
Yes, Assuming they both use the same flash speed, I don't know why they would perform differently,
By "stable" are you referring to performance issues or crashing? |
I did have another look at the
Anyway back to the volatile void *v32 = (void *)((uintptr_t)p8 & ~(uintptr_t)3u); N.B. this is about the idea of using 2nd heap, but if it can be done much simpler by having 48k available then that would be the preferred option. |
I don't see the need unless you use it from an ISR. All references/accesses are in plan view to the compiler.
Okay, I may need to reword some of this. Below is from the Option SummaryThe Arduino IDE Tools menu option,
|
The only thing I could think of why the Sonoff POW r2 may be acting differently is because it does receive a lot of continuous serial data at quite low bitrate of 4800 baud. I don't have the logs/dumps anymore, so I'm not 100% sure what was the reported reboot reason of the Sonoff. What would cause exceptions to be handled by the way? And the reason I was thinking about having the pointer declared volatile was because there is now such an odd direct call to Another thing I did change in the last 2 days in my code is that I try to have the 2nd heap active as short as possible by only activating it in some functions to help move my data or reserve data on the 2nd heap. At least the builds have become quite a bit more stable since I changed this. (even on the non-Sonoff units) About the unclear description:
The 16k cache remark is perfectly clear. |
I installed a 2nd heap build on one of the oldest NodeMCU I have and it also crashes quite often without much to do (nothing accessing the web interface, just some MQTT traffic) |
Did some more testing and also removed the PubSubClient buffer from the 2nd heap as it really only accesses the memory per byte. So I only store arrays of floats in this 2nd heap and large strings. For example No idea if |
Ah it seems like If I'm not mistaken, the iram starts at: #define XCHAL_INSTRAM1_VADDR 0x40100000 So I think the test should be something like this: if ( ((const char *)src >= (const char *)0x40000000) || ((const char *)dest >= (const char *)0x40000000) ) or use the Also there are some left-over |
Hmm quite a lot of functions in xtensa/string_pgmspace.c can be done quite a bit more efficient and also may need some TLC when it comes to 32-bit access.
|
String, byte, and short types rely on the exception handler for accessing IRAM heap data. This consumes an additional 256+ bytes of the stack.
Yes, the Arduino sketch needs to ensure the heap selection in callbacks.
This concern was handled by Arduino/cores/esp8266/mmu_iram.h Lines 183 to 192 in 0301465
The example you referenced is building with the Does this make more sense?
Hmm, the PROGMEM family of functions was written to read from flash/ICACHE not to write to IRAM. So, writing to buf1 is handled through the exception handler. This will be true of all the PROGMEM APIs. These APIs are able to read from PROGMEM or IRAM; however, they will have to rely on the exception handler to write to IRAM. |
Yep, but the Is it OK to try and extend the String class to properly use the 2nd heap and make an PR for it? |
2nd heap works fine here. Maybe you can use it for inspiration: |
It highly depends on the flashchip/ESP module you're using. |
Basic Infos
Platform
Settings in IDE
Tried with these in PlatformIO:
or
PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48
Also tried with these in the build section of the board definition:
Problem Description
The latest version of this ESP8266 Arduino (3.1.2) doesn't leave enough RAM to run stable.
I also spent quite a lot of time on implementing 2nd heap.
This does add some relief to the amount of free RAM, but it seems to depend on the board whether it is usable.
On a Wemos D1 mini board (really old one, so might be one of those "true" Wemos boards) it runs quite OK.
But on a Sonoff POW r2 it runs like what we would say in Dutch: "Like a drunk lad on roller skates".
So I assumed it might have something to do with the extra burden on the flash due to the cache misses?
But using the same
PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
option without actually allocating anything on the 2nd heap, it runs as stable as you can expect with the limited amount of free memory.Therefore I tried to see whether switching to 16k cache and 48k iRAM would be useable, but I don't seem to get any extra free memory.
Found this comment where this user showed an incredible amount of free DRAM.
I used the same
platform_packages
as he did for this post, but I don't seem to get any extra free memory.So what am I doing wrong here?
Or isn't this made available to the normal allocator as this extra memory can perhaps only be addressed with 32-bit alignment?
It would already be a great help if you can store rather static allocated chunks in there like the buffer for MQTT PubSubClient, or a frame buffer for a display.
MCVE Sketch
See: https://community.platformio.org/t/esp8266-mmu-increase-heap/21488/3
The text was updated successfully, but these errors were encountered: