duktape icon indicating copy to clipboard operation
duktape copied to clipboard

how to configure bare metal compilation within Arduino environment

Open dariosalvi78 opened this issue 5 years ago • 4 comments

Hi,

thanks for this amazing work. I am trying to compile duktape within and Arduino IDE, on an ESP8266 board. I know that there is a duktape on ESP32 project which uses the Espressif SDK, but I am aiming at an Arduino-compatible environment for educational purposes.

I have imported the 3 files duktape.c, duktape.h, and duk_config.h from the release into an Arduino "sketch". The sketch compiles and leaves about 50% of free memory, but when I try to execute a simple hello world JS it crashes. I suspect it's because duktape tries to instantiate too much memory?

I wanted to try to minimise the memory occupancy by using the tips suggested here, but I am not sure how to do it: shall I declare the undef after including duktape.h? Or should I go with the full-fledged process involving configure.py as in here?

Has anyone tried to compile duktape within an Arduino IDE? Any suggestion?

Thanks a lot for your patience!

dariosalvi78 avatar Aug 22 '19 07:08 dariosalvi78

How much memory and flash are you working with?

In general, you should use tools/configure.py to configure Duktape for compilation. It's also possible to edit duk_config.h manually, but it's easier for upgrades etc to use configure.py.

svaarala avatar Aug 22 '19 07:08 svaarala

thanks for the quick answer!

Re. memory, this is what the Arduino IDE tells me at the end of the compilation process (including Arduino libraries and duktape):

Sketch uses 457374 bytes (43%) of program storage space. Maximum is 1044464 bytes. Global variables use 45648 bytes (55%) of dynamic memory, leaving 36272 bytes for local variables. Maximum is 81920 bytes.

I will try to go through your get started as soon as I have some time and will feedback here if I get any interesting result (or non-results).

dariosalvi78 avatar Aug 22 '19 08:08 dariosalvi78

Duktape has been used in some environments with less than 64kB of memory, but that requires use of low memory options (especially "ROM built-ins") and a good, pool-based memory allocator which deals well with small allocations. Program space should not be an issue, but RAM will probably be the challenge.

svaarala avatar Aug 22 '19 08:08 svaarala

One documented starting point is to (on Linux) say:

$ make duk-low-rom
$ ./duk-low-rom

This compiles a low memory optimized Duktape command line for testing. It uses around 2kB when starting up:

$ ./duk-low-rom
[...]
  TOTAL: 1520 bytes used, 0 bytes waste, 259600 bytes free, 261120 bytes total; highwater 0 used, 0 waste
((o) Duktape 2.4.99 (v2.4.0-12-ga92dc709)
duk> 

svaarala avatar Aug 22 '19 08:08 svaarala