quickstart-lite-steps-hi3516-running.md 10.3 KB
Newer Older
D
duangavin123 已提交
1
# Running a Hello OHOS Program<a name="EN-US_TOPIC_0000001174270695"></a>
W
wenjun 已提交
2

N
NEEN 已提交
3
This section describes how to create, compile, burn, and run the first program, and finally print  **Hello OHOS!**  on the develop board.
W
wenjun 已提交
4

M
mamingshuai 已提交
5
## Creating a Program<a name="section204672145202"></a>
W
wenjun 已提交
6

N
NEEN 已提交
7
1.  Create a directory and the program source code.
W
wenjun 已提交
8

N
NEEN 已提交
9
    Create the  **applications/sample/camera/apps/src/helloworld.c**  directory and file whose code is shown in the following example. You can customize the content to be printed. For example, you can change  **OHOS**  to  **World**. You can use either C or C++ to develop a program.
W
wenjun 已提交
10

N
NEEN 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    ```
    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
        printf("\n************************************************\n");
        printf("\n\t\tHello OHOS!\n");
        printf("\n************************************************\n\n");
    
        return 0;
    }
    ```

2.  Create a build file.

    Create the  **applications/sample/camera/apps/BUILD.gn**  file. The file content is as follows:

    ```
    import("//build/lite/config/component/lite_component.gni")
    lite_component("hello-OHOS") {
      features = [ ":helloworld" ]
    }
    executable("helloworld") {
      output_name = "helloworld"
      sources = [ "src/helloworld.c" ]
      include_dirs = []
      defines = []
      cflags_c = []
      ldflags = []
    }
    ```

3.  Add a new component.

    Add the configuration of the  **hello\_world\_app**  component to the  **build/lite/components/applications.json**  file. The sample code below shows some configurations defined in the  **applications.json**  file, and the code between  **\#\#start\#\#**  and  **\#\#end\#\#**  is the new configuration \(Delete the rows where  **\#\#start\#\#**  and  **\#\#end\#\#**  are located after the configurations are added.\)

    ```
    {
      "components": [
        {
          "component": "camera_sample_communication",
          "description": "Communication related samples.",
          "optional": "true",
          "dirs": [
            "applications/sample/camera/communication"
          ],
          "targets": [
            "//applications/sample/camera/communication:sample"
          ],
          "rom": "",
          "ram": "",
          "output": [],
          "adapted_kernel": [ "liteos_a" ],
          "features": [],
          "deps": {
            "components": [],
            "third_party": []
          }
        },
    ##start##
        {
          "component": "hello_world_app",
          "description": "Communication related samples.",
          "optional": "true",
          "dirs": [
            "applications/sample/camera/apps"
          ],
          "targets": [
            "//applications/sample/camera/apps:hello-OHOS"
          ],
          "rom": "",
          "ram": "",
          "output": [],
          "adapted_kernel": [ "liteos_a" ],
          "features": [],
          "deps": {
            "components": [],
            "third_party": []
          }
        },
    ##end##
        {
          "component": "camera_sample_app",
          "description": "Camera related samples.",
          "optional": "true",
          "dirs": [
            "applications/sample/camera/launcher",
            "applications/sample/camera/cameraApp",
            "applications/sample/camera/setting",
            "applications/sample/camera/gallery",
            "applications/sample/camera/media"
          ],
    ```

4.  Modify the board configuration file.

    Add the  **hello\_world\_app**  component to the  **vendor/hisilicon/hispark\_taurus/config.json**  file. The sample code below shows the configurations of the  **applications**  subsystem, and the code between  **\#\#start\#\#**  and  **\#\#end\#\#**  is the new configuration \(Delete the rows where  **\#\#start\#\#**  and  **\#\#end\#\#**  are located after the configurations are added.\)

    ```
          {
            "subsystem": "applications",
            "components": [
              { "component": "camera_sample_app", "features":[] },
              { "component": "camera_sample_ai", "features":[] },
    ##start##
              { "component": "hello_world_app", "features":[] },
    ##end##
              { "component": "camera_screensaver_app", "features":[] }
            ]
          },
    ```
W
wenjun 已提交
122 123


Y
yangni 已提交
124
## Building<a name="section1077671315253"></a>
W
wenjun 已提交
125

