Zero cost learning of liteos IOT operating system based on liteos studio

Time:2021-8-24

Summary:When learning the development of Internet of things operating system, everyone has to prepare a set of development board and simulator, which is also a large investment. The liteos community has now opened the adaptation project of QEMU simulator to the outside world. Without using the development board, the liteos development environment can also be built to achieve zero cost, which is very convenient for beginners to learn.

Introduction to QEMU

QEMU is a GPL licensed analog processor written by fabricebellard. It is widely used on GNU / Linux platform and also supports running on X86 environment. For the introduction of QEMU, please refer to its GitHub community content. Liteos stduio uses the QEMU realview-pbx-a9 development board to simulate and run the liteos open source project. This paper mainly introduces running liteos based on QEMU under windows.

Installing QEMU

Install QEMU on windows. Download qemu-w64-setup-20201124.exe, which can be installed by default and will not be repeated. As shown below:

Zero cost learning of liteos IOT operating system based on liteos studio

Liteos studio installation

Huawei liteos studio is a lightweight customized integrated development environment solution based on the open source code of visual studio code community and according to the characteristics of liteos embedded system software development language and business scenarios. It is very easy for developers familiar with visual studio code.

Visit the official website of liteos studio and download the installation software of liteos studio. The installation process is very simple. You can directly see the information on the official website without repeating. After installation, you need to refer to the official website documents to build a Windows development environment

(as shown below).

Zero cost learning of liteos IOT operating system based on liteos studio

Note that git client tool is required when creating a new project. Please ensure that git for windows tool is installed locally and add environment variables.

New QEMU simulation project

Click the new project icon to open the new project interface. When using liteos studio to create a new project, ensure that the network is unblocked and you can access the liteos open source community sitehttps://gitee.com/LiteOS/LiteOS

  • Project Name: fill in the user-defined project name
  • Project directory: fill in or select the project storage path
  • SDK version number: select gitee liteos master
  • Development board list: select qemreakview-pbx-a9 development board

Click OK, the SDK of the selected target board will be downloaded and saved in the background, and the new project will be opened automatically after downloading.

Zero cost learning of liteos IOT operating system based on liteos studio

Compiling QEMU simulation project

Click the compile icon on the toolbar to start compiling. After the compilation is successful, the following information is output on the console:

Zero cost learning of liteos IOT operating system based on liteos studio

After compilation, open the project settings. In the settings of burner and debugger, set the bin file to be burned and ELF executable file to be used for debugging respectively, as shown in the following figure:
Burner configuration:

Zero cost learning of liteos IOT operating system based on liteos studio

Debugger configuration:

Zero cost learning of liteos IOT operating system based on liteos studio

In addition to the burner and debugger, liteos studio project settings also support the setting of development board, compiler, component management, serial port, etc. you can view the corresponding settings by yourself. This article can use the default settings. After setting, click confirm comfirm to save.

Run QEMU simulation project

For a real development board, you need to burn the image bin or hex file to the development board before it can run. The advantage of using QEMU simulator is that there is no need for real burning. Start QEMU and pass in the image parameter. We reuse the burning function, click the icon on the toolbar to burn, start the QEMU simulator and run the compiled liteos project.

The screenshot of successful operation is as follows:

Zero cost learning of liteos IOT operating system based on liteos studio

In the default configuration, after outputting the startup information, we enter the shell mode. We can enter task to view the information of running tasks. For more liteos shell commands, refer tohttps://gitee.com/LiteOS/Lite…。 An example of shell command output is as follows:

Zero cost learning of liteos IOT operating system based on liteos studio

If you want to exit QEMU operation, press Ctrl + A in the terminal terminal window at the same time, and then press X to exit.

Configure QEMU simulation project and run kernel demo

Liteos is a highly configurable system. In addition to the default settings, we can customize the system component configuration in project settings – component management. Here is a demonstration of how to start the kernel demo and run it on the QEMU simulator.

Zero cost learning of liteos IOT operating system based on liteos studio

The kernel task demo code execution entry opened is as follows:

