Skip to content

Commit 3844dc3

Browse files
committed
targets: add nuttx interpreter build
JerryScript-DCO-1.0-Signed-off-by: SaeHie Park [email protected]
1 parent ba95cb0 commit 3844dc3

File tree

3 files changed

+527
-0
lines changed

3 files changed

+527
-0
lines changed

targets/nuttx-stm32f4/Makefile.nuttx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2016 Samsung Electronics Co., Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# use TAB-8
16+
17+
CURDIR = `pwd`
18+
NUTTX ?= $(CURDIR)/../nuttx/nuttx
19+
TYPE ?= release
20+
JERRYHEAP ?= 64
21+
STFLASH ?= ../../stlink/st-flash
22+
23+
NUTTXINC = $(NUTTX)/include
24+
NUTTXLIB = $(NUTTX)/lib
25+
INTERM = build/obj-nuttx-stm32f4
26+
OUTPUT = build/bin/$(TYPE).nuttx-stm32f4
27+
COPYTARGET = $(NUTTXLIB)
28+
29+
EXT_CFLAGS := -mlittle-endian -mthumb -mcpu=cortex-m4 -march=armv7e-m
30+
EXT_CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Wno-conversion
31+
32+
33+
.PHONY: nutx flash clean
34+
35+
36+
all:
37+
mkdir -p $(INTERM)
38+
mkdir -p $(OUTPUT)
39+
cmake -B$(INTERM) -H./ \
40+
-DENABLE_LTO=OFF \
41+
-DENABLE_VALGRIND=OFF \
42+
-DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \
43+
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=armv7l-hf \
44+
-DEXTERNAL_CMAKE_C_COMPILER=arm-none-eabi-gcc \
45+
-DEXTERNAL_CMAKE_CXX_COMPILER=arm-none-eabi-g++ \
46+
-DEXTERNAL_BUILD_ENTRY_FILE=./targets/nuttx-stm32f4/main-nuttx.cpp \
47+
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
48+
-DEXTERNAL_LIBC_INTERFACE=$(NUTTXINC) \
49+
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=arm \
50+
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP)
51+
make -C $(INTERM) $(TYPE).external
52+
cp `cat $(INTERM)/$(TYPE).external/list` $(OUTPUT)/.
53+
cp $(OUTPUT)/lib$(TYPE).jerry-core.a $(COPYTARGET)/libjerrycore.a
54+
cp $(OUTPUT)/lib$(TYPE).jerry-fdlibm.third_party.lib.a \
55+
$(COPYTARGET)/libfdlibm.a
56+
cp $(INTERM)/lib$(TYPE).external-entry.a $(OUTPUT)/.
57+
cp $(OUTPUT)/lib$(TYPE).external-entry.a $(COPYTARGET)/libjerryentry.a
58+
59+
60+
nuttx:
61+
cd $(NUTTX); make
62+
63+
64+
flash:
65+
cd $(NUTTX); $(STFLASH) write nuttx.bin 0x8000000
66+
67+
clean:
68+
rm -rf $(INTERM)
69+
rm -rf $(OUTPUT)

