• Some questions regarding the RAM size and board definition file for Espruino on ESP32.

    1. 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?

    2. How can I increase the current 2300 blocks of total available RAM?

      >process.memory()
      ={ free: 2259, usage: 41, total: 2300, history: 13,
      gc: 0, gctime: 2.346, blocksize: 16 }
      

      (I tried with reducing ESP_STACK_SIZE from the boards/*.py file and it worked.
      I tried removing BLUETOOTH but build failed with errors)

    3. What does ESP_STACK_SIZE mean in boards/ESP32.py? Is that reserved for function calls in JS code? Is the stack here using the same RAM chunk as the runtime RAM?

  • Answer to question 3:
    Seems ESP_STACK_SIZE is used by xTAskCreatePinnedToCore() in task_init() as an input argument. The function creates a FreeRTOS task to run Espruino, and ESP_STACK_SIZE defines the stack size for the task.

  • 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/iss­ues/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.

  • Try to answer question 2:
    Just realized 2300 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
  • 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.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Total available RAM size on ESP32 and the meaning of `ESP_STACK_SIZE`?

Posted by Avatar for Ragtime @Ragtime

Actions