Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions targets/mbedstm32f429i/.yotta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"build": {
"target": "stm32f429i-disco-gcc,*",
"targetSetExplicitly": true
}
}
65 changes: 65 additions & 0 deletions targets/mbedstm32f429i/Makefile.mbedstm32f429i
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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.

# use TAB-8

CURDIR = `pwd`
TYPE = release
INTERM = build/obj-mbed-stm32f429i
OUTPUT = build/bin/$(TYPE).mbedstm32f429i
COPYTARGET = targets/mbedstm32f429i/libjerry
JERRYHEAP ?= 16

EXT_CFLAGS := -D__TARGET_MBED_STM32F429I
EXT_CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
EXT_CFLAGS += -Wno-error=format=

all: jerry js2c yotta

jerry:
mkdir -p $(INTERM)
mkdir -p $(OUTPUT)
mkdir -p $(COPYTARGET)
cmake -B$(INTERM) -H./ \
-DENABLE_LTO=OFF \
-DENABLE_VALGRIND=OFF \
-DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \
-DUSE_COMPILER_DEFAULT_LIBC=YES \
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=arm7-m \
-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)

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-fdlibm.third_party.lib.a $(COPYTARGET)/libfdlibm.a

js2c:
cd targets/mbedstm32f429i; ../tools/js2c.py;

yotta:
cd targets/mbedstm32f429i; \
yotta target stm32f429i-disco-gcc; \
yotta build

flash:
st-flash write targets/mbedstm32f429i/build/stm32f429i-disco-gcc/source/jerry.bin 0x08000000
@echo "Jerry on the board!"

clean:
rm -rf $(INTERM)
rm -rf $(OUTPUT)
rm -rf targets/mbedstm32f429i/build
9 changes: 9 additions & 0 deletions targets/mbedstm32f429i/js/blink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var check = 1;

function blink() {
var blk = (check > 8) ? 1 : 0;
led(1, blk);
check = (check >= 10) ? 1 : check+1;
}

print("blink js OK");
5 changes: 5 additions & 0 deletions targets/mbedstm32f429i/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function sysloop(ticknow) {
blink();
}

print("main js OK");
12 changes: 12 additions & 0 deletions targets/mbedstm32f429i/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "jerry",
"version": "0.0.1",
"bin": "./source",
"private": true,
"description": "JerryScript in mbed OS - STM32F429ZI-Discovery",
"author": "Imre Kiss",
"license": "Apache-2.0",
"dependencies": {
"mbed-drivers": "~0.11.8"
}
}
101 changes: 101 additions & 0 deletions targets/mbedstm32f429i/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
This folder contains files to run JerryScript in mbed / DISCO-F429ZI board.

#### IMPORTANT
You have to clone this repository into the JerryScript targets folder! This is a new target,
not an independent application!

#### yotta

You need to install yotta before proceeding.
Please visit http://yottadocs.mbed.com/#installing-on-linux

##### Cross-compiler for DISCO-F429ZI

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 STM32F429ZI.

#### How to build JerryScript
It assumes the current folder is the JerryScript root folder.

```
make -f targets/mbedstm32f429i/Makefile.mbedstm32f429i clean
make -f targets/mbedstm32f429i/Makefile.mbedstm32f429i jerry
```

#### JerryScript output files

Two files will be generated at `targets/mbedstm32f429i/libjerry`
* libjerrycore.a
* libfdlibm.a

#### Building mbed binary

```
make -f targets/mbedstm32f429i/Makefile.mbedstm32f429i js2c yotta
```

Or, cd to `targets/mbedstm32f429i` where `Makefile.mbedstm32f429i` exist

```
cd targets/mbedstm32f429i
yotta target stm32f429i-disco-gcc
yotta build
```

#### The binary file

The file will be generated at targets/mbedstm32f429i/build/stm32f429i-disco-gcc/source/jerry.bin

#### Flashing to STM32F429ZI

This borad does not support the drag&drop and Virtual Comm Port features. You will have to use an external tool (for example the STM32 STLink utility) to program your code .bin file.