UINT32 Example_TskCaseEntry(VOID)
{

UINT32 ret;
TSK_INIT_PARAM_S stInitParam; /* lock task shcedue */ printf("nKernel task demo begin.n");
LOS_TaskLock();

printf("LOS_TaskLock() ok.n");

stInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_TaskHi;
stInitParam.usTaskPrio = TSK_PRIOR_HI;
stInitParam.pcName = "HIGH_NAME";
stInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; /* create high prio task */ ret = LOS_TaskCreate(&g_demoTaskHiId, &stInitParam); if (ret != LOS_OK) {
    LOS_TaskUnlock();

    printf("Example_TaskHi failed.n"); return LOS_NOK;
}

printf("Create Example_TaskHi ok.n");

stInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_TaskLo;
stInitParam.usTaskPrio = TSK_PRIOR_LO;
stInitParam.pcName = "LOW_NAME";
stInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; /* create low prio task */ ret = LOS_TaskCreate(&g_demoTaskLoId, &stInitParam); if (ret != LOS_OK) { /* delete high prio task */
    if (LOS_OK != LOS_TaskDelete(g_demoTaskHiId)) {
        printf("Delete TaskHi failed.n");
    }

    LOS_TaskUnlock();

    printf("Create Example_TaskLo failed.n"); return LOS_NOK;
}

printf("Create Example_TaskLo ok.n"); /* unlock task schedue */ LOS_TaskUnlock();
LOS_TaskDelay(40); return ret;

}

The sample code successively creates two tasks, one named high_ Name, one named low_ NAME。 In the two tasks, the task related interface LOS is demonstrated_ TaskSuspend、LOS_ TaskResume、LOS_ TaskDelay、LOS_ Use of taskdelete. For a more complete example, visithttps://gitee.com/LiteOS/Lite…
Once you know the demo code, recompile it. After the compilation is successful, click the burn button to run, and you can see the following output:

Zero cost learning of liteos IOT operating system based on liteos studio

After seeing the actual operation effect, readers are advised to read the relevant demo code, including task, memory management, interrupt, IPC communication, time management, two-way linked list, task synchronization, etc. Please refer to:https://gitee.com/LiteOS/Lite…

Commissioning QEMU simulation project

Huawei liteos studio debugging is very simple and easy to use. Click the debugging button on the toolbar to start GDB graphical debugging. For our QEMU project, the interface after commissioning is as follows:

Zero cost learning of liteos IOT operating system based on liteos studio

Introduce the areas on the interface as follows:

  • Variable variable

Display the values of local variables, global variables and static variables.

  • Monitor Watch

Monitor the specified expression. You can enter the variable name or expression to calculate the result in real time.

  • Call stack

Show the task call stack in the current running state and suspended state.

  • Breakpoints breakpoints

Show the set breakpoints.

  • Registers

View the values of each register and support the operation of copying values.

  • Source code window

Highlight the currently executing source line.

  • Disassembly window

The disassembly code corresponding to the line of the current source code file.

  • Output output

Displays the output log of the GDB client.

  • Debug console

Display the output log of GDB server.
Readers can continue to try, continue, single step, jump in, test, stop and other test actions. For a more detailed introduction to commissioning, please refer to  — Debugger – performs debugging.

This article demonstrates how to prepare the liteos studio environment, how to create a QEMU project, how to compile and burn, how to configure the kernel demo component, and how to debug GDB.
Liteos studio tool is easy to use and is very suitable for learning the development of the Internet of things. Especially for beginners, they can learn and experience the development of liteos Internet of things operating system without buying a development board. Through the study and practical practice of the kernel demo provided by the liteos open source community, you will have a deeper understanding of the liteos operating system kernel.

Attached data:

Liteos studio community materials:https://liteos.gitee.io/liteo…

Lieos open source code:https://gitee.com/liteos

QEMU introduction:https://github.com/qemu/qemu

QEMU binaries for windows (64 bit) Download:https://qemu.weilnetz.de/w64/

Linux environment runs liteos based on QEMU. Please refer to:https://gitee.com/LiteOS/Lite…

Click focus to learn about Huawei cloud’s new technologies for the first time~