D
duangavin123 已提交
126
If the Linux environment is installed using Docker, perform the building by referring to  [Using Docker to Prepare the Build Environment](../get-code/gettools-acquire.md#section107932281315). If the Linux environment is installed using a software package, go to the root directory of the source code and run the following commands for source code compilation:
W
wenjun 已提交
127 128

```
N
NEEN 已提交
129 130 131 132
hb set (Set the building path.)
. (Select the current path.)
Select ipcamera_hispark_taurus@hisilicon and press Enter.
hb build -f (Start building.)
W
wenjun 已提交
133 134
```

D
duangavin123 已提交
135 136
**Figure  1**  Hi3516 settings<a name="fig1458988766"></a>  
![](figures/hi3516-settings.png "hi3516-settings")
N
NEEN 已提交
137 138 139

The result files are generated in the  **out/hispark\_taurus/ipcamera\_hispark\_taurus**  directory.

D
duangavin123 已提交
140
>![](../public_sys-resources/icon-notice.gif) **NOTICE:** 
D
duangavin123 已提交
141
>The U-Boot file of the Hi3516D V300 development board can be obtained from the following path: device/hisilicon/hispark\_taurus/sdk\_liteos/uboot/out/boot/u-boot-hi3516dv300.bin
Y
yangni 已提交
142

M
mamingshuai 已提交
143
## Burning<a name="section1347011412201"></a>
W
wenjun 已提交
144

[
[yang] 已提交
145
The Hi3516 development board allows you to burn flash memory over the USB port, serial port, or network port. The following uses the network port burning as an example.
W
wenjun 已提交
146

D
duangavin123 已提交
147
### Burning Through the Network Port<a name="section1935410617363"></a>
D
duangavin123 已提交
148

D
duangavin123 已提交
149
To burn Hi3516D V300 through the network port in the Windows or Linux environment:
D
duangavin123 已提交
150 151

1.  Connect the PC and the target development board through the serial port, network port, and power port. For details, see  [Introduction to the Hi3516 Development Board](https://device.harmonyos.com/en/docs/start/introduce/oem_minitinier_des_3516-0000001152041033).
N
NEEN 已提交
152
2.  <a name="en-us_topic_0000001056443961_li142386399535"></a>Open Device Manager, then check and record the serial port number corresponding to the development board.
W
wenjun 已提交
153

D
duangavin123 已提交
154
    >![](../public_sys-resources/icon-note.gif) **NOTE:** 
[
[yang] 已提交
155
    >If the serial port number is not displayed correctly, follow the steps described in  [Installing the Serial Port Driver on the Hi3516 or Hi3518 Series Development Boards](https://device.harmonyos.com/en/docs/ide/user-guides/hi3516_hi3518-drivers-0000001050743695).
W
wenjun 已提交
156

D
duangavin123 已提交
157
    ![](figures/hi3516-record-the-serial-port-number.png)
N
NEEN 已提交
158

D
duangavin123 已提交
159
3.  Open DevEco Device Tool, choose  **QUICK ACCESS**  \>  **DevEco Home**  \>  **Projects**, and then click  **Settings**.
N
NEEN 已提交
160

D
duangavin123 已提交
161
    ![](figures/hi3516-deveco-device-tool-setting.png)
N
NEEN 已提交
162

M
mamingshuai 已提交
163
4.  On the  **Partition Configuration**  tab page, modify the settings. In general cases, you can leave the fields at their default settings.
D
duangavin123 已提交
164
5.  On the  **hi3516dv300**  tab page, configure the burning options.
N
NEEN 已提交
165

D
duangavin123 已提交
166
    -   **upload\_port**: Select the serial port number obtained in step  [2](#en-us_topic_0000001056443961_li142386399535).
D
duangavin123 已提交
167 168
    -   **upload\_protocol**: Select the burning protocol  **hiburn-net**.
    -   **upload\_partitions**: Select the file to be burnt. By default, the  **fastboot**,  **kernel**,  **rootfs**, and  **userfs**  files are burnt at the same time.
N
NEEN 已提交
169

D
duangavin123 已提交
170
    ![](figures/hi3516-upload-options.png)
N
NEEN 已提交
171

D
duangavin123 已提交
172 173
6.  <a name="en-us_topic_0000001056443961_li1558813168234"></a>Check and set the IP address of the network adapter connected to the development board. For details, see  [Setting the IP Address of the Network Port for Burning to Hi3516](https://device.harmonyos.com/en/docs/ide/user-guides/set_ipaddress-0000001141825075).
7.  Set the IP address of the network port for burning:
N
NEEN 已提交
174

D
duangavin123 已提交
175 176
    -   **upload\_net\_server\_ip**: Select the IP address set in step  [6](#en-us_topic_0000001056443961_li1558813168234), such as 192.168.1.2.
    -   **upload\_net\_client\_mask**: Set the subnet mask of the development board, such as 255.255.255.0. Once the  **upload\_net\_server\_ip**  field is set, this field will be automatically populated.
D
duangavin123 已提交
177 178
    -   **upload\_net\_client\_gw**: Set the gateway of the development board, such as 192.168.1.1. Once the  **upload\_net\_server\_ip**  field is set, this field will be automatically populated.
    -   **upload\_net\_client\_ip**: Set the IP address of the development board, such as 192.168.1.3. Once the  **upload\_net\_server\_ip**  field is set, this field will be automatically populated.
N
NEEN 已提交
179

D
duangavin123 已提交
180
    ![](figures/ip-address-information.png)
N
NEEN 已提交
181

N
NEEN 已提交
182
8.  When you finish modifying, click  **Save**  in the upper right corner.
D
duangavin123 已提交
183
9.  Open the project file and go to  ![](figures/hi3516-deveco-device-tool-logo.png)  \>  **PROJECT TASKS**  \>  **hi3516dv300**  \>  **Upload**  to start burning.
N
NEEN 已提交
184

D
duangavin123 已提交
185
    ![](figures/hi3516-upload-start-burning.png)
N
NEEN 已提交
186

N
NEEN 已提交
187
10. When the following message is displayed, power off the development board and then power it on.
N
NEEN 已提交
188

D
duangavin123 已提交
189
    ![](figures/hi3516-restart-the-development-board.png)
N
NEEN 已提交
190

D
duangavin123 已提交
191
11. If the following message is displayed, it indicates that the burning is successful.
N
NEEN 已提交
192

D
duangavin123 已提交
193
    ![](figures/hi3516-burning-succeeded-net.png)
N
NEEN 已提交
194

D
duangavin123 已提交
195
12. When the burning is successful, perform the operations in Running an Image to start the system.
W
wenjun 已提交
196

D
duangavin123 已提交
197
### Running an Image<a name="section24721014162010"></a>
W
wenjun 已提交
198

D
duangavin123 已提交
199
After burning is completed, you need to configure the bootloader to run the OpenHarmony system.
D
duangavin123 已提交
200

D
duangavin123 已提交
201
1.  In the Hi3516D V300 task, click  **Configure bootloader \(Boot OS\)**  to configure the bootloader.
D
duangavin123 已提交
202

D
duangavin123 已提交
203 204
    >![](../public_sys-resources/icon-note.gif) **NOTE:** 
    >The bootloader configuration in DevEco Device Tool has been adapted to Hi3516D V300. Therefore, no manual modification is needed.
D
duangavin123 已提交
205

D
duangavin123 已提交
206
    ![](figures/bootloader.png)
D
duangavin123 已提交
207

D
duangavin123 已提交
208
2.  When the message shown below is displayed, restart the development board. If  **SUCCESS**  is displayed, it indicates that the configuration is successful.
D
duangavin123 已提交
209

D
duangavin123 已提交
210
    ![](figures/reset_success.png)
D
duangavin123 已提交
211

D
duangavin123 已提交
212
3.  Click  **Monitor**  on the taskbar to start the serial port tool.
D
duangavin123 已提交
213

D
duangavin123 已提交
214
    ![](figures/monitor.png)
D
duangavin123 已提交
215

D
duangavin123 已提交
216
4.  Follow the onscreen instructions until  **OHOS \#**  is displayed, indicating that the system is started successfully.
D
duangavin123 已提交
217

D
duangavin123 已提交
218
    ![](figures/reboot_success.png)
W
wenjun 已提交
219 220


N
NEEN 已提交
221
## Running a Program<a name="section5276734182615"></a>
W
wenjun 已提交
222

N
NEEN 已提交
223
In the root directory, run the  **./bin/helloworld**  command to operate the demo program. The compilation result is shown in the following example.
W
wenjun 已提交
224

D
duangavin123 已提交
225 226
**Figure  2**  Successful system startup and program execution<a name="fig149821431194515"></a>  
![](figures/successful-system-startup-and-program-execution.png "successful-system-startup-and-program-execution")
W
wenjun 已提交
227