Update the nuttx-stm32f4 target

Related issue: #1202

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
This commit is contained in:
Zsolt Borbély
2016-08-26 07:45:52 +02:00
parent e93e32635f
commit 1e82ae1eb5
6 changed files with 267 additions and 245 deletions
+54 -117
View File
@@ -1,143 +1,91 @@
### About
This folder contains files to run JerryScript on NuttX with
[STM32F4-Discovery with BB](http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/LN1199/PF255417)
This folder contains files to run JerryScript on
[STM32F4-Discovery board](http://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-discovery-kits/stm32f4discovery.html) with [NuttX](http://nuttx.org/)
### How to build
#### 1. Preface
#### 1. Setting up the build environment for STM32F4-Discovery board
1, Directory structure
Assume `harmony` as the root folder to the projects to build.
The folder tree related would look like this.
Clone JerryScript and NuttX into jerry-nuttx directory
```
harmony
mkdir jerry-nuttx
cd jerry-nuttx
git clone https://github.com/Samsung/jerryscript.git
git clone https://bitbucket.org/nuttx/nuttx.git
git clone https://bitbucket.org/nuttx/apps.git
git clone https://github.com/texane/stlink.git
```
The following directory structure is created after these commands
```
jerry-nuttx
+ apps
+ jerryscript
| + targets
| + nuttx-stm32f4
+ nuttx
| + nuttx
| + lib
+ st-link
+ stlink
```
#### 2. Adding JerryScript as an interpreter for NuttX
2, Target board
Assume [STM32F4-Discovery with BB](http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/LN1199/PF255417)
as the target board.
3, Micro SD-Card memory for Script source files
#### 2. Prepare NuttX
Follow [this](https://bitbucket.org/seanshpark/nuttx/wiki/Home) page to get
NuttX source and do the first build. When it stops with and error,
change default project from `IoT.js` to `JerryScript` as follows;
2-1) run menuconfig
```
# assume you are in nuttx folder where .config exist
cd apps/interpreters
mkdir jerryscript
cp ../../jerryscript/targets/nuttx-stm32f4/* ./jerryscript/
```
#### 3. Configure NuttX
```
# assuming you are in jerry-nuttx folder
cd nuttx/tools
# configure NuttX USB console shell
./configure.sh stm32f4discovery/usbnsh
cd ..
# might require to run "make menuconfig" twice
make menuconfig
```
2-2) Select `Application Configuration` --> `Interpreters`
2-3) Check `[*] JerryScript interpreter` (Move cursor to the line and press `Space`)
Change "Build Setup" -> "Build Host Platform" from "Windows" to "Linux"
Enable "System Type" -> "FPU support"
Enable "Library Routines" -> "Standard Math library"
Enable "Application Configuration" -> "Interpreters->JerryScript"
2-4) `< Exit >` once on the bottom of the sceen (Press `Right arrow` and `Enter`)
#### 4. Build JerryScript for NuttX
2-5) Select `System Libraries and NSH Add-Ons`
2-6) Un-Check `[ ] iotjs program` (Move cursor to the line and press `Space`)
2-7) `< Exit >` till `menuconfig` ends. Save new configugation when asked.
2-7) `make` again
```
# assuming you are in jerry-nuttx folder
cd nuttx/
make
```
It'll show the last error but it's ok. Nows the time to build JerryScript.
#### 3. Build JerryScript for NuttX
```
# assume you are in harmony folder
cd jerryscript
make -f ./targets/nuttx-stm32f4/Makefile.nuttx
```
If you have NuttX at another path than described above, you can give the
absolute path with `NUTTX` variable , for example,
```
NUTTX=/home/user/work/nuttx make -f ./targets/nuttx-stm32f4/Makefile.nuttx
```
Make will copy three library files to `nuttx/nuttx/lib` folder
```
libjerryentry.a
libjerrycore.a
libjerrylibm.a
```
In NuttX, if you run `make clean`, above library files are also removed so you
may have to build JerryScript again.
#### 4. Continue build NuttX
```
# asssume you are in harmony folder
cd nuttx/nuttx
make
```
#### 5. Flashing
Connect Mini-USB for power supply and connect Micro-USB for `NSH` console.
Please refer [this](https://github.com/Samsung/iotjs/wiki/Build-for-NuttX#prepare-flashing-to-target-board)
link to prepare `stlink` utility.
To configure `stlink` utility for flashing, follow the instructions [here](https://github.com/texane/stlink#build-from-sources).
To flash with `Makefile.nuttx`,
To flash,
```
# assume you are in jerryscript folder
make -f ./targets/nuttx-stm32f4/Makefile.nuttx flash
# assuming you are in nuttx folder
sudo ../stlink/build/st-flash write nuttx.bin 0x8000000
```
#### 6. Cleaning
To clean the build result,
```
make -f ./targets/nuttx-stm32f4/Makefile.nuttx clean
```
### Running JerryScript
Prepare a micro SD-card and prepare `hello.js` like this in the root directory of SD-card.
```
print("Hello JerryScript!");
```
Power Off(unplug both USB cables), plug the memory card to BB, and power on again.
You can use `minicom` for terminal program, or any other you may like, but match
You can use `minicom` for terminal program, or any other you may like, but set
baud rate to `115200`.
```
minicom --device=/dev/ttyACM0 --baud=115200
sudo minicom --device=/dev/ttyACM0 --baud=115200
```
You may have to press `RESET` on the board and press `Enter` keys on the console
several times to make `nsh` prompt to appear.
@@ -152,27 +100,16 @@ please set `Add Carriage Ret` option by `CTRL-A` > `Z` > `U` at the console,
if you're using `minicom`.
Run `jerryscript` with `hello.js`
Run `jerry` with javascript file(s)
```
NuttShell (NSH)
nsh>
nsh>
nsh> jerryscript /mnt/sdcard/hello.js
PARAM 1 : [/mnt/sdcard/hello.js]
Hello JerryScript!
nsh> jerry full_path/any.js
```
Please give absolute path of the script file or may get an error like this.
Without argument it prints:
```
nsh> cd /mnt/sdcard
nsh> jerryscript ./hello.js
PARAM 1 : [./hello.js]
Failed to fopen [./hello.js]
JERRY_STANDALONE_EXIT_CODE_FAIL
nsh>
nsh>
nsh> jerryscript /mnt/sdcard/hello.js
PARAM 1 : [/mnt/sdcard/hello.js]
Hello JerryScript!
nsh> jerry
No input files, running a hello world demo:
Hello world 5 times from JerryScript
```