Abstract: Everyone has to prepare a development board and emulator when learning the development of Internet of Things operating system, which is also a large investment. The LiteOS community is now open to the public to adapt the Qemu simulator. Without using the development board, you can also build the LiteOS development environment, which is very convenient for beginners to learn at zero cost.

Qemu profile

Qemu is a set of gPL-licensed analog processors written by FabriceBellard and widely used on the GNU/Linux platform, as well as X86 environments. An introduction to Qemu can be found on its Github community. LiteOS Stduio uses the Qemu RealView-PBX-A9 development board to simulate running the LiteOS open source project. This article mainly introduces LiteOS running on Qemu under Windows.

Install Qemu

Install Qemu on Windows. Qemu-w64-setup-20201124.exe is installed by default. The diagram below:

LiteOS Studio installation

HUAWEI LiteOS Studio is a lightweight customized integrated development environment solution developed based on the open source Code of the Visual Studio Code community and based on the characteristics of LiteOS embedded system software development language and business scenarios. For developers familiar with Visual Studio Code, it is very easy to get started.

Visit the LiteOS Studio website to download the LiteOS Studio installation software. The installation process is very simple. After the installation is complete, set up the Windows development environment by referring to the documents on the official website

(Figure below).

Note When creating a project, the Git client tool is required. Ensure that the Git for Windows tool has been installed locally and environment variables have been added.

New Qemu simulation project

Click the new project icon to open the New project interface. When using LiteOS Studio for new projects, make sure your network is up and running. Visit the LiteOS open Source community site at gitee.com/LiteOS/Lite…

  • Project name: Enter a customized project name
  • Project directory: Enter or select the project storage path
  • SDK version number: select Giee-LiteOS-Master
  • Development board list: Select qemureakView-PBX-A9 development board

Click OK, the background will download and save the SDK of the selected target board, and open the new project automatically after downloading.

Compile Qemu simulation project

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

After compiling, open the project Settings, and in the Burner and Debugger Settings, set the bin file to burn and the ELF executable file to debug, as shown below: Burner configuration:

Debugger configuration:

In addition to burners and debuggers, LiteOS Studio project Settings also allow you to set up development boards, compilers, component management, serial ports, etc. You can view the corresponding Settings by yourself. Use the default Settings for this article. After setting, click confirm Comfirm to save.

Run Qemu simulation project

For the real board, you need to burn the mirror bin or HEX file to the board to run. The advantage of using a Qemu emulator is that there is no need to actually burn, just start Qemu and pass in the image parameters. We reuse the burning function, click the icon on the toolbar to burn, and start the Qemu simulator to run the compiled LiteOS project.

The following screenshot shows the successful operation:

By default, after the startup information is output, the shell mode is entered. You can enter task to view information about running tasks. For more LiteOS shell commands, see gitee.com/LiteOS/Lite… . The following is an example of the Shell command output:

To exit Qemu, press Ctrl + A in the Terminal window and then press X to exit.

Configure the 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 Engineering Settings – Component Management. Here is how to start Kernel Demo to run on the Qemu emulator.

The Kernel Task Demo code execution entry 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;Copy the code

}

The sample code creates two tasks in sequence, one named HIGH_NAME and one named LOW_NAME. In two tasks, we demonstrate the use of task-related interfaces LOS_TaskSuspend, LOS_TaskResume, LOS_TaskDelay, and LOS_TaskDelete. A more complete example can be found at gitee.com/LiteOS/Lite… Once you know the Demo code, recompile it. After compiling successfully, click the burn button to run, you can see the following output:

After seeing the effect of the actual operation, I suggest readers to read the relevant Demo code, including task, memory management, interrupt, IPC communication, time management, two-way linked list, task synchronization and so on. Please refer to: gitee.com/LiteOS/Lite…

Commissioning Qemu simulation project

HUAWEI LiteOS Studio commissioning is very easy to use. Click the commissioning button on the toolbar to start GDB graphical commissioning. For our Qemu project, the interface after commissioning is as follows:

Describe the areas on the interface:

  • Variable Variable

Displays values for local, global, and static variables.

  • Monitor the Watch

Monitor the specified expression, you can enter a variable name or expression, real-time calculation results.

  • Call Stack

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

  • Breakpoint Breakpoints

Shows breakpoints set.

  • Registers Registers

View the value of each register, support to copy the value operation.

  • Source code window

Highlight the source code line that is currently executing.

  • Disassembly window

Disassembly code corresponding to the current source file line.

  • Output the Output

Displays the GDB client output logs.

  • Debugging Console Debug Console

The GDB Server output logs are displayed. Readers can keep trying, continue, step, jump, test, stop, and so on. For more details on commissioning, see Debugger debug.

This article demonstrates how to prepare a LiteOS Studio environment, how to create a Qemu project, how to compile and burn, how to configure Kernel Demo components, and how to debug GDB. The LiteOS Studio tool is also easy to use and perfect for learning about iot development. Especially for beginners, there is no need to buy a development board, that is, you can learn and experience LiteOS iot OS development. Through learning Kernel Demo provided by LiteOS open source community and practical hands-on practice, we will have a deeper understanding of the Kernel of LiteOS operating system.

Attached information:

Liteos.giee.io/LiteOS_stud…

LieOS open source: gitee.com/liteos

Qemu introduction: github.com/qemu/qemu

QEMU Binaries for Windows (64-bit) download: qemu.weilnetz.de/w64/

Linux environments running LiteOS based on Qemu can be found at gitee.com/LiteOS/Lite…

Click to follow, the first time to learn about Huawei cloud fresh technology ~