1425bb815Sopenharmony_ci### About 2425bb815Sopenharmony_ci 3425bb815Sopenharmony_ciThis folder contains files to run JerryScript on 4425bb815Sopenharmony_ci[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/) 5425bb815Sopenharmony_ci 6425bb815Sopenharmony_ci### How to build 7425bb815Sopenharmony_ci 8425bb815Sopenharmony_ci#### 1. Setup the build environment for STM32F4-Discovery board 9425bb815Sopenharmony_ci 10425bb815Sopenharmony_ciClone the necessary projects into a `jerry-nuttx` directory. The last tested working version of NuttX is 7.28. 11425bb815Sopenharmony_ci 12425bb815Sopenharmony_ci```sh 13425bb815Sopenharmony_ci# Create a base folder for all the projects. 14425bb815Sopenharmony_cimkdir jerry-nuttx && cd jerry-nuttx 15425bb815Sopenharmony_ci 16425bb815Sopenharmony_cigit clone https://github.com/jerryscript-project/jerryscript.git 17425bb815Sopenharmony_cigit clone https://bitbucket.org/nuttx/nuttx.git -b nuttx-7.28 18425bb815Sopenharmony_cigit clone https://bitbucket.org/nuttx/apps.git -b nuttx-7.28 19425bb815Sopenharmony_cigit clone https://github.com/texane/stlink.git -b v1.5.1 20425bb815Sopenharmony_ci``` 21425bb815Sopenharmony_ci 22425bb815Sopenharmony_ciThe following directory structure is created after these commands: 23425bb815Sopenharmony_ci 24425bb815Sopenharmony_ci``` 25425bb815Sopenharmony_cijerry-nuttx 26425bb815Sopenharmony_ci + apps 27425bb815Sopenharmony_ci + jerryscript 28425bb815Sopenharmony_ci | + targets 29425bb815Sopenharmony_ci | + nuttx-stm32f4 30425bb815Sopenharmony_ci + nuttx 31425bb815Sopenharmony_ci + stlink 32425bb815Sopenharmony_ci``` 33425bb815Sopenharmony_ci 34425bb815Sopenharmony_ci#### 2. Build JerryScript for NuttX 35425bb815Sopenharmony_ci 36425bb815Sopenharmony_ciBuild JerryScript as a static library using the NuttX folder as sysroot. The created static libraries will be used later by NuttX. 37425bb815Sopenharmony_ci 38425bb815Sopenharmony_ci```sh 39425bb815Sopenharmony_ci# Assuming you are in jerry-nuttx folder. 40425bb815Sopenharmony_cijerryscript/tools/build.py \ 41425bb815Sopenharmony_ci --clean \ 42425bb815Sopenharmony_ci --lto=OFF \ 43425bb815Sopenharmony_ci --jerry-cmdline=OFF \ 44425bb815Sopenharmony_ci --jerry-libm=ON \ 45425bb815Sopenharmony_ci --all-in-one=ON \ 46425bb815Sopenharmony_ci --mem-heap=70 \ 47425bb815Sopenharmony_ci --profile=es2015-subset \ 48425bb815Sopenharmony_ci --compile-flag="--sysroot=${PWD}/nuttx" \ 49425bb815Sopenharmony_ci --toolchain=${PWD}/jerryscript/cmake/toolchain_mcu_stm32f4.cmake 50425bb815Sopenharmony_ci``` 51425bb815Sopenharmony_ci 52425bb815Sopenharmony_ci#### 3. Copy JerryScript's application files to NuttX 53425bb815Sopenharmony_ci 54425bb815Sopenharmony_ciAfter creating the static libs (see previous step), it is needed to move the JerryScript application files to the NuttX's interpreter path. 55425bb815Sopenharmony_ci 56425bb815Sopenharmony_ci```sh 57425bb815Sopenharmony_ci# Assuming you are in jerry-nuttx folder. 58425bb815Sopenharmony_cimkdir -p apps/interpreters/jerryscript 59425bb815Sopenharmony_cicp jerryscript/targets/nuttx-stm32f4/* apps/interpreters/jerryscript/ 60425bb815Sopenharmony_ci 61425bb815Sopenharmony_ci# Or more simply: 62425bb815Sopenharmony_ci# ln -s jerryscript/targets/nuttx-stm32f4 apps/interpreters/jerryscript 63425bb815Sopenharmony_ci``` 64425bb815Sopenharmony_ci 65425bb815Sopenharmony_ci#### 4. Configure NuttX 66425bb815Sopenharmony_ci 67425bb815Sopenharmony_ciNuttX requires configuration first. The configuration creates a `.config` file in the root folder of NuttX that has all the necessary options for the build. 68425bb815Sopenharmony_ci 69425bb815Sopenharmony_ci```sh 70425bb815Sopenharmony_ci# Assuming you are in jerry-nuttx folder. 71425bb815Sopenharmony_cicd nuttx/tools 72425bb815Sopenharmony_ci 73425bb815Sopenharmony_ci# Configure NuttX to use USB console shell. 74425bb815Sopenharmony_ci./configure.sh stm32f4discovery/usbnsh 75425bb815Sopenharmony_ci``` 76425bb815Sopenharmony_ci 77425bb815Sopenharmony_ciBy default, JerryScript is not enabled, so it is needed to modify the configuration file. 78425bb815Sopenharmony_ci 79425bb815Sopenharmony_ci##### 4.1 Enable JerryScript without user interaction 80425bb815Sopenharmony_ci 81425bb815Sopenharmony_ci```sh 82425bb815Sopenharmony_ci# Assuming you are in jerry-nuttx folder. 83425bb815Sopenharmony_cised --in-place "s/CONFIG_HOST_WINDOWS/# CONFIG_HOST_WINDOWS/g" nuttx/.config 84425bb815Sopenharmony_cised --in-place "s/CONFIG_WINDOWS_CYGWIN/# CONFIG_WINDOWS_CYGWIN/g" nuttx/.config 85425bb815Sopenharmony_cised --in-place "s/CONFIG_TOOLCHAIN_WINDOWS/# CONFIG_TOOLCHAIN_WINDOWS/g" nuttx/.config 86425bb815Sopenharmony_ci 87425bb815Sopenharmony_cicat >> nuttx/.config << EOL 88425bb815Sopenharmony_ciCONFIG_HOST_LINUX=y 89425bb815Sopenharmony_ciCONFIG_ARCH_FPU=y 90425bb815Sopenharmony_ciCONFIG_JERRYSCRIPT=y 91425bb815Sopenharmony_ciCONFIG_JERRYSCRIPT_PRIORITY=100 92425bb815Sopenharmony_ciCONFIG_JERRYSCRIPT_STACKSIZE=16384 93425bb815Sopenharmony_ciEOL 94425bb815Sopenharmony_ci``` 95425bb815Sopenharmony_ci 96425bb815Sopenharmony_ci##### 4.2 Enable JerryScript using kconfig-frontend 97425bb815Sopenharmony_ci 98425bb815Sopenharmony_ci`kconfig-frontend` could be useful if there are another options that should be enabled or disabled in NuttX. 99425bb815Sopenharmony_ci 100425bb815Sopenharmony_ci###### 4.2.1 Install kconfig-frontend 101425bb815Sopenharmony_ci 102425bb815Sopenharmony_ci```sh 103425bb815Sopenharmony_ci# Assuming you are in jerry-nuttx folder. 104425bb815Sopenharmony_cigit clone https://bitbucket.org/nuttx/tools.git nuttx-tools 105425bb815Sopenharmony_cicd nuttx-tools/kconfig-frontends 106425bb815Sopenharmony_ci 107425bb815Sopenharmony_ci./configure \ 108425bb815Sopenharmony_ci --disable-nconf \ 109425bb815Sopenharmony_ci --disable-gconf \ 110425bb815Sopenharmony_ci --disable-qconf \ 111425bb815Sopenharmony_ci --disable-utils \ 112425bb815Sopenharmony_ci --disable-shared \ 113425bb815Sopenharmony_ci --enable-static \ 114425bb815Sopenharmony_ci --prefix=${PWD}/install 115425bb815Sopenharmony_ci 116425bb815Sopenharmony_cimake 117425bb815Sopenharmony_cisudo make install 118425bb815Sopenharmony_ci 119425bb815Sopenharmony_ci# Add the install folder to PATH 120425bb815Sopenharmony_ciPATH=$PATH:${PWD}/install/bin 121425bb815Sopenharmony_ci``` 122425bb815Sopenharmony_ci 123425bb815Sopenharmony_ci###### 4.2.2 Enable JerryScript 124425bb815Sopenharmony_ci```sh 125425bb815Sopenharmony_ci# Assuming you are in jerry-nuttx folder. 126425bb815Sopenharmony_ci# Might be required to run `make menuconfig` twice. 127425bb815Sopenharmony_cimake -C nuttx menuconfig 128425bb815Sopenharmony_ci``` 129425bb815Sopenharmony_ci 130425bb815Sopenharmony_ci* Change `Build Setup -> Build Host Platform` to Linux 131425bb815Sopenharmony_ci* Enable `System Type -> FPU support` 132425bb815Sopenharmony_ci* Enable JerryScript `Application Configuration -> Interpreters -> JerryScript` 133425bb815Sopenharmony_ci 134425bb815Sopenharmony_ci#### 5. Build NuttX 135425bb815Sopenharmony_ci 136425bb815Sopenharmony_ci```sh 137425bb815Sopenharmony_ci# Assuming you are in jerry-nuttx folder. 138425bb815Sopenharmony_cimake -C nuttx 139425bb815Sopenharmony_ci``` 140425bb815Sopenharmony_ci 141425bb815Sopenharmony_ci#### 6. Flash the device 142425bb815Sopenharmony_ci 143425bb815Sopenharmony_ciConnect Mini-USB for power supply and connect Micro-USB for `NSH` console. 144425bb815Sopenharmony_ci 145425bb815Sopenharmony_ci```sh 146425bb815Sopenharmony_ci# Assuming you are in jerry-nuttx folder. 147425bb815Sopenharmony_cimake -C stlink release 148425bb815Sopenharmony_ci 149425bb815Sopenharmony_cisudo stlink/build/Release/st-flash write nuttx/nuttx.bin 0x8000000 150425bb815Sopenharmony_ci``` 151425bb815Sopenharmony_ci 152425bb815Sopenharmony_ci### Running JerryScript 153425bb815Sopenharmony_ci 154425bb815Sopenharmony_ciYou can use `minicom` for terminal program, or any other you may like, but set 155425bb815Sopenharmony_cibaud rate to `115200`. 156425bb815Sopenharmony_ci 157425bb815Sopenharmony_ci```sh 158425bb815Sopenharmony_cisudo minicom --device=/dev/ttyACM0 --baud=115200 159425bb815Sopenharmony_ci``` 160425bb815Sopenharmony_ci 161425bb815Sopenharmony_ciYou may have to press `RESET` on the board and press `Enter` keys on the console 162425bb815Sopenharmony_ciseveral times to make `nsh` prompt to appear. 163425bb815Sopenharmony_ci 164425bb815Sopenharmony_ciIf the prompt shows like this, 165425bb815Sopenharmony_ci``` 166425bb815Sopenharmony_ciNuttShell (NSH) 167425bb815Sopenharmony_ci nsh> 168425bb815Sopenharmony_ci nsh> 169425bb815Sopenharmony_ci nsh> 170425bb815Sopenharmony_ci``` 171425bb815Sopenharmony_ciplease set `Add Carriage Ret` option by `CTRL-A` > `Z` > `U` at the console, 172425bb815Sopenharmony_ciif you're using `minicom`. 173425bb815Sopenharmony_ci 174425bb815Sopenharmony_ci 175425bb815Sopenharmony_ciRun `jerry` with javascript file(s) 176425bb815Sopenharmony_ci 177425bb815Sopenharmony_ci``` 178425bb815Sopenharmony_ciNuttShell (NSH) 179425bb815Sopenharmony_cinsh> jerry full_path/any.js 180425bb815Sopenharmony_ci``` 181425bb815Sopenharmony_ci 182425bb815Sopenharmony_ciWithout argument it prints: 183425bb815Sopenharmony_ci``` 184425bb815Sopenharmony_cinsh> jerry 185425bb815Sopenharmony_ciNo input files, running a hello world demo: 186425bb815Sopenharmony_ciHello world 5 times from JerryScript 187425bb815Sopenharmony_ci``` 188