1### About 2 3This folder contains files to run JerryScript on 4[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/) 5 6### How to build 7 8#### 1. Setup the build environment for STM32F4-Discovery board 9 10Clone the necessary projects into a `jerry-nuttx` directory. The last tested working version of NuttX is 7.28. 11 12```sh 13# Create a base folder for all the projects. 14mkdir jerry-nuttx && cd jerry-nuttx 15 16git clone https://github.com/jerryscript-project/jerryscript.git 17git clone https://bitbucket.org/nuttx/nuttx.git -b nuttx-7.28 18git clone https://bitbucket.org/nuttx/apps.git -b nuttx-7.28 19git clone https://github.com/texane/stlink.git -b v1.5.1 20``` 21 22The following directory structure is created after these commands: 23 24``` 25jerry-nuttx 26 + apps 27 + jerryscript 28 | + targets 29 | + nuttx-stm32f4 30 + nuttx 31 + stlink 32``` 33 34#### 2. Build JerryScript for NuttX 35 36Build JerryScript as a static library using the NuttX folder as sysroot. The created static libraries will be used later by NuttX. 37 38```sh 39# Assuming you are in jerry-nuttx folder. 40jerryscript/tools/build.py \ 41 --clean \ 42 --lto=OFF \ 43 --jerry-cmdline=OFF \ 44 --jerry-libm=ON \ 45 --all-in-one=ON \ 46 --mem-heap=70 \ 47 --profile=es2015-subset \ 48 --compile-flag="--sysroot=${PWD}/nuttx" \ 49 --toolchain=${PWD}/jerryscript/cmake/toolchain_mcu_stm32f4.cmake 50``` 51 52#### 3. Copy JerryScript's application files to NuttX 53 54After creating the static libs (see previous step), it is needed to move the JerryScript application files to the NuttX's interpreter path. 55 56```sh 57# Assuming you are in jerry-nuttx folder. 58mkdir -p apps/interpreters/jerryscript 59cp jerryscript/targets/nuttx-stm32f4/* apps/interpreters/jerryscript/ 60 61# Or more simply: 62# ln -s jerryscript/targets/nuttx-stm32f4 apps/interpreters/jerryscript 63``` 64 65#### 4. Configure NuttX 66 67NuttX requires configuration first. The configuration creates a `.config` file in the root folder of NuttX that has all the necessary options for the build. 68 69```sh 70# Assuming you are in jerry-nuttx folder. 71cd nuttx/tools 72 73# Configure NuttX to use USB console shell. 74./configure.sh stm32f4discovery/usbnsh 75``` 76 77By default, JerryScript is not enabled, so it is needed to modify the configuration file. 78 79##### 4.1 Enable JerryScript without user interaction 80 81```sh 82# Assuming you are in jerry-nuttx folder. 83sed --in-place "s/CONFIG_HOST_WINDOWS/# CONFIG_HOST_WINDOWS/g" nuttx/.config 84sed --in-place "s/CONFIG_WINDOWS_CYGWIN/# CONFIG_WINDOWS_CYGWIN/g" nuttx/.config 85sed --in-place "s/CONFIG_TOOLCHAIN_WINDOWS/# CONFIG_TOOLCHAIN_WINDOWS/g" nuttx/.config 86 87cat >> nuttx/.config << EOL 88CONFIG_HOST_LINUX=y 89CONFIG_ARCH_FPU=y 90CONFIG_JERRYSCRIPT=y 91CONFIG_JERRYSCRIPT_PRIORITY=100 92CONFIG_JERRYSCRIPT_STACKSIZE=16384 93EOL 94``` 95 96##### 4.2 Enable JerryScript using kconfig-frontend 97 98`kconfig-frontend` could be useful if there are another options that should be enabled or disabled in NuttX. 99 100###### 4.2.1 Install kconfig-frontend 101 102```sh 103# Assuming you are in jerry-nuttx folder. 104git clone https://bitbucket.org/nuttx/tools.git nuttx-tools 105cd nuttx-tools/kconfig-frontends 106 107./configure \ 108 --disable-nconf \ 109 --disable-gconf \ 110 --disable-qconf \ 111 --disable-utils \ 112 --disable-shared \ 113 --enable-static \ 114 --prefix=${PWD}/install 115 116make 117sudo make install 118 119# Add the install folder to PATH 120PATH=$PATH:${PWD}/install/bin 121``` 122 123###### 4.2.2 Enable JerryScript 124```sh 125# Assuming you are in jerry-nuttx folder. 126# Might be required to run `make menuconfig` twice. 127make -C nuttx menuconfig 128``` 129 130* Change `Build Setup -> Build Host Platform` to Linux 131* Enable `System Type -> FPU support` 132* Enable JerryScript `Application Configuration -> Interpreters -> JerryScript` 133 134#### 5. Build NuttX 135 136```sh 137# Assuming you are in jerry-nuttx folder. 138make -C nuttx 139``` 140 141#### 6. Flash the device 142 143Connect Mini-USB for power supply and connect Micro-USB for `NSH` console. 144 145```sh 146# Assuming you are in jerry-nuttx folder. 147make -C stlink release 148 149sudo stlink/build/Release/st-flash write nuttx/nuttx.bin 0x8000000 150``` 151 152### Running JerryScript 153 154You can use `minicom` for terminal program, or any other you may like, but set 155baud rate to `115200`. 156 157```sh 158sudo minicom --device=/dev/ttyACM0 --baud=115200 159``` 160 161You may have to press `RESET` on the board and press `Enter` keys on the console 162several times to make `nsh` prompt to appear. 163 164If the prompt shows like this, 165``` 166NuttShell (NSH) 167 nsh> 168 nsh> 169 nsh> 170``` 171please set `Add Carriage Ret` option by `CTRL-A` > `Z` > `U` at the console, 172if you're using `minicom`. 173 174 175Run `jerry` with javascript file(s) 176 177``` 178NuttShell (NSH) 179nsh> jerry full_path/any.js 180``` 181 182Without argument it prints: 183``` 184nsh> jerry 185No input files, running a hello world demo: 186Hello world 5 times from JerryScript 187``` 188