Separate targets into os and baremetal-sdk parts (#4842)

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs roland.takacs@h-lab.eu
This commit is contained in:
Roland Takacs
2021-12-06 11:02:52 +01:00
committed by GitHub
parent 9860d66a56
commit af297bc578
110 changed files with 119 additions and 85 deletions
@@ -0,0 +1,56 @@
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 ²úÆ·µÄÓ¦Óÿª·¢¡£ÔÚ´ËÇé¿öÏ£¬¸ÃÐí¿ÉÖ¤Ãâ·ÑÊÚȨÈκλñµÃ¸Ã
Èí¼þ¼°ÆäÏà¹ØÎĵµ£¨Í³³ÆÎª¡°Èí¼þ¡±£©µÄÈËÎÞÏÞÖÆµØ¾­Óª¸ÃÈí¼þ£¬°üÀ¨ÎÞÏÞÖÆµÄʹÓᢸ´ÖÆ¡¢Ð޸ġ¢ºÏ²¢¡¢
³ö°æ·¢ÐС¢É¢²¼¡¢ÔÙÊÚȨ¡¢¼°··ÊÛÈí¼þ¼°Èí¼þ¸±±¾µÄȨÀû¡£±»ÊÚȨÈËÔÚÏíÊÜÕâЩȨÀûµÄͬʱ£¬Ðè·þ´ÓÏÂÃæ
µÄÌõ¼þ£º
ÔÚÈí¼þºÍÈí¼þµÄËùÓи±±¾Öж¼±ØÐë°üº¬ÒÔÉϵİæÈ¨ÉùÃ÷ºÍÊÚȨÉùÃ÷¡£
¸ÃÈí¼þ°´±¾À´µÄÑù×ÓÌṩ£¬Ã»ÓÐÈκÎÃ÷È·»ò°µº¬µÄµ£±££¬°üÀ¨µ«²»½öÏÞÓÚ¹ØÓÚÊÔÏúÐÔ¡¢ÊʺÏÄ³Ò»ÌØ¶¨ÓÃ;
ºÍ·ÇÇÖȨµÄ±£Ö¤¡£×÷ÕߺͰæÈ¨³ÖÓÐÈËÔÚÈκÎÇé¿öϾù²»¾ÍÓÉÈí¼þ»òÈí¼þʹÓÃÒýÆðµÄÒÔºÏͬÐÎʽ¡¢ÃñÊÂÇÖȨ
»òÆäËü·½Ê½Ìá³öµÄÈκÎË÷Åâ¡¢Ë𺦻òÆäËüÔðÈθºÔð¡£
@@ -0,0 +1,162 @@
# 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:
@@ -0,0 +1,88 @@
# 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 \
-DJERRY_PROFILE="es5.1" \
-DEXTERNAL_COMPILE_FLAGS="$(ESP_CFLAGS)" \
-DJERRY_GLOBAL_HEAP_SIZE=$(JERRYHEAP)
make -C$(BUILD_DIR) jerry-core jerry-math
cp $(BUILD_DIR)/lib/libjerry-core.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)
@@ -0,0 +1,46 @@
# 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 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 Espressif SDK and Xtensa libraries.
install-espressif-sdk:
git clone https://github.com/espressif/ESP8266_RTOS_SDK.git ../ESP8266_RTOS_SDK -b v2.1.0
# Perform all the necessary (JerryScript-independent) installation steps.
install-noapt: install-xtensa-kx106-gcc install-espressif-sdk
install: install-apt-get-deps install-noapt
## Targets for building ESP8266 with JerryScript.
# 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
@@ -0,0 +1,120 @@
#### 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
@@ -0,0 +1,30 @@
/* 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__ */
@@ -0,0 +1,32 @@
/* 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__ */
@@ -0,0 +1,24 @@
/* 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__ */
@@ -0,0 +1,30 @@
/* 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");
@@ -0,0 +1,20 @@
/* 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");
@@ -0,0 +1,32 @@
/* 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 = 0x7C000
}
INCLUDE ../ld/eagle.app.v6.common.ld
@@ -0,0 +1,88 @@
### 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
@@ -0,0 +1,44 @@
#############################################################
# 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
@@ -0,0 +1,182 @@
/* 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 */
@@ -0,0 +1,73 @@
/* 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 <stdio.h>
#include <stdarg.h>
#include <sys/time.h>
#include "esp_common.h"
#include "jerryscript-port.h"
/**
* Provide log message implementation for the engine.
*/
void
jerry_port_log (jerry_log_level_t level, /**< log level */
const char *format, /**< format string */
...) /**< parameters */
{
(void) level; /* ignore log level */
va_list args;
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
} /* jerry_port_log */
/**
* Provide fatal message implementation for the engine.
*/
void
jerry_port_fatal (jerry_fatal_code_t code)
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Jerry Fatal Error!\n");
while (true);
} /* jerry_port_fatal */
/**
* Implementation of jerry_port_get_current_time.
*
* @return current timer's counter value in milliseconds
*/
double
jerry_port_get_current_time (void)
{
uint32_t rtc_time = system_rtc_clock_cali_proc();
return (double) rtc_time;
} /* jerry_port_get_current_time */
/**
* Dummy function to get the time zone adjustment.
*
* @return 0
*/
double
jerry_port_get_local_time_zone_adjustment (double unix_ms, bool is_utc)
{
/* We live in UTC. */
return 0;
} /* jerry_port_get_local_time_zone_adjustment */
@@ -0,0 +1,109 @@
/* 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_get_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 ();
}
@@ -0,0 +1,147 @@
/* 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;
}