|
| 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 | +#### 4. Continue build NuttX |
| 93 | + |
| 94 | +``` |
| 95 | +# asssume you are in harmony folder |
| 96 | +cd nuttx/nuttx |
| 97 | +make |
| 98 | +``` |
| 99 | + |
| 100 | + |
| 101 | +#### 5. Flashing |
| 102 | + |
| 103 | +Connect Mini-USB for power supply and connect Micro-USB for `NSH` console. |
| 104 | + |
| 105 | +Please refer [this](https://github.com/Samsung/iotjs/wiki/Build-for-NuttX#prepare-flashing-to-target-board) |
| 106 | +link to prepare `stlink` utility. |
| 107 | + |
| 108 | + |
| 109 | +To flash with `Makefile.nuttx`, |
| 110 | +``` |
| 111 | +# assume you are in jerryscript folder |
| 112 | +make -f ./targets/nuttx-stm32f4/Makefile.nuttx flash |
| 113 | +``` |
| 114 | + |
| 115 | +#### 6. Cleaning |
| 116 | + |
| 117 | +To clean the build result, |
| 118 | +``` |
| 119 | +make -f ./targets/nuttx-stm32f4/Makefile.nuttx clean |
| 120 | +``` |
| 121 | + |
| 122 | + |
| 123 | +### Running JerryScript |
| 124 | + |
| 125 | +Prepare a micro SD-card and prepare `hello.js` like this in the root directory of SD-card. |
| 126 | + |
| 127 | +``` |
| 128 | +print("Hello JerryScript!"); |
| 129 | +``` |
| 130 | + |
| 131 | +Power Off(unplug both USB cables), plug the memory card to BB, and power on again. |
| 132 | + |
| 133 | +You can use `minicom` for terminal program, or any other you may like, but match |
| 134 | +baud rate to `115200`. |
| 135 | + |
| 136 | +``` |
| 137 | +minicom --device=/dev/ttyACM0 --baud=115200 |
| 138 | +``` |
| 139 | + |
| 140 | + |
| 141 | +You may have to press `RESET` on the board and press `Enter` keys on the console |
| 142 | +several times to make `nsh` prompt to appear. |
| 143 | + |
| 144 | +If the prompt shows like this, |
| 145 | +``` |
| 146 | +NuttShell (NSH) |
| 147 | + nsh> |
| 148 | + nsh> |
| 149 | + nsh> |
| 150 | +``` |
| 151 | +please set `Add Carriage Ret` option by `CTRL-A` > `Z` > `U` at the console, |
| 152 | +if you're using `minicom`. |
| 153 | + |
| 154 | + |
| 155 | +Run `jerryscript` with `hello.js` |
| 156 | + |
| 157 | +``` |
| 158 | +NuttShell (NSH) |
| 159 | +nsh> |
| 160 | +nsh> |
| 161 | +nsh> jerryscript /mnt/sdcard/hello.js |
| 162 | +PARAM 1 : [/mnt/sdcard/hello.js] |
| 163 | +Hello JerryScript! |
| 164 | +``` |
| 165 | + |
| 166 | +Please give absolute path of the script file or may get an error like this. |
| 167 | +``` |
| 168 | +nsh> cd /mnt/sdcard |
| 169 | +nsh> jerryscript ./hello.js |
| 170 | +PARAM 1 : [./hello.js] |
| 171 | +Failed to fopen [./hello.js] |
| 172 | +JERRY_STANDALONE_EXIT_CODE_FAIL |
| 173 | +nsh> |
| 174 | +nsh> |
| 175 | +nsh> jerryscript /mnt/sdcard/hello.js |
| 176 | +PARAM 1 : [/mnt/sdcard/hello.js] |
| 177 | +Hello JerryScript! |
| 178 | +``` |
0 commit comments