Update Iot.js
[platform/upstream/iotjs.git] / tools / docs / build / Build-for-NuttX.md
1 ## Build IoT.js with NuttX
2
3 ### Target board
4 We work on STM32F4 board for NuttX and the detail of the reference board is well described at [STM32F4-discovery with BB](http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/LN1199/PF255417).
5
6 ### Relation with STM board?
7 We do not have any business relation with STM board. It is selected because it has enough RAM and Flash ROM, so that development can be more comfortable. And it has lots of pins to play with.
8
9 When IoT.js is built up and optimized, it may work in devices having smaller resource.
10
11
12 ### 1. Prepare for prerequisite
13 #### Linux
14
15 ```bash
16 $ sudo apt-get install autoconf libtool gperf flex bison autoconf2.13
17 $ sudo apt-get install cmake libncurses-dev libusb-1.0-0-dev
18 $ sudo apt-get install libsgutils2-dev gcc-arm-none-eabi minicom
19 ```
20
21 To use menuconfig in NuttX, you may need to install kconfig frontend.
22
23 ```bash
24 $ git clone https://github.com/jameswalmsley/kconfig-frontends.git
25 $ cd kconfig-frontends
26 $ ./bootstrap
27 $ ./configure --enable-mconf
28 $ make
29 $ sudo make install
30 $ sudo ldconfig
31 ```
32
33 #### macOS
34
35 * Install Xcode from the app store and run once Xcode to install components.
36 * Install Xcode command line tools.
37 ```bash
38 $ xcode-select --install
39 ```
40 * Install [Homebrew package manager](http://brew.sh/)
41 * Install packages
42 ```bash
43 $ brew tap PX4/homebrew-px4
44 $ brew update
45 $ brew install cmake bash-completion pkg-config kconfig-frontends
46 $ brew install gcc-arm-none-eabi libusb minicom
47 ```
48
49 ### 2. Build NuttX (For the first time)
50
51 To generate headers which are required to build IoT.js, for the first time, you need to build NuttX at least once. This time nuttx build will be failed. But don't worry at this time. After one execution, you don't need this sequence any more.
52
53 #### Supported Nuttx version
54 |Repository|Tag Name|
55 |----------|:------:|
56 | nuttx | nuttx-7.19 |
57 | app | nuttx-7.19 |
58
59 We only guarantee that the specified version will work well. It is recommended to check out with the specified tag from a git repository.
60
61
62 #### Follow the instruction
63 * [STM32F4-discovery](../../targets/nuttx-stm32f4/README.md)
64
65
66 ### 3. Build IoT.js for NuttX
67
68 These options are needed.
69 ```bash
70 --target-arch=arm
71 --target-os=nuttx
72 --nuttx-home=/path/to/nuttx
73 --target-board=stm32f4dis
74 --jerry-heaplimit=[..]
75 ```
76
77 For example,
78 ```bash
79 $ ./tools/build.py \
80 --target-arch=arm --target-os=nuttx --nuttx-home=../nuttx \
81 --target-board=stm32f4dis --jerry-heaplimit=78
82 ```
83
84 Library files will be generated like below when build is successful.
85
86 ```bash
87 $ ls build/arm-nuttx/release/lib
88 libhttpparser.a libiotjs.a libjerrycore.a libtuv.a
89 ```
90
91 ### 4. Build NuttX
92
93 This time make command for NuttX has to be successful unlike above.
94
95 #### Follow the instruction
96 * [STM32F4-discovery](../../targets/nuttx-stm32f4/README.md)
97
98 ### 5. Run IoT.js
99
100 #### USB Connection
101
102 There are two USB Connections on the Target board. USB mini CN1 and USB micro CN5. Both USB ports need to be connected to your Host. CN1 is used for power and Flashing, but it will not appear as a device in Linux. CN5 is used for NSH and will appear as `/dev/ttyACM0(linux)` or  `/dev/tty.usbmodem1(macOS)` when things work well.
103
104 #### Use minicom
105
106 ```bash
107 // linux
108 $ minicom --device=/dev/ttyACM0
109 // macOS
110 $ minicom --device=/dev/tty.usbmodem1
111
112 ```
113 You may need to enable _Add Carriage Return_ option.
114 * Press <kbd>Ctrl-A</kbd> + <kbd>Z</kbd> + <kbd>U</kbd> for short in minicom screen. (For linux user)
115 * Press <kbd>[Meta](http://osxdaily.com/2013/02/01/use-option-as-meta-key-in-mac-os-x-terminal/)</kbd> + <kbd>Z</kbd> for short in minicom screen. (For macOS user)
116
117 Press _Enter_ key several times to trigger NuttShell to start.
118
119 If micro SD is enabled, you can copy any script file to it and run with _nsh_, for example;
120 ```
121 NuttShell (NSH)
122 nsh> mount -t vfat /dev/mmcsd0 /mnt/sdcard
123 nsh> iotjs /mnt/sdcard/path_to_file.js
124 ```
125
126 If you see
127 ```
128 +-----------------------------+                  
129 |                             |                  
130 |  Cannot open /dev/ttyACM0!  |                  
131 |                             |                  
132 +-----------------------------+
133 ```
134 and it stays on the screen, something is wrong. Blue LED may blink if NuttX is in abnormal state. Press black(reset) button on the board and try again. If you still see this warning message, begin with original NuttX code and check your board, USB line and other softwares.