Merged target for mbed boards.

Merged the mbed releated targets into one source.
Available targets: FRDM-K64f, Discovery-STM32F4, Discovery-STM32F429ZI, NUCLEO-STM32F4

JerryScript-DCO-1.0-Signed-off-by: Imre Kiss kissi@inf.u-szeged.hu
This commit is contained in:
Imre Kiss 2016-04-19 14:04:18 +02:00
parent 94161d350a
commit 5369fd4515
20 changed files with 301 additions and 299 deletions

View File

@ -148,7 +148,9 @@ project (JerryCore C ASM)
${SOURCE_CORE_JRT})
# Jerry port
file(GLOB SOURCE_PORT_FILES ${PORT_DIR}/*.c)
if(NOT ("${PORT_DIR}" STREQUAL ""))
file(GLOB SOURCE_PORT_FILES ${PORT_DIR}/*.c)
endif()
# All-in-one build
if("${ENABLE_ALL_IN_ONE}" STREQUAL "ON")

View File

@ -1,4 +1,5 @@
# Copyright 2015-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.
@ -14,25 +15,43 @@
# use TAB-8
CURDIR = `pwd`
TYPE = release
INTERM = build/obj-mbed-k64f
OUTPUT = build/bin/$(TYPE).mbedk64f
COPYTARGET = targets/mbedk64f/libjerry
JERRYHEAP ?= 16
TARGET_DIR ?= /media/$(USER)/MBED
TYPE = release
TARGET_LIST = k64f stm32f4 stm32f429i nucleo
JERRYHEAP ?= 16
EXT_CFLAGS := -D__TARGET_MBED_K64F
ifneq ($(filter $(board), $(TARGET_LIST)),)
TARGET = $(board)
ifeq ($(TARGET), k64f)
YOTTA_TARGET = frdm-k64f-gcc
TARGET_DIR ?= /media/$(USER)/MBED
else ifeq ($(TARGET), stm32f4)
YOTTA_TARGET = stm32f4-disco-gcc
else ifeq ($(TARGET), stm32f429i)
YOTTA_TARGET = stm32f429i-disco-gcc
else ifeq ($(TARGET), nucleo)
YOTTA_TARGET = st-nucleo-f401re-gcc
TARGET_DIR ?= /media/$(USER)/NODE_F401RE
endif
UPPERC_TARGET = $(shell echo $(TARGET) | tr a-z A-Z)
INTERM = build/obj-mbed-$(TARGET)
OUTPUT = build/bin/$(TYPE).mbed$(TARGET)
COPYTARGET = targets/mbed/libjerry
else
$(error This board ($(board)) is not supported!)
endif
EXT_CFLAGS := -D__TARGET_MBED_$(UPPERC_TARGET)
EXT_CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
EXT_CFLAGS += -Wno-error=format=
EXT_PORT_DIR := ""
.PHONY: jerry js2c yotta flash check_mbed clean
.PHONY: jerry js2c yotta flash clean
all: jerry js2c yotta
jerry:
mkdir -p $(INTERM)
mkdir -p $(OUTPUT)
@ -46,38 +65,36 @@ jerry:
-DEXTERNAL_CMAKE_C_COMPILER=arm-none-eabi-gcc \
-DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP)
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP) \
-DEXTERNAL_PORT_DIR=$(EXT_PORT_DIR)
make -C $(INTERM) $(TYPE).external
cp `cat $(INTERM)/$(TYPE).external/list` $(OUTPUT)/.
cp $(OUTPUT)/lib$(TYPE).jerry-core.a $(COPYTARGET)/libjerrycore.a
cp $(OUTPUT)/lib$(TYPE).jerry-libm.lib.a $(COPYTARGET)/libjerrylibm.a
js2c:
cd targets/mbedk64f; ../tools/js2c.py;
cd targets/mbed; ../tools/js2c.py;
yotta:
cd targets/mbedk64f; \
yotta target frdm-k64f-gcc; \
cd targets/mbed; \
yotta target $(YOTTA_TARGET); \
yotta build
flash: check_mbed
cp targets/mbedk64f/build/frdm-k64f-gcc/source/jerry.bin \
"$(TARGET_DIR)/."
flash:
ifndef TARGET_DIR
st-flash write targets/mbed/build/$(YOTTA_TARGET)/source/jerry.bin 0x08000000
else
@if [ ! -d "${TARGET_DIR}" ] ; then \
echo "The board not mounted at ${TARGET_DIR}"; \
exit 1; \
fi
cp targets/mbed/build/$(YOTTA_TARGET)/source/jerry.bin \
"$(TARGET_DIR)/."
endif
@echo "Wait till LED flashing stops..."
check_mbed:
@if [ ! -d "${TARGET_DIR}" ] ; then \
echo "MBED not mounted at ${TARGET_DIR}"; \
exit 1; \
fi
clean:
rm -rf $(INTERM)
rm -rf $(OUTPUT)
rm -rf targets/mbedk64f/build
rm -rf targets/mbed/build

10
targets/mbed/js/blink.js Normal file
View File

@ -0,0 +1,10 @@
var check = 1;
function blink ()
{
var blk = (check > 8) ? 1 : 0;
led (0, blk);
check = (check >= 10) ? 1 : check + 1;
}
print ("blink js OK");

6
targets/mbed/js/main.js Normal file
View File

@ -0,0 +1,6 @@
function sysloop (ticknow)
{
blink ();
}
print ("main js OK");

View File

@ -1,12 +1,12 @@
{
"name": "jerry",
"version": "0.0.0",
"version": "0.0.1",
"bin": "./source",
"private": true,
"description": "JerryScript in mbed",
"author": "",
"license": "Apache-2.0",
"dependencies": {
"mbed-drivers": "~0.11.1"
"mbed-drivers": "^1.5.0"
}
}

68
targets/mbed/readme.md Normal file
View File

@ -0,0 +1,68 @@
This folder contains files to run JerryScript in mbed / for:
* Freedom-K64F (k64)
* Discovery-STM32F4 (stm32f4)
* Discovery-STM32F429ZI (stm32f429i)
* Nucleo-F401RE (nucleo)
####Yotta
You need to install yotta before proceeding. Please visit [Yotta docs page](http://yottadocs.mbed.com/#installing-on-linux).
####Cross-compiler
For cross-compilation the GCC 5.2.1 is suggested to be used. All the supported targets were tested with this version. If you don't have any GCC compiler installed, please visit [this](https://launchpad.net/gcc-arm-embedded/+download) page to download GCC 5.2.1.
####How to build a target
Navigate to your JerryScript root folder (after you cloned this repository into the targets folder) and use the following command:
```
make -f targets/target-mbed/Makefile.mbed board=$(TARGET)
```
Where the `$(TARGET)` is one of the following options: `k64f`, `stm32f4`, `stm32f429i` or `nucleo`.
This command will create a new folder for your target and build the jerryscript and mbed OS into that folder.
####How to build a completely new target
If you want to build a new target (which is not available in this folder) you have to modify the makefile.
You have to add the new board name to the `TARGET_LIST` and you have to add a new branch with the new `YOTTA_TARGET` and a new `TARGET_DIR` path (if it neccessary) to the if at the top in the Makefile (just as you see right now).
There is a little code snippet:
```
ifeq ($(TARGET), k64f)
YOTTA_TARGET = frdm-k64f-gcc
TARGET_DIR ?= /media/$(USER)/MBED
else ifeq ($(TARGET), stm32f4)
YOTTA_TARGET =
```
Basically, you can create a new target in this way (If the mbed OS support your board).
#####Let's get into the details!
1. The next rule is the `jerry` rule. This rule builds the JerryScript and copy the output files into the target libjerry folder. Two files will be generated at `targets/mbed$(TARGET)/libjerry`:
* libjerrycore.a
* libfdlibm.a
You can run this rule with the following command:
- `make -f targets/target-mbed/Makefile.mbed board=$(TARGET) jerry`
2. The next rule is the `js2c`. This rule calls a `js2c.py` python script from the `jerryscript/targets/tools` and creates the JavaScript builtin file into the `targets/mbed$(TARGET)/source/` folder. This file is the `jerry_targetjs.h`. You can run this rule with the follwoing command:
- `make -f targets/target-mbed/Makefile.mbed board=$(TARGET) js2c`
3. The last rule is the `yotta`. This rule sets the yotta target and install the mbed-drivers module, install the dependencies for the mbed OS and finaly creates the mbed binary file. The binary file will be genrated at `targets/mbed$(TARGET)/build/$(YOTTA_TARGET)/source/jerry.bin`. You can run this rule with the following command:
- `make -f targets/target-mbed/Makefile.mbed board=$(TARGET) yotta`
4. Optional rule: `clean`. It removes the build folder from the target-mbed and jerry. You can run this rule with this command:
- `make -f targets/target-mbed/Makefile.mbed board=$(TARGET) clean`
#####Flashing
When the build is finished you can flash the binary into your board if you want. In case of ST boards you have to install the `st-link` software. Please visit [this page](https://github.com/texane/stlink) to install STLink-v2.
You can flash your binary into your board with the following command:
```
make -f targets/target-mbed/Makefile.mbed board=$(TARGET) flash
```
The flash rule grabs the binary and copies it to the mounted board or use the STLink-v2 to flash.
When the status LED of the board stops blinking, press RESET button on the board to execute JerryScript led flashing sample program in js folder.
###Note
If you use an STM32F4 board your build will stop with missing header errors. To fix this error please visit to [this page](http://browser.sed.hu/blog/20160407/how-run-javascripts-jerryscript-mbed) and read about the fix in the `New target for STM32F4` block.

View File

@ -13,25 +13,23 @@
* limitations under the License.
*/
#include "jerry-core/jerry.h"
#include <stdlib.h>
#include <stdio.h>
#include "jerry-core/jerry.h"
#include "jerry_extapi.h"
#include "native_mbedk64f.h"
#include "native_mbed.h"
#ifndef MIN
#define MIN(A,B) ((A)<(B)?(A):(B))
#endif
//-----------------------------------------------------------------------------
#define __UNSED__ __attribute__((unused))
#define DELCARE_HANDLER(NAME) \
#define DECLARE_HANDLER(NAME) \
static bool \
NAME ## _handler (const jerry_api_object_t * function_obj_p __UNSED__, \
const jerry_api_value_t * this_p __UNSED__, \
@ -42,14 +40,13 @@ NAME ## _handler (const jerry_api_object_t * function_obj_p __UNSED__, \
#define REGISTER_HANDLER(NAME) \
register_native_function ( # NAME, NAME ## _handler)
//-----------------------------------------------------------------------------
DELCARE_HANDLER(assert)
DECLARE_HANDLER(assert)
{
if (args_cnt == 1
&& args_p[0].type == JERRY_API_DATA_TYPE_BOOLEAN
&& args_p[0].v_bool == true)
&& args_p[0].u.v_bool == true)
{
printf (">> Jerry assert true\r\n");
return true;
@ -59,40 +56,7 @@ DELCARE_HANDLER(assert)
return false;
}
DELCARE_HANDLER(print)
{
jerry_api_length_t cc;
if (args_cnt)
{
printf(">> print(%d) :", (int)args_cnt);
for (cc=0; cc<args_cnt; cc++)
{
if (args_p[cc].type == JERRY_API_DATA_TYPE_STRING && args_p[cc].v_string)
{
static char buffer[128];
int length, maxlength;
length = -jerry_api_string_to_char_buffer (args_p[0].v_string, NULL, 0);
maxlength = MIN(length, 126);
jerry_api_string_to_char_buffer (args_p[cc].v_string,
(jerry_api_char_t *) buffer,
maxlength);
*(buffer + length) = 0;
printf("[%s] ", buffer);
}
else
{
printf ("(%d) ", args_p[cc].type);
}
}
printf ("\r\n");
}
return true;
}
DELCARE_HANDLER(led)
DECLARE_HANDLER(led)
{
if (args_cnt < 2)
{
@ -104,17 +68,18 @@ DELCARE_HANDLER(led)
value = (int)JS_VALUE_TO_NUMBER (&args_p[1]);
ret_val_p->type = JERRY_API_DATA_TYPE_BOOLEAN;
if (port >=0 && port <= 3) {
if (port >=0 && port <= 3)
{
native_led(port, value);
ret_val_p->v_bool = true;
ret_val_p->u.v_bool = true;
}
else {
ret_val_p->v_bool = false;
else
{
ret_val_p->u.v_bool = false;
}
return true;
}
//-----------------------------------------------------------------------------
static bool
@ -130,8 +95,8 @@ register_native_function (const char* name,
reg_func_p = jerry_api_create_external_function (handler);
if (!(reg_func_p != NULL
&& jerry_api_is_function (reg_func_p)
&& jerry_api_is_constructor (reg_func_p)))
&& jerry_api_is_function (reg_func_p)
&& jerry_api_is_constructor (reg_func_p)))
{
printf ("Error: create_external_function failed !!!\r\n");
jerry_api_release_object (global_obj_p);
@ -140,10 +105,10 @@ register_native_function (const char* name,
jerry_api_acquire_object (reg_func_p);
reg_value.type = JERRY_API_DATA_TYPE_OBJECT;
reg_value.v_object = reg_func_p;
reg_value.u.v_object = reg_func_p;
bok = jerry_api_set_object_field_value (global_obj_p,
(jerry_api_char_t *)name,
(jerry_api_char_t *) name,
&reg_value);
jerry_api_release_value (&reg_value);
@ -158,10 +123,8 @@ register_native_function (const char* name,
return bok;
}
void js_register_functions (void)
{
REGISTER_HANDLER (assert);
REGISTER_HANDLER (print);
REGISTER_HANDLER (led);
}

View File

@ -16,27 +16,23 @@
#ifndef __JERRY_EXTAPI_H__
#define __JERRY_EXTAPI_H__
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
#define API_DATA_IS_OBJECT(val_p) \
((val_p)->type == JERRY_API_DATA_TYPE_OBJECT)
#define API_DATA_IS_FUNCTION(val_p) \
(API_DATA_IS_OBJECT(val_p) && \
jerry_api_is_function((val_p)->v_object))
(API_DATA_IS_OBJECT (val_p) && \
jerry_api_is_function ((val_p)->u.v_object))
#define JS_VALUE_TO_NUMBER(val_p) \
((val_p)->type == JERRY_API_DATA_TYPE_FLOAT32 ? \
(double) ((val_p)->v_float32) : \
(val_p)->type == JERRY_API_DATA_TYPE_FLOAT64 ? \
(double) ((val_p)->v_float64) : \
(double) ((val_p)->v_uint32))
static_cast<double>((val_p)->u.v_float32) : \
(val_p)->type == JERRY_API_DATA_TYPE_FLOAT64 ? \
static_cast<double>((val_p)->u.v_float64) : \
static_cast<double>((val_p)->u.v_uint32))
void js_register_functions (void);
#endif

View File

@ -1,4 +1,5 @@
/* Copyright 2014-2015 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.
@ -13,38 +14,44 @@
* limitations under the License.
*/
#include "jerry-core/jerry.h"
#include <stdlib.h>
#include <stdio.h>
#include "jerry_run.h"
#include "jerry-core/jerry.h"
#include "jerry_extapi.h"
#include "jerry_run.h"
static const char* fn_sys_loop_name = "sysloop";
int js_entry (const char *source_p, const size_t source_size)
{
const jerry_api_char_t *jerry_src = (const jerry_api_char_t *) source_p;
jerry_completion_code_t ret_code = JERRY_COMPLETION_CODE_OK;
jerry_flag_t flags = JERRY_FLAG_EMPTY;
jerry_api_object_t *err_obj_p = NULL;
jerry_api_value_t err_value = jerry_api_create_void_value ();
jerry_init (flags);
js_register_functions ();
if (!jerry_parse (jerry_src, source_size))
if (!jerry_parse (jerry_src, source_size, &err_obj_p))
{
printf ("Error: jerry_parse failed\r\n");
ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;
jerry_api_release_object (err_obj_p);
}
else
{
if ((flags & JERRY_FLAG_PARSE_ONLY) == 0)
{
ret_code = jerry_run ();
ret_code = jerry_run (&err_value);
jerry_api_string_t *err_str_p = NULL;
if (err_str_p != NULL)
{
jerry_api_release_string (err_str_p);
}
}
}
@ -75,7 +82,7 @@ int js_loop (uint32_t ticknow)
global_obj_p = jerry_api_get_global ();
is_ok = jerry_api_get_object_field_value (global_obj_p,
(const jerry_api_char_t*)fn_sys_loop_name,
(const jerry_api_char_t*) fn_sys_loop_name,
&sysloop_func);
if (!is_ok)
{
@ -96,12 +103,12 @@ int js_loop (uint32_t ticknow)
uint16_t val_argv;
val_argv = 1;
val_args = (jerry_api_value_t*)malloc (sizeof (jerry_api_value_t) * val_argv);
val_args = (jerry_api_value_t*) malloc (sizeof (jerry_api_value_t) * val_argv);
val_args[0].type = JERRY_API_DATA_TYPE_UINT32;
val_args[0].v_uint32 = ticknow;
val_args[0].u.v_uint32 = ticknow;
jerry_api_value_t res;
is_ok = jerry_api_call_function (sysloop_func.v_object,
is_ok = jerry_api_call_function (sysloop_func.u.v_object,
global_obj_p,
&res,
val_args,
@ -119,4 +126,3 @@ void js_exit (void)
{
jerry_cleanup ();
}

View File

@ -16,11 +16,9 @@
#ifndef __JERRY_RUN_H__
#define __JERRY_RUN_H__
int js_entry (const char *source_p, const size_t source_size);
int js_eval (const char *source_p, const size_t source_size);
int js_loop (uint32_t ticknow);
void js_exit (void);
#endif

View File

@ -18,55 +18,58 @@
#include "jerry-core/jerry.h"
#include "jerry_run.h"
//-----------------------------------------------------------------------------
#include "jerry_targetjs.h"
static int jerry_init(void) {
static Serial pc (USBTX, USBRX); //tx, rx
static int jerry_init (void)
{
int retcode;
int src;
DECLARE_JS_CODES;
/* run main.js */
retcode = js_entry(js_codes[0].source, js_codes[0].length);
if (retcode != 0) {
printf("js_entry failed code(%d) [%s]\r\n", retcode, js_codes[0].name);
js_exit();
retcode = js_entry (js_codes[0].source, js_codes[0].length);
if (retcode != 0)
{
printf ("js_entry failed code(%d) [%s]\r\n", retcode, js_codes[0].name);
js_exit ();
return -1;
}
/* run rest of the js files */
for (src=1; js_codes[src].source; src++) {
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);
js_exit();
for (src = 1; js_codes[src].source; src++)
{
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);
js_exit ();
return -2;
}
}
return 0;
}
static void jerry_loop(void) {
static void jerry_loop (void)
{
static uint32_t _jcount = 0;
js_loop(_jcount++);
js_loop (_jcount++);
}
void app_start (int, char**)
{
// set 9600 baud rate for stdout
pc.baud (9600);
void app_start(int, char**){
// set 115200 baud rate for stdout
static Serial pc(USBTX, USBRX);
pc.baud(115200);
printf ("\r\nJerryScript in mbed K64F\r\n");
printf ("\r\nJerryScript in mbed\r\n");
printf (" build %s\r\n", jerry_build_date);
printf (" hash %s\r\n", jerry_commit_hash);
printf (" branch %s\r\n", jerry_branch_name);
if (jerry_init() == 0) {
minar::Scheduler::postCallback(jerry_loop)
.period(minar::milliseconds(100))
;
if (jerry_init () == 0)
{
minar::Scheduler::postCallback(jerry_loop).period(minar::milliseconds(100));
}
}

View File

@ -20,11 +20,7 @@ set(LJCORE ${CMAKE_CURRENT_LIST_DIR}/../../../)
include_directories(${LJCORE})
# compile flags
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS}
-mlittle-endian
-mthumb
-mcpu=cortex-m4
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlittle-endian -mthumb -mcpu=cortex-m4" )
# link jerryscript
set(LJPATH ${CMAKE_CURRENT_LIST_DIR}/../libjerry)

View File

@ -15,11 +15,11 @@
#include "mbed-drivers/mbed.h"
#include "native_mbedk64f.h"
#include "native_mbed.h"
void native_led(int port, int val) {
void native_led (int port, int val)
{
static const PinName portmap[] = { LED1, LED2, LED3, LED4 };
DigitalOut led(portmap[port]);
static DigitalOut led (portmap[port]);
led = val;
}

View File

@ -13,11 +13,9 @@
* limitations under the License.
*/
#ifndef __NATIVE_MBEDK64F_H__
#define __NATIVE_MBEDK64F_H__
#ifndef __NATIVE_MBED_H__
#define __NATIVE_MBED_H__
void native_led (int port, int val);
void native_led(int port, int val);
#endif
#endif /* !__NATIVE_MBED_H__ */

View File

@ -0,0 +1,87 @@
/* 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.
*/
#define _BSD_SOURCE
#include <stdarg.h>
#include <stdlib.h>
#include <sys/time.h>
#include "jerry-core/jerry-port.h"
#include "mbed-hal/us_ticker_api.h"
/**
* Provide log message to filestream implementation for the engine.
*/
int
jerry_port_logmsg (FILE *stream, /**< stream pointer */
const char *format, /**< format string */
...) /**< parameters */
{
va_list args;
int count;
va_start (args, format);
count = vfprintf (stream, format, args);
va_end (args);
return count;
} /* jerry_port_logmsg */
/**
* Provide error message to console implementation for the engine.
*/
int
jerry_port_errormsg (const char *format, /**< format string */
...) /**< parameters */
{
va_list args;
int count;
va_start (args, format);
count = vfprintf (stderr, format, args);
va_end (args);
return count;
} /* jerry_port_errormsg */
/**
* Implementation of jerry_port_fatal.
*/
void
jerry_port_fatal (jerry_fatal_code_t code) /**< fatal code enum item */
{
exit (code);
} /* jerry_port_fatal */
/**
* Implementation of jerry_port_get_time_zone.
*
* @return true - if success
*/
bool
jerry_port_get_time_zone (jerry_time_zone_t *tz_p) /**< timezone pointer */
{
tz_p->offset = 0;
tz_p->daylight_saving_time = 0;
return true;
} /* jerry_port_get_time_zone */
/**
* Implementation of jerry_port_get_current_time.
*
* @return current timer's counter value in microseconds
*/
double
jerry_port_get_current_time ()
{
return (double) us_ticker_read ();
} /* jerry_port_get_current_time */

View File

@ -1,5 +0,0 @@
{
"build": {
"target": "frdm-k64f-gcc,*"
}
}

View File

@ -1,9 +0,0 @@
var check = 1;
function blink() {
var blk = (check > 8) ? 1 : 0;
led(1, blk);
check = (check >= 10) ? 1 : check+1;
}
print("blink js OK");

View File

@ -1,4 +0,0 @@
function sysloop(ticknow) {
blink();
};
print("main js OK");

View File

@ -1,85 +0,0 @@
### About
This folder contains files to run JerryScript in mbed / FRDM-K64F board.
#### Installing yotta
You need to install yotta before proceeding.
Please visit http://yottadocs.mbed.com/#installing-on-linux
##### Cross-compiler for FRDM-K64F
If you don't have any GCC compiler installed, please visit [this]
(https://launchpad.net/gcc-arm-embedded/+download) page to download GCC 4.8.4
which was tested for building JerryScript for K64F.
#### How to build JerryScript
```
make -f targets/mbedk64f/Makefile.mbedk64f clean
make -f targets/mbedk64f/Makefile.mbedk64f jerry
```
#### JerryScript output files
Two files will be generated at `targets/mbedk64f/libjerry`
* libjerrycore.a
* libjerrylibm.a
#### Building mbed binary
```
make -f targets/mbedk64f/Makefile.mbedk64f js2c yotta
```
Or, cd to `targets/mbedk64f` where `Makefile.mbedk64f` exist
```
cd targets/mbedk64f
yotta target frdm-k64f-gcc
yotta build
```
#### Build at once
Omit target name to build both jerry library and mbed binary.
```
make -f targets/mbedk64f/Makefile.mbedk64f
```
#### Flashing to k64f
```
make -f targets/mbedk64f/Makefile.mbedk64f flash
```
It assumes default mound folder is `/media/(user)/MBED`
If its mounted to other path, give it with `TARGET_DIR` variable, for example,
```
TARGET_DIR=/mnt/media/MBED make -f targets/mbedk64f/Makefile.mbedk64f flash
```
Or you can just copy `targets/mbedk64f/build/frdm-k64f-gcc/source/jerry.bin`
file to mounted folder.
When LED near the USB port flashing stops and `MBED` folder shows up on the
desktop(if you are using GUI), press RESET button on the board to execute
JerryScript led flashing sample program in js folder.
#### How blink sample program works
All `.js` files in `js` folder are executed, with `main.js` in first order.
`sysloop()` function in main.js is called periodically in every 100msec by
below code in `main.c` `jerry_loop()`, which calls `js_loop()` in
`jerry_mbedk64f.c`
```
minar::Scheduler::postCallback(jerry_loop)
.period(minar::milliseconds(100))
```
`sysloop()` then calls `blink()` in `blink.js` which blinks the `LED` in
every second.

View File

@ -1,45 +0,0 @@
/* Copyright 2014-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.
*/
#include "mbed-drivers/mbed.h"
#include "jerry-core/jerry.h"
/**
* Provide log message to filestream implementation for the engine.
*/
int jerry_port_logmsg (FILE* stream, const char* format, ...)
{
va_list args;
int count;
va_start (args, format);
count = vfprintf (stream, format, args);
va_end (args);
return count;
}
/**
* Provide error message to console implementation for the engine.
*/
int jerry_port_errormsg (const char* format, ...)
{
va_list args;
int count;
va_start (args, format);
count = vfprintf (stderr, format, args);
va_end (args);
return count;
}