Added target to compile JerryScript beside Particle Device Firmware on Photon board. (#1391)

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
This commit is contained in:
Robert Sipka
2016-10-17 13:54:08 +02:00
committed by yichoi
parent 535743412e
commit 42be0704b9
3 changed files with 319 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
# Copyright 2016 Samsung Electronics Co., Ltd.
# Copyright 2016 University of Szeged
#
# 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.
PARTICLE_FIRMWARE := $(CURDIR)/../particle/firmware
JERRYDIR ?= $(CURDIR)
JERRYHEAP ?= 16
BUILD_DIR ?= $(JERRYDIR)/build/particle
EXT_CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
EXT_CFLAGS += -Wno-error=format=
.PHONY: jerrycore jerry-main flash clean
PARTICLE_BUILD_CONFIG = \
INCLUDE_DIRS=$(JERRYDIR)/jerry-core \
LIBS=jerry-core \
PLATFORM=photon \
LIB_DIRS=$(BUILD_DIR)/lib \
APPDIR=$(JERRYDIR)/targets/particle/source \
TARGET_FILE=jerry_main \
TARGET_DIR=$(BUILD_DIR) \
LDFLAGS=--specs=nano.specs
all: jerrycore jerry-main
jerrycore:
mkdir -p $(BUILD_DIR)
cmake -B$(BUILD_DIR) -H./ \
-DJERRY_LIBC=OFF \
-DJERRY_LIBM=OFF \
-DJERRY_CMDLINE=OFF \
-DUNITTESTS=OFF \
-DENABLE_LTO=ON \
-DFEATURE_PROFILE=minimal \
-DCMAKE_TOOLCHAIN_FILE=$(JERRYDIR)/cmake/toolchain_external.cmake \
-DENABLE_ALL_IN_ONE=OFF \
-DENABLE_STRIP=OFF \
-DENABLE_STATIC_LINK=ON \
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=armv7l \
-DEXTERNAL_CMAKE_C_COMPILER=arm-none-eabi-gcc \
-DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
-DFEATURE_ERROR_MESSAGES=OFF \
-DFEATURE_VALGRIND=OFF \
-DFEATURE_VALGRIND_FREYA=OFF \
-DFEATURE_CPOINTER_32_BIT=OFF \
-DFEATURE_MEM_STRESS_TEST=OFF \
-DFEATURE_MEM_STATS=OFF \
-DFEATURE_PARSER_DUMP=OFF \
-DFEATURE_REGEXP_DUMP=OFF \
-DFEATURE_SNAPSHOT_SAVE=OFF \
-DFEATURE_SNAPSHOT_EXEC=OFF \
-DMEM_HEAP_SIZE_KB=$(JERRYHEAP)
make -C$(BUILD_DIR) jerry-core
jerry-main: jerrycore
$(PARTICLE_BUILD_CONFIG) make -C$(PARTICLE_FIRMWARE) -f $(PARTICLE_FIRMWARE)/makefile
flash:
$(PARTICLE_BUILD_CONFIG) make -C$(PARTICLE_FIRMWARE)/main -f $(PARTICLE_FIRMWARE)/main/makefile program-dfu
clean:
$(PARTICLE_BUILD_CONFIG) make -C$(PARTICLE_FIRMWARE) -f $(PARTICLE_FIRMWARE)/makefile clean
rm -rf $(BUILD_DIR)
+91
View File
@@ -0,0 +1,91 @@
### About
This folder contains files to run JerryScript beside Particle Device Firmware on Photon board.
It runs a mini example, blinking an LED which is the "Hello World" example of the microcontroller universe.
### How to build
#### 1. Preface / Directory structure
Assume `root` as the path to the projects to build.
The folder tree related would look like this.
```
root
+ jerryscript
| + targets
| + particle
+ particle
| + firmware
```
#### 2, Update/Install the Particle Firmware
For detailed descriptions please visit the official website of the firmware: https://www.particle.io/
You can checkout the firmware with the following command:
```
# assume you are in root folder
git clone https://github.com/spark/firmware.git particle/firmware particle/firmware
````
The Photons latest firmware release is hosted in the latest branch of the firmware repo.
```
# assume you are in root folder
cd particle/firmware
git checkout latest
```
Before you type any commands, put your Photon in DFU mode: hold down both the SETUP and RESET buttons. Then release RESET, but hold SETUP until you see the RGB blink yellow. That means the Photon is in DFU mode. To verify that the Photon is in DFU mode and dfu-util is installed properly, try the dfu-util -l command. You should see the device, and the important parts there are the hex values inside the braces the USB VID and PID, which should be 2b04 and d006 for the Photon.
To build and flash the firmware: switch to the modules directory then call make with a few parameters to build and upload the firmware:
```
cd modules
make PLATFORM=photon clean all program-dfu
```
#### 3. Build JerryScript
```
# assume you are in root folder
cd jerryscript
make -f ./targets/particle/Makefile.particle
```
This will create a binary file in the `/build/particle/` folder:
```
jerry_main.bin
```
Thats the binary what well be flashing with dfu-util.
#### 4. Flashing
Make sure you put your Photon in DFU mode.
Alternatively, you can make your life a bit easier by using the make command to invoke dfu-util:
```
make -f targets/particle/Makefile.particle flash
```
You can also use this dfu-util command directly to upload your BIN file to the Photons application memory:
```
dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x80A0000:leave -D build/particle/jerry_main.bin
```
#### 5. Cleaning
To clean the build result:
```
make -f targets/particle/Makefile.particle clean
```
### Running the example
The example program will blinks the D7 led periodically after the flash.
+149
View File
@@ -0,0 +1,149 @@
/* Copyright 2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
*
* 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 "application.h"
#include "jerry-api.h"
SYSTEM_MODE (MANUAL);
/**
* Set led value
*/
static jerry_value_t
set_led (const jerry_value_t func_value, /**< function object */
const jerry_value_t this_value, /**< this arg */
const jerry_value_t *args_p, /**< function arguments */
const jerry_length_t args_cnt) /**< number of function arguments */
{
if (args_cnt != 2)
{
Serial.println ("Wrong arguments count in 'test.setLed' function.");
return jerry_create_boolean (false);
}
int ledPin = jerry_get_number_value (args_p[0]);
bool value = jerry_get_boolean_value (args_p[1]);
pinMode (ledPin, OUTPUT);
digitalWrite (ledPin, value);
return jerry_create_boolean (true);
} /* set_led */
/**
* Delay function
*/
static jerry_value_t
js_delay (const jerry_value_t func_value, /**< function object */
const jerry_value_t this_value, /**< this arg */
const jerry_value_t *args_p, /**< function arguments */
const jerry_length_t args_cnt) /**< number of function arguments */
{
if (args_cnt != 1)
{
Serial.println ("Wrong arguments count in 'test.delay' function.");
return jerry_create_boolean (false);
}
int millisec = jerry_get_number_value (args_p[0]);
delay (millisec);
return jerry_create_boolean (true);
} /* js_delay */
/*
* Init available js functions
*/
static void
init_jerry ()
{
jerry_init (JERRY_INIT_EMPTY);
/* Create an empty JS object */
jerry_value_t object = jerry_create_object ();
jerry_value_t func_obj;
jerry_value_t prop_name;
func_obj = jerry_create_external_function (set_led);
prop_name = jerry_create_string ((const jerry_char_t *) "setLed");
jerry_set_property (object, prop_name, func_obj);
jerry_release_value (prop_name);
jerry_release_value (func_obj);
func_obj = jerry_create_external_function (js_delay);
prop_name = jerry_create_string ((const jerry_char_t *) "delay");
jerry_set_property (object, prop_name, func_obj);
jerry_release_value (prop_name);
jerry_release_value (func_obj);
/* Wrap the JS object (not empty anymore) into a jerry api value */
jerry_value_t global_object = jerry_get_global_object ();
/* Add the JS object to the global context */
prop_name = jerry_create_string ((const jerry_char_t *) "test");
jerry_set_property (global_object, prop_name, object);
jerry_release_value (prop_name);
jerry_release_value (object);
jerry_release_value (global_object);
} /* init_jerry */
/**
* Jerryscript simple test
*/
static void
test_jerry ()
{
const jerry_char_t script[] = " \
test.setLed(7, true); \
test.delay(250); \
test.setLed(7, false); \
test.delay(250); \
";
size_t script_size = strlen ((const char *) script);
jerry_value_t eval_ret = jerry_eval (script, script_size, false);
/* Free JavaScript value, returned by eval */
jerry_release_value (eval_ret);
} /* test_jerry */
/**
* Setup code for particle firmware
*/
void
setup ()
{
Serial.begin (9600);
delay (2000);
Serial.println ("Beginning Listening mode test!");
} /* setup */
/**
* Loop code for particle firmware
*/
void
loop ()
{
init_jerry ();
/* Turn on and off the D7 LED */
test_jerry ();
jerry_cleanup ();
} /* loop */