Initial RAM optimization for ESP8266
by putting big constants into ROM, instead of residing in RAM. Related to https://github.com/Samsung/jerryscript/issues/1224. JerryScript-DCO-1.0-Signed-off-by: Slavey Karadzhov slaff@attachix.com
This commit is contained in:
@@ -30,9 +30,21 @@ ESPTOOL ?= /opt/Espressif/esptool-py/esptool.py
|
||||
|
||||
# compile flags
|
||||
ESP_CFLAGS := -D__TARGET_ESP8266 -D__attr_always_inline___=
|
||||
|
||||
MFORCE32 = `xtensa-lx106-elf-gcc --help=target | grep mforce-l32`
|
||||
|
||||
ifneq ($(MFORCE32),)
|
||||
# Your compiler supports the -mforce-l32 flag which means that
|
||||
# constants can be placed in ROM to free additional RAM
|
||||
ESP_CFLAGS += -DJERRY_CONST_DATA="__attribute__((aligned(4))) __attribute__((section(\".irom.text\")))"
|
||||
endif
|
||||
|
||||
ESP_CFLAGS += -Wl,-EL -fno-inline-functions
|
||||
ESP_CFLAGS += -ffunction-sections -fdata-sections
|
||||
ESP_CFLAGS += -mlongcalls -mtext-section-literals -mno-serialize-volatile
|
||||
ifneq ($(MFORCE32),)
|
||||
ESP_CFLAGS += -mforce-l32
|
||||
endif
|
||||
|
||||
# include path
|
||||
ESP_LIBS_INC :=$(CURDIR)/targets/esp8266/include
|
||||
|
||||
@@ -68,3 +68,46 @@ Sample program here works with LED and a SW with below connection.
|
||||
* Connect GPIO0 between VCC > 4K resistor and GND
|
||||
|
||||
If GPIO0 is High then LED is turned on longer. If L vice versa.
|
||||
|
||||
### 6. Optimizing initial RAM usage (ESP8266 specific)
|
||||
The existing open source gcc compiler with Xtensa support stores const(ants) in
|
||||
the same limited RAM where our code needs to run.
|
||||
|
||||
It is possible to force the compiler to 1)store a constant into ROM and also 2) read it from there thus saving 1.1) RAM.
|
||||
It will require two things though:
|
||||
1. To add the attribute JERRY_CONST_DATA to your constant. For example
|
||||
|
||||
```C
|
||||
static const lit_magic_size_t lit_magic_string_sizes[] =
|
||||
```
|
||||
|
||||
can be modified to
|
||||
|
||||
```C
|
||||
static const lit_magic_size_t lit_magic_string_sizes[] JERRY_CONST_DATA =
|
||||
```
|
||||
|
||||
That is already done to some constants in jerry-core.
|
||||
|
||||
1.1) Below is a short list:
|
||||
|
||||
|
||||
Bytes | Name
|
||||
-------- | ---------
|
||||
928 | magic_strings$2428
|
||||
610 | vm_decode_table
|
||||
424 | unicode_letter_interv_sps
|
||||
235 | cbc_flags
|
||||
232 | lit_magic_string_sizes
|
||||
212 | unicode_letter_interv_len
|
||||
196 | unicode_non_letter_ident_
|
||||
112 | unicode_letter_chars
|
||||
|
||||
Which frees 2949 bytes in RAM.
|
||||
|
||||
2. To compile your code with compiler that supports the `-mforce-l32` parameter. You can check if your compiler is
|
||||
supporting that parameter by calling:
|
||||
```bash
|
||||
xtensa-lx106-elf-gcc --help=target | grep mforce-l32
|
||||
```
|
||||
If the command above does not provide a result then you will need to upgrade your compiler.
|
||||
Reference in New Issue
Block a user