Merge esp8266-rtos-sdk and esp-idf targets (#4958)

This patch bumps esp8266-rtos-sdk to the latest release. This required to
modify the directory structure and the build system to conform to ESP-IDF
Style. Since esp-idf target already supports ESP-IDF Style, the espressif
targets has been merged to eliminate code duplication.
The target application code has been modified from blinking leds to hello
world to be aligned to other targets.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs roland.takacs@h-lab.eu
This commit is contained in:
Roland Takacs
2022-02-22 10:58:18 +01:00
committed by GitHub
parent c9e9f8e818
commit 0d49696618
28 changed files with 495 additions and 1361 deletions
+14 -4
View File
@@ -271,15 +271,25 @@ jobs:
- run: make -f ./targets/os/riot/Makefile.travis install-noapt
- run: make -f ./targets/os/riot/Makefile.travis script
ESP8266_Build_Test:
ESP8266_RTOS_SDK_Build_Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '2.7' # needed due to ESP8266_RTOS_SDK/tools/gen_appbin.py
- run: make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.travis install-noapt
- run: make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.travis script
python-version: '3.8'
- run: make -f ./targets/baremetal-sdk/espressif/esp8266-rtos-sdk/Makefile.travis install-noapt
- run: make -f ./targets/baremetal-sdk/espressif/esp8266-rtos-sdk/Makefile.travis script
ESP_IDF_Build_Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
- run: make -f ./targets/baremetal-sdk/espressif/esp-idf/Makefile.travis install-noapt
- run: make -f ./targets/baremetal-sdk/espressif/esp-idf/Makefile.travis script
Notification:
runs-on: ubuntu-latest
@@ -1,16 +0,0 @@
# assumes there is a component with this the following
# - set the JERRY_DIR wherever the jerryscript source code (the include files) is
# - a "lib" directory with the 2 libraries below
set(JERRY_DIR ${PROJECT_DIR}/../../../jerryscript/)
idf_component_register(
SRC_DIRS ${JERRY_DIR}/targets/baremetal-sdk/esp-idf
INCLUDE_DIRS ${JERRY_DIR}/jerry-core/include ${JERRY_DIR}/jerry-ext/include
)
add_prebuilt_library(libjerry-core lib/libjerry-core.a REQUIRES newlib PRIV_REQUIRES ${COMPONENT_NAME})
add_prebuilt_library(libjerry-ext lib/libjerry-ext.a PRIV_REQUIRES ${COMPONENT_NAME})
target_link_libraries(${COMPONENT_LIB} INTERFACE libjerry-core)
target_link_libraries(${COMPONENT_LIB} INTERFACE libjerry-ext)
-28
View File
@@ -1,28 +0,0 @@
This is a port for espressif's esp-idf (esp32). The MATH, LTO and STRIP options should be disabled, so to build under the IDF toolchain, just run the following command
```
python tools\build.py --toolchain=cmake/toolchain-esp32.cmake --cmake-param "-GUnix Makefiles" --jerry-cmdline=OFF --jerry-port=OFF --lto=OFF --strip=OFF
```
NB: the MATH, STRIP and LTO might be disabled by platform as well. I strongly suggest limiting heap memory with '--mem-heap=128' but that really depends on the SRAM available on your esp32.
Then copy the artifacts 'build/lib/\*.a' in an esp-idf component named 'jerryscript' (eg) and use a 'CMakeLists.txt' like this one
```
# assumes there is a component with this the following
# - set the JERRY_DIR wherever the jerryscript source code (the include files) is
# - a "lib" directory with the 2 libraries below
set(JERRY_DIR ${PROJECT_DIR}/../../jerryscript/)
idf_component_register(
SRC_DIRS ${JERRY_DIR}/targets/baremetal-sdk/esp-idf
INCLUDE_DIRS ${JERRY_DIR}/jerry-core/include ${JERRY_DIR}/jerry-ext/include
)
add_prebuilt_library(libjerry-core lib/libjerry-core.a REQUIRES newlib PRIV_REQUIRES ${COMPONENT_NAME})
add_prebuilt_library(libjerry-ext lib/libjerry-ext.a PRIV_REQUIRES ${COMPONENT_NAME})
target_link_libraries(${COMPONENT_LIB} INTERFACE libjerry-core)
target_link_libraries(${COMPONENT_LIB} INTERFACE libjerry-ext)
```
@@ -1,56 +0,0 @@
Copyright 2015 Samsung Electronics Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================================================
ESPRSSIF MIT License
Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
it is free of charge, to any person obtaining a copy of this software and associated
documentation files (the ¡°Software¡±), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED ¡°AS IS¡±, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
ÀÖöÎ MIT Ðí¿ÉÖ¤
°æÈ¨ (c) 2015 <ÀÖöÎÐÅÏ¢¿Æ¼¼£¨ÉϺ££©ÓÐÏÞ¹«Ë¾>
¸ÃÐí¿ÉÖ¤ÊÚȨ½öÏÞÓÚÀÖöÎÐÅÏ¢¿Æ¼¼ ESP8266 ²úÆ·µÄÓ¦Óÿª·¢¡£ÔÚ´ËÇé¿öÏ£¬¸ÃÐí¿ÉÖ¤Ãâ·ÑÊÚȨÈκλñµÃ¸Ã
Èí¼þ¼°ÆäÏà¹ØÎĵµ£¨Í³³ÆÎª¡°Èí¼þ¡±£©µÄÈËÎÞÏÞÖÆµØ¾­Óª¸ÃÈí¼þ£¬°üÀ¨ÎÞÏÞÖÆµÄʹÓᢸ´ÖÆ¡¢Ð޸ġ¢ºÏ²¢¡¢
³ö°æ·¢ÐС¢É¢²¼¡¢ÔÙÊÚȨ¡¢¼°··ÊÛÈí¼þ¼°Èí¼þ¸±±¾µÄȨÀû¡£±»ÊÚȨÈËÔÚÏíÊÜÕâЩȨÀûµÄͬʱ£¬Ðè·þ´ÓÏÂÃæ
µÄÌõ¼þ£º
ÔÚÈí¼þºÍÈí¼þµÄËùÓи±±¾Öж¼±ØÐë°üº¬ÒÔÉϵİæÈ¨ÉùÃ÷ºÍÊÚȨÉùÃ÷¡£
¸ÃÈí¼þ°´±¾À´µÄÑù×ÓÌṩ£¬Ã»ÓÐÈκÎÃ÷È·»ò°µº¬µÄµ£±££¬°üÀ¨µ«²»½öÏÞÓÚ¹ØÓÚÊÔÏúÐÔ¡¢ÊʺÏÄ³Ò»ÌØ¶¨ÓÃ;
ºÍ·ÇÇÖȨµÄ±£Ö¤¡£×÷ÕߺͰæÈ¨³ÖÓÐÈËÔÚÈκÎÇé¿öϾù²»¾ÍÓÉÈí¼þ»òÈí¼þʹÓÃÒýÆðµÄÒÔºÏͬÐÎʽ¡¢ÃñÊÂÇÖȨ
»òÆäËü·½Ê½Ìá³öµÄÈκÎË÷Åâ¡¢Ë𺦻òÆäËüÔðÈθºÔð¡£
@@ -1,162 +0,0 @@
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of object file images to be generated ()
# GEN_BINS - list of binaries to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
# Tabsize : 8
#
TARGET = eagle
FLAVOR = release
#FLAVOR = debug
#EXTRA_CCFLAGS += -u
ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out
GEN_BINS= eagle.app.v6.bin
SPECIAL_MKTARGETS=$(APP_MKTARGETS)
SUBDIRS= user
endif # } PDIR
# path to the JERRYSCRIPT directory
JERRYDIR ?= $(CURDIR)/../../../..
LDDIR = $(SDK_PATH)/ld
#############################################################
# JerryScript requires a modified linker script with specified alignments
# so we use it instead of the original one from SDK.
JERRY_LD_FILE = $(CURDIR)/ld/eagle.app.v6.ld
CCFLAGS += -Os -std=c99
#CCFLAGS += -O0
TARGET_LDFLAGS = \
-nostdlib \
-Wl,-EL \
--longcalls \
--text-section-literals
ifeq ($(FLAVOR),debug)
TARGET_LDFLAGS += -O0 -g
endif
ifeq ($(FLAVOR),release)
TARGET_LDFLAGS += -Os
endif
COMPONENTS_eagle.app.v6 = \
user/libuser.a
LINKFLAGS_eagle.app.v6 = \
-L$(SDK_PATH)/lib \
-Wl,--gc-sections \
-Wl,-Map,output.map \
-nostdlib \
-T$(JERRY_LD_FILE) \
-Wl,--no-check-sections \
-u call_user_start \
-Wl,-static \
-Wl,--start-group \
-lcirom \
-lcrypto \
-lespconn \
-lespnow \
-lfreertos \
-lgcc \
-lhal \
-ljson \
-llwip \
-ldriver \
-lmain \
-lmirom \
-lnet80211 \
-lnopoll \
-lphy \
-lpp \
-lpwm \
-lsmartconfig \
-lspiffs \
-lssl \
-lwpa \
-lwps \
-L./libs \
-ljerry-core \
-ljerry-math \
$(DEP_LIBS_eagle.app.v6) \
-Wl,--end-group
DEPENDS_eagle.app.v6 = \
$(JERRY_LD_FILE) \
$(LDDIR)/eagle.rom.addr.v6.ld \
./include/jerry-targetjs.h \
./libs/libjerry-core.a \
./libs/libjerry-math.a
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#UNIVERSAL_TARGET_DEFINES = \
# Other potential configuration flags include:
# -DTXRX_TXBUF_DEBUG
# -DTXRX_RXBUF_DEBUG
# -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES = -DICACHE_FLASH
DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
DDEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := -I $(JERRYDIR)/jerry-core/include
INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)source
sinclude $(SDK_PATH)/Makefile
.PHONY: FORCE
FORCE:
@@ -1,88 +0,0 @@
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
CURDIR = `pwd`
ESP_LIB = $(SDK_PATH)/lib
BUILD_DIR = build/obj-esp8266
COPYTARGET = targets/baremetal-sdk/esp8266-rtos-sdk/libs
USBDEVICE ?= /dev/ttyUSB0
JERRYHEAP ?= 20
ESPTOOL ?= $(ESPTOOL_PATH)/esptool.py
# compile flags
ESP_CFLAGS := -D__TARGET_ESP8266 -D__attr_always_inline___=
MFORCE32 = $(shell 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_ATTR_CONST_DATA="__attribute__((aligned(4))) __attribute__((section(\".irom.text\")))"
ESP_CFLAGS += -mforce-l32
endif
ESP_CFLAGS += -Wl,-EL -fno-inline-functions
ESP_CFLAGS += -ffunction-sections -fdata-sections
ESP_CFLAGS += -mlongcalls -mtext-section-literals -mno-serialize-volatile
.PHONY: jerry js2c mkbin check-env flash clean
all: check-env jerry js2c mkbin
jerry:
mkdir -p $(BUILD_DIR)
mkdir -p $(COPYTARGET)
cmake -B$(BUILD_DIR) -H./ \
-DCMAKE_SYSTEM_NAME=MCU \
-DCMAKE_SYSTEM_PROCESSOR=xtensia-lx106 \
-DCMAKE_C_COMPILER=xtensa-lx106-elf-gcc \
-DCMAKE_C_COMPILER_WORKS=TRUE \
-DENABLE_LTO=OFF \
-DENABLE_AMALGAM=ON \
-DJERRY_MATH=ON \
-DJERRY_CMDLINE=OFF \
-DEXTERNAL_COMPILE_FLAGS="$(ESP_CFLAGS)" \
-DJERRY_GLOBAL_HEAP_SIZE=$(JERRYHEAP)
make -C$(BUILD_DIR) jerry-core jerry-ext jerry-math
cp $(BUILD_DIR)/lib/libjerry-core.a $(COPYTARGET)/
cp $(BUILD_DIR)/lib/libjerry-ext.a $(COPYTARGET)/
cp $(BUILD_DIR)/lib/libjerry-math.a $(COPYTARGET)/
js2c:
tools/js2c.py --dest targets/baremetal-sdk/esp8266-rtos-sdk/include --js-source targets/baremetal-sdk/esp8266-rtos-sdk/js
mkbin:
make -Ctargets/baremetal-sdk/esp8266-rtos-sdk clean
make -Ctargets/baremetal-sdk/esp8266-rtos-sdk BOOT=new APP=0 SPI_SPEED=40 SPI_MODE=DIO SPI_SIZE_MAP=4
check-env:
ifndef SDK_PATH
$(error SDK_PATH is undefined for ESP8266)
endif
ifndef BIN_PATH
$(error BIN_PATH is undefined for ESP8266)
endif
flash:
$(ESPTOOL) --port $(USBDEVICE) write_flash \
0x00000 $(BIN_PATH)/eagle.flash.bin \
0x20000 $(BIN_PATH)/eagle.irom0text.bin \
0x3FC000 $(SDK_PATH)/bin/esp_init_data_default.bin
erase_flash:
$(ESPTOOL) --port $(USBDEVICE) erase_flash
clean:
rm -rf $(BUILD_DIR)
@@ -1,120 +0,0 @@
#### Preparation
##### Accessories
You need,
* 3.3V power supply. You can use bread board power (+5V, +3.3V). I used LM317 like this;
* Use [LM317](http://www.ti.com/lit/ds/symlink/lm317.pdf)
* R1 = 330 Ohm, R2 = 545 Ohm (1K + 1.2K in parallel)
* 5V 2A adaptor
* USB to RS-232 Serial + RS-232 Serial to Digital or USB-to-RS232 TTL converter
#### Tools
The rest of this document will assume that you download all necessary tools into
a common directory structure. For the sake of simplicity, `$HOME/Espressif` will
be used as the root of this structure. Feel free to deviate from this but then
adapt all the paths accordingly.
```
mkdir $HOME/Espressif
```
##### Toolchain
Download the [toolchain](https://github.com/espressif/ESP8266_RTOS_SDK/tree/v3.0.1#get-toolchain)
pre-built for your development platform to `$HOME/Espressif` and untar it. E.g.,
on Linux/x86-64:
```
cd $HOME/Espressif
tar xvfz xtensa-lx106-elf-linux64-1.22.0-88-gde0bdc1-4.8.5.tar.gz
```
##### Espressif SDK: use Espressif official
```
cd $HOME/Esprissif
git clone https://github.com/espressif/ESP8266_RTOS_SDK.git -b v2.1.0
```
This version is tested and works properly.
##### ESP image tool
```
cd $HOME/Espressif
wget -O esptool_0.0.2-1_i386.deb https://github.com/esp8266/esp8266-wiki/raw/master/deb/esptool_0.0.2-1_i386.deb
sudo dpkg -i esptool_0.0.2-1_i386.deb
```
##### ESP upload tool
```
cd $HOME/Espressif
git clone https://github.com/themadinventor/esptool
```
##### Set environment variables
Set environment variables, might also go in your `.profile`:
```
export PATH=$HOME/Espressif/xtensa-lx106-elf/bin:$PATH
export SDK_PATH=$HOME/Espressif/ESP8266_RTOS_SDK
export ESPTOOL_PATH=$HOME/Espressif/esptool
export BIN_PATH=(to output folder path)
```
#### Test writing with Blinky example
##### Get the source
found one example that works with SDK V1.2 (which is based on FreeRTOS, as of writing)
* https://github.com/mattcallow/esp8266-sdk/tree/master/rtos_apps/01blinky
##### Compile
Read `2A-ESP8266__IOT_SDK_User_Manual_EN` document in
[this](http://bbs.espressif.com/viewtopic.php?f=51&t=1024) link.
It's configured 2048KB flash
```
BOOT=new APP=1 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=5 make
BOOT=new APP=2 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=5 make
```
or old way... this works not sure this is ok.
```
make BOOT=new APP=0 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=2
```
##### Flashing
* power off ESP8266 board
* connect GPIO0 to GND, connect GPIO2 to VCC
* power on
* write
```
sudo $HOME/Espressif/esptool/esptool.py \
--port /dev/ttyUSB0 write_flash \
0x00000 $SDK_PATH/bin/"boot_v1.7.bin" \
0x01000 $BIN_PATH/upgrade/user1.2048.new.5.bin \
0x101000 $BIN_PATH/upgrade/user2.2048.new.5.bin \
0x3FE000 $SDK_PATH/bin/blank.bin \
0x3FC000 $SDK_PATH/bin/esp_init_data_default.bin
```
_change `/dev/ttyUSB1` to whatever you have._
or the old way...this works not sure this is ok.
```
cd $BIN_PATH
sudo $HOME/Espressif/esptool/esptool.py \
--port /dev/ttyUSB0 write_flash \
0x00000 eagle.flash.bin 0x40000 eagle.irom0text.bin
```
* power off
* disconnect GPIO0 so that it is floating
* connect GPIO2 with serial of 470 Ohm + LED and to GND
* power On
@@ -1,30 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __JERRY_EXTAPI_H__
#define __JERRY_EXTAPI_H__
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
#include "jerryscript.h"
JERRY_C_API_BEGIN
void js_register_functions (void);
JERRY_C_API_END
#endif /* __JERRY_EXTAPI_H__ */
@@ -1,32 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __JERRY_RUN_H__
#define __JERRY_RUN_H__
#include <stdint.h>
#include "jerryscript.h"
JERRY_C_API_BEGIN
void js_entry (void);
int js_eval (const char *source_p, const size_t source_size);
int js_loop (uint32_t ticknow);
void js_exit (void);
JERRY_C_API_END
#endif /* __JERRY_RUN_H__ */
@@ -1,24 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __USER_CONFIG_H__
#define __USER_CONFIG_H__
/* number of stack items, x4 for bytes */
#define JERRY_STACK_SIZE 2000
#endif /* __USER_CONFIG_H__ */
@@ -1,30 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var check = 1;
function blink() {
var inp = gpio_get(0);
var blk = (check > 8) ? 1 - inp : inp;
gpio_set(2, blk);
check = check >= 10 ? 1 : check+1;
}
// GPIO 0 as input
// GPIO 2 as output
gpio_dir(0, 0);
gpio_dir(2, 1);
print("blink js OK");
@@ -1,20 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function sysloop(ticknow) {
blink();
};
print("Random generated number: ", Math.random());
print("main js OK");
@@ -1,32 +0,0 @@
/* eagle.flash.bin @ 0x00000 */
/* eagle.irom0text.bin @ 0x20000 */
/* Flash Map, support 512KB/1MB/2MB/4MB SPI Flash */
/* |......|..............................|..........................|.....|....| */
/* ^ ^ ^ ^ ^ */
/* |_flash.bin start(0x00000) |_irom0text.bin start(0x20000) | */
/* |_flash.bin end |_irom0text.bin end */
/* |_system param area(0x7b000) */
/* NOTICE: */
/* 1. You can change irom0 org, but MUST make sure irom0text.bin start not overlap flash.bin end. */
/* 2. You can change irom0 len, but MUST make sure irom0text.bin end not overlap system param area. */
/* 3. Space between flash.bin end and irom0text.bin start can be used as user param area. */
/* 4. Space between irom0text.bin end and system param area can be used as user param area. */
/* 5. Make sure irom0text.bin end < 0x100000 */
/* 6. system param area: */
/* 1>. 512KB--->0x07b000 */
/* 2>. 1MB----->0x0fb000 */
/* 3>. 2MB----->0x1fb000 */
/* 4>. 4MB----->0x3fb000 */
/* 7. Don't change any other seg. */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x18000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40220000, len = 0xBC000
}
INCLUDE ../ld/eagle.app.v6.common.ld
@@ -1,88 +0,0 @@
### About
Files in this folder (targets/baremetal-sdk/esp8266-rtos-sdk) are copied from
`examples/project_template` of `esp_iot_rtos_sdk` and modified for JerryScript.
You can view online from
[this](https://github.com/espressif/esp_iot_rtos_sdk/tree/master/examples/project_template) page.
### How to build JerryScript for ESP8266
#### 1. SDK
Follow [this](./docs/ESP-PREREQUISITES.md) page to setup build environment
#### 2. Building JerryScript
```
# assume you are in jerryscript folder
make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266
```
Output files should be placed at $BIN_PATH
#### 3. Flashing for ESP8266 12E
Follow
[this](http://www.kloppenborg.net/images/blog/esp8266/esp8266-esp12e-specs.pdf) page to get details about this board.
```
make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 flash
```
Default USB device is `/dev/ttyUSB0`. If you have different one, give with `USBDEVICE`, like;
```
USBDEVICE=/dev/ttyUSB1 make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 flash
```
### 4. Running
* power off
* connect GPIO2 with serial of 470 Ohm + LED and to GND
* power On
LED should blink on and off every second
#### 5. Cleaning
To clean the build result:
```
make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 clean
```
To clean the board's flash memory:
```
make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 erase_flash
```
### 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 store a constant into ROM and also read it from there thus saving RAM.
The only requirement is to add `JERRY_ATTR_CONST_DATA` attribute 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_ATTR_CONST_DATA =
```
That is already done to some constants in jerry-core. E.g.:
- vm_decode_table
- ecma_property_hashmap_steps
- lit_magic_string_sizes
- unicode_letter_interv_sps
- unicode_letter_interv_len
- unicode_non_letter_ident_
- unicode_letter_chars
@@ -1,44 +0,0 @@
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = libuser.a
endif
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
@@ -1,182 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jerry_extapi.h"
#include <stdio.h>
#include <stdlib.h>
#include "jerryscript.h"
#include "c_types.h"
#include "gpio.h"
#define __UNUSED__ __attribute__ ((unused))
#define DELCARE_HANDLER(NAME) \
static jerry_value_t NAME##_handler (const jerry_call_info_t *call_info_p __UNUSED__, \
const jerry_value_t args_p[], \
const jerry_length_t args_cnt)
#define REGISTER_HANDLER(NAME) register_native_function (#NAME, NAME##_handler)
DELCARE_HANDLER (assert)
{
if (args_cnt == 1 && jerry_value_is_true (args_p[0]))
{
printf (">> Jerry assert true\r\n");
return jerry_boolean (true);
}
printf ("Script assertion failed\n");
exit (JERRY_STANDALONE_EXIT_CODE_FAIL);
return jerry_boolean (false);
} /* assert */
DELCARE_HANDLER (print)
{
if (args_cnt)
{
for (jerry_length_t cc = 0; cc < args_cnt; cc++)
{
if (jerry_value_is_string (args_p[cc]))
{
jerry_size_t size = jerry_string_size (args_p[0], JERRY_ENCODING_UTF8);
char *buffer;
buffer = (char *) malloc (size + 1);
if (!buffer)
{
// not enough memory for this string.
printf ("[<too-long-string>]");
continue;
}
jerry_string_to_buffer (args_p[cc], JERRY_ENCODING_UTF8, (jerry_char_t *) buffer, size);
buffer[size] = '\0';
printf ("%s ", buffer);
free (buffer);
}
else if (jerry_value_is_number (args_p[cc]))
{
double number = jerry_value_as_number (args_p[cc]);
if ((int) number == number)
{
printf ("%d", (int) number);
}
else
{
char buff[50];
sprintf (buff, "%.10f", number);
printf ("%s", buff);
}
}
}
printf ("\r\n");
}
return jerry_boolean (true);
} /* print */
DELCARE_HANDLER (gpio_dir)
{
if (args_cnt < 2)
{
return jerry_boolean (false);
}
int port = (int) jerry_value_as_number (args_p[0]);
int value = (int) jerry_value_as_number (args_p[1]);
if (value)
{
GPIO_AS_OUTPUT (1 << port);
}
else
{
GPIO_AS_INPUT (1 << port);
}
return jerry_boolean (true);
} /* gpio_dir */
DELCARE_HANDLER (gpio_set)
{
if (args_cnt < 2)
{
return jerry_boolean (false);
}
int port = (int) jerry_value_as_number (args_p[0]);
int value = (int) jerry_value_as_number (args_p[1]);
GPIO_OUTPUT_SET (port, value);
return jerry_boolean (true);
} /* gpio_set */
DELCARE_HANDLER (gpio_get)
{
if (args_cnt < 1)
{
return jerry_boolean (false);
}
int port = (int) jerry_value_as_number (args_p[0]);
int value = GPIO_INPUT_GET (port) ? 1 : 0;
return jerry_number ((double) value);
} /* gpio_get */
static bool
register_native_function (const char *name, jerry_external_handler_t handler)
{
jerry_value_t global_obj_val = jerry_current_realm ();
jerry_value_t reg_func_val = jerry_function_external (handler);
if (!(jerry_value_is_function (reg_func_val) && jerry_value_is_constructor (reg_func_val)))
{
printf ("!!! create_external_function failed !!!\r\n");
jerry_value_free (reg_func_val);
jerry_value_free (global_obj_val);
return false;
}
jerry_value_t prop_name_val = jerry_string_sz (name);
jerry_value_t res = jerry_object_set (global_obj_val, prop_name_val, reg_func_val);
jerry_value_free (reg_func_val);
jerry_value_free (global_obj_val);
jerry_value_free (prop_name_val);
if (jerry_value_is_exception (res))
{
printf ("!!! register_native_function failed: [%s]\r\n", name);
jerry_value_free (res);
return false;
}
jerry_value_free (res);
return true;
} /* register_native_function */
void
js_register_functions (void)
{
REGISTER_HANDLER (assert);
REGISTER_HANDLER (print);
REGISTER_HANDLER (gpio_dir);
REGISTER_HANDLER (gpio_set);
REGISTER_HANDLER (gpio_get);
} /* js_register_functions */
@@ -1,72 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdarg.h>
#include <stdio.h>
#include <sys/time.h>
#include "jerryscript-port.h"
#include "esp_common.h"
/**
* Provide log message implementation for the engine.
*/
void
jerry_port_log (const char *message_p) /**< message */
{
fputs (message_p, stderr);
} /* jerry_port_log */
/**
* Provide fatal message implementation for the engine.
*/
void
jerry_port_fatal (jerry_fatal_code_t code)
{
(void) code;
jerry_port_log ("Jerry Fatal Error!\n");
while (true)
{
}
} /* jerry_port_fatal */
/**
* Implementation of jerry_port_current_time.
*
* @return current timer's counter value in milliseconds
*/
double
jerry_port_current_time (void)
{
uint32_t rtc_time = system_rtc_clock_cali_proc ();
return (double) rtc_time;
} /* jerry_port_current_time */
/**
* Dummy function to get the time zone adjustment.
*
* @return 0
*/
int32_t
jerry_port_local_tza (double unix_ms)
{
(void) unix_ms;
/* We live in UTC. */
return 0;
} /* jerry_port_local_tza */
@@ -1,109 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jerry_run.h"
#include <stdio.h>
#include <stdlib.h>
#include "jerryscript-port.h"
#include "jerryscript.h"
#include "jerry_extapi.h"
static const char *fn_sys_loop_name = "sysloop";
void
js_entry ()
{
union
{
double d;
unsigned u;
} now = { .d = jerry_port_current_time () };
srand (now.u);
jerry_init (JERRY_INIT_EMPTY);
js_register_functions ();
}
int
js_eval (const char *source_p, const size_t source_size)
{
jerry_value_t res = jerry_eval ((jerry_char_t *) source_p, source_size, JERRY_PARSE_NO_OPTS);
if (jerry_value_is_exception (res))
{
jerry_value_free (res);
return -1;
}
jerry_value_free (res);
return 0;
}
int
js_loop (uint32_t ticknow)
{
jerry_value_t global_obj_val = jerry_current_realm ();
jerry_value_t prop_name_val = jerry_string_sz (fn_sys_loop_name);
jerry_value_t sysloop_func = jerry_object_get (global_obj_val, prop_name_val);
jerry_value_free (prop_name_val);
if (jerry_value_is_exception (sysloop_func))
{
printf ("Error: '%s' not defined!!!\r\n", fn_sys_loop_name);
jerry_value_free (sysloop_func);
jerry_value_free (global_obj_val);
return -1;
}
if (!jerry_value_is_function (sysloop_func))
{
printf ("Error: '%s' is not a function!!!\r\n", fn_sys_loop_name);
jerry_value_free (sysloop_func);
jerry_value_free (global_obj_val);
return -2;
}
jerry_value_t val_args[] = { jerry_number (ticknow) };
uint16_t val_argv = sizeof (val_args) / sizeof (jerry_value_t);
jerry_value_t res = jerry_call (sysloop_func, global_obj_val, val_args, val_argv);
for (uint16_t i = 0; i < val_argv; i++)
{
jerry_value_free (val_args[i]);
}
jerry_value_free (sysloop_func);
jerry_value_free (global_obj_val);
if (jerry_value_is_exception (res))
{
jerry_value_free (res);
return -3;
}
jerry_value_free (res);
return 0;
}
void
js_exit (void)
{
jerry_cleanup ();
}
@@ -1,147 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_main.c
*
* Description: entry file of user application
*
* Modification history:
* 2014/12/1, v1.0 create this file.
*******************************************************************************/
#include "esp_common.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "uart.h"
#include "user_config.h"
#include "jerry_run.h"
#include "jerry-targetjs.h"
static void show_free_mem(int idx) {
size_t res = xPortGetFreeHeapSize();
printf("dbg free memory(%d): %d\r\n", idx, res);
}
static int jerry_task_init(void) {
DECLARE_JS_CODES;
js_entry();
/* run rest of the js files first */
show_free_mem(2);
for (int src = 1; js_codes[src].source; src++) {
int retcode = js_eval(js_codes[src].source, js_codes[src].length);
if (retcode != 0) {
printf("js_eval failed code(%d) [%s]\r\n", retcode, js_codes[src].name);
return -1;
}
}
/* run main.js */
int retcode = js_eval(js_codes[0].source, js_codes[0].length);
if (retcode != 0) {
printf("js_eval failed code(%d) [%s]\r\n", retcode, js_codes[0].name);
return -2;
}
show_free_mem(3);
return 0;
}
static void jerry_task(void *pvParameters) {
if (jerry_task_init() == 0) {
const portTickType xDelay = 100 / portTICK_RATE_MS;
uint32_t ticknow = 0;
for (;;) {
vTaskDelay(xDelay);
js_loop(ticknow);
if (!ticknow) {
show_free_mem(4);
}
ticknow++;
}
}
js_exit();
}
/*
* This is entry point for user code
*/
void ICACHE_FLASH_ATTR user_init(void)
{
UART_SetBaudrate(UART0, BIT_RATE_115200);
show_free_mem(0);
wifi_softap_dhcps_stop();
show_free_mem(1);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); // GPIO 0
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); // GPIO 2
xTaskCreate(jerry_task, "jerry", JERRY_STACK_SIZE, NULL, 2, NULL);
}
/*
* FunctionName : user_rf_cal_sector_set
* Description : SDK just reserved 4 sectors, used for rf init data and Parameters.
* We add this function to force users to set rf cal sector, since
* we don't know which sector is free in user's application.
* sector map for last several sectors : ABCCC
* A : rf cal
* B : rf init data
* C : sdk parameters
* Parameters : none
* Returns : rf cal sector
*/
uint32 user_rf_cal_sector_set(void)
{
flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;
case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;
case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;
case FLASH_SIZE_64M_MAP_1024_1024:
rf_cal_sec = 2048 - 5;
break;
case FLASH_SIZE_128M_MAP_1024_1024:
rf_cal_sec = 4096 - 5;
break;
default:
rf_cal_sec = 0;
break;
}
return rf_cal_sec;
}
@@ -0,0 +1,23 @@
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.5)
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)
# Workaround to generate sdkconfig into the build directory.
file(TOUCH ${SDKCONFIG})
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(jerryscript)
+13
View File
@@ -0,0 +1,13 @@
### About
This folder contains files to run JerryScript on
[ESP8666 board](https://www.espressif.com/en/products/socs/esp8266) with
[ESP8266 RTOS SDK](https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/) and
[ESP32 board](https://www.espressif.com/en/products/socs/esp32) with
[esp-idf](https://docs.espressif.com/projects/esp-idf/en/latest/).
Both targets is based on ESP-IDF Style so the build system and the directory structure is the same.
Please see the following documents for additional information about the targets:
- [esp8266-rtos-sdk](esp8266-rtos-sdk/README.md)
- [esp-idf](esp-idf/README.md)
@@ -0,0 +1,52 @@
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Default target for running the build test outside the Travis CI environment.
all:
$(MAKE) install
$(MAKE) script
## Targets for installing build dependencies of the ESP8266 JerryScript target.
# Install tools via apt.
install-apt-get-deps:
sudo apt-get install -q -y wget
# Fetch and extract Xtensa toolchain.
install-xtensa-esp32-gcc:
wget https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz --no-check-certificate --directory-prefix /tmp
tar xvfz /tmp/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz --directory /tmp
# Fetch Espressif IoT Development Framework and install its dependencies.
install-esp-idf:
git clone https://github.com/espressif/esp-idf.git /tmp/esp-idf -b release/v4.4
IDF_PATH=/tmp/esp-idf python -m pip install --user -r /tmp/esp-idf/requirements.txt
# Perform all the necessary (JerryScript-independent) installation steps.
install-noapt: install-xtensa-esp32-gcc install-esp-idf
install: install-apt-get-deps install-noapt
## Targets for building ESP-IDF with JerryScript.
# Build the firmware (ESP-IDF with JerryScript).
script:
PATH=/tmp/xtensa-esp32-elf/bin:$(PATH) \
python /tmp/esp-idf/tools/idf.py \
--project-dir ./targets/baremetal-sdk/espressif \
--build-dir ./build/esp-idf \
set-target esp32 \
all
@@ -0,0 +1,129 @@
### About
This folder contains files to run JerryScript on
[ESP32 board](https://www.espressif.com/en/products/socs/esp32) with
[ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/latest/).
The document had been validated on Ubuntu 20.04 operating system.
### How to build
#### 1. Setup the build environment
Clone the necessary projects into a `jerry-esp` directory.
The latest tested working version of ESP-IDF SDK is `release/v4.4`.
```sh
# Create a base folder for all the projects.
mkdir jerry-esp && cd jerry-esp
git clone https://github.com/jerryscript-project/jerryscript.git
git clone https://github.com/espressif/esp-idf.git -b release/v4.4
# SDK requires Xtensa toolchain.
wget https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz
```
The following directory structure has been created:
```
jerry-esp
+ jerryscript
| + targets
| + baremetal-sdk
| + espressif
|
+ esp-idf
+ xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz
```
#### 2. Install dependencies of the projects
```sh
# Assuming you are in jerry-esp folder.
jerryscript/tools/apt-get-install-deps.sh
# Install dependencies of esp-idf.
python -m pip install --user -r esp-idf/requirements.txt
# Extract the downloaded toolchain.
tar -xvf xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz
```
#### 3. Build ESP-IDF (with JerryScript)
```sh
# Assuming you are in jerry-esp folder.
PATH=${PWD}/xtensa-esp32-elf/bin:$PATH esp-idf/tools/idf.py \
--project-dir jerryscript/targets/baremetal-sdk/espressif \
--build-dir jerryscript/build/esp-idf \
set-target esp32 \
all
```
The created binary is a `jerrycript.bin` named file located in `jerryscript/build/esp-idf` folder.
#### 4. Flash the device
Connect Micro-USB for charging and flashing the device. The device should be visible as /dev/ttyUSB0.
```sh
# Assuming you are in jerry-esp folder.
sudo python esp-idf/components/esptool_py/esptool/esptool.py \
--chip esp32 \
--port /dev/ttyUSB0 \
--baud 460800 \
--before default_reset \
--after hard_reset \
write_flash \
--flash_mode dio \
--flash_size detect \
--flash_freq 40m \
0x1000 jerryscript/build/esp-idf/bootloader/bootloader.bin \
0x8000 jerryscript/build/esp-idf/partition_table/partition-table.bin \
0x10000 jerryscript/build/esp-idf/jerryscript.bin
```
#### 5. Connect to the device
esp-idf provides a Python script for serial communication.
Other programs also can be used such as minicom, picocom, etc.
* The device should be visible as `/dev/ttyUSB0`
* The device uses `115200` baud rate for serial communication
* Press `CTRL` + `ALT` + `]` to exit monitor program
```sh
# Assuming you are in jerry-esp folder.
PATH=${PWD}/xtensa-esp32-elf/bin:$PATH esp-idf/tools/idf_monitor.py \
--port /dev/ttyUSB0 \
--baud 115200 \
--toolchain-prefix=xtensa-esp32-elf- \
jerryscript/build/esp-idf/jerryscript.elf
```
The following output should be captured:
```
I (0) cpu_start: App cpu up.
I (326) cpu_start: Pro cpu start user code
I (326) cpu_start: cpu freq: 160000000
I (326) cpu_start: Application information:
I (331) cpu_start: Project name: jerryscript
I (336) cpu_start: App version: v2.4.0-278-ge815e540-dirty
I (342) cpu_start: Compile time: Jan 21 2022 11:38:44
I (349) cpu_start: ELF file SHA256: 2e874acb5a45c0cb...
I (355) cpu_start: ESP-IDF: v4.4-beta1-284-gd83021a6e8-dirt
I (362) heap_init: Initializing. RAM available for dynamic allocation:
I (369) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (375) heap_init: At 3FFB8510 len 00027AF0 (158 KiB): DRAM
I (381) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (387) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (394) heap_init: At 4008B3E8 len 00014C18 (83 KiB): IRAM
I (401) spi_flash: detected chip: generic
I (405) spi_flash: flash io: dio
I (410) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (420) JS: This test run the following script code:
I (430) JS: print ('Hello, World!');
Hello, World!
```
@@ -25,17 +25,18 @@ all:
install-apt-get-deps:
sudo apt-get install -q -y wget
# Fetch and build crosstool-NG with support for Xtensa.
install-xtensa-kx106-gcc:
wget https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-88-gde0bdc1-4.8.5.tar.gz -O ../xtensa-lx106-elf-linux64-1.22.0-88-gde0bdc1-4.8.5.tar.gz --no-check-certificate
cd .. && tar xvfz xtensa-lx106-elf-linux64-1.22.0-88-gde0bdc1-4.8.5.tar.gz
# Fetch and extract Xtensa toolchain.
install-xtensa-lx106-gcc:
wget https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz --no-check-certificate --directory-prefix /tmp
tar xvfz /tmp/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz --directory /tmp
# Fetch Espressif SDK and Xtensa libraries.
# Fetch Espressif SDK and install its dependencies.
install-espressif-sdk:
git clone https://github.com/espressif/ESP8266_RTOS_SDK.git ../ESP8266_RTOS_SDK -b v2.1.0
git clone https://github.com/espressif/ESP8266_RTOS_SDK.git /tmp/ESP8266_RTOS_SDK -b release/v3.4
python -m pip install --user -r /tmp/ESP8266_RTOS_SDK/requirements.txt
# Perform all the necessary (JerryScript-independent) installation steps.
install-noapt: install-xtensa-kx106-gcc install-espressif-sdk
# Perform all the necessary (JerryScript-independent) installation steps. - edited -
install-noapt: install-xtensa-lx106-gcc install-espressif-sdk
install: install-apt-get-deps install-noapt
@@ -43,4 +44,8 @@ install: install-apt-get-deps install-noapt
# Build the firmware (ESP8266 with JerryScript).
script:
PATH=$(CURDIR)/../xtensa-lx106-elf/bin:$$PATH $(MAKE) -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 BIN_PATH=build/obj-esp8266 SDK_PATH=$(CURDIR)/../ESP8266_RTOS_SDK
PATH=/tmp/xtensa-lx106-elf/bin:$(PATH) \
python /tmp/ESP8266_RTOS_SDK/tools/idf.py \
--project-dir ./targets/baremetal-sdk/espressif \
--build-dir ./build/esp8266-rtos-sdk \
all
@@ -0,0 +1,128 @@
### About
This folder contains files to run JerryScript on
[ESP8666 board](https://www.espressif.com/en/products/socs/esp8266) with
[ESP8266 RTOS SDK](https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/).
The document had been validated on Ubuntu 20.04 operating system.
### How to build
#### 1. Setup the build environment
Clone the necessary projects into a `jerry-esp` directory.
The latest tested working version of ESP8266 RTOS SDK is `release/v3.4`.
```sh
# Create a base folder for all the projects.
mkdir jerry-esp && cd jerry-esp
git clone https://github.com/jerryscript-project/jerryscript.git
git clone https://github.com/espressif/ESP8266_RTOS_SDK -b release/v3.4
# SDK requires Xtensa toolchain.
wget https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
```
The following directory structure has been created:
```
jerry-esp
+ jerryscript
| + targets
| + baremetal-sdk
| + espressif
|
+ ESP8266_RTOS_SDK
+ xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
```
#### 2. Install dependencies of the projects
```sh
# Assuming you are in jerry-esp folder.
jerryscript/tools/apt-get-install-deps.sh
# Install dependencies of ESP8266-RTOS-SDK.
python -m pip install --user -r ESP8266_RTOS_SDK/requirements.txt
# Extract the downloaded toolchain.
tar -xvf xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
```
#### 3. Build ESP8266-RTOS-SDK (with JerryScript)
```sh
# Assuming you are in jerry-esp folder.
PATH=${PWD}/xtensa-lx106-elf/bin:$PATH ESP8266_RTOS_SDK/tools/idf.py \
--project-dir jerryscript/targets/baremetal-sdk/espressif \
--build-dir jerryscript/build/esp8266-rtos-sdk \
all
```
The created binary is a `jerryscript.bin` named file located in `jerryscript/build/esp8266-rtos-sdk` folder.
#### 4. Flash the device
Connect Micro-USB for charging and flashing the device. The device should be visible as /dev/ttyUSB0.
```sh
# Assuming you are in jerry-esp folder.
sudo python ESP8266_RTOS_SDK/components/esptool_py/esptool/esptool.py \
--port /dev/ttyUSB0 \
--baud 460800 \
--before default_reset \
--after hard_reset \
write_flash \
--flash_mode dio \
--flash_freq 40m \
--flash_size 2MB \
0x0 jerryscript/build/esp8266-rtos-sdk/bootloader/bootloader.bin \
0x8000 jerryscript/build/esp8266-rtos-sdk/partition_table/partition-table.bin \
0x10000 jerryscript/build/esp8266-rtos-sdk/jerryscript.bin
```
#### 5. Connect to the device
ESP8266-RTOS-SDK provides a Python script for serial communication.
Other programs also can be used such as minicom, picocom, etc.
* The device should be visible as `/dev/ttyUSB0`
* The device uses `74880` baud rate for serial communication
* Press `CTRL` + `ALT` + `]` to exit monitor program
```sh
# Assuming you are in jerry-esp folder.
sudo PATH=${PWD}/xtensa-lx106-elf/bin:$PATH ESP8266_RTOS_SDK/tools/idf_monitor.py \
--port /dev/ttyUSB0 \
--baud 78880 \
--toolchain-prefix=xtensa-lx106-elf- \
jerryscript/build/esp8266-rtos-sdk/jerryscript.elf
```
The following output should be captured:
```
I (43) boot: ESP-IDF v3.4-43-ge9516e4c 2nd stage bootloader
I (43) boot: compile time 11:14:06
I (43) qio_mode: Enabling default flash chip QIO
I (51) boot: SPI Speed : 40MHz
I (57) boot: SPI Mode : QIO
I (63) boot: SPI Flash Size : 2MB
I (69) boot: Partition Table:
I (75) boot: ## Label Usage Type ST Offset Length
I (86) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (97) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (108) boot: 2 factory factory app 00 00 00010000 000f0000
I (120) boot: End of partition table
I (126) esp_image: segment 0: paddr=0x00010010 vaddr=0x40210010 size=0x5c540 (378176) map
0x40210010: _stext at ??:?
I (140) esp_image: segment 1: paddr=0x0006c558 vaddr=0x4026c550 size=0x0baa8 ( 47784) map
I (153) esp_image: segment 2: paddr=0x00078008 vaddr=0x3ffe8000 size=0x0042c ( 1068) load
I (167) esp_image: segment 3: paddr=0x0007843c vaddr=0x40100000 size=0x00080 ( 128) load
I (181) esp_image: segment 4: paddr=0x000784c4 vaddr=0x40100080 size=0x0484c ( 18508) load
I (194) boot: Loaded app from partition at offset 0x10000
I (215) JS: This test run the following script code:
I (216) JS: print ('Hello, World!');
Hello, World!
```
@@ -0,0 +1,52 @@
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.5)
# Set JerryScript variables
set(JERRY_ROOT_DIR ${PROJECT_DIR}/../../..)
set(JERRY_BUILD_DIR ${JERRY_ROOT_DIR}/build/jerry)
set(JERRY_INCLUDE_DIRS "${JERRY_ROOT_DIR}/jerry-ext/include" "${JERRY_ROOT_DIR}/jerry-core/include")
set(JERRY_HEAP_SIZE 20)
# Make compile flags separated by spaces
string(REPLACE ";" " " COMPILE_FLAGS "${COMPILE_OPTIONS};${C_COMPILE_OPTIONS}")
# Build JerryScript
execute_process(COMMAND ${JERRY_ROOT_DIR}/tools/build.py
--clean
--builddir=${JERRY_BUILD_DIR}
--lto=OFF
--jerry-cmdline=OFF
--jerry-math=OFF
--amalgam=ON
--mem-heap=${JERRY_HEAP_SIZE}
--profile=es.next
--compile-flag=${COMPILE_FLAGS}
--toolchain=${CMAKE_TOOLCHAIN_FILE})
# Register JerryScript target application
idf_component_register(SRCS "jerry-main.c" "jerry-port.c" INCLUDE_DIRS ${JERRY_INCLUDE_DIRS})
add_library(jerry-core STATIC IMPORTED)
add_library(jerry-ext STATIC IMPORTED)
add_library(jerry-port STATIC IMPORTED)
set_target_properties(jerry-core PROPERTIES IMPORTED_LOCATION "${JERRY_BUILD_DIR}/lib/libjerry-core.a")
set_target_properties(jerry-ext PROPERTIES IMPORTED_LOCATION "${JERRY_BUILD_DIR}/lib/libjerry-ext.a")
set_target_properties(jerry-port PROPERTIES IMPORTED_LOCATION "${JERRY_BUILD_DIR}/lib/libjerry-port.a")
# jerry-core has espressif/main/jerry-port.c as dependency
target_link_libraries(jerry-core INTERFACE ${COMPONENT_LIB})
# jerry-main has jerry-core, jerry-ext, jerry-port as dependencies
target_link_libraries(${COMPONENT_LIB} INTERFACE jerry-core jerry-ext jerry-port)
@@ -0,0 +1,54 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jerryscript.h"
#include "jerryscript-ext/handlers.h"
#include "jerryscript-ext/properties.h"
/**
* Jerryscript simple test
*/
void app_main()
{
jerry_value_t ret_value = jerry_undefined ();
const jerry_char_t script[] = "print ('Hello, World!');";
/* Initialize engine */
jerry_init (JERRY_INIT_EMPTY);
jerry_log_set_level (JERRY_LOG_LEVEL_DEBUG);
jerry_log (JERRY_LOG_LEVEL_DEBUG, "This test run the following script code: %s", script);
/* Register the print function in the global object */
jerryx_register_global ("print", jerryx_handler_print);
/* Setup Global scope code */
ret_value = jerry_parse (script, sizeof (script) - 1, NULL);
if (!jerry_value_is_exception (ret_value))
{
/* Execute the parsed source code in the Global scope */
ret_value = jerry_run (ret_value);
}
if (jerry_value_is_exception (ret_value))
{
jerry_log (JERRY_LOG_LEVEL_DEBUG, "Script error...\n\n");
}
jerry_value_free (ret_value);
/* Cleanup engine */
jerry_cleanup ();
} /* test_jerry */
@@ -28,80 +28,29 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
static const char TAG[] = "JS";
static const char ESP_JS_TAG[] = "JS";
/**
* Default implementation of jerry_port_fatal. Calls 'abort' if exit code is
* non-zero, 'exit' otherwise.
* Provide log message implementation for the engine.
*/
void
jerry_port_log (const char *message_p) /**< message */
{
ESP_LOGI (ESP_JS_TAG, "%s", message_p);
} /* jerry_port_log */
/**
* Implementation of jerry_port_fatal.
* Calls 'abort' if exit code is non-zero, 'exit' otherwise.
*/
void
jerry_port_fatal (jerry_fatal_code_t code) /**< cause of error */
{
ESP_LOGE (TAG, "Fatal error %d", code);
ESP_LOGE (ESP_JS_TAG, "Fatal error: %d", code);
vTaskSuspend (NULL);
abort ();
} /* jerry_port_fatal */
/**
* Default implementation of jerry_port_sleep. Uses 'nanosleep' or 'usleep' if
* available on the system, does nothing otherwise.
*/
void
jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
{
vTaskDelay (sleep_time / portTICK_PERIOD_MS);
} /* jerry_port_sleep */
/**
* Opens file with the given path and reads its source.
* @return the source of the file
*/
jerry_char_t *
jerry_port_source_read (const char *file_name_p, /**< file name */
jerry_size_t *out_size_p) /**< [out] read bytes */
{
FILE *file_p = fopen (file_name_p, "rb");
if (file_p == NULL)
{
return NULL;
}
struct stat info = {};
fstat (fileno (file_p), &info);
jerry_char_t *buffer_p = (jerry_char_t *) malloc (info.st_size);
if (buffer_p == NULL)
{
fclose (file_p);
return NULL;
}
size_t bytes_read = fread (buffer_p, 1u, info.st_size, file_p);
if (bytes_read != info.st_size)
{
fclose (file_p);
free (buffer_p);
return NULL;
}
fclose (file_p);
*out_size_p = (jerry_size_t) bytes_read;
return buffer_p;
} /* jerry_port_source_read */
/**
* Release the previously opened file's content.
*/
void
jerry_port_source_free (uint8_t *buffer_p) /**< buffer to free */
{
free (buffer_p);
} /* jerry_port_source_free */
/**
* Default implementation of jerry_port_local_tza. Uses the 'tm_gmtoff' field
* of 'struct tm' (a GNU extension) filled by 'localtime_r' if available on the
@@ -123,11 +72,10 @@ jerry_port_local_tza (double unix_ms)
} /* jerry_port_local_tza */
/**
* Default implementation of jerry_port_current_time. Uses 'gettimeofday' if
* available on the system, does nothing otherwise.
* Implementation of jerry_port_get_current_time.
* Uses 'gettimeofday' if available on the system, does nothing otherwise.
*
* @return milliseconds since Unix epoch - if 'gettimeofday' is available and
* executed successfully,
* @return milliseconds since Unix epoch if 'gettimeofday' is available
* 0 - otherwise.
*/
double