If you don't have STlink installed, please visit [this]
(https://github.com/texane/stlink) page to install STLink-v2.

```
make -f targets/mbedstm32f429i/Makefile.mbedstm32f429i flash
```
OR
```
cd targets/mbedstm32f429i/build/stm32f429i-disco-gcc/source
st-flash write jerry.bin 0x08000000
```
It assumes the st-flash there is in your /usr/bin folder.

When LED near the USB port flashing stops, 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.cpp` `jerry_loop()`, which calls `js_loop()`.

```
minar::Scheduler::postCallback(jerry_loop).period(minar::milliseconds(100))
```

`sysloop()` then calls `blink()` in `blink.js` which blinks the `LED` in
every second.

#### printf

There is no the possibility to use the printf directly in your code.
If you want to use it, you have to use a TTL to USB adapter and a serial communcation program,
like [this](http://www.cyberciti.biz/tips/connect-soekris-single-board-computer-using-minicom.html).

Connect the adapter to the board with the USBTX, USBRX pin (PA10, PA9 in this case), then the board will appear in your host /dev folder.

```
/dev/ttyUSB0
```

After you connected the board to the host over the adapter and configurated your serial communicate program,
you can use the printf the following way:

```
Serial pc(USBTX, USBRX); //tx, rx
pc.printf("%s\n\r", str);
```
130 changes: 130 additions & 0 deletions targets/mbedstm32f429i/source/jerry_extapi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/* 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 <stdlib.h>
#include <stdio.h>

#include "jerry-core/jerry.h"
#include "jerry_extapi.h"

#include "native_mbedstm32f429i.h"

#ifndef MIN
#define MIN(A,B) ((A)<(B)?(A):(B))
#endif

//-----------------------------------------------------------------------------

#define __UNSED__ __attribute__((unused))

#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__, \
jerry_api_value_t * ret_val_p __UNSED__, \
const jerry_api_value_t args_p[], \
const jerry_api_length_t args_cnt)

#define REGISTER_HANDLER(NAME) \
register_native_function ( # NAME, NAME ## _handler)

//-----------------------------------------------------------------------------

DECLARE_HANDLER(assert)
{
if (args_cnt == 1
&& args_p[0].type == JERRY_API_DATA_TYPE_BOOLEAN
&& args_p[0].u.v_bool == true)
{
printf (">> Jerry assert true\r\n");
return true;
}
printf ("ERROR: Script assertion failed\n");
exit (JERRY_STANDALONE_EXIT_CODE_FAIL);
return false;
}

DECLARE_HANDLER(led)
{
if (args_cnt < 2)
{
return false;
}

int port, value;
port = (int)JS_VALUE_TO_NUMBER (&args_p[0]);
value = (int)JS_VALUE_TO_NUMBER (&args_p[1]);

ret_val_p->type = JERRY_API_DATA_TYPE_BOOLEAN;
if (port >=0 && port <= 3)
{
native_led(port, value);
ret_val_p->u.v_bool = true;
}
else
{
ret_val_p->u.v_bool = false;
}
return true;
}

//-----------------------------------------------------------------------------

static bool
register_native_function (const char* name,
jerry_external_handler_t handler)
{
jerry_api_object_t *global_obj_p;
jerry_api_object_t *reg_func_p;
jerry_api_value_t reg_value;
bool bok;

global_obj_p = jerry_api_get_global ();
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)))
{
printf ("Error: create_external_function failed !!!\r\n");
jerry_api_release_object (global_obj_p);
return false;
}

jerry_api_acquire_object (reg_func_p);
reg_value.type = JERRY_API_DATA_TYPE_OBJECT;
reg_value.u.v_object = reg_func_p;

bok = jerry_api_set_object_field_value (global_obj_p,
(jerry_api_char_t *) name,
&reg_value);

jerry_api_release_value (&reg_value);
jerry_api_release_object (reg_func_p);
jerry_api_release_object (global_obj_p);

if (!bok)
{
printf ("Error: register_native_function failed: [%s]\r\n", name);
}

return bok;
}

void js_register_functions (void)
{
REGISTER_HANDLER (assert);
REGISTER_HANDLER (led);
}
38 changes: 38 additions & 0 deletions targets/mbedstm32f429i/source/jerry_extapi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* 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.
*/

#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)->u.v_object))

#define JS_VALUE_TO_NUMBER(val_p) \
((val_p)->type == JERRY_API_DATA_TYPE_FLOAT32 ? \
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
Loading