Take a natural course in artificial intelligence, from theory to action, and then click here to enter the portal

Create the HelloWorld project

Open IoT Studio and click Create IoT Studio project:

Note the following points when filling in the project Settings:

  • The project name and directory cannot contain Chinese characters or Spaces
  • SDK version Select the latest IoT_LINK version, the current latest 1.0.0
  • Hardware Platform SelectionSTM32L431RC_BearPi
  • Sample project selectionhello_world_demo

After creation, enter the IoT Studio interface as shown in the following figure:

2. IoT_LINK SDK

When creating the project, the SDK version is selected, as shown below:

Huawei IoT link SDK

The Huawei IoT Link SDK (SDK for short) is a lightweight interconnection middleware deployed on terminals that have WAN capabilities and strict limits on power consumption, storage, and computing resources. You can quickly connect devices to the Internet of Things platform, report data, and receive commands by invoking API interfaces.

SDK provides end-cloud collaboration capability, integrates MQTT, LwM2M, CoAP, MBEDTLS and LwIP full set of IoT interconnection protocol stacks, and provides open API on the basis of these protocol stacks. Users only need to pay attention to their own applications without paying attention to internal implementation details of protocols. Using the API encapsulated by the SDK, you can quickly and securely connect to huawei OceanConnect cloud platform by following four steps: connection, data reporting, command receiving, and disconnection. Using the SDK, users can greatly reduce the development cycle, focus on their own business development, and quickly build their own products.

Relationship between SDK and LiteOS

The Huawei IoT Link SDK has an OS adaptation layer that can be adapted to Linux, MacOS, LiteOS, and other third-party oss (self-adaptation is required). The SDK used in this tutorial ADAPTS to LiteOS.

Relationship between SDK and IoT Studio

For the convenience of user development, the SDK code does not appear in IoT Studio, only the user’s target project code (IoT Studio), but the SDK code is compiled into the project at compile time.

So, where is the code for the SDK? How do I view the SDK code?

The SDK code is in C:\Users\Administrator\.icode\ SDK \ iot_link_1.0.0, where Administrator is my user name, in reality would be your current user name, SDK code is more, Therefore, VS Code is recommended to directly open the iot_link_1.0.0 folder to view.

How to update the SDK

The SDK is constantly updated. In the IoT Studio project, go to “File -> Preferences” and choose “SDK Management”. If a new version is detected, the status will change to “Updatable”.

Every time you open the project, you need to check whether the SDK has been updated. The latest update is 2019-11-28(today). In addition, after updating the SDK, you need to create the project again to refresh the configuration.

3. HelloWorld Demo

HelloWorld example code in the Demos/hello_world_demo/hello_world_demo.c file, the example code creates a task named HelloWorld, priority 2, which prints data at serial port every 4s, The code is as follows:

#include <osal.h>

static int app_hello_world_entry(a)
{
    while (1)
    {
        printf("Hello World! This is LiteOS! \r\n");
        osal_task_sleep(4*1000); }}int standard_app_demo_main(a)
{
    osal_task_create("helloworld",app_hello_world_entry,NULL.0x400.NULL.2);
    return 0;
}
Copy the code

4. Compile

IoT Studio uses the ARM-None-eabi-gcc tool chain for compilation, builds builds with the make tool, and leaves some options in the makefile for the user to configure with the *.mk file.

Set the compiler and make tool paths

Remember the developer tool path you viewed when installing IoT Studio in the previous article? Yes, next we need to configure these two paths:

  • arm-none-eabi-Compiler path

The path to the compiler is: C:\Users\Administrator\openSourceTools\GNU Tools Arm Embedded\7 2018-q2-update\bin

In IoT Studio, go to Project -> Project Configuration, select Compiler, and configure the compiler path:

  • makeBuilder path

C:\Users\Administrator\openSourceTools\GNU MCU Eclipse\Build Tools\2.11-20180428-1604\bin, Administrator is my user name. You can change it to your user name.

In IoT Studio, go to Project -> Project Configuration, select Compiler, and configure the make path:

Set the makefile for the project

The makefile for the entire project is in the GCC directory. Make sure to specify the makefile in IoT Studio before compiling:

Compile the project

After specifying the Makefile, click the Compile buttonTo compile the entire project, all the compiled output is printed on the console:

Ignore the warnings in the SDK so far and click compile again.

5. Burn

IoT Studio supports the use of Jlink or ST-Link download program, Bear development board ST-Link download, and is stlink-V2.1 version, so use OpenOCD through ST-Link download, download Settings as shown in the figure:

The st-link-v2. CFG and ST-link-v2-1. CFG parameters in OpenOCD are different.

After setting up, connect the Bear development board to the PC and click the Download buttonThe console will print out the download information:

After burning, the development board automatically reset and the program started to run. You can see the following words on the LCD screen:

Welcome to IoTCluB!
BearPi IoT Develop Board
Powerd by Huawei LiteOS!
Please wait for system init!
Copy the code

6. View the serial port output

IoT Studio integrates a serial port terminal, which makes it easy to view serial port output information.

Set up the serial port before using:

Connect the Bear development board and make sure the serial port selector switch in the upper right corner of the Bear development board is switched to one end of the AT-MCU.

Then click the view button, select serial terminal:

The serial terminal interface will be displayed on the console. Click the button to open the serial port, and you can see the output of Demo program in the serial port as shown in the figure below:

This article was first published on the public account “McUlover666”. During the course of this tutorial, you can log on to the Huawei Cloud Forum xiaoxiong Pai section to post and communicate!