6c4f7d1300c93ef2f163d76894cff62d621440b3
[platform/upstream/iotjs.git] / targets / nuttx-stm32f4 / README.md
1 ### About
2
3 This directory contains files to run IoT.js 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. Set up the build environment for STM32F4-Discovery board
9
10 Clone IoT.js and NuttX into iotjs-nuttx directory
11
12 ```bash
13 $ mkdir iotjs-nuttx
14 $ cd iotjs-nuttx
15 $ git clone https://github.com/Samsung/iotjs.git
16 $ git clone https://bitbucket.org/nuttx/nuttx.git --branch nuttx-7.19
17 $ git clone https://bitbucket.org/nuttx/apps.git --branch nuttx-7.19
18 $ git clone https://github.com/texane/stlink.git
19 ```
20
21 Note that we only support the specified git tag from nuttx repository
22
23 The following directory structure is created after these commands
24
25 ```bash
26 iotjs-nuttx
27   + apps
28   + iotjs
29   |  + targets
30   |      + nuttx-stm32f4
31   + nuttx
32   + stlink
33 ```
34
35 #### 2. Add IoT.js as a builtin application for NuttX
36
37 ```bash
38 $ cd apps/system
39 $ mkdir iotjs
40 $ cp ../../iotjs/targets/nuttx-stm32f4/app/* ./iotjs/
41 ```
42
43 #### 3. Configure NuttX
44
45 ```bash
46 # assuming you are in iotjs-nuttx folder
47 $ cd nuttx/tools
48
49 # configure NuttX USB console shell
50 $ ./configure.sh stm32f4discovery/usbnsh
51 ```
52
53 Now you can configure nuttx like either of below. For convenience, we provide built-in configure file for you. (This configure file is equipped with modules specified as `always`. For `optional` modules, you might follow instructions below.)
54 ```bash
55 $ cd ..
56 $ cp ../iotjs/targets/nuttx-stm32f4/nuttx/.config.default .config
57 ```
58
59 Or if you want to configure yourself, you can follow guide below.
60 ```bash
61 $ cd ..
62 # might require to run "make menuconfig" twice
63 $ make menuconfig
64 ```
65
66 Followings are the options to set:
67
68 * Common
69   * Change `Build Setup -> Build Host Platform` from _Windows_ to [_Linux_|_OSX_]
70   * Enable `System Type -> FPU support`
71   * Enable `System Type -> STM32 Peripheral Support -> SDIO`
72   * Enable `RTOS Features -> Clocks and Timers -> Support CLOCK_MONOTONIC`
73   * Enable `RTOS Features -> Pthread Options -> Enable mutex types`
74   * Enable `RTOS Features -> Files and I/O -> Enable /dev/console`
75   * Enable `RTOS Features -> Work queue support -> High priority (kernel) worker thread`
76   * Disable `Device Drivers -> Disable driver poll interfaces`
77   * Enable `Device Drivers -> MMC/SD Driver Support`
78   * Enable `Device Drivers -> MMC/SD Driver Support -> MMC/SD SDIO transfer support`
79   * Enable `Networking Support -> Networking Support`
80   * Enable `Networking Support -> Socket Support -> Socket options`
81   * Enable `Networking Support -> Unix Domain Socket Support`
82   * Enable `Networking Support -> TCP/IP Networking`
83   * Enable `Networking Support -> TCP/IP Networking -> Enable TCP/IP write buffering`
84   * Enable `File Systems -> FAT file system`
85   * Enable `File Systems -> FAT file system -> FAT upper/lower names`
86   * Enable `File Systems -> FAT file system -> FAT long file names`
87   * Enable `Device Drivers -> Network Device/PHY Support -> Late driver initialization`
88   * Enable `Library Routines -> Standard Math library`
89   * Enable `Application Configuration -> System Libraries and NSH Add-ons -> IoT.js`
90   * Enable all children of `Application Configuration -> System Libraries and NSH Add-ons -> readline() Support` (for those who wants to use readline)
91
92 * For `net` module
93   * Enable `System Type -> STM32 Peripheral Support -> Ethernet MAC`
94   * Disable `System Type -> STM32 Peripheral Support -> USART2`
95   * Enable `System Type -> STM32 Peripheral Support -> USART6`
96   * Set `System Type -> Ethernet MAC configuration -> PHY address` to `0`
97   * Set `System Type -> Ethernet MAC configuration -> PHY Status Register Address (decimal)` to `31`
98   * Enable `System Type -> Ethernet MAC configuration -> PHY Status Alternate Bit Layout`
99   * Set `System Type -> Ethernet MAC configuration -> PHY Mode Mask` to `0x001c`
100   * Set `System Type -> Ethernet MAC configuration -> 10MBase-T Half Duplex Value` to `0x0004`
101   * Set `System Type -> Ethernet MAC configuration -> 100Base-T Half Duplex Value` to `0x0008`
102   * Set `System Type -> Ethernet MAC configuration -> 10Base-T Full Duplex Value` to `0x0014`
103   * Set `System Type -> Ethernet MAC configuration -> 10MBase-T Full Duplex Value` to `0x0018`
104   * Set `System Type -> Ethernet MAC configuration -> RMII clock configuration` to `External RMII clock`
105   * Enable `Board Selection -> STM32F4DIS-BB base board`
106   * Set `Device Drivers -> Network Device/PHY Support -> Board PHY Selection` to `SMSC LAN8720 PHY`
107   * Enable `Networking Support -> Data link support -> Local loopback`
108   * Enable `Networking Support -> TCP/IP Networking -> TCP/IP backlog support`
109   * Enable `Networking Support -> ARP Configuration -> ARP send`
110
111 * For `dgram`
112   * Enable `Networking Support > UDP Networking`
113
114 * For `pwm` module
115   * Enable `System Type -> STM32 Peripheral Support -> TIM(N)`
116   * Enable `System Type -> Timer Configuration -> TIM(N) PWM`
117   * Set `System Type -> Timer Configuration -> TIM(N) PWM -> TIM(n) PWM Output Channel` to channel number you want
118   * Enable `Device Drivers -> PWM Driver Support`
119
120 * For `adc` module
121   * Enable `System Type -> STM32 Peripheral Support -> ADC(N)`
122   * Enable `System Type -> STM32 Peripheral Support -> TIM(M)`
123   * Enable `System Type -> Timer Configuration -> TIM(M) ADC`
124   * Enable `Device Drivers -> Analog Device(ADC/DAC) Support`
125   * Enable `Device Drivers -> Analog Device(ADC/DAC) Support -> Analog-to-Digital Conversion`
126
127 * For `uart` module
128   * Enable `System Type -> STM32 Peripheral Support -> U[S]ART(N)`
129
130 #### 4. Build IoT.js for NuttX
131
132 ##### Follow the instruction
133 * [Build-for-NuttX](../../docs/build/Build-for-NuttX.md)
134
135 #### 5. Build NuttX
136
137 ```bash
138 # assuming you are in iotjs-nuttx folder
139 $ cd nuttx/
140 $ make
141 ```
142 For release version, you can type R=1 make on the command shell.
143
144 #### 6. Flashing
145
146 Connect Mini-USB for power supply and connect Micro-USB for `NSH` console.
147
148 To configure `stlink` utility for flashing, follow the instructions [here](https://github.com/texane/stlink#build-from-sources).
149
150 To flash,
151 ```bash
152 # assuming you are in nuttx folder
153 $ sudo ../stlink/build/st-flash write nuttx.bin 0x8000000
154 ```