Skip to content

Commit 3218b26

Browse files
committed
Added target to compile RIOT-OS against jerryscript
This patch contains an example in which you can run a small js on RIOT-OS with STM32F4-Discovery. Check the README.md for a more detailed explanation of how to compile and run it. JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
1 parent 7583b63 commit 3218b26

File tree

4 files changed

+262
-0
lines changed

4 files changed

+262
-0
lines changed

targets/riot-stm32f4/Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2016 Samsung Electronics Co., Ltd.
2+
# Copyright 2016 University of Szeged
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# application name
17+
APPLICATION = riot_jerry
18+
19+
# default BOARD enviroment
20+
BOARD ?= stm32f4discovery
21+
22+
# path to the RIOT base directory
23+
RIOTBASE ?= $(CURDIR)/../RIOT
24+
# path to the JERRYSCRIPT directory
25+
JERRYDIR ?= $(CURDIR)
26+
27+
# path to the application directory
28+
APPDIR ?= $(JERRYDIR)/targets/riot-stm32f4/source
29+
30+
# path to the binary directory
31+
BINDIR ?= $(JERRYDIR)/targets/riot-stm32f4/bin/
32+
33+
# Comment this out to disable code in RIOT that does safety checking
34+
# which is not needed in a production environment but helps in the
35+
# development process:
36+
CFLAGS += -DDEVELHELP
37+
38+
# Change this to 0 show compiler invocation lines by default:
39+
QUIET ?= 1
40+
41+
INCLUDES += -I$(JERRYDIR)/jerry-core/
42+
43+
# Add the shell and some shell commands
44+
USEMODULE += shell
45+
USEMODULE += shell_commands
46+
47+
# Add the jerry lib
48+
USEMODULE += libjerrycore
49+
50+
include $(RIOTBASE)/Makefile.include

targets/riot-stm32f4/Makefile.riot

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2016 Samsung Electronics Co., Ltd.
2+
# Copyright 2016 University of Szeged
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
TYPE ?= release
17+
INTERM ?= build/obj-riot-stm32f4
18+
OUTPUT ?= build/bin/$(TYPE).riotstm32f4
19+
COPYTARGET ?= targets/riot-stm32f4/bin/
20+
21+
JERRYHEAP ?= 16
22+
23+
EXT_CFLAGS := -D__TARGET_RIOT_STM32F4
24+
EXT_CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
25+
EXT_CFLAGS += -Wno-error=format=
26+
27+
.PHONY: libjerry riot-jerry flash clean
28+
29+
all: libjerry riot-jerry
30+
31+
libjerry:
32+
mkdir -p $(INTERM)
33+
mkdir -p $(OUTPUT)
34+
mkdir -p $(COPYTARGET)
35+
cmake -B$(INTERM) -H./ \
36+
-DEXTERNAL_PORT_DIR=UNDEFINED \
37+
-DENABLE_LTO=OFF \
38+
-DENABLE_VALGRIND=OFF \
39+
-DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \
40+
-DCOMPILER_DEFAULT_LIBC=ON \
41+
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=armv7l-hf \
42+
-DEXTERNAL_CMAKE_C_COMPILER=arm-none-eabi-gcc \
43+
-DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \
44+
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
45+
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP)
46+
47+
make -C $(INTERM) $(TYPE).external
48+
cp `cat $(INTERM)/$(TYPE).external/list` $(OUTPUT)/.
49+
cp $(OUTPUT)/lib$(TYPE).jerry-core.a $(COPYTARGET)/libjerrycore.a
50+
51+
riot-jerry: libjerry
52+
make -f ./targets/riot-stm32f4/Makefile
53+
54+
flash: libjerry
55+
make -f ./targets/riot-stm32f4/Makefile flash
56+
57+
clean:
58+
rm -rf $(INTERM)
59+
rm -rf $(OUTPUT)
60+
rm -rf $(COPYTARGET)
61+
make -f ./targets/riot-stm32f4/Makefile clean