targets/nuttx-stm32f4/README.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
### About
2+
3+
This folder contains files to run JerryScript on NuttX with
4+
[STM32F4-Discovery with BB](http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/LN1199/PF255417)
5+
6+
7+
### How to build
8+
9+
#### 1. Preface
10+
11+
1, Directory structure
12+
13+
Assume `harmony` as the root folder to the projects to build.
14+
The folder tree related would look like this.
15+
16+
```
17+
harmony
18+
+ jerryscript
19+
| + targets
20+
| + nuttx-stm32f4
21+
+ nuttx
22+
| + nuttx
23+
| + lib
24+
+ st-link
25+
```
26+
27+
28+
2, Target board
29+
30+
Assume [STM32F4-Discovery with BB](http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/LN1199/PF255417)
31+
as the target board.
32+
33+
34+
3, Micro SD-Card memory for Script source files
35+
36+
37+
#### 2. Prepare NuttX
38+
39+
Follow [this](https://bitbucket.org/seanshpark/nuttx/wiki/Home) page to get
40+
NuttX source and do the first build. When it stops with and error,
41+
change default project from `IoT.js` to `JerryScript` as follows;
42+
43+
2-1) run menuconfig
44+
```
45+
# assume you are in nuttx folder where .config exist
46+
make menuconfig
47+
```
48+
2-2) Select `Application Configuration` --> `Interpreters`
49+
50+
2-3) Check `[*] JerryScript interpreter` (Move cursor to the line and press `Space`)
51+
52+
2-4) `< Exit >` once on the bottom of the sceen (Press `Right arrow` and `Enter`)
53+
54+
2-5) Select `System Libraries and NSH Add-Ons`
55+
56+
2-6) Un-Check `[ ] iotjs program` (Move cursor to the line and press `Space`)
57+
58+
2-7) `< Exit >` till `menuconfig` ends. Save new configugation when asked.
59+
60+
2-7) `make` again
61+
```
62+
make
63+
```
64+
65+
It'll show the last error but it's ok. Nows the time to build JerryScript.
66+
67+
68+
#### 3. Build JerryScript for NuttX
69+
70+
```
71+
# assume you are in harmony folder
72+
cd jerryscript
73+
make -f ./targets/nuttx-stm32f4/Makefile.nuttx
74+
```
75+
76+
If you have NuttX at another path than described above, you can give the
77+
absolute path with `NUTTX` variable , for example,
78+
```
79+
NUTTX=/home/user/work/nuttx make -f ./targets/nuttx-stm32f4/Makefile.nuttx
80+
```
81+
82+
Make will copy three library files to `nuttx/nuttx/lib` folder
83+
```
84+
libjerryentry.a
85+
libjerrycore.a
86+
libfdlibm.a
87+
```
88+
89+
In NuttX, if you run `make clean`, above library files are also removed so you
90+
may have to build JerryScript again.
91+
92+
93+
#### 4. Flashing
94+
95+
Connect Mini-USB for power supply and connect Micro-USB for `NSH` console.
96+
97+
Please refer [this](https://github.com/Samsung/iotjs/wiki/Build-for-NuttX#prepare-flashing-to-target-board)
98+
link to prepare `stlink` utility.
99+
100+
101+
To flash with `Makefile.nuttx`,
102+
```
103+
make -f ./targets/nuttx-stm32f4/Makefile.nuttx flash
104+
```
105+
106+
#### 5. Clean
107+
108+
To clean the build result,
109+
```
110+
make -f ./targets/nuttx-stm32f4/Makefile.nuttx clean
111+
```
112+
113+
114+
### Running JerryScript
115+
116+
Prepare a micro SD-card and prepare `hello.js` like this in the root directory of SD-card.
117+
118+
```
119+
print("Hello JerryScript!");
120+
```
121+
122+
Power Off(unplug both USB cables), plug the memory card to BB, and power on again.
123+
124+
You can use `minicom` for terminal program, or any other you may like, but match
125+
baud rate to `115200`.
126+
127+
```
128+
minicom --device=/dev/ttyACM0 --baud=115200
129+
```
130+
131+
132+
You may have to press `RESET` on the board and press `Enter` keys on the console
133+
several times to make `nsh` prompt to appear.
134+
135+
If the prompt shows like this,
136+
```
137+
NuttShell (NSH)
138+
nsh>
139+
nsh>
140+
nsh>
141+
```
142+
please set `Add Carriage Ret` option by `CTRL-A` > `Z` > `U` at the console,
143+
if you're using `minicom`.
144+
145+
146+
Run `jerryscript` with `hello.js`
147+
148+
```
149+
NuttShell (NSH)
150+
nsh>
151+
nsh>
152+
nsh> jerryscript /mnt/sdcard/hello.js
153+
PARAM 1 : [/mnt/sdcard/hello.js]
154+
Hello JerryScript!
155+
```
156+
157+
Please give absolute path of the script file or may get an error like this.
158+
```
159+
nsh> cd /mnt/sdcard
160+
nsh> jerryscript ./hello.js
161+
PARAM 1 : [./hello.js]
162+
Failed to fopen [./hello.js]
163+
JERRY_STANDALONE_EXIT_CODE_FAIL
164+
nsh>
165+
nsh>
166+
nsh> jerryscript /mnt/sdcard/hello.js
167+
PARAM 1 : [/mnt/sdcard/hello.js]
168+
Hello JerryScript!
169+
```

0 commit comments

Comments
 (0)