Hallo,
I switched from Arduino IDE to PlatformIO a half year ago. PlatformIO is a great product. I was able to structure my code for my ESP8266 and ESP32’s in a way that wasn’t possible with Arduino IDE.
Also the compilations are very fast and gives me a lot more control.
Hence I have a question. I want to increase the heap, to try to use the bear ssl client with a extensive code for my esp8266. I run a standard webserver in the esp and some advances features for processing sensors, actuators etc.
But for using a ssl client to communicate securely to my domotic solution, I run out of heap.
In the arduino IDE there is a option, to customise the memory allocation, but I can’t find the way to do that with PlatformIO.
See: PoC cache configuration control by mhightower83 · Pull Request #7060 · esp8266/Arduino · GitHub
Is there a way to do this in platform IO?
First of all, as someone who worked with an ESP8266 + TLS, connecting to some TLS websites is just impossible if they use big certificate chains and inefficient algorithms like RSA instead of ECC-based stuff, even if you have a little bit more memory, they’d need a lot more memory – some things are just out of reach for an ESP8266.
Second of all, the MMU feature is only available in the new 3.0.0 core for which PlatformIO doesn’t yet built-in support, see Arduino Core 3.0, when?. However, with certatin configuration options as outlined in this thread, it’s possible to get the 3.0.0 version.
Further if I read
correctly then the different MMU / heap options just boil down to adding a few macros to the build process, which we can do as well using build_flags
.
So if you want the e.g. the 16KB cache + 48KB IRAM and 2nd Heap (shared)
option, you would add the corresponding mmuflags
as
build_flags = -DMMU_IRAM_SIZE=0xC000 -DMMU_ICACHE_SIZE=0x4000 -DMMU_IRAM_HEAP
to the platformio.ini
.
I have not tested this at the moment.
The MMU options would be documented in Espressif 8266 — PlatformIO latest documentation but aren’t now; this is because PlatformIO officially supports only up to core version 2.7.4 and not the new 3.0.0 as of now. If PlatformIO updates, those options should be added.
1 Like
Yes that definitely works. If I do
[env:esp8266]
platform = espressif8266
board = nodemcuv2
framework = arduino
platform_packages =
framework-arduinoespressif8266@https://github.com/esp8266/Arduino.git#3.0.0
mcspr/toolchain-xtensa@~5.100200.0
build_flags = -DMMU_IRAM_SIZE=0xC000 -DMMU_ICACHE_SIZE=0x4000 -DMMU_IRAM_HEAP
monitor_speed = 74880
upload_speed = 921600
with code
#include <Arduino.h>
#include <umm_malloc/umm_heap_select.h>
void setup()
{
Serial.begin(74880);
HeapSelectIram ephemeral;
Serial.printf("IRAM free: %6d bytes\r\n", ESP.getFreeHeap());
{
HeapSelectDram ephemeral;
Serial.printf("DRAM free: %6d bytes\r\n", ESP.getFreeHeap());
}
}
void loop() {
// put your main code here, to run repeatedly:
}
I get
IRAM free: 21592 bytes
DRAM free: 52336 bytes
^~^ so the options are totally usable.
As you can see in here they also already updated the platformio-build.py
script for PlatformIO integration.
1 Like
Your solution works like charm. Thanks.
Great to hear, just keep a watch on Update core to 3.0.0 · Issue #249 · platformio/platform-espressif8266 · GitHub and Releases · platformio/platform-espressif8266 · GitHub for when an official update for platform-espressif8266 is released; then you should use that via a normal update (PIO Home → Platforms → Update) instead of platform_packages
modifications above.