-
• #2
Answer to question 3:
Seems ESP_STACK_SIZE is used byxTAskCreatePinnedToCore()
in task_init() as an input argument. The function creates a FreeRTOS task to run Espruino, andESP_STACK_SIZE
defines the stack size for the task. -
• #3
Try to answer question 1:
Since Espruino creates its task with xTAskCreatePinnedToCore() in task_init(), the available RAM size for Espruino depends on the available DRAM heap which is dynamically allocated from the data RAM (composed of DRAM and I/DRAM in several non-contiguous regions).The available heap for a FreeRTOS task is all of the data RAM which is not statically allocated. https://github.com/espressif/esp-idf/issues/2042#issuecomment-396101249
Since ESP32 has 328 KiB of data RAM, the theoretical maximum DRAM heap for Espruino is 328 KiB. But the stack size needs to be allocated from the heap. Other tasks also take up the data RAM.
In the end, the total available heap (data RAM) for Espruino may be less than 190 KiB if the Bluetooth stack is used. -
• #4
Try to answer question 2:
Just realized2300
is actually the number of JsVars allocated for Espruino. The number is automatically calculated in targets/esp32/main.c based on the available heap - 40000 bytes (I guess it's for the Bluetooth stack?).
So the approaches to increase the number of JsVars (e.g. RAM for Espruino) could be:- remove unused libraries from build to save more heap space (remove that 40000 if Bluetooth stack is removed)
- decrease the ESP_STACK_SIZE to allocate less DRAM heap for Espruino task's stack
- remove unused libraries from build to save more heap space (remove that 40000 if Bluetooth stack is removed)
-
• #5
I ran into the same problem when trying to build a board without the BLUETOOTH module. To fix it, you need to edit the file
make/family/ESP32.make
and add this line after line 10:
SOURCES += targets/esp32/jshardwareESP32.c
.BTW: Removing Bluetooth also reduces power consumption by around 40ma.
-
• #6
Hi.
Were you aware of:
ESP32.enableBLE(disable)
?
It will disable the BLE functionality on the ESP32. It will also erase all your code. But when you restart the board, it should give you an additional 2K JSVars, so around 4K JSVars total. You can then reflash your program and take advantage of the additional memory space.
Additionally, if you get a board with PSRAM (4MB or 8MB), it will give you up to another 16K JSVars, which will bring your total up to 20K.
-hfc
-
• #7
@hungryforcodes - I did exactly as you suggest - actually I removed the BLUETOOTH module entirely - for Espruino on the TWATCH. See
https://github.com/jeffmer/Twatch_Espruino
. -
• #8
Wow, that's really impressive! I had been thinking of throwing up a github just like that for the TTGO Watch 2020. You've ever got the unbuffered frame buffer modification for the ST7789V. I'll have a deeper look at this. :)
Some questions regarding the RAM size and board definition file for Espruino on ESP32.
What is the theoretical maximum number of the available RAM for Espruino on ESP32? Since ESP32's RAM is not contiguous, is Espruino taking up only one of the chunks? Is that configurable somewhere?
How can I increase the current
2300
blocks of total available RAM?(I tried with reducing
ESP_STACK_SIZE
from theboards/*.py
file and it worked.I tried removing
BLUETOOTH
but build failed with errors)What does
ESP_STACK_SIZE
mean inboards/ESP32.py
? Is that reserved for function calls in JS code? Is the stack here using the same RAM chunk as the runtime RAM?