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/mbed-stm32f401nucleo/.yotta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"build": {
"target": "st-nucleo-f401re-gcc,*",
"targetSetExplicitly": true
}
}
86 changes: 86 additions & 0 deletions targets/mbed-stm32f401nucleo/Makefile.stm32f401nucleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 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-stm32f401nucleo
OUTPUT = build/bin/$(TYPE).mbed-stm32f401nucleo
COPYTARGET = targets/mbed-stm32f401nucleo/libjerry
JERRYHEAP ?= 16
TARGET_DIR ?= /media/$(USER)/MBED

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


.PHONY: jerry js2c yotta flash check_mbed clean


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_ID=GNU \
-DEXTERNAL_CMAKE_C_COMPILER=arm-none-eabi-gcc \
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP)


make -C $(INTERM) $(TYPE).external-mem_stats
cp `cat $(INTERM)/$(TYPE).external-mem_stats/list` $(OUTPUT)/.
cp $(OUTPUT)/lib$(TYPE)-mem_stats.jerry-core.a $(COPYTARGET)/libjerrycore.a
cp $(OUTPUT)/lib$(TYPE)-mem_stats.jerry-fdlibm.third_party.lib.a $(COPYTARGET)/libfdlibm.a


js2c:
cd targets/mbed-stm32f401nucleo; ../tools/js2c.py;


yotta:
cd targets/mbed-stm32f401nucleo; \
yotta target st-nucleo-f401re-gcc; \
yotta build


flash: check_mbed
cp targets/mbed-stm32f401nucleo/build/st-nucleo-f401re-gcc/source/jerry.bin \
"$(TARGET_DIR)/."
@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/mbed-stm32f401nucleo/build

10 changes: 10 additions & 0 deletions targets/mbed-stm32f401nucleo/js/blink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var check = 1;

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

print("blink js OK\n");
5 changes: 5 additions & 0 deletions targets/mbed-stm32f401nucleo/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\n");
12 changes: 12 additions & 0 deletions targets/mbed-stm32f401nucleo/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "jerry",
"version": "1.0.0",
"bin": "./source",
"private": true,
"description": "There is a target bugfix for ST32F401 Nucleo board.",
"author": "orbanl",
"license": "Apache-2.0",
"dependencies": {
"mbed-drivers": "^1.4.0"
}
}
126 changes: 126 additions & 0 deletions targets/mbed-stm32f401nucleo/source/jerry_extapi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/* 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_stm32f401nucleo.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/mbed-stm32f401nucleo/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 ? \
(double) ((val_p)->u.v_float32) : \
(val_p)->type == JERRY_API_DATA_TYPE_FLOAT64 ? \
(double) ((val_p)->u.v_float64) : \
(double) ((val_p)->u.v_uint32))

void js_register_functions (void);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
* limitations under the License.
*/

#include "mbed-drivers/mbed.h"

#include <stdarg.h>
#include "jerry-core/jerry.h"


/**
* Provide log message to filestream implementation for the engine.
*/
Expand Down
Loading