targets/riot-stm32f4/README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
### About
2+
3+
This folder contains files to run JerryScript on RIOT-OS with STM32F4-Discovery board.
4+
5+
### How to build
6+
7+
#### 1. Preface
8+
9+
1, Directory structure
10+
11+
Assume `harmony` as the path to the projects to build.
12+
The folder tree related would look like this.
13+
14+
```
15+
harmony
16+
+ jerryscript
17+
| + targets
18+
| + riot-stm32f4
19+
+ RIOT
20+
```
21+
22+
2, Target board
23+
24+
Assume [STM32F4-Discovery with BB](http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/LN1199/PF255417)
25+
as the target board.
26+
27+
#### 2. Prepare RIOT-OS
28+
29+
Follow [this](https://www.riot-os.org/#download) page to get the RIOT-OS source.
30+
31+
Follow the [Inroduction](https://github.com/RIOT-OS/RIOT/wiki/Introduction) wiki site and also check that you can flash the stm32f4-board.
32+
33+
34+
#### 3. Build JerryScript for RIOT-OS
35+
36+
```
37+
# assume you are in harmony folder
38+
cd jerryscript
39+
make -f ./targets/riot-stm32f4/Makefile.riot
40+
```
41+
42+
This will generate the following libraries:
43+
```
44+
/build/bin/release.riotstm32f4/librelease.jerry-core.a
45+
/build/bin/release.riotstm32f4/librelease.jerry-libm.lib.a
46+
```
47+
48+
This will copy one library files to `targets/riot-stm32f4/bin` folder:
49+
```
50+
libjerrycore.a
51+
```
52+
53+
This will create a hex file in the `targets/riot-stm32f4/bin` folder:
54+
```
55+
riot_jerry.elf
56+
```
57+
58+
#### 4. Flashing
59+
60+
```
61+
make -f ./targets/riot-stm32f4/Makefile.riot flash
62+
```
63+
64+
For how to flash the image with other alternative way can be found here:
65+
[Alternative way to flash](https://github.com/RIOT-OS/RIOT/wiki/Board:-STM32F4discovery#alternative-way-to-flash)
66+
67+
#### 5. Cleaning
68+
69+
To clean the build result:
70+
```
71+
make -f ./targets/riot-stm32f4/Makefile.riot clean
72+
```
73+
74+
75+
### 5. Running JerryScript Hello World! example
76+
77+
You may have to press `RESET` on the board after the flash.
78+
79+
You can use `minicom` for terminal program, and if the prompt shows like this:
80+
```
81+
main(): This is RIOT! (Version: ****)
82+
You are running RIOT on a(n) stm32f4discovery board.
83+
This board features a(n) stm32f4 MCU.
84+
```
85+
please set `Add Carriage Ret` option by `CTRL-A` > `Z` > `U` at the console, if you're using `minicom`.
86+
87+
88+
Help will provide a list of commands:
89+
```
90+
> help
91+
```
92+
93+
The `test` command will run the test example, which contains the following script code:
94+
```
95+
print ('Hello, World!');
96+
```
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* Copyright 2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <string.h>
18+
#include "shell.h"
19+
#include "jerry.h"
20+
21+
/**
22+
* Jerryscript simple test
23+
*/
24+
int test_jerry (int argc, char **argv)
25+
{
26+
/* Suppress compiler errors */
27+
(void) argc;
28+
(void) argv;
29+
const jerry_api_char_t script[] = "print ('Hello, World!');";
30+
printf ("This test run the following script code: [%s]\n\n", script);
31+
32+
size_t script_size = strlen ((const char *) script);
33+
jerry_completion_code_t return_code = jerry_run_simple (script,
34+
script_size,
35+
JERRY_FLAG_EMPTY);
36+
37+
return return_code;
38+
} /* test_jerry */
39+
40+
const shell_command_t shell_commands[] = {
41+
{ "test", "Jerryscript Hello World test", test_jerry },
42+
{ NULL, NULL, NULL }
43+
};
44+
45+
int main (void)
46+
{
47+
printf ("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
48+
printf ("This board features a(n) %s MCU.\n", RIOT_MCU);
49+
50+
/* start the shell */
51+
char line_buf[SHELL_DEFAULT_BUFSIZE];
52+
shell_run (shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
53+
54+
return 0;
55+
}

0 commit comments

Comments
 (0)