1425bb815Sopenharmony_ci### About 2425bb815Sopenharmony_ci 3425bb815Sopenharmony_ciThis folder contains files to integrate JerryScript with Zephyr RTOS to 4425bb815Sopenharmony_cirun on a number of supported boards (like 5425bb815Sopenharmony_ci[Arduino 101 / Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101), 6425bb815Sopenharmony_ci[Zephyr Arduino 101](https://www.zephyrproject.org/doc/board/arduino_101.html)). 7425bb815Sopenharmony_ci 8425bb815Sopenharmony_ci### How to build 9425bb815Sopenharmony_ci 10425bb815Sopenharmony_ci#### 1. Preface 11425bb815Sopenharmony_ci 12425bb815Sopenharmony_ci1. Directory structure 13425bb815Sopenharmony_ci 14425bb815Sopenharmony_ciAssume `harmony` as the path to the projects to build. 15425bb815Sopenharmony_ciThe folder tree related would look like this. 16425bb815Sopenharmony_ci 17425bb815Sopenharmony_ci``` 18425bb815Sopenharmony_ciharmony 19425bb815Sopenharmony_ci + jerryscript 20425bb815Sopenharmony_ci | + targets 21425bb815Sopenharmony_ci | + zephyr 22425bb815Sopenharmony_ci + zephyr-project 23425bb815Sopenharmony_ci``` 24425bb815Sopenharmony_ci 25425bb815Sopenharmony_ci 26425bb815Sopenharmony_ci2. Target boards/emulations 27425bb815Sopenharmony_ci 28425bb815Sopenharmony_ciFollowing Zephyr boards were tested: qemu_x86, qemu_cortex_m3, arduino_101, 29425bb815Sopenharmony_cifrdm_k64f. 30425bb815Sopenharmony_ci 31425bb815Sopenharmony_ci 32425bb815Sopenharmony_ci#### 2. Prepare Zephyr 33425bb815Sopenharmony_ci 34425bb815Sopenharmony_ciFollow [this](https://www.zephyrproject.org/doc/getting_started/getting_started.html) page to get 35425bb815Sopenharmony_cithe Zephyr source and configure the environment. 36425bb815Sopenharmony_ci 37425bb815Sopenharmony_ciIf you just start with Zephyr, you may want to follow "Building a Sample 38425bb815Sopenharmony_ciApplication" section in the doc above and check that you can flash your 39425bb815Sopenharmony_citarget board. 40425bb815Sopenharmony_ci 41425bb815Sopenharmony_ciRemember to source the Zephyr environment as explained in the zephyr documenation: 42425bb815Sopenharmony_ci 43425bb815Sopenharmony_ci``` 44425bb815Sopenharmony_cicd zephyr-project 45425bb815Sopenharmony_cisource zephyr-env.sh 46425bb815Sopenharmony_ci 47425bb815Sopenharmony_ciexport ZEPHYR_GCC_VARIANT=zephyr 48425bb815Sopenharmony_ciexport ZEPHYR_SDK_INSTALL_DIR=<sdk installation directory> 49425bb815Sopenharmony_ci``` 50425bb815Sopenharmony_ci 51425bb815Sopenharmony_ci#### 3. Build JerryScript for Zephyr 52425bb815Sopenharmony_ci 53425bb815Sopenharmony_ciThe easiest way is to build and run on a QEMU emulator: 54425bb815Sopenharmony_ci 55425bb815Sopenharmony_ciFor x86 architecture: 56425bb815Sopenharmony_ci 57425bb815Sopenharmony_ci``` 58425bb815Sopenharmony_cimake -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_x86 run 59425bb815Sopenharmony_ci``` 60425bb815Sopenharmony_ci 61425bb815Sopenharmony_ciFor ARM (Cortex-M) architecture: 62425bb815Sopenharmony_ci 63425bb815Sopenharmony_ci``` 64425bb815Sopenharmony_cimake -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_cortex_m3 run 65425bb815Sopenharmony_ci``` 66425bb815Sopenharmony_ci 67425bb815Sopenharmony_ci#### 4. Build for Arduino 101 68425bb815Sopenharmony_ci 69425bb815Sopenharmony_ci``` 70425bb815Sopenharmony_ci# assume you are in harmony folder 71425bb815Sopenharmony_cicd jerryscript 72425bb815Sopenharmony_cimake -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101 73425bb815Sopenharmony_ci``` 74425bb815Sopenharmony_ci 75425bb815Sopenharmony_ciThis will generate the following libraries: 76425bb815Sopenharmony_ci``` 77425bb815Sopenharmony_ci./build/arduino_101/librelease-cp_minimal.jerry-core.a 78425bb815Sopenharmony_ci./build/arduino_101/librelease-cp_minimal.jerry-libm.lib.a 79425bb815Sopenharmony_ci./build/arduino_101/librelease.external-cp_minimal-entry.a 80425bb815Sopenharmony_ci``` 81425bb815Sopenharmony_ci 82425bb815Sopenharmony_ciThe final Zephyr image will be located here: 83425bb815Sopenharmony_ci``` 84425bb815Sopenharmony_ci./build/arduino_101/zephyr/zephyr.strip 85425bb815Sopenharmony_ci``` 86425bb815Sopenharmony_ci 87425bb815Sopenharmony_ci#### 5. Flashing 88425bb815Sopenharmony_ci 89425bb815Sopenharmony_ciDetails on how to flash the image can be found here: 90425bb815Sopenharmony_ci[Flashing image](https://www.zephyrproject.org/doc/board/arduino_101.html) 91425bb815Sopenharmony_ci(or similar page for other supported boards). 92425bb815Sopenharmony_ci 93425bb815Sopenharmony_ciTo be able to use this demo in hardware you will need the serial console 94425bb815Sopenharmony_ciwhich will be generating output to Pins 0 & 1. 95425bb815Sopenharmony_ci 96425bb815Sopenharmony_ciYou will need a 3.3v TTL to RS232, please follow the zephyr documentation on it. 97425bb815Sopenharmony_ci 98425bb815Sopenharmony_ciSome examples of building the software 99425bb815Sopenharmony_ci 100425bb815Sopenharmony_ci``` 101425bb815Sopenharmony_cimake -f ./targets/zephyr/Makefile.zephyr BOARD=<board> clean 102425bb815Sopenharmony_ci``` 103425bb815Sopenharmony_ci 104425bb815Sopenharmony_ci- Not using a Jtag and having a factory stock Arduino 101. 105425bb815Sopenharmony_ciYou can follow the Zephyr instructions to flash using the dfu-util command 106425bb815Sopenharmony_cior use this helper: 107425bb815Sopenharmony_ci 108425bb815Sopenharmony_ci``` 109425bb815Sopenharmony_cimake -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101 dfu-x86 110425bb815Sopenharmony_ci``` 111425bb815Sopenharmony_ci 112425bb815Sopenharmony_ciMake sure you have the factory bootloader in your device to use this method or it will not flash. 113425bb815Sopenharmony_ci 114425bb815Sopenharmony_ci- Using JTAG 115425bb815Sopenharmony_ci 116425bb815Sopenharmony_ciThere is a helper function to flash using the JTAG and Flywatter2 117425bb815Sopenharmony_ci 118425bb815Sopenharmony_ci 119425bb815Sopenharmony_ci 120425bb815Sopenharmony_ci``` 121425bb815Sopenharmony_cimake -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101 flash 122425bb815Sopenharmony_ci``` 123425bb815Sopenharmony_ci 124425bb815Sopenharmony_ci<warning> Careful if you flash the BOARD arduino_101, you will lose the bootloader 125425bb815Sopenharmony_ciand you will have to follow the zephyr documentation to get it back from 126425bb815Sopenharmony_cithe backup we all know you did at the setup. </warning> 127425bb815Sopenharmony_ci 128425bb815Sopenharmony_ci#### 6. Serial terminal 129425bb815Sopenharmony_ci 130425bb815Sopenharmony_ciTest command line in a serial terminal. 131425bb815Sopenharmony_ci 132425bb815Sopenharmony_ci 133425bb815Sopenharmony_ciYou should see something similar to this: 134425bb815Sopenharmony_ci``` 135425bb815Sopenharmony_ciJerryScript build: Aug 12 2016 17:12:55 136425bb815Sopenharmony_ciJerryScript API 1.0 137425bb815Sopenharmony_ciZephyr version 1.4.0 138425bb815Sopenharmony_cijs> 139425bb815Sopenharmony_ci``` 140425bb815Sopenharmony_ci 141425bb815Sopenharmony_ci 142425bb815Sopenharmony_ciRun the example javascript command test function 143425bb815Sopenharmony_ci``` 144425bb815Sopenharmony_cijs> var test=0; for (t=100; t<1000; t++) test+=t; print ('Hi JS World! '+test); 145425bb815Sopenharmony_ciHi JS World! 494550 146425bb815Sopenharmony_ci``` 147425bb815Sopenharmony_ci 148425bb815Sopenharmony_ci 149425bb815Sopenharmony_ciTry a more complex function: 150425bb815Sopenharmony_ci``` 151425bb815Sopenharmony_cijs> function hello(t) {t=t*10;return t}; print("result"+hello(10.5)); 152425bb815Sopenharmony_ci``` 153